shannonmoeller / gulp-hb

A sane Gulp plugin to compile Handlebars templates. Useful as a static site generator.
http://npm.im/gulp-hb
MIT License
147 stars 14 forks source link

Not pulling in partials or data (when path contains a space) #42

Closed WolfieZero closed 8 years ago

WolfieZero commented 8 years ago

I have the following gulp task setup.

gulpfile.js

gulp.task('html', function() {

    return gulp.src('./src/html/*.{hbs,html}')
        .pipe(hb({
            data: [
                './src/html/data/*.json'
            ],
            partials: [
                './src/html/partials/*.{hbs,html}'
            ]
        }))
        .pipe(gulp.dest('./dist'));

});

src/html/data/var.json

{
    "title": "Test boom!"
}

src/html/data-test.html

{{ title }}
{{ var.title }}
{{ @var.title }}

src/html/partial-test.html

{{> boom }}
{{> show message="boom boom" }}

src/html/partials/boom.hbs

hi

src/html/partials/show.hbs

{{ message }}

With the data, the file returns empty and the partials returns this error.

events.js:141
      throw er; // Unhandled 'error' event
      ^
Error: The partial boom could not be found
    at Object.invokePartial (/Users/neil/Dropbox (Personal)/Code/email-builder/node_modules/handlebars/dist/cjs/handlebars/runtime.js:266:11)
    at Object.invokePartialWrapper [as invokePartial] (/Users/neil/Dropbox (Personal)/Code/email-builder/node_modules/handlebars/dist/cjs/handlebars/runtime.js:68:39)
    at Object.eval (eval at createFunctionContext (/Users/neil/Dropbox (Personal)/Code/email-builder/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:254:23), <anonymous>:8:28)
    at main (/Users/neil/Dropbox (Personal)/Code/email-builder/node_modules/handlebars/dist/cjs/handlebars/runtime.js:173:32)
    at ret (/Users/neil/Dropbox (Personal)/Code/email-builder/node_modules/handlebars/dist/cjs/handlebars/runtime.js:176:12)
    at ret (/Users/neil/Dropbox (Personal)/Code/email-builder/node_modules/handlebars/dist/cjs/handlebars/compiler/compiler.js:525:21)
    at /Users/neil/Dropbox (Personal)/Code/email-builder/node_modules/handlebars-wax/src/handlebars-wax.js:202:10
    at DestroyableTransform._transform (/Users/neil/Dropbox (Personal)/Code/email-builder/node_modules/gulp-hb/src/gulp-hb.js:94:31)
    at DestroyableTransform.Transform._read (/Users/neil/Dropbox (Personal)/Code/email-builder/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:159:10)
    at DestroyableTransform.Transform._write (/Users/neil/Dropbox (Personal)/Code/email-builder/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:147:83)

Really confused what I'm doing wrong 😕

Thanks.

shannonmoeller commented 8 years ago

I don't see anything obviously wrong. Can you add the debug flag to the options you pass into hb() and post the output?

...
.pipe(hb({
    debug: true,
    data: [
...
WolfieZero commented 8 years ago

Heh, looks like it's due to there being a space in one of the folders leading up to the project folder. Just ran it again and the contexts where correct. Thanks for the tip on the debug setting.

I don't normally have spaces in folders but on this particular machine Dropbox made it so.

Before

 data-test.html
    context:
      Dropbox (Personal)
    data:

    decorators:
      inline
    helpers:
      blockHelperMissing  helperMissing       log                 unless
      each                if                  lookup              with
    partials:
      Dropbox-(Personal)/Code/email-builder/src/html/partials/boom  Dropbox-(Personal)/Code/email-builder/src/html/partials/show

  partial-test.html
    context:
      Dropbox (Personal)
    data:

    decorators:
      inline
    helpers:
      blockHelperMissing  helperMissing       log                 unless
      each                if                  lookup              with
    partials:
      Dropbox-(Personal)/Code/email-builder/src/html/partials/boom  Dropbox-(Personal)/Code/email-builder/src/html/partials/show

After

  data-test.html
    context:
      var
    data:

    decorators:
      inline
    helpers:
      blockHelperMissing  helperMissing       log                 unless
      each                if                  lookup              with
    partials:
      boom  show

  partial-test.html
    context:
      var
    data:

    decorators:
      inline
    helpers:
      blockHelperMissing  helperMissing       log                 unless
      each                if                  lookup              with
    partials:
      boom  show
shannonmoeller commented 8 years ago

Thanks for the output. Looks like I'll need to update the path handling to account for that.

Glad you got a workaround!

Edit: Changed title of issue to reflect actual bug.

WolfieZero commented 8 years ago

👍 Awesome, thanks for the help!

shannonmoeller commented 8 years ago

@WolfieZero I just released 5.1.2 with some path fixes to another issue. I'm curious if those fixes address this issue as well. Any chance you're still working on this and able to test it?

ry5n commented 8 years ago

I just happened to run into this same issue today. Same thing, project in Dropbox. (Update: I’m using 5.1.2, so recent changes don’t seem to resolve this across the board.)

I think it might be an issue upstream in handlebars-wax, specifically the keygenPartial function.

It’s handy that this can be passed in as an option (both to handlebars-wax and to grunt-hb). I passed in following, which seems to work.

var fs = require('fs');
var path = require('path');

function parsePartialName(options, file) {
  var realPath = fs.realpathSync(file.path);
  return path.basename(realPath, path.extname(realPath));
}
shannonmoeller commented 8 years ago

Thanks, @ry5n! I'll setup a test case in handlebars-wax and update this project when that's been updated.

shannonmoeller commented 8 years ago

Found the bug was one layer deeper in require-glob. The issue wasn't spaces, but parentheses that caused a glob mismatch. Patch coming soon.

shannonmoeller commented 8 years ago

Released 5.1.4 which resolves this issue.

ry5n commented 8 years ago

Updated to 5.1.4; working like a charm. Thanks!