npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-nunjucks-with-env

v1.0.2

Published

Use Nunjucks Environment Class to get more control

Downloads

1

Readme

gulp-nunjucks-with-env

Use Nunjucks Environment Class to get more control

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

Install

Install with npm

npm install --save-dev gulp-nunjucks-with-env

Example : Using Environment Class

var gulp = require('gulp');
var nunjucksRender = require('gulp-nunjucks-with-env');

var environment = nunjucksRender.nunjucks.configure(['src/templates/']);
environment.addFilter('stringify', function(obj) {
    return JSON.stringify(obj);
});
nunjucksRender = nunjucksRender.bind(nunjucksRender,environment);

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

Check Nunjucks API for more information on Environment Class

Note: To keep Nunjucks render from eating up all your ram, make sure to specify your watch path. nunjucksRender.nunjucks.configure(['src/path/to/templates/']); This will also allow you to define your paths relatively.

Example : Using with gulp data

var gulp = require('gulp');
var nunjucksRender = require('gulp-nunjucks-render');
var data = require('gulp-data');

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

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

Example : Using with pass by reference globals

var gulp = require('gulp');
var nunjucksRender = require('gulp-nunjucks-with-env');

var environment = nunjucksRender.nunjucks.configure(['src/templates/']);
environment.addFilter('stringify', function(obj) {
    return JSON.stringify(obj);
});
var files = {widgetFiles : []};
templateEngine = templateEngine.bind(templateEngine,environment,{},files);

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

gulp.task('newtask',['task'],function() {
  return gulp.src(files.widgetFiles)
		.pipe(/*Some Task*/)
});

API

nunjucksRender(environment, context, passByReferenceGlobals)

environment (optional) Environment Class : Environment Class

context (optional) Object : Same context as nunjucks.render() Note : You will have to pass empty object {}, if you want to use passByReferenceGlobals

passByReferenceGlobals (optional) Object : Parameters from this object will be added to context through pass by reference rather than pass by value

Example :

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

or

nunjucksRender({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" />

License

MIT © AvcS

Shout-outs

Sindre Sorhus who wrote the original gulp-nunjucks for precompiling Nunjucks templates.

Carlos G. Limardo updated this to render instead of precompile in gulp-nunjucks-render

I updated this to facilitate using of Environment Class for more control