template-options
templeo/options
templeo options module
- templeo/options
- static
- .Options :
Object
- .Options :
- inner
- ~TemplateOpts
- new TemplateOpts([opts])
- instance
- .build(opts, optd, to, [valids]) ⇒
Object
- .build(opts, optd, to, [valids]) ⇒
- static
- .defaultOptions ⇒
Object|Object|Object - .defaultOptionMerge(options, to)
- .defaultOptions ⇒
- ~TemplateOpts
- static
templeo/options.Options : Object
Template compilation options
Kind: static typedef of templeo/options
Properties
| Name | Type | Default | Description |
|---|---|---|---|
| [useCommonJs] | Boolean | true | When 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] | RegExp | /^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 | '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 | '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 | '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 | '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 | '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] | String | 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 | 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 | 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 | 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 | 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 | '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 | '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 | `/^(.*[\/] | ^)([^.])(.)$/` |
| [cacheRawTemplates] | Boolean | 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 | true | Whether or not to add a `//# sourceURL to generated rendering functions. Some option types may have a different default value. |
| [debugger] | Boolean | false | When true, a debugger statement will be inserted into each compiled template rendering function at the end of execution (compile-time options only) |
templeo/options~TemplateOpts
Template compilation options. See Options for a full listing of options.
Kind: inner class of templeo/options
See: module:templeo/options.Options
- ~TemplateOpts
- new TemplateOpts([opts])
- instance
- .build(opts, optd, to, [valids]) ⇒
Object
- .build(opts, optd, to, [valids]) ⇒
- static
- .defaultOptions ⇒
Object|Object|Object - .defaultOptionMerge(options, to)
- .defaultOptions ⇒
new TemplateOpts([opts])
Template compilation options
| Param | Type | Description |
|---|---|---|
| [opts] | Options | The template compilation 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.
Kind: instance method of TemplateOpts
Returns: Object - The to object
See: module:templeo/options.Options
| Param | Type | Description |
|---|---|---|
| opts | Options | The template compilation options |
| optd | Object | An object that generatd from TemplateOpts.defaultOptionMerge that contains the default options |
| optd.defaults | Object | The object that contains option properties with default property values as the default values |
| [optd.valids] | Object | 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. |
| to | Object | The object where the options will be set- typically a TemplateOpts instance |
| [valids] | Object | An object that contains option names as properties. Each property should contain an Array of primitive values that represent valid values for a given option. |
TemplateOpts.defaultOptions ⇒ Object | Object | Object
Kind: static property of TemplateOpts
Returns: Object - An immutable object that describes how Options will be builtObject - defaults The object that contains option properties with default property values as the default valuesObject - valids 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: module:templeo/options.Options
TemplateOpts.defaultOptionMerge(options, to)
Merges option objects into another object
Kind: static method of TemplateOpts
Access: protected
| Param | Type | Description |
|---|---|---|
| options | Object | The option object to merge options from |
| to | Object | The object where that will be merged into |