feat: some experiments
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
// Package blocks contains the logic for parsing template blocks.
|
||||
// Package template contains the logic for parsing templates.
|
||||
package template
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -16,8 +15,8 @@ const (
|
||||
)
|
||||
|
||||
// DetectTemplateType checks if the template is short or long.
|
||||
func DetectTemplateType(tmpl string) TemplateType {
|
||||
trimmed := strings.TrimSpace(tmpl)
|
||||
func DetectTemplateType(tmpl Slice) TemplateType {
|
||||
trimmed := strings.TrimSpace(tmpl.String())
|
||||
|
||||
// Short type: starts with "{" and ends with "}" on a single line,
|
||||
// and contains "|" or "," inside for inline definition
|
||||
@@ -43,15 +42,15 @@ func DetectTemplateType(tmpl string) TemplateType {
|
||||
return InvalidTemplate
|
||||
}
|
||||
|
||||
func cleanTemplate(input string) string {
|
||||
s := strings.TrimSpace(input)
|
||||
func cleanTemplate(input Slice) string {
|
||||
s := strings.TrimSpace(input.String())
|
||||
s = strings.TrimPrefix(s, "{")
|
||||
s = strings.TrimSuffix(s, "}")
|
||||
s = strings.Trim(s, "\n")
|
||||
return s
|
||||
}
|
||||
|
||||
func ParseTemplateBlock(template string, blockType BlockType) (block Block, err error) {
|
||||
func ParseTemplateBlock(template Slice, blockType BlockType) (block Block, err error) {
|
||||
if blockType == MatchingBlock {
|
||||
return Block{
|
||||
Type: MatchingBlock,
|
||||
@@ -66,5 +65,5 @@ func ParseTemplateBlock(template string, blockType BlockType) (block Block, err
|
||||
return parseYamlTemplate(template)
|
||||
}
|
||||
|
||||
return block, fmt.Errorf("invalid template")
|
||||
return block, NewErrorf("invalid template").WithPosition(template.start, template.end)
|
||||
}
|
||||
|
Reference in New Issue
Block a user