All Projects → sindresorhus → Gulp Nunjucks

sindresorhus / Gulp Nunjucks

Licence: mit
Precompile Nunjucks templates

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Gulp Nunjucks

Gulp Template
Render/precompile Lodash templates
Stars: ✭ 276 (+93.01%)
Mutual labels:  gulp-plugin, template
Tedivms Flask
Flask starter app with celery, bootstrap, and docker environment
Stars: ✭ 142 (-0.7%)
Mutual labels:  template
Beginners C Program Examples
Simple, Short and Sweet beginners friendly C language programs
Stars: ✭ 138 (-3.5%)
Mutual labels:  template
Oldterminal
an old terminal template for html pages
Stars: ✭ 140 (-2.1%)
Mutual labels:  template
Glup
Some of the gulp tutorial -《gulp笔记》
Stars: ✭ 136 (-4.9%)
Mutual labels:  gulp-plugin
Studorlio
Portfolio website template
Stars: ✭ 141 (-1.4%)
Mutual labels:  template
Gatsby Starter Foundation
A starter to launch your blazing fast personal website and a blog, Built with Gatsby and Netlify CMS. Made with ❤ by Stackrole
Stars: ✭ 135 (-5.59%)
Mutual labels:  template
Eros Template
🔧 eros app 开发模板。
Stars: ✭ 143 (+0%)
Mutual labels:  template
Smoke
💨 Simple yet powerful file-based mock server with recording abilities
Stars: ✭ 142 (-0.7%)
Mutual labels:  template
Automatic Gatsbyjs App Landing Page
Automatic GatsbyJS App Landing Page - Automatically generate iOS app landing page using GatsbyJS
Stars: ✭ 137 (-4.2%)
Mutual labels:  template
Westwind.razorhosting
Hosting the Razor Runtime outside of ASP.NET/MVC for use in non-Web .NET applications.
Stars: ✭ 136 (-4.9%)
Mutual labels:  template
Latex Cheatsheet
Template for a compact LaTeX Cheatsheet I made some years ago.
Stars: ✭ 136 (-4.9%)
Mutual labels:  template
Kotlin Gradle Plugin Template
🐘 A template to let you started with custom Gradle Plugins + Kotlin in a few seconds
Stars: ✭ 141 (-1.4%)
Mutual labels:  template
Swift Project Template
Script to easily create an iOS project base code!
Stars: ✭ 136 (-4.9%)
Mutual labels:  template
Touch Bar Istats
Show CPU/GPU/MEM temperature on Touch Bar with BetterTouchTool!
Stars: ✭ 141 (-1.4%)
Mutual labels:  template
Vertx Maven Starter
Maven project template for Vert.x
Stars: ✭ 135 (-5.59%)
Mutual labels:  template
Workshop Template
The Carpentries Workshop Template
Stars: ✭ 137 (-4.2%)
Mutual labels:  template
Jupiter
jupiter是一个aio web框架,基于aiohttp。支持(restful格式、扫描注解、依赖注入、jinja2模板引擎、ORM框架)等。
Stars: ✭ 140 (-2.1%)
Mutual labels:  template
Android Template
Android app starter template
Stars: ✭ 141 (-1.4%)
Mutual labels:  template
Uicard
Generic UI for card games like Hearthstone, Magic Arena and Slay the Spire...
Stars: ✭ 142 (-0.7%)
Mutual labels:  template

gulp-nunjucks

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');

exports.default = () => (
	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');

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

Precompile

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

exports.default = () => (
	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 the Nunjucks Environment 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.

options.filters

Type: object

An object containing custom filters that will be passed to Nunjucks, with the filter's name as key and the filter function as value.

Async filters should be defined as async functions. You cannot use just a promise-returning function.

Example:

{
	'shorten': string => string.slice(0, 5),
	'round': number => Math.round(number),
	'fetch': async url => {
		const response = await fetch(url);
		const result = await response.text();
		return result;
	}
}

nunjucks.precompile(options?)

Precompile a template for rendering dynamically at a later time.

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

options

Type: object

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 => `template-${file.relative}`
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].