/workspace/getTemplate
The module exports the getTemplate method which is required by the query, languageTemplates, getLayer, and getLocale modules.
Requires
- module:/provider/getFrom
- module:/workspace/cache
- module:/utils/processEnv
Methods
(async, inner) cacheTemplate(workspace, template, responseopt) → {Promise.<(Object|Error)>}
The method assigns the response object to the template object and removes the src property.
This effectively caches the template since the src to fetch the template is removed.
A src property is assigned as key for an object without an key property.
This allows to cache templates which should be merged into their respective parent objects.
A src property beginning with file: is not removed since file resources do not require caching.
| Name | Type | Attributes | Description |
|---|---|---|---|
workspace | workspace | ||
template | object | ||
response | object | <optional> | An object from a template src |
JSON Template
- Type:
- Promise.<(Object|Error)>
(async, inner) getTemplate(key, cache) → {Promise.<(Object|Error)>}
The workspace will be checked and cached by the Workspace API checkWorkspaceCache method.
A JSON template object will be requested from the getTemplateObject method.
An error will be returned if the lookup failed.
A template will be fetched from the templates src property.
A template can be cached by removing the src property in the workspace.templates.
The key will be assigned to the template object as key property.
| Name | Type | Description |
|---|---|---|
key | string | |
cache | boolean | Templates should be cached and not requested multiple times. |
JSON Template
- Type:
- Promise.<(Object|Error)>
(async, inner) getTemplateObject(template) → {Promise.<(Object|Error)>}
A template object matching the template_key param in the workspace.templates{} object will be returned.
The template string will be checked to include only whitelisted characters.
An error exception will be returned if the template object lookup from the workspace failed.
| Name | Type | Description |
|---|---|---|
template | string |
JSON Template
- Type:
- Promise.<(Object|Error)>
(async, inner) moduleTemplate(template, response) → {Promise.<(Object|Error)>}
The script string is converted to a JavaScript data URL which can be used in a dynamic ESM import.
The default export or the imported module itself will be assigned as the render method in the module template.
Module templates are not cached.
| Name | Type | Description |
|---|---|---|
template | object | |
response | string | Module script as string. |
JSON Template
- Type:
- Promise.<(Object|Error)>