swig-extensions
v0.1.0
Published
A growing collection of tags and filters for Swig Templates.
Downloads
10
Readme
swig extensions
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
Getting started
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');
Available Filters
- condense
- markdown (using Marked)
- prettify
Available Tags
- markdown
- prettify
Usage with Assemble
1. Install assemble-swig
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');
2. Add swig to assemble
Specify swig
as the current engine for processing templates:
assemble: {
options: {
engine: 'swig'
}
}
3. Add swig tags and filters
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']
}
}
load them as modules
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]);
}
}
};
Related projects
License
Licensed under the MIT License (MIT)
Copyright (c) 2013 Jon Schlinkert