-
Notifications
You must be signed in to change notification settings - Fork 77
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 example to create partials using gulp-wrap #11
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,29 @@ gulp.task('templates', function(){ | |
}); | ||
``` | ||
|
||
## Compiling to a partial for the browser | ||
|
||
[gulp-wrap] 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'); | ||
var wrap = require('gulp-wrap'); | ||
|
||
gulp.task('templates', function() { | ||
gulp.src(['client/templates/_*.hbs']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add a comment here that indicates you can use whatever glob you want to match your partials. |
||
.pipe(handlebars()) | ||
.pipe(wrap('Handlebars.registerPartial(<%= processPartialName(file.relative) %>, Handlebars.template(<%= contents %>))', {}, { | ||
'imports': { | ||
'processPartialName': function(fileName) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't quote property names in object literals unless necessary |
||
return JSON.stringify( | ||
require('path').basename(fileName, '.js').substr(1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would require |
||
); | ||
} | ||
} | ||
})) | ||
.pipe(gulp.dest('build/js/')); | ||
}); | ||
``` | ||
|
||
## API | ||
|
||
|
@@ -75,4 +98,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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.