Skip to content

Commit

Permalink
Merge pull request #999 from simon-leech/main
Browse files Browse the repository at this point in the history
Layer should be merged into workspace values
  • Loading branch information
RobAndrewHurst authored Nov 14, 2023
2 parents cacc06e + 52fb74d commit 4a547b7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
9 changes: 6 additions & 3 deletions mod/workspace/getLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,24 @@ module.exports = async (params) => {
return new Error('Unable to validate layer param.')
}

const layer = locale.layers[params.layer]
let layer = locale.layers[params.layer]

// Assign key value as key on layer object.
layer.key ??= params.layer

if (Object.hasOwn(workspace.templates, layer.template || layer.key)) {

merge(layer, await getTemplate(workspace.templates[layer.template || layer.key]))
// Merge the workspace template into the layer.
layer = merge(await getTemplate(workspace.templates[layer.template || layer.key]), layer)
}

if (Array.isArray(layer.templates)) {

// Merge templates from templates array into layer.
layer.templates.forEach(async template => {
merge(layer, await getTemplate(workspace.templates[template]))

// Merge the workspace template into the layer.
layer = merge(await getTemplate(workspace.templates[template]), layer)
})
}

Expand Down
4 changes: 2 additions & 2 deletions mod/workspace/getLocale.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = async (params) => {
return new Error('Unable to validate locale param.')
}

const locale = workspace.locales[params.locale]
let locale = workspace.locales[params.locale]

const roles = params.user?.roles || []

Expand All @@ -26,7 +26,7 @@ module.exports = async (params) => {
if (Object.hasOwn(workspace.templates, params.locale)) {

// Merge the workspace template into workspace.
merge(locale, await getTemplate(workspace.templates[params.locale]))
locale = merge(await getTemplate(workspace.templates[params.locale]), locale)
}

return locale
Expand Down
2 changes: 1 addition & 1 deletion mod/workspace/getTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module.exports = async (template) => {
if (typeof response === 'object') {

// Get template from src.
merge(template, response)
template = merge(response, template)

} else if (typeof response === 'string') {

Expand Down

0 comments on commit 4a547b7

Please sign in to comment.