Grunt plugin to compile Swig templates to static HTML
This plugin requires Grunt.
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-swig-templates --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-swig-templates');
In your project's Gruntfile, add a section named swig
to the data object passed into grunt.initConfig()
.
grunt.initConfig({
swig: {
options: {
// Task-specific options go here.
},
your_target: {
// Target-specific file lists and/or options go here.
},
},
})
Type: Object
Default value: {}
A Object that will get passed into swig templates
Type: Boolean
Default value: false
A boolean that determines if templates should be cached. See more info here
Type: String
Default value: undefined
A filepath string that allows loading of templates from a specific directory (does not require using relative paths in your templates)
In this example, the default options are used to show a very basic grunt configuration that will take and array of .swig
files and compile them to HTML
grunt.initConfig({
swig: {
options: {},
files: {
'dest/test.html': ['test.swig'],
},
},
})
In this example, custom options are used to pass custom data to sepecified templates. This also uses the Grunt file expand mapping rather than just using the files object.
grunt.initConfig({
swig: {
options: {
data: {
title: 'Hello World'
}
},
expand: true,
cwd: 'templates',
dest: 'dest/',
src: ['*.swig'],
ext: '.html'
},
})
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
v0.1.4 - Added cache
options
v0.1.3 - Added templatePath
options #1
v0.1.2 - Updated swig library
v0.1.1 - Fixed issues with swig templating
v0.1.0 - Initial Release
Copyright (c) 2014 Jake Larson. Licensed under the MIT license.