Add Clone function

This commit is contained in:
Elara 2023-10-28 19:49:12 -07:00
parent ff838fe84d
commit fb7010dae3

View File

@ -6,6 +6,7 @@ import (
"fmt"
"html"
"io"
"maps"
"reflect"
"go.elara.ws/salix/internal/ast"
@ -55,6 +56,20 @@ func New() *Template {
return t.WithTagMap(defaultTags).WithFuncMap(defaultFuncs)
}
// Clone returns a shallow clone of a template.
func (t *Template) Clone() *Template {
return &Template{
file: t.file,
ast: t.ast,
escapeHTML: t.escapeHTML,
tags: maps.Clone(t.tags),
funcs: maps.Clone(t.funcs),
vars: maps.Clone(t.vars),
}
}
// WithFuncMap adds all the functions in m to the template's
// global function map. If a function with the given name already
// exists, it will be overwritten.