From fb7010dae321643408dc10856de8484e8e2a5508 Mon Sep 17 00:00:00 2001 From: Elara Musayelyan Date: Sat, 28 Oct 2023 19:49:12 -0700 Subject: [PATCH] Add Clone function --- salix.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/salix.go b/salix.go index 73bc294..5fff137 100644 --- a/salix.go +++ b/salix.go @@ -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.