some updates
This commit is contained in:
@@ -71,7 +71,6 @@ func parseYamlTemplate(input string) (block TemplateBlock, err error) {
|
||||
dec.KnownFields(true)
|
||||
|
||||
if err := dec.Decode(&blk); err != nil {
|
||||
fmt.Printf("Failed to parse:\n---\n%s\n---\n", cleaned)
|
||||
return block, err
|
||||
}
|
||||
|
||||
@@ -79,18 +78,46 @@ func parseYamlTemplate(input string) (block TemplateBlock, err error) {
|
||||
return block, fmt.Errorf("missing top-level 'path'")
|
||||
}
|
||||
|
||||
if blk.Codec == "" {
|
||||
blk.Codec = "text"
|
||||
}
|
||||
|
||||
codec, err := parseCodecType(blk.Codec)
|
||||
if err != nil {
|
||||
return block, fmt.Errorf("failed to parse codec: %w", err)
|
||||
}
|
||||
|
||||
var fields []BlockField
|
||||
|
||||
for _, field := range blk.Fields {
|
||||
if field.Path == "" {
|
||||
return block, fmt.Errorf("failed to parse field: %v", field)
|
||||
}
|
||||
|
||||
if field.Codec == "" {
|
||||
field.Codec = "text"
|
||||
}
|
||||
|
||||
fieldCodec, err := parseCodecType(field.Codec)
|
||||
if err != nil {
|
||||
return block, fmt.Errorf("failed to parse codec: %w", err)
|
||||
}
|
||||
|
||||
fields = append(fields, BlockField{
|
||||
Path: field.Path,
|
||||
CodecType: fieldCodec,
|
||||
Required: field.Required,
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
return TemplateBlock{
|
||||
Type: DataBlock,
|
||||
Path: blk.Path,
|
||||
Codec: codec,
|
||||
Fields: fields,
|
||||
content: input,
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
func ParseTemplateBlock(template string, blockType BlockType) (block TemplateBlock, err error) {
|
||||
@@ -102,17 +129,13 @@ func ParseTemplateBlock(template string, blockType BlockType) (block TemplateBlo
|
||||
}, nil
|
||||
}
|
||||
|
||||
block.Type = DataBlock
|
||||
block.content = template
|
||||
|
||||
templateType := DetectTemplateType(template)
|
||||
if templateType == InvalidTemplate {
|
||||
return block, fmt.Errorf("Invalid Template")
|
||||
}
|
||||
|
||||
if templateType == ShortTemplate {
|
||||
switch DetectTemplateType(template) {
|
||||
case ShortTemplate:
|
||||
return parseShortTemplate(template)
|
||||
case ExtendedTemplate:
|
||||
return parseYamlTemplate(template)
|
||||
}
|
||||
|
||||
return parseYamlTemplate(template)
|
||||
return block, fmt.Errorf("Invalid Template")
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user