Skip to content

Commit

Permalink
Merge branch 'master' into slim-funcmap
Browse files Browse the repository at this point in the history
  • Loading branch information
efectn authored May 20, 2023
2 parents 3f71525 + 9e393f1 commit d945a1b
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 115 deletions.
26 changes: 10 additions & 16 deletions ace/ace.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ type Engine struct {
reload bool
// debug prints the parsed templates
debug bool
// lock for funcmap and templates
// lock for funcMap and templates
mutex sync.RWMutex
// template funcmap
funcmap map[string]interface{}
// template funcMap
funcMap map[string]interface{}
// templates
Templates *template.Template
}
Expand All @@ -49,7 +49,7 @@ func New(directory, extension string) *Engine {
directory: directory,
extension: extension,
layout: "embed",
funcmap: make(map[string]interface{}),
funcMap: make(map[string]interface{}),
}
engine.AddFunc(engine.layout, func() error {
return fmt.Errorf("content called unexpectedly.")
Expand All @@ -65,7 +65,7 @@ func NewFileSystem(fs http.FileSystem, extension string) *Engine {
fileSystem: fs,
extension: extension,
layout: "embed",
funcmap: make(map[string]interface{}),
funcMap: make(map[string]interface{}),
}
engine.AddFunc(engine.layout, func() error {
return fmt.Errorf("content called unexpectedly.")
Expand All @@ -91,7 +91,7 @@ func (e *Engine) Delims(left, right string) *Engine {
// It is legal to overwrite elements of the default actions
func (e *Engine) AddFunc(name string, fn interface{}) *Engine {
e.mutex.Lock()
e.funcmap[name] = fn
e.funcMap[name] = fn
e.mutex.Unlock()
return e
}
Expand All @@ -101,7 +101,7 @@ func (e *Engine) AddFunc(name string, fn interface{}) *Engine {
func (e *Engine) AddFuncMap(m map[string]interface{}) *Engine {
e.mutex.Lock()
for name, fn := range m {
e.funcmap[name] = fn
e.funcMap[name] = fn
}
e.mutex.Unlock()
return e
Expand All @@ -121,12 +121,6 @@ func (e *Engine) Debug(enabled bool) *Engine {
return e
}

// Parse is deprecated, please use Load() instead
func (e *Engine) Parse() error {
fmt.Println("Parse() is deprecated, please use Load() instead.")
return e.Load()
}

// Load parses the templates to the engine.
func (e *Engine) Load() error {
// race safe
Expand All @@ -136,7 +130,7 @@ func (e *Engine) Load() error {
e.Templates = template.New(e.directory)

e.Templates.Delims(e.left, e.right)
e.Templates.Funcs(e.funcmap)
e.Templates.Funcs(e.funcMap)

// Loop trough each directory and register template files
walkFn := func(path string, info os.FileInfo, err error) error {
Expand Down Expand Up @@ -181,7 +175,7 @@ func (e *Engine) Load() error {
}
atmpl, err := ace.CompileResult(name, rslt, &ace.Options{
Extension: e.extension[1:],
FuncMap: e.funcmap,
FuncMap: e.funcMap,
DelimLeft: e.left,
DelimRight: e.right,
})
Expand Down Expand Up @@ -239,5 +233,5 @@ func (e *Engine) Render(out io.Writer, template string, binding interface{}, lay

// FuncMap returns the template's function map.
func (e *Engine) FuncMap() map[string]interface{} {
return e.funcmap
return e.funcMap
}
24 changes: 9 additions & 15 deletions amber/amber.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ type Engine struct {
reload bool
// debug prints the parsed templates
debug bool
// lock for funcmap and templates
// lock for funcMap and templates
mutex sync.RWMutex
// template funcmap
funcmap map[string]interface{}
// template funcMap
funcMap map[string]interface{}
// templates
Templates map[string]*template.Template
}
Expand All @@ -44,7 +44,7 @@ func New(directory, extension string) *Engine {
directory: directory,
extension: extension,
layout: "embed",
funcmap: make(map[string]interface{}),
funcMap: make(map[string]interface{}),
}
engine.AddFunc(engine.layout, func() error {
return fmt.Errorf("layout called unexpectedly.")
Expand All @@ -58,7 +58,7 @@ func NewFileSystem(fs http.FileSystem, extension string) *Engine {
fileSystem: fs,
extension: extension,
layout: "embed",
funcmap: make(map[string]interface{}),
funcMap: make(map[string]interface{}),
}
engine.AddFunc(engine.layout, func() error {
return fmt.Errorf("layout called unexpectedly.")
Expand All @@ -84,7 +84,7 @@ func (e *Engine) Delims(left, right string) *Engine {
// It is legal to overwrite elements of the default actions
func (e *Engine) AddFunc(name string, fn interface{}) *Engine {
e.mutex.Lock()
e.funcmap[name] = fn
e.funcMap[name] = fn
e.mutex.Unlock()
return e
}
Expand All @@ -94,7 +94,7 @@ func (e *Engine) AddFunc(name string, fn interface{}) *Engine {
func (e *Engine) AddFuncMap(m map[string]interface{}) *Engine {
e.mutex.Lock()
for name, fn := range m {
e.funcmap[name] = fn
e.funcMap[name] = fn
}
e.mutex.Unlock()
return e
Expand All @@ -114,12 +114,6 @@ func (e *Engine) Debug(enabled bool) *Engine {
return e
}

// Parse is deprecated, please use Load() instead
func (e *Engine) Parse() error {
fmt.Println("Parse() is deprecated, please use Load() instead.")
return e.Load()
}

// Load parses the templates to the engine.
func (e *Engine) Load() error {
// race safe
Expand All @@ -136,7 +130,7 @@ func (e *Engine) Load() error {
funcs[k] = v
}

for k, v := range e.funcmap {
for k, v := range e.funcMap {
funcs[k] = v
}

Expand Down Expand Up @@ -230,5 +224,5 @@ func (e *Engine) Render(out io.Writer, template string, binding interface{}, lay

// FuncMap returns the template's function map.
func (e *Engine) FuncMap() map[string]interface{} {
return e.funcmap
return e.funcMap
}
24 changes: 9 additions & 15 deletions django/django.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ type Engine struct {
debug bool
// forward the base path to the template engine
forwardPath bool
// lock for funcmap and templates
// lock for funcMap and templates
mutex sync.RWMutex
// template funcmap
funcmap map[string]interface{}
// template funcMap
funcMap map[string]interface{}
// templates
Templates map[string]*pongo2.Template
}
Expand All @@ -51,7 +51,7 @@ func New(directory, extension string) *Engine {
directory: directory,
extension: extension,
layout: "embed",
funcmap: make(map[string]interface{}),
funcMap: make(map[string]interface{}),
}
return engine
}
Expand All @@ -64,7 +64,7 @@ func NewFileSystem(fs http.FileSystem, extension string) *Engine {
fileSystem: fs,
extension: extension,
layout: "embed",
funcmap: make(map[string]interface{}),
funcMap: make(map[string]interface{}),
}
return engine
}
Expand Down Expand Up @@ -97,7 +97,7 @@ func (e *Engine) Delims(left, right string) *Engine {
// It is legal to overwrite elements of the default actions
func (e *Engine) AddFunc(name string, fn interface{}) *Engine {
e.mutex.Lock()
e.funcmap[name] = fn
e.funcMap[name] = fn
e.mutex.Unlock()
return e
}
Expand All @@ -107,7 +107,7 @@ func (e *Engine) AddFunc(name string, fn interface{}) *Engine {
func (e *Engine) AddFuncMap(m map[string]interface{}) *Engine {
e.mutex.Lock()
for name, fn := range m {
e.funcmap[name] = fn
e.funcMap[name] = fn
}
e.mutex.Unlock()
return e
Expand All @@ -127,12 +127,6 @@ func (e *Engine) Debug(enabled bool) *Engine {
return e
}

// Parse is deprecated, please use Load() instead
func (e *Engine) Parse() error {
fmt.Println("Parse() is deprecated, please use Load() instead.")
return e.Load()
}

// Load parses the templates to the engine.
func (e *Engine) Load() error {
// race safe
Expand All @@ -158,7 +152,7 @@ func (e *Engine) Load() error {
// New pongo2 defaultset
pongoset := pongo2.NewSet("default", pongoloader)
// Set template settings
pongoset.Globals.Update(e.funcmap)
pongoset.Globals.Update(e.funcMap)
pongo2.SetAutoescape(false)

// Loop trough each directory and register template files
Expand Down Expand Up @@ -273,5 +267,5 @@ func (e *Engine) Render(out io.Writer, template string, binding interface{}, lay

// FuncMap returns the template's function map.
func (e *Engine) FuncMap() map[string]interface{} {
return e.funcmap
return e.funcMap
}
24 changes: 9 additions & 15 deletions handlebars/handlebars.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ type Engine struct {
reload bool
// debug prints the parsed templates
debug bool
// lock for funcmap and templates
// lock for funcMap and templates
mutex sync.RWMutex
// object to bind custom helpers once
registerHelpersOnce sync.Once
// template funcmap
funcmap map[string]interface{}
// template funcMap
funcMap map[string]interface{}
// templates
Templates map[string]*raymond.Template
}
Expand All @@ -46,7 +46,7 @@ func New(directory, extension string) *Engine {
directory: directory,
extension: extension,
layout: "embed",
funcmap: make(map[string]interface{}),
funcMap: make(map[string]interface{}),
}
return engine
}
Expand All @@ -57,7 +57,7 @@ func NewFileSystem(fs http.FileSystem, extension string) *Engine {
fileSystem: fs,
extension: extension,
layout: "embed",
funcmap: make(map[string]interface{}),
funcMap: make(map[string]interface{}),
}
return engine
}
Expand All @@ -80,7 +80,7 @@ func (e *Engine) Layout(key string) *Engine {
// It is legal to overwrite elements of the default actions
func (e *Engine) AddFunc(name string, fn interface{}) *Engine {
e.mutex.Lock()
e.funcmap[name] = fn
e.funcMap[name] = fn
e.mutex.Unlock()
return e
}
Expand All @@ -90,7 +90,7 @@ func (e *Engine) AddFunc(name string, fn interface{}) *Engine {
func (e *Engine) AddFuncMap(m map[string]interface{}) *Engine {
e.mutex.Lock()
for name, fn := range m {
e.funcmap[name] = fn
e.funcMap[name] = fn
}
e.mutex.Unlock()
return e
Expand All @@ -110,12 +110,6 @@ func (e *Engine) Debug(enabled bool) *Engine {
return e
}

// Parse is deprecated, please use Load() instead
func (e *Engine) Parse() error {
fmt.Println("Parse() is deprecated, please use Load() instead.")
return e.Load()
}

// Parse parses the templates to the engine.
func (e *Engine) Load() (err error) {
// race safe
Expand All @@ -124,7 +118,7 @@ func (e *Engine) Load() (err error) {
// Set template settings
e.Templates = make(map[string]*raymond.Template)
e.registerHelpersOnce.Do(func() {
raymond.RegisterHelpers(e.funcmap)
raymond.RegisterHelpers(e.funcMap)
})
// Loop trough each directory and register template files
walkFn := func(path string, info os.FileInfo, err error) error {
Expand Down Expand Up @@ -240,5 +234,5 @@ func (e *Engine) Render(out io.Writer, template string, binding interface{}, lay

// FuncMap returns the template's function map.
func (e *Engine) FuncMap() map[string]interface{} {
return e.funcmap
return e.funcMap
}
Loading

0 comments on commit d945a1b

Please sign in to comment.