Engine

templeo. Engine

new Engine(optsopt, formatFuncopt, loggeropt)

Creates a template literal engine

Source:
Parameters:
Name Type Attributes Description
opts TemplateOpts <optional>

The TemplateOpts to use

formatFunc function <optional>

The function(string, formatOptions) that will return a formatted string for a specified code block, passing the formatting options from opts.formatOptions (e.g. minification and/or beautifying)

logger Object <optional>

The logger for handling logging output

Name Type Attributes Description
debug function <optional>

A function that will accept debug level logging messages (i.e. debug('some message to log'))

info function <optional>

A function that will accept info level logging messages (i.e. info('some message to log'))

warn function <optional>

A function that will accept warning level logging messages (i.e. warn('some message to log'))

error function <optional>

A function that will accept error level logging messages (i.e. error('some message to log'))

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

Source:

legacyRenderOptions

Source:

options

Source:

Methods

(static) create(cachier) → {Engine}

Creates a new Engine from a Cachier instance

Source:
Parameters:
Name Type Description
cachier Cachier

The Cachier to use for persistence management

Returns:
Type:
Engine

The generated Engine

(async) clearCache(allopt)

Clears the underlying cache

Source:
Parameters:
Name Type Attributes Default Description
all Boolean <optional>
false

true to clear ALL unassociated cache instances when possible as well as any partials that have been registered

(async) compile(content, optsopt, callbackopt) → {function}

Compiles a template and returns a function that renders the template results using the passed context object

Source:
Parameters:
Name Type Attributes Description
content String

The raw template content

opts Object <optional>

The options sent for compilation (omit to use the options set on the Engine)

callback function <optional>

Optional callback style support for LEGACY-ONLY APIs:
compile(content, opts, (error, (ctx, opts, cb) => cb(error, results)) => {}) or omit to run via await compile(content, opts). Omission will return the normal stand-alone renderer that can be serialized/deserialized. When a callback function is specified, serialization/deserialization of the rendering function will not be possible!

Returns:
Type:
function

The rendering function(context) that returns a template result string based upon the provided context

registerHelper(func)

Registers a directive function that can be used within template interpolations

Source:
Parameters:
Name Type Description
func function

A named function that has no external scope dependencies/closures other than those exposed via templates during rendering

registerPartial(name, contentOrParams, extensionopt) → {String}

Registers and caches a partial template

Source:
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 URLSearchParams that will be passed during the content read

extension String <optional>
options.defaultExtension

Optional override for a file extension designation for the partial

Returns:
Type:
String

The partial content

(async) registerPartials(partialsopt, readopt) → {Object}

Registers and caches partial compile-time partial templates

Source:
Parameters:
Name Type Attributes Default Description
partials Array.<Object> <optional>

The partials to register

Name Type Attributes Description
name String

The template name that uniquely identifies the template content

params URLSearchParams <optional>

The URLSearchParams that will be passed during the content read (ignored when content is specified)

extension String <optional>

Optional override for a file extension designation for the partial

read Boolean <optional>
true

When true, an attempt will be made to also read any partials that do not have a content property

Returns:
Type:
Object

An object that contains the registration results:

  • partials The partials object that contains the fragments that have been registered
    • name The template name that uniquely identifies the template content
    • content The template content
    • extension The template file extension designation
    • params The URLSearchParams passed during the initial content read
    • fromRead A flag that indicates that the
  • dirs Present only when Engine.filesEngine was used. Contains the directories/sub-directories that were created

(async) renderPartial(name, contextopt) → {String}

On-Demand compilation of a registered template

Source:
Parameters:
Name Type Attributes Default Description
name String

The name of the registered tempalte

context Object <optional>
{}

The object that contains contextual data used in the template

Returns:
Type:
String

The compiled template

renderPartialGenerate() → {function}

Source:
Returns:
Type:
function

A reference safe async function to Engine.renderPartial that can be safely passed into other functions

unregister(name)

Unregisters a partial template from cache

Source:
Parameters:
Name Type Description
name String

The template name that uniquely identifies the template content


0.1.0 (2019-02-06)

Full Changelog

Features: