Add support for baseof.ace templates in themes.
authorJonathan Anderson <jonathan.anderson@ieee.org>
Fri, 19 Jun 2015 01:29:08 +0000 (22:59 -0230)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 25 Jun 2015 16:05:43 +0000 (18:05 +0200)
When we find a template that requires a base template, we should also look
for that base template in the current theme.

Fixes #1215.

docs/content/templates/ace.md
tpl/template.go

index bd13f592e2a12ff0b5b243c265f2ce1e671a31f2..397def3e146cf9e12eaec4dd2a01de1378bac79f 100644 (file)
@@ -35,6 +35,8 @@ In Hugo the base template will be chosen in the following order:
 2. <current-path>/baseof.ace
 3. _default/<template-name>-baseof.ace, e.g. list-baseof.ace.
 4. _default/baseof.ace 
+5. <themedir>/layouts/_default/<template-name>-baseof.ace
+6. <themedir>/layouts/_default/baseof.ace
 ```
 
 In the above, `current-path` is where the corresponding inner template lives, `list.ace`, `single.ace`, `index.ace` ...
index 15c1f794d01b61e6782653c5fc86e674db728e89..7740850eb156b97da025195bc21b2e1986dd1aaa 100644 (file)
@@ -21,6 +21,7 @@ import (
        "github.com/spf13/hugo/helpers"
        "github.com/spf13/hugo/hugofs"
        jww "github.com/spf13/jwalterweatherman"
+       "github.com/spf13/viper"
        "github.com/yosssi/ace"
        "html/template"
        "io"
@@ -300,15 +301,22 @@ func (t *GoHTMLTemplate) loadTemplates(absPath string, prefix string) {
                                        //   2. <current-path>/baseof.ace
                                        //   3. _default/<template-name>-baseof.ace, e.g. list-baseof.ace.
                                        //   4. _default/baseof.ace
+                                       //   5. <themedir>/layouts/_default/<template-name>-baseof.ace
+                                       //   6. <themedir>/layouts/_default/baseof.ace
 
                                        currBaseAceFilename := fmt.Sprintf("%s-%s", helpers.Filename(path), baseAceFilename)
                                        templateDir := filepath.Dir(path)
+                                       themeDir := filepath.Join(
+                                               viper.GetString("WorkingDir"), "themes", viper.GetString("theme"))
 
                                        pathsToCheck := []string{
                                                filepath.Join(templateDir, currBaseAceFilename),
                                                filepath.Join(templateDir, baseAceFilename),
                                                filepath.Join(absPath, "_default", currBaseAceFilename),
-                                               filepath.Join(absPath, "_default", baseAceFilename)}
+                                               filepath.Join(absPath, "_default", baseAceFilename),
+                                               filepath.Join(themeDir, "layouts", "_default", currBaseAceFilename),
+                                               filepath.Join(themeDir, "layouts", "_default", baseAceFilename),
+                                       }
 
                                        for _, pathToCheck := range pathsToCheck {
                                                if ok, err := helpers.Exists(pathToCheck, hugofs.OsFs); err == nil && ok {