0.0.1 • Published 9 years ago

grunt-ejs-compile v0.0.1

Weekly downloads
10
License
-
Repository
-
Last release
9 years ago

grunt-ejs

A Grunt task for compiling ejs templates.

Getting Started

Install this grunt plugin next to your project's Gruntfile.js with: npm install grunt-ejs-compile --save-dev.

Then add this line to your project's Gruntfile.js:

grunt.loadNpmTasks('grunt-ejs-compile');

Documentation

Add the task to your config and specify the destination for the compiled file:

grunt.initConfig({
  ejs-compile: {
    all: {
      src: ['app/**/*.ejs', '!app/partials/**/*'],
      dest: 'dist/',
      expand: true,
      ext: '.html',
    },
  },
});

Passing data/helpers to the templates

Use options to pass data and helpers to the templates:

Gruntfile.js:

grunt.initConfig({
  ejs: {
    all: {
      src: ['app/**/*.ejs', '!app/partials/**/*'],
      dest: 'dist/',
      expand: true,
      ext: '.ejs.js',
    },
  },
});

app/index.ejs:

<html>
  <head>
    <title><%= title %></title>
  </head>
  <body>
    <a href="<%= url('home.html') %>">Home Page</a>
  </body>
</html>

Ideally all your helpers and non-app specific config should be another module and merged in like this:

grunt.initConfig({
  ejs: {
    all: {
      options: grunt.util._.merge(require('my-helpers'), {
        title: 'My Website'
      }),
      src: 'index.ejs',
      dest: 'index.html',
    },
  },
});

License

Licensed under the MIT license.