wp-go/app/theme/wp/components/widget/fn.go

27 lines
815 B
Go
Raw Permalink Normal View History

2023-03-28 13:45:20 +00:00
package widget
2023-05-03 15:57:49 +00:00
import (
2023-05-04 12:37:06 +00:00
"github.com/fthvgb1/wp-go/app/theme/wp"
"github.com/fthvgb1/wp-go/app/wpconfig"
2023-11-12 13:39:04 +00:00
"github.com/fthvgb1/wp-go/cache/reload"
2023-05-03 15:57:49 +00:00
"github.com/fthvgb1/wp-go/helper/maps"
str "github.com/fthvgb1/wp-go/helper/strings"
)
2023-03-28 13:45:20 +00:00
func Fn(id string, fn func(*wp.Handle, string) string) func(h *wp.Handle) string {
return func(h *wp.Handle) string {
return fn(h, id)
}
}
2023-05-03 15:57:49 +00:00
func configFns[K comparable, V any](m map[K]V, key string, a ...any) func(_ ...any) map[K]V {
return func(_ ...any) map[K]V {
c := wpconfig.GetPHPArrayVal[map[K]V](key, nil, a...)
return maps.FilterZeroMerge(maps.Copy(m), c)
}
}
func BuildconfigFn[K comparable, V any](m map[K]V, key string, a ...any) func(_ ...any) map[K]V {
return reload.BuildValFnWithAnyParams(str.Join("widget-config-", key), configFns(m, key, a...))
2023-05-03 15:57:49 +00:00
}