From 7dc22821a93b21fce579104aa252251693c5e3f9 Mon Sep 17 00:00:00 2001 From: Fenny <25108519+Fenny@users.noreply.github.com> Date: Wed, 17 Jun 2020 09:59:57 +0200 Subject: [PATCH] Improve reload --- amber/amber.go | 4 ++-- mustache/mustache.go | 5 +++-- pug/pug.go | 1 - 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/amber/amber.go b/amber/amber.go index db66fdc..23ed4a0 100644 --- a/amber/amber.go +++ b/amber/amber.go @@ -43,7 +43,6 @@ func New(directory, extension string) *Engine { extension: extension, layout: "embed", funcmap: make(map[string]interface{}), - Templates: make(map[string]*template.Template), } engine.AddFunc(engine.layout, func() error { return fmt.Errorf("layout called unexpectedly.") @@ -58,7 +57,6 @@ func NewFileSystem(fs http.FileSystem, extension string) *Engine { extension: extension, layout: "embed", funcmap: make(map[string]interface{}), - Templates: make(map[string]*template.Template), } engine.AddFunc(engine.layout, func() error { return fmt.Errorf("layout called unexpectedly.") @@ -115,6 +113,8 @@ func (e *Engine) Load() error { e.mutex.Lock() defer e.mutex.Unlock() + e.Templates = make(map[string]*template.Template) + // Set template settings // prepare the global amber funcs funcs := template.FuncMap{} diff --git a/mustache/mustache.go b/mustache/mustache.go index aa2cf95..152df2d 100644 --- a/mustache/mustache.go +++ b/mustache/mustache.go @@ -40,7 +40,6 @@ func New(directory, extension string) *Engine { directory: directory, extension: extension, layout: "embed", - Templates: make(map[string]*mustache.Template), } return engine } @@ -51,7 +50,6 @@ func NewFileSystem(fs http.FileSystem, extension string) *Engine { fileSystem: fs, extension: extension, layout: "embed", - Templates: make(map[string]*mustache.Template), } return engine } @@ -95,6 +93,9 @@ func (e *Engine) Load() error { // race safe e.mutex.Lock() defer e.mutex.Unlock() + + e.Templates = make(map[string]*mustache.Template) + // Loop trough each directory and register template files walkFn := func(path string, info os.FileInfo, err error) error { // Return error if exist diff --git a/pug/pug.go b/pug/pug.go index 7fbfb15..5c712ff 100644 --- a/pug/pug.go +++ b/pug/pug.go @@ -66,7 +66,6 @@ func NewFileSystem(fs http.FileSystem, extension string) *Engine { extension: extension, layout: "embed", funcmap: make(map[string]interface{}), - Templates: template.New("/"), } engine.AddFunc(engine.layout, func() error { return fmt.Errorf("layout called unexpectedly.")