40 lines
773 B
Go
40 lines
773 B
Go
package template
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
func parseShortTemplate(input string) (Block, error) {
|
|
split := strings.Split(cleanTemplate(input), "|")
|
|
if len(split) < 1 {
|
|
return Block{}, fmt.Errorf("invalid short template")
|
|
}
|
|
|
|
block := Block{
|
|
Type: DataBlock,
|
|
Path: strings.TrimSpace(split[0]),
|
|
Codec: CodecText,
|
|
content: input,
|
|
}
|
|
|
|
if len(split) > 1 {
|
|
for option := range strings.SplitSeq(split[1], ",") {
|
|
switch strings.TrimSpace(option) {
|
|
case "number":
|
|
block.Codec = CodecNumber
|
|
case "text":
|
|
block.Codec = CodecText
|
|
case "hashtags":
|
|
block.Codec = CodecHashtags
|
|
case "optional":
|
|
block.Optional = true
|
|
default:
|
|
return block, fmt.Errorf("unknown codec option: %s", option)
|
|
}
|
|
}
|
|
}
|
|
|
|
return block, nil
|
|
}
|