Skip to content

Template options

templeo options module

new TemplateOpts([opts])

Template compilation options. See module:templeo/options.Options for a full listing of options.

Parameters

NameTypeDescription
[opts]module:templeo/options.OptionsThe template compilation options

See also

  • module:templeo/options.Options

templateOpts.build(opts, optd, to, [valids])Object

Builds the Options by iterating over the dflt (default options) object properties and either adding them to the to object when the opts object does not contain the property value (or it's invalid for that option) or adds the value from opts when the property is present and contains a valid value for the option being iterated. The final to object/properties will be frozen using Object.freeze and Object.defineProperty.

Parameters

NameTypeDescription
optsmodule:templeo/options.OptionsThe template compilation options
optdObjectAn object that generatd from TemplateOpts.defaultOptionMerge that contains the default options
optd.defaultsObjectThe object that contains option properties with default property values as the default values
[optd.valids]ObjectAn object that contains option names as properties. Each property value should contain an Array
of primitive values that represent valid values for a given option.
toObjectThe object where the options will be set- typically a TemplateOpts instance
[valids]ObjectAn object that contains option names as properties. Each property should contain an Array of primitive
values that represent valid values for a given option.

Returns

  • Object — The to object

See also

  • module:templeo/options.Options

TemplateOpts.defaultOptionMerge(options, to)

Merges option objects into another object

Access: protected

Parameters

NameTypeDescription
optionsObjectThe option object to merge options from
toObjectThe object where that will be merged into

TemplateOpts.defaultOptionsObject | Object | Object

Returns

  • Object — An immutable object that describes how module:templeo/options.Options will be built
  • Objectdefaults The object that contains option properties with default property values as the default values
  • Objectvalids An object that contains option names as properties. Each property value should contain an Array of primitive values that represent valid values for a given option.

See also

  • module:templeo/options.Options

templeo/options.Options

Template compilation options

Type: Object

Properties

NameTypeDefaultDescription
[useCommonJs=false]BooleanfalseWhen true, CommonJS Module semantics will be used. When false, ECMAScript Module semantics
will be used.
[contextURL='']String''A base URL used as prefix for context read/write operations.
[partialsURL='']String''A base URL used as prefix for partial template HTTP/S read/write operations.
[bypassUrlRegExp=/^https?:/?/?[^:/\s]+/i]RegExp/^https?:/?/?[^:/\s]+/iAn expression that will tested against context, partial and template names
to determine if the template name will be prefixed with the contextURL/partialsURL during read/write operations. Any matches will
not be prefixed.
[defaultExtension='html']String'html'The default extension name to append to template names when performing read/write
operations and an explicit extension is not already provided for a given template name
[defaultContextExtension='json']String'json'The default extension name to append to the context name when performing read/write
operations and an explicit extension is not already provided for a given context name
[defaultContextName='context']String'context'The name assigned to the context when executing a rendering funtion without passing a
context object. The name will be used to read the context during compilation.
[defaultTemplateName='template']String'template'The name assigned to the primary template content passed into Engine.compile,
similar to the name assignment when calling Engine.registerPartial. Set to a falsy value to generate the name.
Since the primary template needs to be present prior to compiling,
the option can only be used during compilation and is ignored during rendering.
[includesParametersName='params']String'params'The name that will be added to each partial template scope that will contain any
parameters passed into the include where the partial was added. For example, ${ await include`somePartName${ { param: 123 } }` }
would cause ${ params.param1 } to equal 123 within the somePartName partial, but not in it's parent where the include was added.
[defaultPartialContent=' ']RegExp' 'The value to use for a partial when a partial returns a non-string value.
[renderTimePolicy=read]StringreadThe policy applied to partial template DB read/write operations when encountering
include directives that do not have template content present in cache storage during rendering. When using any other policy
except "none", include directives defined in a template that reference partials that have not been registered before compiling will
result in a render-time read of the referenced content. The following policies are valid (see any extending option implmentations for
any additional policies):
- read Normal reads will occur for missing partial content encountered via include directives during rendering.
- read-write Same as read, but will also write compiled rendering functions when include directives are encountered during rendering.
- none Only partial templates that are registered before compiling a template will be available to include directives during rendering.
Any include directives found that reference partials that are not found will cause render-time errors to be thrown.
[readFetchRequestOptions]ObjectThe JSON options that will be used when making read requests to capture partial content.
Depending upon the Cachier being used on the Engine, the options will be passed into the standard Fetch API or another cache-specific read
operation or simply ignored.
[writeFetchRequestOptions]ObjectThe JSON options that will be used when making write requests for generated rendering functions.
Depending upon the Cachier being used on the Engine, the options will be passed into the standard Fetch API or another cache-specific write
operation or simply ignored.
[readFormatOptions]ObjectThe formatting options passed into an optional formatter function specified during cache construction
or passed into the rendering function that will format read template content. For example, when a template is read and the desired code can
be formatted using the formatter function (e.g. js-beautify, etc.). The template content will be passed as the first argument and the
readFormatOptions will be passed as the second argument. The returned string will be used as the content for the template.
[writeFormatOptions]ObjectThe formatting options passed into an optional format function specified during cache construction
or passed into the rendering function that will format the compiled template code that will be written. For example, when a generated template
renderer is generated either during compilation or during include discovery, the desired code can be formatted using js-beautify, uglify-js
or any other module that supports the provided arguments. The first argument will be the generated rendering function (as a string). and the
writeFormatOptions will be passed as the second argument. The returned string will be used as the formatted source code that will be written.
[encoding='utf8']String'utf8'The text encoding used by the templates during reads
falsy value or a partial is included that cannot be resolved. Wwhen partial
content is empty or cannot be found errors may be thrown when the template engine is used within an external template plugin.
[varName='it']String'it'The variable name of passed context objects that will be accessible by reference within template expressions
(e.g. ${ it.somePassedVal }). Compile-time only option.
[filename=/^(.[\/]|^)([^.])(.*)$/]RegExp/^(.[\/]|^)([^.])(.*)$/Expression that will be used to capture template names from passed definition
pseudo filenames when a template name hasn't been passed
__ NOTE: Should contain 3 capture groups:__
1. Full pseudo path excluding final pseudo filename w/o extension
1. Pseudo file name w/o extension
1. Extension with preceding .
[cacheRawTemplates=true]BooleantrueIf set to false, raw template content will not be cached (thus will perform a read on every use-
NOT FOR PRODUCTION USE!)
[maxCacheEntries=0]Number0Maximum combined in-memory raw-template and compiled-renderer entries. 0 keeps the existing unlimited behavior. When the limit is exceeded, the least-recently-used entry is evicted.
[maxCacheBytes=0]Number0Approximate maximum combined in-memory cache size in bytes. 0 keeps the existing unlimited behavior. When the limit is exceeded, least-recently-used entries are evicted.
[cacheTTL=0]Number0Idle time-to-live in milliseconds for in-memory cache entries. 0 disables expiration. Each successful cache access refreshes the entry timestamp.
[useSourceURL=true]BooleantrueWhether or not to add a
`//# sourceURL to generated rendering functions. Some option
types may have a different default value.
[debugger=false]BooleanfalseWhen true, a debugger
statement will be inserted into each compiled template rendering function at the end of execution (compile-time options only)

Released under the MIT License.