Globbing patters do not work properly in array foramt
jasonlav opened this issue · 16 comments
"template" and "output" variables do not work according to globbing patters (http://gruntjs.com/configuring-tasks#globbing-patterns).
Works
target: {
template: 'src/**/*.handlebars',
templateData: {},
output: 'src/**/*.html'
}
Does not work
target: {
template: ['src/**/*.handlebars'],
templateData: {},
output: ['src/**/*.html']
}
Does grunt-compile-handlebars not support standard file format (http://gruntjs.com/configuring-tasks#building-the-files-object-dynamically)?
The specific limitation I am running into is ignoring a specific folder (in this case src/partials/*).
Those values are just sent to grunt.file.expand
, so that shouldn't be a problem. What error are you hitting specifically?
No specific error, however, it simply does not write the files.
@jasonlav could you gimme a zip file containing a project showing the issue? I am not able to replicate the problem , but would love to fix it for you
@patrickkettner see the example below.
Works as expected:
dev: {
template: 'src//*.handlebars',
output: 'dev//*/html'
}
Does not work as expected:
dev: {
template: ['src//.handlebars', '!src/about/.handlebars'],
output: ['dev//*.html']
},
Is this operator error? Is there a way to define the selection of files more precisely?
Ok, few things that are confusing me.
Given the following folder structure
.
└── src
├── about
│ ├── bloop.html
│ └── what.handlebars
├── bar.handlebars
├── foo.handlebars
└── test.txt
src//*.handlebars
will only return files in the src
directory, in this case /src/bar.handlebars
and /src/foo.handlebars
. directory, if you want all handlebars files under src
, you would actually want to be using src/**/*.handlebars
['src//.handlebars', '!src/about/.handlebars']
isn't globbing anything at all, it is saying load the file src/.handlebars
literally (ie the file names .handlebars
, and don't load src/about/.handlebars
(which it wouldn't be doing anyway already).
Unless I am completely mistaken, you are wanting to use
['src/**/*.handlebars', '!src/about/*.handlebars']
Could you let me know if I am confused, or missed the point?
thanks!
Sorry, my explanation of the issue was not as precise as it could of been.
You are correct. Your last example is what I am attempting to accomplish. I had a far more complex "real-world" scenario that I improperly, overly simplified. But the essence of the issue is the snippet below:
['src/**/*.handlebars', '!src/about/*.handlebars']
that snippet works for me - is it not for you? I understand that your actual use case is more complicated, and I would love to get it fixed as quickly as possible, but I have yet to actually see the issue
Here is an example of the issue I am running across. All files exist in the same folder...
package.json
{
"name": "my-project-name",
"version": "0.1.0",
"devDependencies": {
"grunt": "^0.4.5",
"grunt-compile-handlebars": "^0.7.5"
}
}
Gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
'compile-handlebars': {
default: {
template: ['**/*.handlebars', '!node_modules/**'],
templateData: {},
output: '**/*.html'
}
}
});
//Plugins
grunt.loadNpmTasks('grunt-compile-handlebars');
//Tasks
grunt.registerTask('default', ['compile-handlebars']);
};
index.handlebars (content doesn't really matter for this example...)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Index</title>
</head>
<body>
</body>
</html>
When I run Grunt, it works, but does not properly create index.handlebars. It creates a "*/.html" file. Let me know if you need any more details...
beautiful, I see the problem now. Thank you so much for sticking with me
I believe this is fixed in 0.7.6 - could you check it out?
Hey @jasonlav - to be clear, you are expecting it to output to about/about.html, right?
Correct.
Instead, it outputs "*/.html".
EDIT: Ignore the part about it outputting to */.html...
Sorry for taking so long on the last update, but I had to spend a long think on this one. Basically, my thoughts are spelled out in the README as of 0.7.8
outputInInput
- most of the time, you define your handlebars files in one directory, and want them to be outputted into another directory. However, when you glob your all your files (./*/.handlebars) this just outputs all your files to your root directory. In this case, you can add the boolean outputInInput to the configuration, which will output the globbed html into the same folders that the handlebar files are found. e.g, given the following configuraiton
gottaGlobEmAll: {
template: ".//*.handlebars",
templateData: {},
output: ".//*.html"
}
./foo/bar.handlebars would output to ./bar.html. By adding outputInInput: true to the configuration, it will output to ./foo/bar.html
Basically... there isn't really a way to do what you expected and not break everything else.
That being said, just set outputInInput to true
, and you should get what you are looking for
Awesome. I appreciate your time and patience on this. It is a very useful Grunt plugin and I use it frequently.
Yay! Internet high five!
On Thu, Jul 31, 2014 at 8:27 PM, jasonlav notifications@github.com
wrote:
Awesome. I appreciate your time and patience on this. It is a very useful Grunt plugin and I use it frequently.
Reply to this email directly or view it on GitHub:
#21 (comment)