-
Notifications
You must be signed in to change notification settings - Fork 0
Adding Additional Templating Engines
There are many templating languages, each of which has one or more implementations (templating engines), which in turn provide a range of different methods. This adapter not only attempts to standardise these interfaces, but also endeavours to make it as straightforward as possible to add further templating engines.
The easiest templating libraries to add are those that:
- provide Express support by way of the
express()orrenderFile()method; - have the same module name as the template file extension.
All that is required for these is to add an entry for an engine to the dependencies in package.json, and a template with the same file extension to the fixtures collection in the tests directory (see test/fixtures). This template will be picked up automatically when running tests, and its presence will cause a test to be run for the corresponding template engine.
The next most simple templating engine to support are those that:
- provide Express support by way of the
express()orrenderFile()method; - have a different module name to the template file extension.
As described in the previous section, an entry is needed in package.json and a template must be added to the fixtures collection in the tests directory in order to trigger tests. But in addition an entry is needed in lib/setModuleDefaults.js to indicate what the real module name is. For example, to use the module hbs to provide Handlebars support, the following needs to be added to the default settings:
handlebars: {
"module": "hbs"
}Without this entry the generic adapter will try to load a module called handlebars.
If the templating engine to add is not Express-compatible but does support a render() method then a renderFile() method will be created for it automatically. This method will load the template referred to in the path parameter and then pass it to the template engine's render() method.
If the render() method is synchronous the adapter will need to know so that an asynchronous wrapper can be added. This is done by setting the sync option in the default configuration:
haml: {
"sync": true
}If the engine doesn't support a render() method then one is created that carries out the steps described in How It Works#render.