new Engine(optsopt, readFormatteropt, writeFormatteropt, logopt)
Creates a template literal engine
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opts |
TemplateOpts
|
<optional> |
The |
||||||||||||||||||||
readFormatter |
function
|
<optional> |
The |
||||||||||||||||||||
writeFormatter |
function
|
<optional> |
The |
||||||||||||||||||||
log |
Object
|
<optional> |
The log for handling logging output
|
Members
legacyRenderOptions
The LEGACY-ONLY API TemplateOpts
to use when no rendering options
are passed (or are empty) into the rendering function and a callback function is specified when
calling Engine.compile
Methods
(static) create(cachier) → {Engine}
Creates a new Engine
from a Cachier
instance
Parameters:
Name | Type | Description |
---|---|---|
cachier |
Cachier
|
The |
Returns:
- Type:
-
Engine
The generated Engine
(async) clearCache(allopt)
Clears the underlying cache
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
all |
Boolean
|
<optional> |
false |
|
(async) compile(contentopt, optsopt, paramsopt, legacyCallbackopt) → {function}
Compiles a template and returns a function that renders the template results using the passed context
object
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
content |
String
|
Boolean
|
<optional> |
The raw template content, |
opts |
Object
|
<optional> |
The options sent for compilation (omit to use the options set on the |
params |
URLSearchParams
|
<optional> |
Any URL search parmeters that will be passed when capturing the primary |
legacyCallback |
function
|
<optional> |
Optional callback style support for LEGACY-ONLY APIs: |
Returns:
- Type:
-
function
The rendering async function
that returns a template result string based upon the provided context.
The following arguments apply:
- {Object}
context
The context JSON that can be used as data during rendering - {TemplateOpts}
[renderOptions]
The rendering options that will superceed any compile-time options - {Function}
[readFormatter]
The function that will format read partials during include discovery (if any). The formatting function takes 1 or 2 arguments with the first being the content that will be formatted and the second being theoptions.readFormatOptions
. The returned result should be a valid string. - {Function}
[writeFormatter]
The function that will format written sources during include discovery (if any). The formatting function takes 1 or 2 arguments with the first being the content that will be formatted and the second being theoptions.writeFormatOptions
. The returned result should be a valid string. - {Object}
[sharedStore]
An object used for in-memory storage space that can be shared between rendering functions. This ensures that updated data within a renderer execution will be retained between rendering calls from the same renderer or different renderers that are passed the same shared store.
(async) getRegistered(name, paramsopt, extensionopt) → {Object}
Retrieves a template, partial or context that resides in-memory.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
name |
String
|
The name that uniquely identifies the template, partial or context |
||
params |
URLSearchParams
|
<optional> |
Any parameters designated during |
|
extension |
String
|
<optional> |
options.defaultExtension |
Optional override for a file extension designation
for the template, partial or context designated during |
Returns:
- Type:
-
Object
A copy of the generated data from Engine.registerPartial
(async) register(dataopt, readopt, writeopt) → {Object}
Registers and caches the template, one or more partial templates and/or context JSON.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
data |
Array.<Object>
|
<optional> |
The template, partials and/or context to register. |
partials[].name |
String
|
The name that uniquely identifies the template, partial or context |
|
partials[].content |
String
|
<optional> |
The raw content that will be registered. Omit when |
partials[].params |
URLSearchParams
|
<optional> |
The |
partials[].extension |
String
|
<optional> |
Optional override for a file extension designated for a template, partial or context. |
read |
Boolean
|
<optional> |
When |
write |
Boolean
|
<optional> |
When |
Returns:
- Type:
-
Object
An object that contains the registration results:
data
The object that contains the template, partial fragments and/or context that have been registeredname
The name that uniquely identifies the template, partial or contextcontent
The raw content of the template, partial or contextextension
The template file extension designationparams
The URLSearchParams passed during the initial content readfromRead
A flag that indicates that the data was set from a read operationoverrideFromFileRead
A flag that indicates if the passed partial content was overridden by content from a file read
dirs
Present only when file system back-end is used. Contains the directories/sub-directories that were created
registerHelper(func)
Registers a directive function that can be used within template interpolations
Parameters:
Name | Type | Description |
---|---|---|
func |
function
|
A named |
(async) registerPartial(name, contentOrParams, extensionopt) → {String}
Registers and stores a partial template in-memory. Use Engine.register
to write
/persist partials to cache (Cachier
)
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
name |
String
|
The template name that uniquely identifies the template content |
||
contentOrParams |
String
|
URLSearchParams
|
Either the partial template content string to register or the
|
||
extension |
String
|
<optional> |
options.defaultExtension |
Optional override for a file extension designation for the partial |
Returns:
- Type:
-
String
The partial content
(async) renderPartial(name, contextopt) → {String}
On-Demand compilation of a registered templates
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
name |
String
|
The name of the registered tempalte |
||
context |
Object
|
<optional> |
{} |
The object that contains contextual data used by the template |
Returns:
- Type:
-
String
The rendered template
renderPartialGenerate() → {function}
Returns:
- Type:
-
function
A reference safe async
function to Engine.renderPartial
that can be safely passed into other functions