Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gulp-njrt

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-njrt

Deprecated, moving to gulp-nunjucks-api.

  • 0.5.0
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

gulp-njrt

Deprecated, moving to gulp-nunjucks-api.

Render Nunjucks templates

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

Install

Install with npm

npm install --save-dev gulp-njrt

Example

var gulp = require('gulp');
var nunjucksRender = require('gulp-njrt');

gulp.task('default', function () {
  return gulp.src('src/templates/*.html')
		.pipe(nunjucksRender({
		  src: 'src/templates' 
		}))
		.pipe(gulp.dest('dist'));
});

Note: To keep Nunjucks render from eating up all your ram, make sure to specify the src path(s) option. This will also allow you to define your paths relatively.

Example with gulp data

var gulp = require('gulp');
var nunjucksRender = require('gulp-njrt');
var data = require('gulp-data');

function getDataForFile(file){
  return {
    example: 'data loaded for ' + file.relative
  };
}

gulp.task('default', function () {
	return gulp.src('src/templates/*.html')
	  .pipe(data(getDataForFile))
		.pipe(nunjucksRender({
      src: ['src/templates/']
    }))
		.pipe(gulp.dest('dist'));
});

API

nunjucks-render(options)

Same options as nunjucks.configure():

  • watch (default: false) reload templates when they are changed.
  • express an express app that nunjucks should install to.
  • autoescape (default: false) controls if output with dangerous characters are escaped automatically.
  • tags: (default: see nunjucks syntax) defines the syntax for nunjucks tags.

With the following additional options:

  • extension (default: ".html") String. File extension to output.
  • src (default: undefined) String or Array. Source path(s) being configured.
  • data (default: {}) Ojbect. Context data available to all templates.
  • globals (default: undefined) Object. Provides filters and functions properties, which are are added to the nunjucks environment or context.

For example

nunjucksRender({
  data: {css_path: 'http://company.com/css/'}
});

For the following template

<link rel="stylesheet" href="{{ css_path }}test.css" />

Would render

<link rel="stylesheet" href="http://company.com/css/test.css" />

Watch mode

Nunjucks' watch feature, which is normally enabled by default, is disabled by default in this plugin. Pass watch: true to enable it:

nunjucksRender({
  src: './source',
  watch: true
});

License

MIT © Devoptix LLC

Shout-outs

Carlos G. Limardo who wrote gulp-nunjucks-render which I am forking in order to update Nunjucks and do other stuff.

Sindre Sorhus who wrote the original gulp-nunjucks for precompiling Nunjucks templates. I updated his to render instead of precompile.

Keywords

FAQs

Package last updated on 21 Jun 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc