shannonmoeller / handlebars-wax

The missing Handlebars API for data, partials, helpers, and decorators.
http://npm.im/handlebars-wax
MIT License
40 stars 9 forks source link

Globbing #11

Closed ethikz closed 7 years ago

ethikz commented 7 years ago

So I've been reading trying to find an answer which led me to here from gulp-hb.

Issue I'm having is trying to extract path from component name. I am using parsePartialName like so

module.exports = function(gulp, cb) {
  return gulp.src(paths.html)
    .pipe(hb()
      .partials('./app/components/**/*.{hbs, js}', {
        base: path.join(__dirname, '../app/components'),
        parsePartialName: function(options, file) {
          return file.path
        }
      })
      .helpers('./helpers/*.js')
    )
    .pipe(rename({
      extname: '.html'
    }))
    .pipe(gulp.dest('./build'))
    .pipe(plugin.connect.reload())
    .on('error', plugin.util.log);
};

The issue I'm running into is I want to be able to include all sub-folders as well. Doing the above way I still have to type the folder in components folder.

{{> button/button
    classes="button__primary"
}}

It would be better if I could glob the directory and just use

{{> button
    classes="button__primary"
}}

Is that possible or is it an issue with conflicts. If I have 2 different button directories I need to specify which one I'm going to use so the parser will know?

shannonmoeller commented 7 years ago

You mention that you're using parsePartialName, but I don't see it in the example you provided.

ethikz commented 7 years ago

You're right! Sorry about that. I corrected the original comment to include it.

shannonmoeller commented 7 years ago

Cool. You're on the right track. Right now you're returning the full path as the partial name, when all you want is the basename. You can see the partial names your code generates by including the debug: true flag to the hb config:

    .pipe(hb({ debug: true })

You'll want to update your parsePartialName method to only return the basename without extension:

const path = require('path');

// ...

      .partials('./app/components/**/*.{hbs,js}', {
        parsePartialName: function(options, file) {
          return path.parse(file.path).name;
        }
      })
ethikz commented 7 years ago

Ahh thanks! That was it! Thanks for your help