gulp-dot-precompiler

0.3.0 • Public • Published

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

Build Status NPM version Coverage Status Dependecy Status

NPM

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 = require('gulp-dot-precompiler'),
    concat = require('gulp-concat'), // npm install gulp-concat --save
    header = require('gulp-header'); // npm install gulp-header --save
 
gulp.task('templates', function() {
  gulp.src('app/views/**/*.dot')
  .pipe(dot())
  .pipe(concat('templates.js'))
  .pipe(header('window.render = {};'))
  .pipe(gulp.dest('public/js'));
});

Will produce public/js/templates.js:

window.render = {};
render['users.list'] = function ...
render['users.detail'] = function ...
...
render['layout'] = function ...

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

Readme

Keywords

none

Package Sidebar

Install

npm i gulp-dot-precompiler

Weekly Downloads

5

Version

0.3.0

License

MIT

Last publish

Collaborators

  • kentliau