Fixing some bugs introduced in prior few commits. Tests now pass.

This commit is contained in:
spf13 2014-04-24 10:18:47 -06:00
parent 11fe227b9e
commit 4f813c09ea
2 changed files with 11 additions and 12 deletions

View file

@ -1,7 +1,6 @@
package hugolib package hugolib
import ( import (
"github.com/spf13/hugo/template/bundle"
"strings" "strings"
"testing" "testing"
) )
@ -10,7 +9,7 @@ func pageFromString(in, filename string) (*Page, error) {
return ReadFrom(strings.NewReader(in), filename) return ReadFrom(strings.NewReader(in), filename)
} }
func CheckShortCodeMatch(t *testing.T, input, expected string, template bundle.Template) { func CheckShortCodeMatch(t *testing.T, input, expected string, template Template) {
p, _ := pageFromString(SIMPLE_PAGE, "simple.md") p, _ := pageFromString(SIMPLE_PAGE, "simple.md")
output := ShortcodesHandle(input, p, template) output := ShortcodesHandle(input, p, template)
@ -21,13 +20,13 @@ func CheckShortCodeMatch(t *testing.T, input, expected string, template bundle.T
} }
func TestNonSC(t *testing.T) { func TestNonSC(t *testing.T) {
tem := bundle.NewTemplate() tem := NewTemplate()
CheckShortCodeMatch(t, "{{% movie 47238zzb %}}", "{{% movie 47238zzb %}}", tem) CheckShortCodeMatch(t, "{{% movie 47238zzb %}}", "{{% movie 47238zzb %}}", tem)
} }
func TestPositionalParamSC(t *testing.T) { func TestPositionalParamSC(t *testing.T) {
tem := bundle.NewTemplate() tem := NewTemplate()
tem.AddInternalShortcode("video.html", `Playing Video {{ .Get 0 }}`) tem.AddInternalShortcode("video.html", `Playing Video {{ .Get 0 }}`)
CheckShortCodeMatch(t, "{{% video 47238zzb %}}", "Playing Video 47238zzb", tem) CheckShortCodeMatch(t, "{{% video 47238zzb %}}", "Playing Video 47238zzb", tem)
@ -38,7 +37,7 @@ func TestPositionalParamSC(t *testing.T) {
} }
func TestNamedParamSC(t *testing.T) { func TestNamedParamSC(t *testing.T) {
tem := bundle.NewTemplate() tem := NewTemplate()
tem.AddInternalShortcode("img.html", `<img{{ with .Get "src" }} src="{{.}}"{{end}}{{with .Get "class"}} class="{{.}}"{{end}}>`) tem.AddInternalShortcode("img.html", `<img{{ with .Get "src" }} src="{{.}}"{{end}}{{with .Get "class"}} class="{{.}}"{{end}}>`)
CheckShortCodeMatch(t, `{{% img src="one" %}}`, `<img src="one">`, tem) CheckShortCodeMatch(t, `{{% img src="one" %}}`, `<img src="one">`, tem)
@ -50,7 +49,7 @@ func TestNamedParamSC(t *testing.T) {
} }
func TestInnerSC(t *testing.T) { func TestInnerSC(t *testing.T) {
tem := bundle.NewTemplate() tem := NewTemplate()
tem.AddInternalShortcode("inside.html", `<div{{with .Get "class"}} class="{{.}}"{{end}}>{{ .Inner }}</div>`) tem.AddInternalShortcode("inside.html", `<div{{with .Get "class"}} class="{{.}}"{{end}}>{{ .Inner }}</div>`)
CheckShortCodeMatch(t, `{{% inside class="aspen" %}}`, `<div class="aspen"></div>`, tem) CheckShortCodeMatch(t, `{{% inside class="aspen" %}}`, `<div class="aspen"></div>`, tem)
@ -59,14 +58,14 @@ func TestInnerSC(t *testing.T) {
} }
func TestEmbeddedSC(t *testing.T) { func TestEmbeddedSC(t *testing.T) {
tem := bundle.NewTemplate() tem := NewTemplate()
CheckShortCodeMatch(t, "{{% test %}}", "This is a simple Test", tem) CheckShortCodeMatch(t, "{{% test %}}", "This is a simple Test", tem)
CheckShortCodeMatch(t, `{{% figure src="/found/here" class="bananas orange" %}}`, "\n<figure class=\"bananas orange\">\n \n <img src=\"/found/here\" />\n \n \n</figure>\n", tem) CheckShortCodeMatch(t, `{{% figure src="/found/here" class="bananas orange" %}}`, "\n<figure class=\"bananas orange\">\n \n <img src=\"/found/here\" />\n \n \n</figure>\n", tem)
CheckShortCodeMatch(t, `{{% figure src="/found/here" class="bananas orange" caption="This is a caption" %}}`, "\n<figure class=\"bananas orange\">\n \n <img src=\"/found/here\" alt=\"This is a caption\" />\n \n \n <figcaption>\n <p>\n This is a caption\n \n \n \n </p> \n </figcaption>\n \n</figure>\n", tem) CheckShortCodeMatch(t, `{{% figure src="/found/here" class="bananas orange" caption="This is a caption" %}}`, "\n<figure class=\"bananas orange\">\n \n <img src=\"/found/here\" alt=\"This is a caption\" />\n \n \n <figcaption>\n <p>\n This is a caption\n \n \n \n </p> \n </figcaption>\n \n</figure>\n", tem)
} }
func TestUnbalancedQuotes(t *testing.T) { func TestUnbalancedQuotes(t *testing.T) {
tem := bundle.NewTemplate() tem := NewTemplate()
CheckShortCodeMatch(t, `{{% figure src="/uploads/2011/12/spf13-mongosv-speaking-copy-1024x749.jpg "Steve Francia speaking at OSCON 2012" alt="MongoSV 2011" %}}`, "\n<figure >\n \n <img src=\"/uploads/2011/12/spf13-mongosv-speaking-copy-1024x749.jpg%20%22Steve%20Francia%20speaking%20at%20OSCON%202012\" alt=\"MongoSV 2011\" />\n \n \n</figure>\n", tem) CheckShortCodeMatch(t, `{{% figure src="/uploads/2011/12/spf13-mongosv-speaking-copy-1024x749.jpg "Steve Francia speaking at OSCON 2012" alt="MongoSV 2011" %}}`, "\n<figure >\n \n <img src=\"/uploads/2011/12/spf13-mongosv-speaking-copy-1024x749.jpg%20%22Steve%20Francia%20speaking%20at%20OSCON%202012\" alt=\"MongoSV 2011\" />\n \n \n</figure>\n", tem)
} }

View file

@ -61,7 +61,7 @@ type Site struct {
Taxonomies TaxonomyList Taxonomies TaxonomyList
Source source.Input Source source.Input
Sections Taxonomy Sections Taxonomy
Info *SiteInfo Info SiteInfo
Shortcodes map[string]ShortcodeFunc Shortcodes map[string]ShortcodeFunc
Menus Menus Menus Menus
timer *nitro.B timer *nitro.B
@ -262,7 +262,7 @@ func (s *Site) initializeSiteInfo() {
permalinks = make(PermalinkOverrides) permalinks = make(PermalinkOverrides)
} }
s.Info = &SiteInfo{ s.Info = SiteInfo{
BaseUrl: template.URL(helpers.SanitizeUrl(viper.GetString("BaseUrl"))), BaseUrl: template.URL(helpers.SanitizeUrl(viper.GetString("BaseUrl"))),
Title: viper.GetString("Title"), Title: viper.GetString("Title"),
Author: viper.GetStringMapString("author"), Author: viper.GetStringMapString("author"),
@ -321,7 +321,7 @@ func (s *Site) CreatePages() (err error) {
if err != nil { if err != nil {
return err return err
} }
page.Site = *s.Info page.Site = s.Info
page.Tmpl = s.Tmpl page.Tmpl = s.Tmpl
page.Section = file.Section page.Section = file.Section
page.Dir = file.Dir page.Dir = file.Dir
@ -726,7 +726,7 @@ func (s *Site) PrettifyPath(in string) string {
func (s *Site) NewNode() *Node { func (s *Site) NewNode() *Node {
return &Node{ return &Node{
Data: make(map[string]interface{}), Data: make(map[string]interface{}),
Site: *s.Info, Site: s.Info,
} }
} }