gulp-dot-precompiler
Better Gulp plugin for precompilation of doT templates. Forked from titarenko/gulp-dotify but with more control and much more logical.
Status
Options
- root : prepend a name for the template name, default ''
- extension : append a name for the template name, default ''
- separator : separator for the name, default '.'
- dictionary : template function name, default 'render'
- varname : refer doT, default 'data'
- strip : refer doT, default true
- append : refer doT, default true
- selfcontained : refer doT, default false
Include Partial View
< p > This is the main view < / p >
{{#def.loadfile('./sub_view.def') }}
This will include the sub_view.def
from the same directory where the loadfile()
is called. Not necessary to use .def
as extension.
Now with Error emitter
listen error in your gulp file
gulp.task('templates', function() {
gulp.src( src_template )
.pipe(plugins['dot-precompiler']({
dictionary:'render',
selfcontained:true,
append:true
})
.on('error', plugins['notify']
.onError({ title: "ERROR",
message: "Error: <%= error.message %>" })))
// Build multiple compressed version
.pipe(plugins['rename']({ extname: '.blade.php' }))
.pipe(plugins['uglify']())
.pipe(gulp.dest( build_template['server'] ))
// Build a concatenated version in public
.pipe(plugins['concat']('all.min.js'))
.pipe(plugins['header']('window.render=window.render||{};'))
.pipe(plugins['uglify']())
.pipe(gulp.dest( build_template['client'] ))
.pipe(plugins['notify']({ title: 'OK', message: 'Templates task complete' }));
});
Example
If we have following folder structure:
app/views/users/list.dot
app/views/users/detail.dot
app/views/products/list.dot
app/views/products/detail.dot
app/views/layout.dot
Then, running this code:
var dot = concat = // npm install gulp-concat --save header = ; // npm install gulp-header --save gulp;
Will produce public/js/templates.js
:
windowrender = {};render'users.list' =
Todo
- rename all the options to be more self-descriptive
- add dot delimiter options
- allow loadfile() using object oriented way of parameter, just like laravel
License
MIT