Code Monkey home page Code Monkey logo

grunt-templater's Introduction

grunt-templater

Universal template compiler task for Grunt. It uses Consolidate under the hood.

Supported template engines

Getting Started

install via npm

npm install grunt-templater

install the template engine you intend to use. For example, if using Jade:

npm install jade

and in your grunt.js file:

grunt.loadNpmTasks('grunt-templater');

Usage

Create a template task in your grunt config. Templater will guess the intended template engine based on the src filename. Pass the engine option to force a specific engine.

When using the Grunt file format, variables is required:

grunt.initConfig({
  template: {
    all: {
      files: [{
        expand: true,
        cwd: 'source',
        src: [ '**/*.hbs' ],
        dest: 'build',
        ext: '.html'
      }],
      variables: {
        env: environment
      }
    }
  }
});

To remain backwards compatible, src, dest can be used to define files aswell:

grunt.initConfig({
  template: {
    dev: {
      src: 'app/homepage.jade',
      dest: 'dev.html',
      variables: {
        css_url: 'app.css'
        title: 'Hello World'
        pretty: true
      }
    },
    dist: {
      src: 'app/homepage.jade',
      dest: 'dist/index.html',
      variables: {
        css_url: 'app.min.css'
        title: 'Hello Production'
      }
    },
    dynamicVariables: {
      src: 'app/homepage.jade',
      dest: 'dist/index.html',
      variables: function () {
        return {
          css: grunt.file.read('app.min.css'),
          now: new Date()
        }
      }
    }
  },
  ...
});

run with:

grunt template

or for a specific target:

grunt template:dev

Engine specific options can also be passed through the variables option. In the case of Jade, pretty: true adds pretty-indentation whitespace to its output.

grunt-templater's People

Contributors

rockwood avatar codepunkt avatar iristyle avatar twolfson avatar plumlee avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.