diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-02-05 10:20:06 +0700 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-02-17 17:15:26 +0100 |
commit | 93ca7c9e958e34469a337e4efcc7c75774ec50fd (patch) | |
tree | 5dfa296cfe74fd5ef8f0d41ea4078704f453aa04 /tpl/template.go | |
parent | e34af6ee30f70f5780a281e2fd8f4ed9b487ee61 (diff) |
all: Refactor to nonglobal Viper, i18n etc.
This is a final rewrite that removes all the global state in Hugo, which also enables
the use if `t.Parallel` in tests.
Updates #2701
Fixes #3016
Diffstat (limited to 'tpl/template.go')
-rw-r--r-- | tpl/template.go | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/tpl/template.go b/tpl/template.go index 844608014..9a6364d5a 100644 --- a/tpl/template.go +++ b/tpl/template.go @@ -21,6 +21,8 @@ import ( "path/filepath" "strings" + "sync" + "github.com/eknkc/amber" "github.com/spf13/afero" bp "github.com/spf13/hugo/bufferpool" @@ -31,6 +33,9 @@ import ( // TODO(bep) globals get rid of the rest of the jww.ERR etc. +// Protecting global map access (Amber) +var amberMu sync.Mutex + type templateErr struct { name string err error @@ -132,6 +137,7 @@ func (t *GoHTMLTemplate) initFuncs(d *deps.Deps) { t.amberFuncMap = template.FuncMap{} + amberMu.Lock() for k, v := range amber.FuncMap { t.amberFuncMap[k] = v } @@ -143,6 +149,7 @@ func (t *GoHTMLTemplate) initFuncs(d *deps.Deps) { panic("should never be invoked") } } + amberMu.Unlock() } @@ -362,7 +369,9 @@ func (t *GoHTMLTemplate) AddTemplateFile(name, baseTemplatePath, path string) er return err } + amberMu.Lock() templ, err := t.CompileAmberWithTemplate(b, path, t.New(templateName)) + amberMu.Unlock() if err != nil { return err } @@ -482,11 +491,11 @@ func (t *GoHTMLTemplate) loadTemplates(absPath string, prefix string) { } if needsBase { - layoutDir := helpers.GetLayoutDirPath() + layoutDir := t.PathSpec.GetLayoutDirPath() currBaseFilename := fmt.Sprintf("%s-%s", helpers.Filename(path), baseFileName) templateDir := filepath.Dir(path) - themeDir := filepath.Join(helpers.GetThemeDir()) - relativeThemeLayoutsDir := filepath.Join(helpers.GetRelativeThemeDir(), "layouts") + themeDir := filepath.Join(t.PathSpec.GetThemeDir()) + relativeThemeLayoutsDir := filepath.Join(t.PathSpec.GetRelativeThemeDir(), "layouts") var baseTemplatedDir string |