patrickkettner / grunt-compile-handlebars

grunt plugin to compile static html from a handlebars plugin
MIT License
115 stars 29 forks source link

Globbing patters do not work properly in array foramt #21

Closed jasonlav closed 10 years ago

jasonlav commented 10 years ago

"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/*).

patrickkettner commented 10 years ago

Those values are just sent to grunt.file.expand, so that shouldn't be a problem. What error are you hitting specifically?

jasonlav commented 10 years ago

No specific error, however, it simply does not write the files.

patrickkettner commented 10 years ago

@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

jasonlav commented 10 years ago

@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?

patrickkettner commented 10 years ago

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!

jasonlav commented 10 years ago

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']
patrickkettner commented 10 years ago

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

jasonlav commented 10 years ago

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...

patrickkettner commented 10 years ago

beautiful, I see the problem now. Thank you so much for sticking with me

patrickkettner commented 10 years ago

I believe this is fixed in 0.7.6 - could you check it out?

jasonlav commented 10 years ago

Quick turn around!

I checked it out, it does fix that specific issue, however, I ran into another issue:

screen shot 2014-07-15 at 3 53 34 pm

Notice how about/about.handlebars is outputting to /about.html? I'm using the same Gruntfile.js as above. Thanks!

patrickkettner commented 10 years ago

Hey @jasonlav - to be clear, you are expecting it to output to about/about.html, right?

jasonlav commented 10 years ago

Correct.

Instead, it outputs "*/.html".

EDIT: Ignore the part about it outputting to */.html...

patrickkettner commented 10 years ago

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

jasonlav commented 10 years ago

Awesome. I appreciate your time and patience on this. It is a very useful Grunt plugin and I use it frequently.

patrickkettner commented 10 years ago

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: https://github.com/patrickkettner/grunt-compile-handlebars/issues/21#issuecomment-50824697