Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Layer should be merged into workspace values #999

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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