Socket
Socket
Sign inDemoInstall

gulp-dot-precompiler2

Package Overview
Dependencies
149
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    gulp-dot-precompiler2

Gulp plugins for precompilation of doT template engine.


Version published
Maintainers
1
Created

Readme

Source

gulp-dot-precompiler2

Better Gulp plugin for precompilation of doT templates. Forked from kentliau/gulp-dot-precompiler with more control and bugfixes.

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'
  • templateSettings : doT template settings

##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-precompiler2'),
    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 ...

License

MIT

Keywords

FAQs

Last updated on 27 Jan 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc