Skip to content
Snippets Groups Projects
Commit ac12cd52 authored by Semyon Krestyaninov's avatar Semyon Krestyaninov :dog2:
Browse files

add comment

parent cd13b7f8
No related branches found
No related tags found
No related merge requests found
......@@ -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
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment