A growing collection of tags and filters for Swig Templates.
MIT License
Tags, filters, and extensions for Swig, the most awesome template engine for node.js.
This project is based on (and complementary to) swig-extras, from @paularmstrong
Use a filter:
var swig = require('swig');
var extensions = require('swig-extensions');
extensions.useFilter(swig, 'markdown');
Use a tag:
var swig = require('swig');
var extensions = require('swig-extensions');
var mySwig = new swig.Swig();
extensions.useTag(mySwig, 'markdown');
npm install assemble-swig --save-dev
Once the assemble-swig engine has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('assemble-swig');
Specify swig
as the current engine for processing templates:
assemble: {
options: {
engine: 'swig'
}
}
Specify the path or paths (optionally using minimatch patterns) to the helpers
property in the Assemble options:
assemble: {
options: {
engine: 'swig',
helpers: ['src/extensions/*.js']
}
}
For Assemble to find and register your custom tags and filters, you must export them either as objects or functions inside a module.exports
object:
module.exports.register = function (swig, opts) {
// filters and tags
};
Example of how to register multiple filters as properties of the filters
object:
var filters = module.exports = {};
filters.one = function (input) {
return input;
};
filters.two = function (input) {
return input;
};
filters.three = function (input) {
return input;
};
module.exports.register = function (swig, opts) {
opts = opts || {};
// filters.useFilter(swig, filters);
for (var filter in filters) {
if (filters.hasOwnProperty(filter)) {
swig.setFilter(filter, filters[filter]);
}
}
};
Copyright (c) 2013 Jon Schlinkert, Brian Woodward, contributors Licensed under the MIT License (MIT)