-
Notifications
You must be signed in to change notification settings - Fork 0
How It Works
The adapter wraps template modules with a standard interface:
renderFile()render()
If a template engine supports a method called __express() then it is used to provide the renderFile() method. If __express() does not exist, but renderFile() does, then this is used instead.
If neither method exists then a renderFile() method is created that will load the template referred to in the path parameter and then call render().
If a templating engines supports render() then the render() adapter method simply points to the engine's method. If the method is synchronous -- i.e., there is no callback parameter -- then a flag can be set in the configuration options so that the adapter will place the render() function into an asynchronous wrapper. For example, the Haml template engine has a synchronous render() method, so the following setting is required:
haml: {
"sync": true
}If the engine does not provide a render() method then one is created which carries out the following steps:
-
newContext()is called on the engine to create a new context; - any provided local variables are added to this context;
-
compile()is called on the engine to compile a template and create a template function; - the template function is called using the context.