/workspace/mergeTemplates
The workspace is cached in the module scope to allow for the mergeObjectTemplates(layer) method to assign template objects defined in a JSON layer to the workspace.templates{}.
Requires
- module:/utils/roles
- module:/utils/merge
- module:/utils/envReplace
- module:/workspace/getTemplate
- module:/workspace/cache
Methods
(inner) assignWorkspaceTemplates(obj)
The method parses an object for a template object property.
The template property value will be assigned to the workspace.templates{} object matching the template key value.
The template._type property will be set to 'template' indicating that the templates origin is in the workspace.
It is possible to overassign _type:'core' templates which are loaded from the /mod/workspace/templates directory.
The method will call itself for nested objects.
Name | Type | Description |
---|---|---|
obj | Object |
(async, inner) mergeTemplates(obj, rolesopt) → {Promise}
The mergeTemplates method will be called for a layer or locale obj.
The locale or layer object will be merged with a template defined as obj.template string property.
The method will check for a template matching the obj.key string property if obj.template is undefined.
An array of templates can be defined as obj.templates[]. The templates will be merged into the obj in the order the template keys are in the templates[] array.
Name | Type | Attributes | Description |
---|---|---|---|
obj | Object | ||
roles | array | <optional> | An array of user roles from request params. |
Name | Type | Attributes | Description |
---|---|---|---|
obj.template | string | <optional> | Key of template for the object. |
obj.key | string | Fallback for lookup of template if not an implicit property. | |
obj.templates | array | <optional> | An array of template keys to be merged into the object. |
The layer or locale provided as obj param.
- Type:
- Promise
(async, inner) objTemplate(obj, template, roles, reverse) → {Promise.<Object>}
The method will request a template object from the getTemplate module method.
Possible error from the template fetch will be added to the obj.err[] array before the obj is returned.
The template will be checked against the request user roles.
The method will shortcircuit if roles restrict access to the template object.
Otherwise the obj will be merged into the template.
The template will be merged into the obj with the reverse flag.
Name | Type | Description |
---|---|---|
obj | Object | |
template | Object | The template maybe an object with a src property or a string. |
roles | array | An array of user roles from request params. |
reverse | boolean | Whether template should be merged into the obj, not the other way around. |
Returns the merged obj.
- Type:
- Promise.<Object>