feat: added keyword codec (partially works)
This commit is contained in:
@@ -17,6 +17,8 @@ func ParseBlock(input string, block template.Block) (any, error) {
|
||||
return Yaml(input, block)
|
||||
case template.CodecList:
|
||||
return List(input, block)
|
||||
case template.CodecHashtags:
|
||||
return Keywords(input, block)
|
||||
}
|
||||
return nil, fmt.Errorf("unknown codec: %s", block.Codec)
|
||||
}
|
||||
|
19
parser/decoders/hashtags.go
Normal file
19
parser/decoders/hashtags.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package decoders
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"git.max-richter.dev/max/marka/template"
|
||||
)
|
||||
|
||||
func Keywords(input string, block template.Block) (value any, error error) {
|
||||
var tags []any
|
||||
split := strings.SplitSeq(input, "#")
|
||||
for tag := range split {
|
||||
tag = strings.TrimSpace(tag)
|
||||
if tag != "" {
|
||||
tags = append(tags, tag)
|
||||
}
|
||||
}
|
||||
return tags, nil
|
||||
}
|
@@ -18,16 +18,24 @@ func Yaml(input string, block template.Block) (value any, error error) {
|
||||
|
||||
var out any
|
||||
for _, f := range block.Fields {
|
||||
if f.Hidden {
|
||||
|
||||
if f.Path == "@schema" {
|
||||
continue
|
||||
}
|
||||
|
||||
if f.CodecType == template.CodecConst {
|
||||
if f.Value != nil {
|
||||
out = utils.SetPathValue(f.Path, f.Value, out)
|
||||
}
|
||||
} else {
|
||||
if value, ok := res[f.Path]; ok {
|
||||
out = utils.SetPathValue(f.Path, value, out)
|
||||
continue
|
||||
}
|
||||
|
||||
if value, ok := renderUtils.GetValueFromPath(res, f.Path); ok {
|
||||
out = utils.SetPathValue(f.Path, value, out)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user