Add Clone function
This commit is contained in:
		
							
								
								
									
										15
									
								
								salix.go
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								salix.go
									
									
									
									
									
								
							| @@ -6,6 +6,7 @@ import ( | |||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"html" | 	"html" | ||||||
| 	"io" | 	"io" | ||||||
|  | 	"maps" | ||||||
| 	"reflect" | 	"reflect" | ||||||
|  |  | ||||||
| 	"go.elara.ws/salix/internal/ast" | 	"go.elara.ws/salix/internal/ast" | ||||||
| @@ -55,6 +56,20 @@ func New() *Template { | |||||||
| 	return t.WithTagMap(defaultTags).WithFuncMap(defaultFuncs) | 	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 | // WithFuncMap adds all the functions in m to the template's | ||||||
| // global function map. If a function with the given name already | // global function map. If a function with the given name already | ||||||
| // exists, it will be overwritten. | // exists, it will be overwritten. | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user