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

Added documentation example to create partials using gulp-wrap #12

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ gulp.task('templates', function(){

## Compiling to a namespace for the browser

[gulp-declare] can be used to compile templates for the browser. Just pipe the output of gulp-handlebars to gulp-declare:
[gulp-declare] can be used to compile templates for the browser. Just pipe the output of `gulp-handlebars` to `gulp-declare`:

```javascript
var handlebars = require('gulp-handlebars');
Expand All @@ -42,6 +42,33 @@ gulp.task('templates', function(){
});
```

## Compiling to a partial

[gulp-wrap] can be used to compile templates for the browser. Just pipe the output of `gulp-handlebars` to `gulp-wrap`:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

`[gulp-wrap]` can be used to declare partials. Just pipe the output of `gulp-handlebars` to `gulp-wrap`:


```javascript
var handlebars = require('gulp-handlebars');
var wrap = require('gulp-wrap');
var path = require('path');

gulp.task('templates', function() {
// glob is match all partials that begin with an underscore
// To match all nonpartials would be 'test/fixtures/**/[^_]*.hbs'
gulp.src(['client/templates/_*.hbs'])
.pipe(handlebars())
.pipe(wrap('Handlebars.registerPartial(<%= processPartialName(file.relative) %>, Handlebars.template(<%= contents %>))', {}, {
imports: {
processPartialName: function(fileName) {
// This names the partial without the first character, the underscore
return JSON.stringify(
path.basename(fileName, '.js').substr(1)
);
}
}
}))
.pipe(gulp.dest('build/js/'));
});
```

## API

Expand Down Expand Up @@ -75,4 +102,5 @@ Compiler options to pass to `Handlebars.precompile()`.
[npm-url]: https://npmjs.org/package/gulp-handlebars
[npm-image]: https://badge.fury.io/js/gulp-handlebars.png

[gulp-declare]: https://github.com/lazd/gulp-declare
[gulp-declare]: https://github.com/lazd/gulp-declare
[gulp-wrap]: https://github.com/adamayres/gulp-wrap