all: Use the configured output types to resolve template type
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 4 Apr 2017 12:10:20 +0000 (14:10 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 4 Apr 2017 13:12:30 +0000 (15:12 +0200)
Closes #320

deps/deps.go
hugolib/hugo_sites.go
tpl/tplimpl/template.go

index 18886387689998e8c68ad4e1478173cac2fc778b..99763c115a965611a50d5b0dc92b4351b7de2c09 100644 (file)
@@ -8,6 +8,7 @@ import (
        "github.com/spf13/hugo/config"
        "github.com/spf13/hugo/helpers"
        "github.com/spf13/hugo/hugofs"
+       "github.com/spf13/hugo/output"
        "github.com/spf13/hugo/tpl"
        jww "github.com/spf13/jwalterweatherman"
 )
@@ -39,6 +40,9 @@ type Deps struct {
 
        Language *helpers.Language
 
+       // All the output formats available for the current site.
+       OutputFormatsConfig output.Formats
+
        templateProvider ResourceProvider
        WithTemplate     func(templ tpl.TemplateHandler) error `json:"-"`
 
index 491bbd8095e31d639b03888e63475ae5567befd6..9ef2dc91e35d9e7c73f0682c11a494d64e507c29 100644 (file)
@@ -101,6 +101,7 @@ func applyDepsIfNeeded(cfg deps.DepsCfg, sites ...*Site) error {
                                return err
                        }
 
+                       d.OutputFormatsConfig = s.outputFormatsConfig
                        s.Deps = d
 
                        if err = d.LoadResources(); err != nil {
@@ -112,6 +113,7 @@ func applyDepsIfNeeded(cfg deps.DepsCfg, sites ...*Site) error {
                        if err != nil {
                                return err
                        }
+                       d.OutputFormatsConfig = s.outputFormatsConfig
                        s.Deps = d
                }
 
index 68528a775bba03e6f68ffa6e58cec1b430662126..c14d24146e521d0b61243ed8ba669d9add6416e6 100644 (file)
@@ -276,8 +276,7 @@ func (t *textTemplates) setFuncs(funcMap map[string]interface{}) {
 // A prefix can be given to indicate a template namespace to load the templates
 // into, i.e. "_internal" etc.
 func (t *templateHandler) LoadTemplates(absPath, prefix string) {
-       // TODO(bep) output formats. Will have to get to complete list when that is ready.
-       t.loadTemplates(absPath, prefix, output.Formats{output.HTMLFormat, output.RSSFormat, output.CalendarFormat, output.AMPFormat, output.JSONFormat})
+       t.loadTemplates(absPath, prefix)
 
 }
 
@@ -376,7 +375,7 @@ func (t *templateHandler) RebuildClone() {
        t.text.clone = texttemplate.Must(t.text.cloneClone.Clone())
 }
 
-func (t *templateHandler) loadTemplates(absPath string, prefix string, formats output.Formats) {
+func (t *templateHandler) loadTemplates(absPath string, prefix string) {
        t.Log.DEBUG.Printf("Load templates from path %q prefix %q", absPath, prefix)
        walker := func(path string, fi os.FileInfo, err error) error {
                if err != nil {
@@ -428,7 +427,7 @@ func (t *templateHandler) loadTemplates(absPath string, prefix string, formats o
                                RelPath:       relPath,
                                Prefix:        prefix,
                                Theme:         t.PathSpec.Theme(),
-                               OutputFormats: formats,
+                               OutputFormats: t.OutputFormatsConfig,
                                FileExists: func(filename string) (bool, error) {
                                        return helpers.Exists(filename, t.Fs.Source)
                                },