Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

globalJsonGlobbedTemplate templateData path fix #63

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

mikemellor11
Copy link

#60 Fixed this issue regarding the templateData path, now does an iteration over all the globbed files and matches the right json to the right hbs and returns the result. Beforehand it was simply changing the extension from hbs to json meaning the hbs src was being used instead of the templateData path

@mikemellor11
Copy link
Author

It might also be worth mentioning in the readme that when using paths this way the folder structure for the json must match the folder structure for the hbs

Like so:

`- hbsFolder
`   - 1.hbs
    - 2.hbs
    - deepFolder
        -3.hbs

-jsonFolder
`   - 1.json
    - 2.json
    - deepFolder
        -3.json

@patrickkettner
Copy link
Owner

hey @mikemellor11!
Thanks so much for this

It might also be worth mentioning in the readme that when using paths this way the folder structure for the json must match the folder structure for the hbs

I actually don't want that to be the case. I would want to change the implementation rather than change hte readme, because that should not be the case

@mikemellor11
Copy link
Author

I figured it was the best of the three options i could think of:

Option A - folder structure matches

`- hbsFolder
`   - 1.hbs
    - 2.hbs
    - deepFolder
        -3.hbs
        -4.hbs

-jsonFolder
`   - 1.json
    - 2.json
    - deepFolder
        -3.json
        -4.json

Option B - single folder (no nesting)

`- hbsFolder
`   - 1.hbs
    - 2.hbs
    - deepFolder
        - 3.hbs
        - 4.hbs

-jsonFolder
    - 1.json
    - 2.json
    - 3.json
    - 4.json

Option C - mixture, structure has no relationship with matching

`- hbsFolder
`   - 1.hbs
    - 2.hbs
    - 3.hbs
    - deepFolder
        -4.hbs

-jsonFolder
`   - 1.json
    - 2.json
    - deepFolder
        - 2.json
        - 3.json
        - 4.json

Option A means you have to match your folder structure hbs and json like i said, but really if your nesting your hbs for a reason then you'll probably want to do the same with your json.

Option B means you can't have two json files with the same name also not being able to have folders might be a downside for some people.

Option C means that if you do have two json files with the same name it would always use the first one it found which might cause bugs in peoples projects.

I strongly! believe option A is the best solution here and its the current way people would interpret the behaviour as working.

@kdamken
Copy link

kdamken commented Feb 18, 2016

Thanks for figuring out this issue @mikemellor11 , it was driving me nuts trying to figure out why it wasn't working correctly. Looking forward to seeing it merged.

@mikemellor11
Copy link
Author

bump, @patrickkettner any danger of this getting pulled in? I'd like to fix the issue #65 also when this ones sorted as it makes my console really bloated in certain projects and i've been meaning to fix it for a while.

Thanks Mike

@mikemellor11
Copy link
Author

mikemellor11 commented May 19, 2016

Maybe i was unclear in my explanation of the readme edit, this pull request won't effect the readme as it is, you can leave it the same. However in it's current state the readme gives an impression that the plugin has functionality which it doesn't as seen in these issues - #60 #62 . This line of the readme -

globbedTemplateAndOutput: {
    files: [{
        expand: true,
        cwd: 'test/fixtures/',
        src: 'deep/**/*.handlebars',
        dest: 'tmp/',
        ext: '.html'
    }],
    templateData: 'test/fixtures/deep/**/*.json',
    helpers: 'test/helpers/**/*.js',
    partials: 'test/fixtures/deep/shared/**/*.handlebars'
  }

Gives the impression the the templateData path can be set to something other than the same path that the plugin is looking for the handlebars files. In reality this currently isn't the case, you could set the grunt config to the following and it will make no difference:

globbedTemplateAndOutput: {
    files: [{
        expand: true,
        cwd: 'test/fixtures/',
        src: 'deep/**/*.handlebars',
        dest: 'tmp/',
        ext: '.html'
    }],
    templateData: '',
    helpers: 'test/helpers/**/*.js',
    partials: 'test/fixtures/deep/shared/**/*.handlebars'
  }

The reason is it doesn't currently use the templateData at all it simply uses the handlebars path and changes the extension from hbs to json. My pull request simply allows you to specify a different path (or you can use the same path as before) and it will look in that location instead making the readme correct and the plugin to work as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants