shannonmoeller / gulp-hb

A sane Gulp plugin to compile Handlebars templates. Useful as a static site generator.

Home Page:http://npm.im/gulp-hb

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ignore partials

MickL opened this issue · comments

I have one folder containing everything mixed(views and partials) and i don't want the partials to be compiled. But gulp-hb is compiling every file.

At gulp-compile-handlebars there is an option ignorePartials: true which does exactly this. Does gulp-hb has something similiar?

e.g.

  • index.hbs
    • layout/base.hbs
    • partials/slider.hbs

But they are totally mixed so it would not be an option to exclude certain directories.

gulp-hb assumes that you're providing globs to exactly match the files you want compiled or included as partials. I'd recommend splitting up your files into separate directories, or possibly using a different extension. Perhaps .html for pages and .hbs for partials.

I'm not familiar with how gulp-compile-handlebars's ignorePartials flag works, but it almost looks like it just suppresses the missing partial warning.

The two provided solutions are no option for our projects. The structure follows something like Angular with nested components. There will be no special directory since it is mixed. Maybe we could use a prefix like "_*.hbs" but gulp.src doesn't accept excludes.

Is there any chance you will implement this like gulp-compile-handlebars did?

I don't think there is a missing partial warning. The partial is registered thats all it needs. It just should not get rendered to .html.

I'm pretty sure that gulp.src will let you do something like this:

gulp
    .src([
        'src/**/*.hbs',
        '!**/layout/**',
        '!**/partials/**',
    ])
    .pipe(hb( ... ))
    .pipe(gulp.dest('dest'));

Would that solve the issue?

gulp.src(['**/*.hbs', '!**/_*.hbs']) does.

Anyway I would leave this issue open and love to see this implemented. gulp-compile-handlebars is pretty small maybe you can adopt the logic.

Thanks for your quick responses!

PRs welcome. :)

@MickL The ignorePartials flag of gulp-compile-handlebars doesn't seem to do what you're asking for. It appears to mock unknown partials such that the template isn't touched. For example, given these two files:

foo.hbs:

{{> header}}
<p>Hi from foo</p>
{{> footer}}

header.hbs:

<h1>Header</h1>

gulp-compile-handlebars would output:

<h1>Header</h1>
<p>Hi from foo</p>
{{> footer}}

It ignored that the footer.hbs partial didn't exist and left the {{> footer}} in the file instead of removing it or throwing an error.


Closing this issue since changing the gulp.src glob pattern addressed the original issue and is the intended way to use gulp-hb.