diff options
Diffstat (limited to 'deps')
-rw-r--r-- | deps/deps.go | 37 | ||||
-rw-r--r-- | deps/deps_test.go | 28 |
2 files changed, 60 insertions, 5 deletions
diff --git a/deps/deps.go b/deps/deps.go index ecbba2e56..092a0b887 100644 --- a/deps/deps.go +++ b/deps/deps.go @@ -5,6 +5,7 @@ import ( "time" "github.com/pkg/errors" + "go.uber.org/atomic" "github.com/gohugoio/hugo/cache/filecache" "github.com/gohugoio/hugo/common/loggers" @@ -38,10 +39,10 @@ type Deps struct { DistinctWarningLog *helpers.DistinctLogger // The templates to use. This will usually implement the full tpl.TemplateManager. - Tmpl tpl.TemplateHandler `json:"-"` + tmpl tpl.TemplateHandler // We use this to parse and execute ad-hoc text templates. - TextTmpl tpl.TemplateParseFinder `json:"-"` + textTmpl tpl.TemplateParseFinder // The file systems to use. Fs *hugofs.Fs `json:"-"` @@ -92,6 +93,9 @@ type Deps struct { // BuildStartListeners will be notified before a build starts. BuildStartListeners *Listeners + // Atomic flags set during a build. + BuildFlags BuildFlags + *globalErrHandler } @@ -153,9 +157,20 @@ type ResourceProvider interface { Clone(deps *Deps) error } -// TemplateHandler returns the used tpl.TemplateFinder as tpl.TemplateHandler. -func (d *Deps) TemplateHandler() tpl.TemplateManager { - return d.Tmpl.(tpl.TemplateManager) +func (d *Deps) Tmpl() tpl.TemplateHandler { + return d.tmpl +} + +func (d *Deps) TextTmpl() tpl.TemplateParseFinder { + return d.textTmpl +} + +func (d *Deps) SetTmpl(tmpl tpl.TemplateHandler) { + d.tmpl = tmpl +} + +func (d *Deps) SetTextTmpl(tmpl tpl.TemplateParseFinder) { + d.textTmpl = tmpl } // LoadResources loads translations and templates. @@ -315,6 +330,7 @@ func (d Deps) ForLanguage(cfg DepsCfg, onCreated func(d *Deps) error) (*Deps, er } d.BuildStartListeners = &Listeners{} + d.BuildFlags = BuildFlags{} return &d, nil @@ -358,3 +374,14 @@ type DepsCfg struct { // Whether we are in running (server) mode Running bool } + +// BuildFlags are flags that may be turned on during a build. +type BuildFlags struct { + HasLateTemplate atomic.Bool +} + +func NewBuildFlags() BuildFlags { + return BuildFlags{ + //HasLateTemplate: atomic.NewBool(false), + } +} diff --git a/deps/deps_test.go b/deps/deps_test.go new file mode 100644 index 000000000..e2dca0ecc --- /dev/null +++ b/deps/deps_test.go @@ -0,0 +1,28 @@ +// Copyright 2019 The Hugo Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package deps + +import ( + "testing" + + qt "github.com/frankban/quicktest" +) + +func TestBuildFlags(t *testing.T) { + c := qt.New(t) + var bf BuildFlags + c.Assert(bf.HasLateTemplate.Load(), qt.Equals, false) + bf.HasLateTemplate.Store(true) + c.Assert(bf.HasLateTemplate.Load(), qt.Equals, true) +} |