new Compiler(options) → {Compiler}
Provides methods for parsing, compiling, and rendering templates.
Parameters:
Name | Type | Description |
---|---|---|
options |
- Source:
Returns:
- Type
- Compiler
Methods
compile(template, options) → {Compiler~RenderFunction}
Parses a given
template
for g-include
and
g-replace
blocks. Said blocks are dealt with appropriately.
Parameters:
Name | Type | Description |
---|---|---|
template |
string | The template to compile |
options |
Compiler~Options | Options to be used by the compiler |
- Source:
Returns:
A function to use for rendering the
compiled template
emptyCache()
If caching is enabled, this method can be used to clear the cache.
- Since:
- 0.5.0
- Source:
loadTemplateNamed(name, isPartial) → {string|null}
Looks for a file in the templates direcory with the given name. If the
file exists, it will be loaded and returned as a string.
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The name of the template to load |
isPartial |
boolean | If set, then the defined partials directory will be used as the base path for loading the template |
- Since:
- 0.5.0
- Source:
Returns:
The template or
null
(wasn't found)
- Type
- string | null
Type Definitions
Options
An object literal that has the following properties:
-
cache
: Set totrue
(default) to enable caching of compiled templates. Set tofalse
to compile templates every load. -
cacheTTL
: Time, in seconds, to keep templates in the cache. Default value is 300 (5 minutes). -
templatesDir
: The location where templates are stored. This should be the full path (use `path.resolve`). If it is not present, then it will be set to an "html" directory that is in the same directory as a node_modules directory. -
partialsDir
: The location where partial templates are stored. This should be the full path (use `path.resolve`). If this option is not present then it will be set to a sub-directory of the specifiedtemplatesDir
. The name of the sub-directory will bepartials
. -
templatesExt
: The file extension used on template files. This defaults to ".html". Note that it should include the leading dot.
Type:
- object
- Source:
RenderFunction(context, options)
Returned from the Compiler#compile method when a template has been
compiled. This function allows you to render the compiled template
with substitued values.
Parameters:
Name | Type | Description |
---|---|---|
context |
object | An object of values that will be substituted in the rendered template |
options |
object | Not used (yet) |
- Source: