diff --git a/template/builder.go b/template/builder.go index a92e8ca3a39a3a9e4865d60f58efb535681f1693..c606622667c7b17628f5a6f18bae86b0e49e19c3 100644 --- a/template/builder.go +++ b/template/builder.go @@ -18,8 +18,6 @@ type Template interface { } type Builder struct { - parseFunc func(data string) (Template, error) - ctx context.Context cnt *content.Content SpaceID string @@ -31,6 +29,9 @@ type Builder struct { space *spaces.Space environment *environments.Environment collection *collections.Collection + + // templateFunc парсит строку и возвращает шаблон для подстановки значений + templateFunc func(data string) (Template, error) } func NewBuilder(cnt *content.Content, space, env, col string) Builder { @@ -41,7 +42,7 @@ func NewBuilder(cnt *content.Content, space, env, col string) Builder { EnvID: env, CollID: col, } - b.parseFunc = func(data string) (Template, error) { + b.templateFunc = func(data string) (Template, error) { return text.New("main_text").Funcs(b.getFuncs()).Parse(data) } return b @@ -55,7 +56,7 @@ func NewHTMLBuilder(cnt *content.Content, space, env, col string) Builder { EnvID: env, CollID: col, } - b.parseFunc = func(data string) (Template, error) { + b.templateFunc = func(data string) (Template, error) { return html.New("main_html").Funcs(b.getFuncs()).Parse(data) } return b @@ -112,7 +113,7 @@ func (b *Builder) Context() context.Context { func (b *Builder) Execute(str string, data ...any) (string, error) { buf := new(bytes.Buffer) - t, err := b.parseFunc(str) + t, err := b.templateFunc(str) if err != nil { return "", err } @@ -129,7 +130,7 @@ func (b *Builder) ExecuteList(str []string, data ...any) ([]string, error) { if tmpl == "" { continue } - t, err := b.parseFunc(tmpl) + t, err := b.templateFunc(tmpl) if err != nil { return []string{}, err }