Code Monkey home page Code Monkey logo

gulp-nunjucks's Introduction

gulp-nunjucks Build Status

Compile/precompile Nunjucks templates

Issues with the output should be reported on the Nunjucks issue tracker.

Install

$ npm install --save-dev gulp-nunjucks

Usage

Compile

const gulp = require('gulp');
const nunjucks = require('gulp-nunjucks');

gulp.task('default', () => {
	return gulp.src('templates/greeting.html')
		.pipe(nunjucks.compile({name: 'Sindre'}))
		.pipe(gulp.dest('dist'));
});

You can alternatively use gulp-data to inject the data:

const gulp = require('gulp');
const nunjucks = require('gulp-nunjucks');
const data = require('gulp-data');

gulp.task('default', () => {
	return gulp.src('templates/greeting.html')
		.pipe(data(() => {
			return {name: 'Sindre'};
		}))
		.pipe(nunjucks.compile())
		.pipe(gulp.dest('dist'));
});

Precompile

const gulp = require('gulp');
const nunjucks = require('gulp-nunjucks');

gulp.task('default', () => {
	return gulp.src('templates/greeting.html')
		.pipe(nunjucks.precompile())
		.pipe(gulp.dest('dist'));
});

API

nunjucks.compile([data], [options])

Compile a template using the provided data.

data

Type: object

The data object used to populate the text.

options

Type: object

Options will be passed directly to Nunjucks Environment object constructor which will be used to compile templates.

options.env

Type: nunjucks.Environment
Default: new nunjucks.Environment()

The custom Nunjucks Environment object which will be used to compile templates. If supplied, the rest of options will be ignored.

nunjucks.precompile([options])

Precompile a template for rendering dynamically at a later time.

Same options as nunjucks.precompile() except for name.

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: file => `tpl-${file.relative}`
}

License

MIT © Sindre Sorhus

gulp-nunjucks's People

Contributors

bnjmnt4n avatar ingro avatar ntwb avatar renanvaz avatar shinnn avatar sindresorhus avatar

Watchers

 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.