templeo/options

templeo options module

Classes

TemplateOpts

Type Definitions

DBOptions

Template options for an IndexedDB-like back-end. All DB options inherit from TemplateOpts.

Properties:
Name Type Attributes Default Description
dbTypeName String <optional>
'indexedDB'

The IndexedDB type to use. The default indexedDB value uses the global accessible instance that contains a property matching the type name. When not present in the current global scope, a module will be loaded using the provided type name.

dbLocName String <optional>
'templeo'

Either the IDBDatabase.name that will be used or the location name/path passed into the IndexedDB-like module loaded via dbTypeName (e.g. LevelDB).

renderTimePolicy String <optional>
read-all-on-init-when-empty

The policy applied to partial template DB read operations when encountering include directives that do not have template content present in cache storage during rendering. In addition to the policies defined in module:templeo/options.Options, the following policies can be applied:

  • read-all-on-init-when-empty When there are no partials registered during compilation other than the primary template designated by options.defaultTemplateName, all partial templates are read during the start of each rendering invocation. If partial templates are present/registered during compilation, no DB reads will be made during rendering.
  • read-all-on-init-when-empty-write Same as read-all-on-init-when-empty, but will also write compiled rendering functions when include directives are encountered during rendering.
  • read-write-and-close Like the read and read-write policy, partial templates are only read when include directives are encountered that do not already contain content. The DB will be opened before each read and closed after each read has completed for each included partial.
Source:
Type:

FileOptions

Template options for a Node.js file/system back-end. All file options inherit from TemplateOpts.

Properties:
Name Type Attributes Default Description
relativeTo String <optional>
.

The base directory path that will be used during file read/write operations for partial template content and generated rendering sources.

contextPath String <optional>
views

The path where the context JSON is located relative to the path set by relativeTo. The name of file is determined by TemplateOpts.defaultContextName.

templatePath String <optional>
views

The path where the primary template is located relative to the path set by relativeTo. The name of file is determined by TemplateOpts.defaultTemplateName. Since the primary template needs to be present prior to compiling, the option can only be used during compilation and is ignored during rendering.

partialsPath String <optional>
views/partials

The path where the partial templates are located/identified relative to the path set by relativeTo. Partials are small segments of template code that can be nested and reused throughout other templates. The path is used during read/write oprtations for prefixing file paths. Any sub-directories within partialsPath will be mirrored within the outputPath or temporary directory.

watchPaths Boolean <optional>

When true, any partialsPath directories discovered when registering partials from a read operation will be watched by the underlying operating system for file changes, adds, etc. When a change occurs the template partial will be registered/re-registered accordingly. The paths being watched are dependent upon FSWatcher support. See Node.js Fs.watch for more details. NOTE: When set to true at compile-time, all watched files will continue to be watched until engine.clearCache is called. When set to true at render-time, all watched files will continue to be watched until the rendering function is called with unwatchPaths set to true.

unwatchPaths Boolean <optional>

When true, all currently watchPaths will be unwatched for changes when the rendering function is called. The rendering function call will return without actually rendering.

outputPath String <optional>

When defined and a valid partialsPath is defined, compiled rendering function sources will be written to corresponding sub-directories mirrored during compilation and partial discovery from Engine.register reads. Omit to use the operating system's temporary directory.

outputPathTempPrefix String <optional>
templeo-files-

When outputPath is falsy the prefix will be used when generating a temporary directory. Otherwise, it's ignored.

Source:
Type:

Options

Template compilation options

Properties:
Name Type Attributes Default Description
useCommonJs Boolean <optional>
true

When true, CommonJS Module semantics will be used. When false, ECMAScript Module semantics will be used.

contextURL String <optional>
''

A base URL used as prefix for context read/write operations.

partialsURL String <optional>
''

A base URL used as prefix for partial template HTTP/S read/write operations.

bypassUrlRegExp RegExp <optional>
/^https?:\/?\/?[^:\/\s]+/i

An 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 String <optional>
'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 String <optional>
'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 String <optional>
'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 String <optional>
'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 String <optional>
'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 <optional>
'&nbsp;'

The value to use for a partial when a partial returns a non-string value.

renderTimePolicy String <optional>
read

The 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 Object <optional>

The 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 window.fetch, https.request, some other read operation or simply ignored.

writeFetchRequestOptions Object <optional>

The 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 window.fetch, https.request some other write operation or simply ignored.

readFormatOptions Object <optional>

The 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 Object <optional>

The 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 String <optional>
'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 String <optional>
'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 <optional>
/^(.*[\\\/]|^)([^\.]*)(.*)$/

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
  2. Pseudo file name w/o extension
  3. Extension with preceding .
cacheRawTemplates Boolean <optional>
true

If set to false, raw template content will not be cached (thus will perform a read on every use- NOT FOR PRODUCTION USE!)

useSourceURL Boolean <optional>
true

Whether or not to add a `//# sourceURL to generated rendering functions. Some option types may have a different default value.

debugger Boolean <optional>
false

When true, a debugger statement will be inserted into each compiled template rendering function at the end of execution (compile-time options only)

Source:
Type:
  • Object

1.0.0 (2019-12-16)

Full Changelog