)
const (
- TEMPLATE_TITLE = "{{ .Title }}"
- PAGE_SIMPLE_TITLE = `---
+ templateTitle = "{{ .Title }}"
+ pageSimpleTitle = `---
title: simple template
---
content`
- TEMPLATE_MISSING_FUNC = "{{ .Title | funcdoesnotexists }}"
- TEMPLATE_FUNC = "{{ .Title | urlize }}"
- TEMPLATE_CONTENT = "{{ .Content }}"
- TEMPLATE_DATE = "{{ .Date }}"
- TEMPLATE_WITH_URL_ABS = "<a href=\"/foobar.jpg\">Going</a>"
+ templateMissingFunc = "{{ .Title | funcdoesnotexists }}"
+ templateFunc = "{{ .Title | urlize }}"
+ templateContent = "{{ .Content }}"
+ templateDate = "{{ .Date }}"
+ templateWithURLAbs = "<a href=\"/foobar.jpg\">Going</a>"
- PAGE_WITH_MD = `---
+ pageWithMd = `---
title: page with md
---
# heading 1
}
func TestDegenerateRenderThingMissingTemplate(t *testing.T) {
- p, _ := NewPageFrom(strings.NewReader(PAGE_SIMPLE_TITLE), "content/a/file.md")
+ p, _ := NewPageFrom(strings.NewReader(pageSimpleTitle), "content/a/file.md")
p.Convert()
s := new(Site)
s.prepTemplates()
func TestAddInvalidTemplate(t *testing.T) {
s := new(Site)
- err := s.prepTemplates("missing", TEMPLATE_MISSING_FUNC)
+ err := s.prepTemplates("missing", templateMissingFunc)
if err == nil {
t.Fatalf("Expecting the template to return an error")
}
template string
expected string
}{
- {PAGE_SIMPLE_TITLE, TEMPLATE_TITLE, "simple template"},
- {PAGE_SIMPLE_TITLE, TEMPLATE_FUNC, "simple-template"},
- {PAGE_WITH_MD, TEMPLATE_CONTENT, "\n\n<h1 id=\"heading-1:91b5c4a22fc6103c73bb91e4a40568f8\">heading 1</h1>\n\n<p>text</p>\n\n<h2 id=\"heading-2:91b5c4a22fc6103c73bb91e4a40568f8\">heading 2</h2>\n\n<p>more text</p>\n"},
- {simplePageRFC3339Date, TEMPLATE_DATE, "2013-05-17 16:59:30 +0000 UTC"},
+ {pageSimpleTitle, templateTitle, "simple template"},
+ {pageSimpleTitle, templateFunc, "simple-template"},
+ {pageWithMd, templateContent, "\n\n<h1 id=\"heading-1:91b5c4a22fc6103c73bb91e4a40568f8\">heading 1</h1>\n\n<p>text</p>\n\n<h2 id=\"heading-2:91b5c4a22fc6103c73bb91e4a40568f8\">heading 2</h2>\n\n<p>more text</p>\n"},
+ {simplePageRFC3339Date, templateDate, "2013-05-17 16:59:30 +0000 UTC"},
}
for i, test := range tests {
template string
expected string
}{
- {true, TEMPLATE_TITLE, HTML("simple template")},
- {true, TEMPLATE_FUNC, HTML("simple-template")},
- {false, TEMPLATE_TITLE, HTML("simple template")},
- {false, TEMPLATE_FUNC, HTML("simple-template")},
+ {true, templateTitle, HTML("simple template")},
+ {true, templateFunc, HTML("simple-template")},
+ {false, templateTitle, HTML("simple template")},
+ {false, templateFunc, HTML("simple-template")},
}
hugofs.InitMemFs()
s := &Site{}
- p, err := NewPageFrom(strings.NewReader(PAGE_SIMPLE_TITLE), "content/a/file.md")
+ p, err := NewPageFrom(strings.NewReader(pageSimpleTitle), "content/a/file.md")
if err != nil {
t.Fatalf("Error parsing buffer: %s", err)
}
t.Logf("Rendering with BaseURL %q and CanonifyURLs set %v", viper.GetString("baseURL"), canonify)
s.initializeSiteInfo()
- s.prepTemplates("blue/single.html", TEMPLATE_WITH_URL_ABS)
+ s.prepTemplates("blue/single.html", templateWithURLAbs)
if err := s.CreatePages(); err != nil {
t.Fatalf("Unable to create pages: %s", err)
}
}
-var WEIGHTED_PAGE_1 = []byte(`+++
+var weightedPage1 = []byte(`+++
weight = "2"
title = "One"
my_param = "foo"
+++
Front Matter with Ordered Pages`)
-var WEIGHTED_PAGE_2 = []byte(`+++
+var weightedPage2 = []byte(`+++
weight = "6"
title = "Two"
publishdate = "2012-03-05"
+++
Front Matter with Ordered Pages 2`)
-var WEIGHTED_PAGE_3 = []byte(`+++
+var weightedPage3 = []byte(`+++
weight = "4"
title = "Three"
date = "2012-04-06"
+++
Front Matter with Ordered Pages 3`)
-var WEIGHTED_PAGE_4 = []byte(`+++
+var weightedPage4 = []byte(`+++
weight = "4"
title = "Four"
date = "2012-01-01"
+++
Front Matter with Ordered Pages 4. This is longer content`)
-var WEIGHTED_SOURCES = []source.ByteSource{
- {filepath.FromSlash("sect/doc1.md"), WEIGHTED_PAGE_1},
- {filepath.FromSlash("sect/doc2.md"), WEIGHTED_PAGE_2},
- {filepath.FromSlash("sect/doc3.md"), WEIGHTED_PAGE_3},
- {filepath.FromSlash("sect/doc4.md"), WEIGHTED_PAGE_4},
+var weightedSources = []source.ByteSource{
+ {filepath.FromSlash("sect/doc1.md"), weightedPage1},
+ {filepath.FromSlash("sect/doc2.md"), weightedPage2},
+ {filepath.FromSlash("sect/doc3.md"), weightedPage3},
+ {filepath.FromSlash("sect/doc4.md"), weightedPage4},
}
func TestOrderedPages(t *testing.T) {
viper.Set("baseurl", "http://auth/bub")
s := &Site{
- Source: &source.InMemorySource{ByteSource: WEIGHTED_SOURCES},
+ Source: &source.InMemorySource{ByteSource: weightedSources},
}
s.initializeSiteInfo()
}
}
-var GROUPED_SOURCES = []source.ByteSource{
- {filepath.FromSlash("sect1/doc1.md"), WEIGHTED_PAGE_1},
- {filepath.FromSlash("sect1/doc2.md"), WEIGHTED_PAGE_2},
- {filepath.FromSlash("sect2/doc3.md"), WEIGHTED_PAGE_3},
- {filepath.FromSlash("sect3/doc4.md"), WEIGHTED_PAGE_4},
+var groupedSources = []source.ByteSource{
+ {filepath.FromSlash("sect1/doc1.md"), weightedPage1},
+ {filepath.FromSlash("sect1/doc2.md"), weightedPage2},
+ {filepath.FromSlash("sect2/doc3.md"), weightedPage3},
+ {filepath.FromSlash("sect3/doc4.md"), weightedPage4},
}
func TestGroupedPages(t *testing.T) {
viper.Set("baseurl", "http://auth/bub")
s := &Site{
- Source: &source.InMemorySource{ByteSource: GROUPED_SOURCES},
+ Source: &source.InMemorySource{ByteSource: groupedSources},
}
s.initializeSiteInfo()
}
}
-var PAGE_WITH_WEIGHTED_TAXONOMIES_2 = []byte(`+++
+var pageWithWeightedTaxonomies1 = []byte(`+++
tags = [ "a", "b", "c" ]
tags_weight = 22
categories = ["d"]
+++
Front Matter with weighted tags and categories`)
-var PAGE_WITH_WEIGHTED_TAXONOMIES_1 = []byte(`+++
+var pageWithWeightedTaxonomies2 = []byte(`+++
tags = "a"
tags_weight = 33
title = "bar"
+++
Front Matter with weighted tags and categories`)
-var PAGE_WITH_WEIGHTED_TAXONOMIES_3 = []byte(`+++
+var pageWithWeightedTaxonomies3 = []byte(`+++
title = "bza"
categories = [ "e" ]
categories_weight = 11
hugofs.InitMemFs()
sources := []source.ByteSource{
- {filepath.FromSlash("sect/doc1.md"), PAGE_WITH_WEIGHTED_TAXONOMIES_1},
- {filepath.FromSlash("sect/doc2.md"), PAGE_WITH_WEIGHTED_TAXONOMIES_2},
- {filepath.FromSlash("sect/doc3.md"), PAGE_WITH_WEIGHTED_TAXONOMIES_3},
+ {filepath.FromSlash("sect/doc1.md"), pageWithWeightedTaxonomies2},
+ {filepath.FromSlash("sect/doc2.md"), pageWithWeightedTaxonomies1},
+ {filepath.FromSlash("sect/doc3.md"), pageWithWeightedTaxonomies3},
}
taxonomies := make(map[string]string)