Code Monkey home page Code Monkey logo

gulp-template-compile's Introduction

gulp-template-compile

Compile Lo-Dash templates (should work with Underscore templates too).

Synopsis

This plugin is heavily inspired by Sindre Sorhus's gulp-nunjucks plugin, in fact I used it as skeleton for creating this one.

Install

Install with npm

npm install --save-dev gulp-template-compile

Example

gulpfile.js

var gulp = require('gulp');
var template = require('gulp-template-compile');
var concat = require('gulp-concat');

gulp.task('default', function () {
	gulp.src('src/*.html')
		.pipe(template())
		.pipe(concat('templates.js'))
		.pipe(gulp.dest('dist'));
});

API

See the Lo-Dash _.template docs.

template(options)

options

Type: Object

options.name

Type: Function Default: Relative template path. Example: templates/list.html

You can override the default behavior by supplying a function which gets the current File object and is expected to return the name.

Example:

{
	name: function (file) {
		return 'tpl-' + file.relative;
	}
}

options.namespace

Type: String Default: 'JST'

The namespace in which the precompiled templates will be assigned. Starting from version 1.0 you could also provide a dotted namespace that will be correctly handled, thanks to fhawkes. For example 'custom.namespace' will result in window['custom']['namespace'].

options.templateSettings

Type: Object Default: null

Lo-Dash _.template options.

Changelog

1.0:

  • BREAKING: Added support for custom dotted namespaces.

Notes

If you use grunt instead of gulp, but want to perform a similar task, use grunt-contrib-jst.

License

MIT © Emanuele Ingrosso

gulp-template-compile's People

Contributors

ingro avatar psychobear42 avatar testreg4 avatar

Watchers

 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.