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

grunt-nunjuckr

Package Overview
Dependencies
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grunt-nunjuckr

A grunt task rendering nunjucks templates to static html files.

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-66.67%
Maintainers
2
Weekly downloads
 
Created
Source

grunt-nunjuckr

Render your nunjucks templates to static files

Getting started

If you haven't used Grunt before, check out the Getting Started guide.

Once you have installed the plugin via npm install --save-dev grunt-nunjuckr include this in your Gruntfile.js

grunt.loadNpmTasks('grunt-nunjuckr');

Options

Data

Type: Object Default: undefined

The data that is passed to the template.

Ext

Type: String Default: .html

The file extension for the output.

SearchPaths

Type: String Default: .

The path where the templates can be found.

Tags

Type: Object Default: undefined

Configures nunjucks to render with different tags

SetUp

Type: Function Default: undefined

A callback function that sets up the nunjucks environment. The environment is passed as a parameter and it is expected to return it.

For more infomation about nunjucks environments see https://mozilla.github.io/nunjucks/api.html#environment

PreprocessData

Type: Function Default: undefined

A preprocessor callback for the data coming in. Gets called on every file with the params data and file

Usage Examples

Basic usage

Render a single input file to a single output file.

grunt.initConfig({

  nunjuckr : {

    testSimple : {
      options : {
        data : grunt.file.readJSON('data/data.json')
      },
      files : [
        {
          src : 'src/input.njs',
          dest : 'dest/output.html'
        }
      ]
    }
  }
});

Different data for every template

load different data files for every file in the templates folder.

var path = require('path');

grunt.initConfig({
  nunjuckr : {
    testExtended : {
      options : {
        data : grunt.file.readJSON('test/extended/data/data.json'),
        ext : '.html'
        searchPaths : 'src',
        preprocessData : function (data, file) {
          var fileExt = path.extname(file);
          var filename = path.basename(file, fileExt);
          var dir = path.dirname(file);
          var jsonPath = path.join('test/extended/data/', dir, filename + '.json');

          data = grunt.file.readJSON(jsonPath);

          return data;
        }
      },
      files : [
        {
          src : 'src/**/*.njs',
          dest : 'dest/'
        }
      ]
    }
  }
});

Custom Environment

Set up a custom environment for the renderer.

grunt.initConfig({
  nunjuckr : {
    testExtended : {
      options : {
        data : grunt.file.readJSON('test/extended/data/data.json'),
        ext : '.html',
        searchPaths : 'test/extended/src',
        setUp : function (env) {
          env.addFilter('crop', function (str, count) {
            return str.slice(0, count || 5);
          });
          return env;
        }
      },
      files : [
        {
          src : 'test/extended/src/**/*.njs',
          dest : 'test/extended/dest/'
        }
      ]
    }
  }
});

Keywords

FAQs

Package last updated on 24 Jul 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