Add support for theme composition and inheritance
This commit adds support for theme composition and inheritance in Hugo.
With this, it helps thinking about a theme as a set of ordered components:
```toml
theme = ["my-shortcodes", "base-theme", "hyde"]
```
The theme definition example above in `config.toml` creates a theme with the 3 components with presedence from left to right.
So, Hugo will, for any given file, data entry etc., look first in the project, and then in `my-shortcode`, `base-theme` and lastly `hyde`.
Hugo uses two different algorithms to merge the filesystems, depending on the file type:
* For `i18n` and `data` files, Hugo merges deeply using the translation id and data key inside the files.
* For `static`, `layouts` (templates) and `archetypes` files, these are merged on file level. So the left-most file will be chosen.
The name used in the `theme` definition above must match a folder in `/your-site/themes`, e.g. `/your-site/themes/my-shortcodes`. There are plans to improve on this and get a URL scheme so this can be resolved automatically.
Also note that a component that is part of a theme can have its own configuration file, e.g. `config.toml`. There are currently some restrictions to what a theme component can configure:
* `params` (global and per language)
* `menu` (global and per language)
* `outputformats` and `mediatypes`
The same rules apply here: The left-most param/menu etc. with the same ID will win. There are some hidden and experimental namespace support in the above, which we will work to improve in the future, but theme authors are encouraged to create their own namespaces to avoid naming conflicts.
A final note: Themes/components can also have a `theme` definition in their `config.toml` and similar, which is the "inheritance" part of this commit's title. This is currently not supported by the Hugo theme site. We will have to wait for some "auto dependency" feature to be implemented for that to happen, but this can be a powerful feature if you want to create your own theme-variant based on others.
Fixes #4460
Fixes #4450
2018-03-01 14:01:25 +00:00
|
|
|
// Copyright 2018 The Hugo Authors. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package maps
|
|
|
|
|
|
|
|
import (
|
2020-10-22 17:14:14 +00:00
|
|
|
"fmt"
|
Add support for theme composition and inheritance
This commit adds support for theme composition and inheritance in Hugo.
With this, it helps thinking about a theme as a set of ordered components:
```toml
theme = ["my-shortcodes", "base-theme", "hyde"]
```
The theme definition example above in `config.toml` creates a theme with the 3 components with presedence from left to right.
So, Hugo will, for any given file, data entry etc., look first in the project, and then in `my-shortcode`, `base-theme` and lastly `hyde`.
Hugo uses two different algorithms to merge the filesystems, depending on the file type:
* For `i18n` and `data` files, Hugo merges deeply using the translation id and data key inside the files.
* For `static`, `layouts` (templates) and `archetypes` files, these are merged on file level. So the left-most file will be chosen.
The name used in the `theme` definition above must match a folder in `/your-site/themes`, e.g. `/your-site/themes/my-shortcodes`. There are plans to improve on this and get a URL scheme so this can be resolved automatically.
Also note that a component that is part of a theme can have its own configuration file, e.g. `config.toml`. There are currently some restrictions to what a theme component can configure:
* `params` (global and per language)
* `menu` (global and per language)
* `outputformats` and `mediatypes`
The same rules apply here: The left-most param/menu etc. with the same ID will win. There are some hidden and experimental namespace support in the above, which we will work to improve in the future, but theme authors are encouraged to create their own namespaces to avoid naming conflicts.
A final note: Themes/components can also have a `theme` definition in their `config.toml` and similar, which is the "inheritance" part of this commit's title. This is currently not supported by the Hugo theme site. We will have to wait for some "auto dependency" feature to be implemented for that to happen, but this can be a powerful feature if you want to create your own theme-variant based on others.
Fixes #4460
Fixes #4450
2018-03-01 14:01:25 +00:00
|
|
|
"strings"
|
|
|
|
|
2021-07-30 08:56:45 +00:00
|
|
|
"github.com/gohugoio/hugo/common/types"
|
|
|
|
|
2018-11-15 08:28:02 +00:00
|
|
|
"github.com/gobwas/glob"
|
Add support for theme composition and inheritance
This commit adds support for theme composition and inheritance in Hugo.
With this, it helps thinking about a theme as a set of ordered components:
```toml
theme = ["my-shortcodes", "base-theme", "hyde"]
```
The theme definition example above in `config.toml` creates a theme with the 3 components with presedence from left to right.
So, Hugo will, for any given file, data entry etc., look first in the project, and then in `my-shortcode`, `base-theme` and lastly `hyde`.
Hugo uses two different algorithms to merge the filesystems, depending on the file type:
* For `i18n` and `data` files, Hugo merges deeply using the translation id and data key inside the files.
* For `static`, `layouts` (templates) and `archetypes` files, these are merged on file level. So the left-most file will be chosen.
The name used in the `theme` definition above must match a folder in `/your-site/themes`, e.g. `/your-site/themes/my-shortcodes`. There are plans to improve on this and get a URL scheme so this can be resolved automatically.
Also note that a component that is part of a theme can have its own configuration file, e.g. `config.toml`. There are currently some restrictions to what a theme component can configure:
* `params` (global and per language)
* `menu` (global and per language)
* `outputformats` and `mediatypes`
The same rules apply here: The left-most param/menu etc. with the same ID will win. There are some hidden and experimental namespace support in the above, which we will work to improve in the future, but theme authors are encouraged to create their own namespaces to avoid naming conflicts.
A final note: Themes/components can also have a `theme` definition in their `config.toml` and similar, which is the "inheritance" part of this commit's title. This is currently not supported by the Hugo theme site. We will have to wait for some "auto dependency" feature to be implemented for that to happen, but this can be a powerful feature if you want to create your own theme-variant based on others.
Fixes #4460
Fixes #4450
2018-03-01 14:01:25 +00:00
|
|
|
"github.com/spf13/cast"
|
|
|
|
)
|
|
|
|
|
2021-06-09 08:58:18 +00:00
|
|
|
// ToStringMapE converts in to map[string]interface{}.
|
2022-03-17 21:03:27 +00:00
|
|
|
func ToStringMapE(in any) (map[string]any, error) {
|
2021-06-09 08:58:18 +00:00
|
|
|
switch vv := in.(type) {
|
|
|
|
case Params:
|
|
|
|
return vv, nil
|
|
|
|
case map[string]string:
|
2022-03-17 21:03:27 +00:00
|
|
|
var m = map[string]any{}
|
2021-06-09 08:58:18 +00:00
|
|
|
for k, v := range vv {
|
|
|
|
m[k] = v
|
Add support for theme composition and inheritance
This commit adds support for theme composition and inheritance in Hugo.
With this, it helps thinking about a theme as a set of ordered components:
```toml
theme = ["my-shortcodes", "base-theme", "hyde"]
```
The theme definition example above in `config.toml` creates a theme with the 3 components with presedence from left to right.
So, Hugo will, for any given file, data entry etc., look first in the project, and then in `my-shortcode`, `base-theme` and lastly `hyde`.
Hugo uses two different algorithms to merge the filesystems, depending on the file type:
* For `i18n` and `data` files, Hugo merges deeply using the translation id and data key inside the files.
* For `static`, `layouts` (templates) and `archetypes` files, these are merged on file level. So the left-most file will be chosen.
The name used in the `theme` definition above must match a folder in `/your-site/themes`, e.g. `/your-site/themes/my-shortcodes`. There are plans to improve on this and get a URL scheme so this can be resolved automatically.
Also note that a component that is part of a theme can have its own configuration file, e.g. `config.toml`. There are currently some restrictions to what a theme component can configure:
* `params` (global and per language)
* `menu` (global and per language)
* `outputformats` and `mediatypes`
The same rules apply here: The left-most param/menu etc. with the same ID will win. There are some hidden and experimental namespace support in the above, which we will work to improve in the future, but theme authors are encouraged to create their own namespaces to avoid naming conflicts.
A final note: Themes/components can also have a `theme` definition in their `config.toml` and similar, which is the "inheritance" part of this commit's title. This is currently not supported by the Hugo theme site. We will have to wait for some "auto dependency" feature to be implemented for that to happen, but this can be a powerful feature if you want to create your own theme-variant based on others.
Fixes #4460
Fixes #4450
2018-03-01 14:01:25 +00:00
|
|
|
}
|
2021-06-09 08:58:18 +00:00
|
|
|
return m, nil
|
Add support for theme composition and inheritance
This commit adds support for theme composition and inheritance in Hugo.
With this, it helps thinking about a theme as a set of ordered components:
```toml
theme = ["my-shortcodes", "base-theme", "hyde"]
```
The theme definition example above in `config.toml` creates a theme with the 3 components with presedence from left to right.
So, Hugo will, for any given file, data entry etc., look first in the project, and then in `my-shortcode`, `base-theme` and lastly `hyde`.
Hugo uses two different algorithms to merge the filesystems, depending on the file type:
* For `i18n` and `data` files, Hugo merges deeply using the translation id and data key inside the files.
* For `static`, `layouts` (templates) and `archetypes` files, these are merged on file level. So the left-most file will be chosen.
The name used in the `theme` definition above must match a folder in `/your-site/themes`, e.g. `/your-site/themes/my-shortcodes`. There are plans to improve on this and get a URL scheme so this can be resolved automatically.
Also note that a component that is part of a theme can have its own configuration file, e.g. `config.toml`. There are currently some restrictions to what a theme component can configure:
* `params` (global and per language)
* `menu` (global and per language)
* `outputformats` and `mediatypes`
The same rules apply here: The left-most param/menu etc. with the same ID will win. There are some hidden and experimental namespace support in the above, which we will work to improve in the future, but theme authors are encouraged to create their own namespaces to avoid naming conflicts.
A final note: Themes/components can also have a `theme` definition in their `config.toml` and similar, which is the "inheritance" part of this commit's title. This is currently not supported by the Hugo theme site. We will have to wait for some "auto dependency" feature to be implemented for that to happen, but this can be a powerful feature if you want to create your own theme-variant based on others.
Fixes #4460
Fixes #4450
2018-03-01 14:01:25 +00:00
|
|
|
|
2021-06-09 08:58:18 +00:00
|
|
|
default:
|
|
|
|
return cast.ToStringMapE(in)
|
2019-11-21 20:59:38 +00:00
|
|
|
}
|
|
|
|
}
|
Add support for theme composition and inheritance
This commit adds support for theme composition and inheritance in Hugo.
With this, it helps thinking about a theme as a set of ordered components:
```toml
theme = ["my-shortcodes", "base-theme", "hyde"]
```
The theme definition example above in `config.toml` creates a theme with the 3 components with presedence from left to right.
So, Hugo will, for any given file, data entry etc., look first in the project, and then in `my-shortcode`, `base-theme` and lastly `hyde`.
Hugo uses two different algorithms to merge the filesystems, depending on the file type:
* For `i18n` and `data` files, Hugo merges deeply using the translation id and data key inside the files.
* For `static`, `layouts` (templates) and `archetypes` files, these are merged on file level. So the left-most file will be chosen.
The name used in the `theme` definition above must match a folder in `/your-site/themes`, e.g. `/your-site/themes/my-shortcodes`. There are plans to improve on this and get a URL scheme so this can be resolved automatically.
Also note that a component that is part of a theme can have its own configuration file, e.g. `config.toml`. There are currently some restrictions to what a theme component can configure:
* `params` (global and per language)
* `menu` (global and per language)
* `outputformats` and `mediatypes`
The same rules apply here: The left-most param/menu etc. with the same ID will win. There are some hidden and experimental namespace support in the above, which we will work to improve in the future, but theme authors are encouraged to create their own namespaces to avoid naming conflicts.
A final note: Themes/components can also have a `theme` definition in their `config.toml` and similar, which is the "inheritance" part of this commit's title. This is currently not supported by the Hugo theme site. We will have to wait for some "auto dependency" feature to be implemented for that to happen, but this can be a powerful feature if you want to create your own theme-variant based on others.
Fixes #4460
Fixes #4450
2018-03-01 14:01:25 +00:00
|
|
|
|
2021-06-09 08:58:18 +00:00
|
|
|
// ToParamsAndPrepare converts in to Params and prepares it for use.
|
2021-07-30 08:56:45 +00:00
|
|
|
// If in is nil, an empty map is returned.
|
2021-06-09 08:58:18 +00:00
|
|
|
// See PrepareParams.
|
2023-01-04 17:24:36 +00:00
|
|
|
func ToParamsAndPrepare(in any) (Params, error) {
|
2021-07-30 08:56:45 +00:00
|
|
|
if types.IsNil(in) {
|
2023-01-04 17:24:36 +00:00
|
|
|
return Params{}, nil
|
2021-07-30 08:56:45 +00:00
|
|
|
}
|
2021-06-09 08:58:18 +00:00
|
|
|
m, err := ToStringMapE(in)
|
|
|
|
if err != nil {
|
2023-01-04 17:24:36 +00:00
|
|
|
return nil, err
|
Add support for theme composition and inheritance
This commit adds support for theme composition and inheritance in Hugo.
With this, it helps thinking about a theme as a set of ordered components:
```toml
theme = ["my-shortcodes", "base-theme", "hyde"]
```
The theme definition example above in `config.toml` creates a theme with the 3 components with presedence from left to right.
So, Hugo will, for any given file, data entry etc., look first in the project, and then in `my-shortcode`, `base-theme` and lastly `hyde`.
Hugo uses two different algorithms to merge the filesystems, depending on the file type:
* For `i18n` and `data` files, Hugo merges deeply using the translation id and data key inside the files.
* For `static`, `layouts` (templates) and `archetypes` files, these are merged on file level. So the left-most file will be chosen.
The name used in the `theme` definition above must match a folder in `/your-site/themes`, e.g. `/your-site/themes/my-shortcodes`. There are plans to improve on this and get a URL scheme so this can be resolved automatically.
Also note that a component that is part of a theme can have its own configuration file, e.g. `config.toml`. There are currently some restrictions to what a theme component can configure:
* `params` (global and per language)
* `menu` (global and per language)
* `outputformats` and `mediatypes`
The same rules apply here: The left-most param/menu etc. with the same ID will win. There are some hidden and experimental namespace support in the above, which we will work to improve in the future, but theme authors are encouraged to create their own namespaces to avoid naming conflicts.
A final note: Themes/components can also have a `theme` definition in their `config.toml` and similar, which is the "inheritance" part of this commit's title. This is currently not supported by the Hugo theme site. We will have to wait for some "auto dependency" feature to be implemented for that to happen, but this can be a powerful feature if you want to create your own theme-variant based on others.
Fixes #4460
Fixes #4450
2018-03-01 14:01:25 +00:00
|
|
|
}
|
2021-06-09 08:58:18 +00:00
|
|
|
PrepareParams(m)
|
2023-01-04 17:24:36 +00:00
|
|
|
return m, nil
|
Add support for theme composition and inheritance
This commit adds support for theme composition and inheritance in Hugo.
With this, it helps thinking about a theme as a set of ordered components:
```toml
theme = ["my-shortcodes", "base-theme", "hyde"]
```
The theme definition example above in `config.toml` creates a theme with the 3 components with presedence from left to right.
So, Hugo will, for any given file, data entry etc., look first in the project, and then in `my-shortcode`, `base-theme` and lastly `hyde`.
Hugo uses two different algorithms to merge the filesystems, depending on the file type:
* For `i18n` and `data` files, Hugo merges deeply using the translation id and data key inside the files.
* For `static`, `layouts` (templates) and `archetypes` files, these are merged on file level. So the left-most file will be chosen.
The name used in the `theme` definition above must match a folder in `/your-site/themes`, e.g. `/your-site/themes/my-shortcodes`. There are plans to improve on this and get a URL scheme so this can be resolved automatically.
Also note that a component that is part of a theme can have its own configuration file, e.g. `config.toml`. There are currently some restrictions to what a theme component can configure:
* `params` (global and per language)
* `menu` (global and per language)
* `outputformats` and `mediatypes`
The same rules apply here: The left-most param/menu etc. with the same ID will win. There are some hidden and experimental namespace support in the above, which we will work to improve in the future, but theme authors are encouraged to create their own namespaces to avoid naming conflicts.
A final note: Themes/components can also have a `theme` definition in their `config.toml` and similar, which is the "inheritance" part of this commit's title. This is currently not supported by the Hugo theme site. We will have to wait for some "auto dependency" feature to be implemented for that to happen, but this can be a powerful feature if you want to create your own theme-variant based on others.
Fixes #4460
Fixes #4450
2018-03-01 14:01:25 +00:00
|
|
|
}
|
2018-11-15 08:28:02 +00:00
|
|
|
|
2021-06-22 07:53:37 +00:00
|
|
|
// MustToParamsAndPrepare calls ToParamsAndPrepare and panics if it fails.
|
2022-03-17 21:03:27 +00:00
|
|
|
func MustToParamsAndPrepare(in any) Params {
|
2023-01-04 17:24:36 +00:00
|
|
|
p, err := ToParamsAndPrepare(in)
|
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Sprintf("cannot convert %T to maps.Params: %s", in, err))
|
2021-06-22 07:53:37 +00:00
|
|
|
}
|
2023-01-04 17:24:36 +00:00
|
|
|
return p
|
2021-06-22 07:53:37 +00:00
|
|
|
}
|
|
|
|
|
2021-06-09 08:58:18 +00:00
|
|
|
// ToStringMap converts in to map[string]interface{}.
|
2022-03-17 21:03:27 +00:00
|
|
|
func ToStringMap(in any) map[string]any {
|
2019-11-21 20:59:38 +00:00
|
|
|
m, _ := ToStringMapE(in)
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-06-09 08:58:18 +00:00
|
|
|
// ToStringMapStringE converts in to map[string]string.
|
2022-03-17 21:03:27 +00:00
|
|
|
func ToStringMapStringE(in any) (map[string]string, error) {
|
2021-06-09 08:58:18 +00:00
|
|
|
m, err := ToStringMapE(in)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return cast.ToStringMapStringE(m)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToStringMapString converts in to map[string]string.
|
2022-03-17 21:03:27 +00:00
|
|
|
func ToStringMapString(in any) map[string]string {
|
2021-06-09 08:58:18 +00:00
|
|
|
m, _ := ToStringMapStringE(in)
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToStringMapBool converts in to bool.
|
2022-03-17 21:03:27 +00:00
|
|
|
func ToStringMapBool(in any) map[string]bool {
|
2021-06-09 08:58:18 +00:00
|
|
|
m, _ := ToStringMapE(in)
|
|
|
|
return cast.ToStringMapBool(m)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToSliceStringMap converts in to []map[string]interface{}.
|
2022-03-17 21:03:27 +00:00
|
|
|
func ToSliceStringMap(in any) ([]map[string]any, error) {
|
2020-10-22 17:14:14 +00:00
|
|
|
switch v := in.(type) {
|
2022-03-17 21:03:27 +00:00
|
|
|
case []map[string]any:
|
2020-10-22 17:14:14 +00:00
|
|
|
return v, nil
|
2023-01-04 17:24:36 +00:00
|
|
|
case Params:
|
|
|
|
return []map[string]any{v}, nil
|
2022-03-17 21:03:27 +00:00
|
|
|
case []any:
|
|
|
|
var s []map[string]any
|
2020-10-22 17:14:14 +00:00
|
|
|
for _, entry := range v {
|
2022-03-17 21:03:27 +00:00
|
|
|
if vv, ok := entry.(map[string]any); ok {
|
2020-10-22 17:14:14 +00:00
|
|
|
s = append(s, vv)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return s, nil
|
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("unable to cast %#v of type %T to []map[string]interface{}", in, in)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-11 08:34:08 +00:00
|
|
|
// LookupEqualFold finds key in m with case insensitive equality checks.
|
|
|
|
func LookupEqualFold[T any | string](m map[string]T, key string) (T, bool) {
|
|
|
|
if v, found := m[key]; found {
|
|
|
|
return v, true
|
|
|
|
}
|
|
|
|
for k, v := range m {
|
|
|
|
if strings.EqualFold(k, key) {
|
|
|
|
return v, true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var s T
|
|
|
|
return s, false
|
|
|
|
}
|
|
|
|
|
2023-01-04 17:24:36 +00:00
|
|
|
// MergeShallow merges src into dst, but only if the key does not already exist in dst.
|
|
|
|
// The keys are compared case insensitively.
|
|
|
|
func MergeShallow(dst, src map[string]any) {
|
|
|
|
for k, v := range src {
|
|
|
|
found := false
|
|
|
|
for dk := range dst {
|
|
|
|
if strings.EqualFold(dk, k) {
|
|
|
|
found = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !found {
|
|
|
|
dst[k] = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-15 08:28:02 +00:00
|
|
|
type keyRename struct {
|
|
|
|
pattern glob.Glob
|
|
|
|
newKey string
|
|
|
|
}
|
|
|
|
|
|
|
|
// KeyRenamer supports renaming of keys in a map.
|
|
|
|
type KeyRenamer struct {
|
|
|
|
renames []keyRename
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewKeyRenamer creates a new KeyRenamer given a list of pattern and new key
|
|
|
|
// value pairs.
|
|
|
|
func NewKeyRenamer(patternKeys ...string) (KeyRenamer, error) {
|
|
|
|
var renames []keyRename
|
|
|
|
for i := 0; i < len(patternKeys); i += 2 {
|
|
|
|
g, err := glob.Compile(strings.ToLower(patternKeys[i]), '/')
|
|
|
|
if err != nil {
|
|
|
|
return KeyRenamer{}, err
|
|
|
|
}
|
|
|
|
renames = append(renames, keyRename{pattern: g, newKey: patternKeys[i+1]})
|
|
|
|
}
|
|
|
|
|
|
|
|
return KeyRenamer{renames: renames}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r KeyRenamer) getNewKey(keyPath string) string {
|
|
|
|
for _, matcher := range r.renames {
|
|
|
|
if matcher.pattern.Match(keyPath) {
|
|
|
|
return matcher.newKey
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rename renames the keys in the given map according
|
|
|
|
// to the patterns in the current KeyRenamer.
|
2022-03-17 21:03:27 +00:00
|
|
|
func (r KeyRenamer) Rename(m map[string]any) {
|
2018-11-15 08:28:02 +00:00
|
|
|
r.renamePath("", m)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (KeyRenamer) keyPath(k1, k2 string) string {
|
|
|
|
k1, k2 = strings.ToLower(k1), strings.ToLower(k2)
|
|
|
|
if k1 == "" {
|
|
|
|
return k2
|
|
|
|
}
|
2021-06-09 08:58:18 +00:00
|
|
|
return k1 + "/" + k2
|
2018-11-15 08:28:02 +00:00
|
|
|
}
|
|
|
|
|
2022-03-17 21:03:27 +00:00
|
|
|
func (r KeyRenamer) renamePath(parentKeyPath string, m map[string]any) {
|
2018-11-15 08:28:02 +00:00
|
|
|
for key, val := range m {
|
|
|
|
keyPath := r.keyPath(parentKeyPath, key)
|
|
|
|
switch val.(type) {
|
2022-03-17 21:03:27 +00:00
|
|
|
case map[any]any:
|
2018-11-15 08:28:02 +00:00
|
|
|
val = cast.ToStringMap(val)
|
2022-03-17 21:03:27 +00:00
|
|
|
r.renamePath(keyPath, val.(map[string]any))
|
|
|
|
case map[string]any:
|
|
|
|
r.renamePath(keyPath, val.(map[string]any))
|
2018-11-15 08:28:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
newKey := r.getNewKey(keyPath)
|
|
|
|
|
|
|
|
if newKey != "" {
|
|
|
|
delete(m, key)
|
|
|
|
m[newKey] = val
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|