generated from hugomods/template-mod
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow configurations nested extending
- Loading branch information
Showing
6 changed files
with
82 additions
and
15 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
layouts/partials/decap-cms/functions/compute-definition.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{{- $definitions := .definitions -}} | ||
{{- $name := .name -}} | ||
{{- $def := $definitions.Get $name -}} | ||
{{- $extends := default slice (index $def "_extends") -}} | ||
{{- if not (reflect.IsSlice $extends) }} | ||
{{- errorf "[decap-cms] %q _extends is not an array." $name }} | ||
{{- end }} | ||
{{- $merging := slice -}} | ||
{{- range $extends -}} | ||
{{- $parentName := . -}} | ||
{{- with $definitions.Get $parentName -}} | ||
{{- $parent := . -}} | ||
{{/* Handle nested extends. */}} | ||
{{- with index $parent "_extends" -}} | ||
{{- partial "decap-cms/functions/compute-definition" (dict "definitions" $definitions "name" $parentName) -}} | ||
{{- end -}} | ||
{{- $merging = $merging | append ($definitions.Get $parentName) -}} | ||
{{- else -}} | ||
{{- errorf "[decap-cms] no such extensible config: %s" $name -}} | ||
{{- end -}} | ||
{{- end -}} | ||
{{/* Override with the computed definition. */}} | ||
{{- with $merging -}} | ||
{{- $def = partial "decap-cms/functions/deep-merge" (. | append $def) -}} | ||
{{- $definitions.Set $name $def.Values -}} | ||
{{- end -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{{- $definitions := newScratch -}} | ||
{{/* Convert definitions from map to scratch. */}} | ||
{{- range $name, $def := . -}} | ||
{{- with $def.fields -}} | ||
{{- $fields := partial "decap-cms/functions/format-fields" . -}} | ||
{{- $def = merge $def (dict "fields" $fields) -}} | ||
{{- end -}} | ||
{{- $definitions.Set $name $def -}} | ||
{{- end -}} | ||
{{- range $name, $def := . -}} | ||
{{- partial "decap-cms/functions/compute-definition" (dict "definitions" $definitions "name" $name) -}} | ||
{{- end -}} | ||
{{- return $definitions.Values -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{{- $scratch := newScratch }} | ||
{{- range $key, $val := index . 0 }} | ||
{{- range $key, $val := . }} | ||
{{- $scratch.Set $key $val }} | ||
{{- end }} | ||
{{- return $scratch }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{{/* Format fields to add _weight and convert it to map if it's an array. */}} | ||
{{- $fields := newScratch -}} | ||
{{- with . -}} | ||
{{- $isMap := reflect.IsMap . -}} | ||
{{- $weight := 0 -}} | ||
{{- range $name, $field := . -}} | ||
{{- if isset $field "_weight" }} | ||
{{- continue }} | ||
{{- end }} | ||
{{- $field = merge $field (dict "_weight" (add $weight 1)) -}} | ||
{{- if not $isMap -}} | ||
{{- $name = $field.name -}} | ||
{{- end -}} | ||
{{- $fields.Set $name $field -}} | ||
{{- end -}} | ||
{{- end -}} | ||
{{- return $fields.Values -}} |