Use / for template names regardless of platform.
authorNoah Campbell <noahcampbell@gmail.com>
Mon, 12 Aug 2013 20:57:47 +0000 (13:57 -0700)
committerNoah Campbell <noahcampbell@gmail.com>
Mon, 12 Aug 2013 22:03:06 +0000 (15:03 -0700)
The path seperator was causing templates to not be loaded on windows.
Now all template names use / internally.

hugolib/config.go
hugolib/path_seperators_test.go
hugolib/path_seperators_windows_test.go [new file with mode: 0644]
hugolib/site.go

index c612b1d8c7b812d217d51093a346bf38e6f134d5..12dc544c794389c8e49fb91b68829c5d5bd277e4 100644 (file)
@@ -148,7 +148,7 @@ func FindPath() (string, error) {
 }
 
 func (c *Config) GetAbsPath(name string) string {
-       if path.IsAbs(name) {
+       if filepath.IsAbs(name) {
                return name
        }
 
index 3478e55cd25b25ff2bcae59905808ce7b53bb0b8..f13eea1ef1c8f0a0b015de72952cd73a5e0bade7 100644 (file)
@@ -23,25 +23,29 @@ func TestDegenerateMissingFolderInPageFilename(t *testing.T) {
 }
 
 func TestNewPageWithFilePath(t *testing.T) {
-       toCheck := []map[string]string{
-               {"input": filepath.Join("sub", "foobar.html"), "expect": "sub"},
-               {"input": filepath.Join("content", "sub", "foobar.html"), "expect": "sub"},
-               {"input": filepath.Join("content", "dub", "sub", "foobar.html"), "expect": "sub"},
+       toCheck := []struct{
+               input string
+               section string
+               layout string
+       }{
+               {filepath.Join("sub", "foobar.html"), "sub", "sub/single.html"},
+               {filepath.Join("content", "sub", "foobar.html"), "sub", "sub/single.html"},
+               {filepath.Join("content", "dub", "sub", "foobar.html"), "sub", "sub/single.html"},
        }
 
        for _, el := range toCheck {
-               p, err := ReadFrom(strings.NewReader(SIMPLE_PAGE_YAML), el["input"])
+               p, err := ReadFrom(strings.NewReader(SIMPLE_PAGE_YAML), el.input)
                if err != nil {
                        t.Fatalf("Reading from SIMPLE_PAGE_YAML resulted in an error: %s", err)
                }
-               if p.Section != el["expect"] {
-                       t.Fatalf("Section not set to %s for page %s. Got: %s", el["expect"], el["input"], p.Section)
+               if p.Section != el.section {
+                       t.Fatalf("Section not set to %s for page %s. Got: %s", el.section, el.input, p.Section)
+               }
+
+               if p.Layout() != el.layout {
+                       t.Fatalf("Layout incorrect. Expected: '%s', Got: '%s'", el.layout, p.Layout())
                }
        }
 }
 
-func TestSettingOutFileOnPageContainsCorrectSlashes(t *testing.T) {
-       s := &Site{Config: Config{}}
-       p := NewPage(filepath.Join("sub", "foobar"))
-       s.setOutFile(p)
-}
+
diff --git a/hugolib/path_seperators_windows_test.go b/hugolib/path_seperators_windows_test.go
new file mode 100644 (file)
index 0000000..85b9722
--- /dev/null
@@ -0,0 +1,16 @@
+package hugolib
+
+import (
+       "testing"
+)
+
+func TestTemplatePathSeperator(t *testing.T) {
+       config := Config{
+               LayoutDir: "c:\\a\\windows\\path\\layout",
+               Path: "c:\\a\\windows\\path",
+       }
+       s := &Site{Config: config}
+       if name := s.generateTemplateNameFrom("c:\\a\\windows\\path\\layout\\sub1\\index.html"); name != "sub1/index.html" {
+               t.Fatalf("Template name incorrect.  Expected: %s, Got: %s", "sub1/index.html", name)
+       }
+}
index e4f7cbdfe6ae89404f302885373a58c395a1e31e..10503487806ad06f19886cc60839cd901fb77845 100644 (file)
@@ -163,14 +163,18 @@ func (s *Site) loadTemplates() {
                                return err
                        }
                        text := string(filetext)
-                       name := path[len(s.Config.GetAbsPath(s.Config.LayoutDir))+1:]
-                       t := s.Tmpl.New(name)
+                       t := s.Tmpl.New(s.generateTemplateNameFrom(path))
                        template.Must(t.Parse(text))
                }
                return nil
        }
 
-       filepath.Walk(s.Config.GetAbsPath(s.Config.LayoutDir), walker)
+       filepath.Walk(s.absLayoutDir(), walker)
+}
+
+func (s *Site) generateTemplateNameFrom(path string) (name string) {
+       name = filepath.ToSlash(path[len(s.absLayoutDir())+1:])
+       return
 }
 
 func (s *Site) primeTemplates() {