diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-01-10 01:36:59 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-10 01:36:59 +0100 |
commit | d6000a208c7687ca3a3efd6961ac941ce325e199 (patch) | |
tree | 9644609a0d19894b46d065faec2cfe2aaeb410bd /hugolib/embedded_shortcodes_test.go | |
parent | 4ea4359ac17a3b5304fb0d73773f99a07975ee1e (diff) |
all: Refactor to nonglobal template handling
Updates #2701
Diffstat (limited to 'hugolib/embedded_shortcodes_test.go')
-rw-r--r-- | hugolib/embedded_shortcodes_test.go | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/hugolib/embedded_shortcodes_test.go b/hugolib/embedded_shortcodes_test.go index e2eb4706b..61c40cf01 100644 --- a/hugolib/embedded_shortcodes_test.go +++ b/hugolib/embedded_shortcodes_test.go @@ -19,16 +19,17 @@ import ( "html/template" "net/url" "os" - "path/filepath" "regexp" "strings" "testing" "io/ioutil" "log" + "path/filepath" - "github.com/spf13/hugo/helpers" "github.com/spf13/hugo/tpl" + + "github.com/spf13/hugo/helpers" jww "github.com/spf13/jwalterweatherman" "github.com/spf13/viper" "github.com/stretchr/testify/require" @@ -106,9 +107,8 @@ void do(); "(?s)^\n<div class=\"highlight\" style=\"background: #f0f0f0\"><pre style=\"line-height: 125%\">.*?void</span>.*?do</span>.*?().*?</pre></div>\n$", }, } { - templ := tpl.New(logger) p, _ := pageFromString(simplePage, "simple.md") - output, err := HandleShortcodes(this.in, p, templ) + output, err := HandleShortcodes(this.in, p) if err != nil { t.Fatalf("[%d] Handle shortcode error", i) @@ -150,9 +150,8 @@ func TestShortcodeFigure(t *testing.T) { "(?s)^\n<figure >.*?<img src=\"/img/hugo-logo.png\" />.*?<figcaption>.*?<p>.*?<a href=\"/img/hugo-logo.png\">.*?Hugo logo.*?</a>.*?</p>.*?</figcaption>.*?</figure>\n$", }, } { - templ := tpl.New(logger) p, _ := pageFromString(simplePage, "simple.md") - output, err := HandleShortcodes(this.in, p, templ) + output, err := HandleShortcodes(this.in, p) matched, err := regexp.MatchString(this.expected, output) @@ -175,9 +174,8 @@ func TestShortcodeSpeakerdeck(t *testing.T) { "(?s)^<script async class='speakerdeck-embed' data-id='4e8126e72d853c0060001f97'.*?>.*?</script>$", }, } { - templ := tpl.New(logger) p, _ := pageFromString(simplePage, "simple.md") - output, err := HandleShortcodes(this.in, p, templ) + output, err := HandleShortcodes(this.in, p) matched, err := regexp.MatchString(this.expected, output) @@ -210,9 +208,8 @@ func TestShortcodeYoutube(t *testing.T) { "(?s)^\n<div class=\"video\">.*?<iframe src=\"//www.youtube.com/embed/w7Ft2ymGmfc\\?autoplay=1\".*?allowfullscreen frameborder=\"0\">.*?</iframe>.*?</div>$", }, } { - templ := tpl.New(logger) p, _ := pageFromString(simplePage, "simple.md") - output, err := HandleShortcodes(this.in, p, templ) + output, err := HandleShortcodes(this.in, p) matched, err := regexp.MatchString(this.expected, output) @@ -245,9 +242,8 @@ func TestShortcodeVimeo(t *testing.T) { "(?s)^<div class=\"video\">.*?<iframe src=\"//player.vimeo.com/video/146022717\" webkitallowfullscreen mozallowfullscreen allowfullscreen>.*?</iframe>.*?</div>$", }, } { - templ := tpl.New(logger) p, _ := pageFromString(simplePage, "simple.md") - output, err := HandleShortcodes(this.in, p, templ) + output, err := HandleShortcodes(this.in, p) matched, err := regexp.MatchString(this.expected, output) @@ -274,9 +270,8 @@ func TestShortcodeGist(t *testing.T) { "(?s)^<script src=\"//gist.github.com/spf13/7896402.js\\?file=img.html\"></script>$", }, } { - templ := tpl.New(logger) p, _ := pageFromString(simplePage, "simple.md") - output, err := HandleShortcodes(this.in, p, templ) + output, err := HandleShortcodes(this.in, p) matched, err := regexp.MatchString(this.expected, output) @@ -313,13 +308,14 @@ func TestShortcodeTweet(t *testing.T) { }, } - templ := tpl.New(logger) - templ.Lookup("").Funcs(tweetFuncMap) + p, _ := pageFromString(simplePage, "simple.md", func(templ tpl.Template) error { + templ.Funcs(tweetFuncMap) + return nil + }) - p, _ := pageFromString(simplePage, "simple.md") cacheFileID := viper.GetString("cacheDir") + url.QueryEscape("https://api.twitter.com/1/statuses/oembed.json?id=666616452582129664") defer os.Remove(cacheFileID) - output, err := HandleShortcodes(this.in, p, templ) + output, err := HandleShortcodes(this.in, p) matched, err := regexp.MatchString(this.expected, output) @@ -353,7 +349,7 @@ func TestShortcodeInstagram(t *testing.T) { }, } { // overload getJSON to return mock API response from Instagram - tweetFuncMap := template.FuncMap{ + instagramFuncMap := template.FuncMap{ "getJSON": func(urlParts ...string) interface{} { var v interface{} err := json.Unmarshal([]byte(this.resp), &v) @@ -365,13 +361,14 @@ func TestShortcodeInstagram(t *testing.T) { }, } - templ := tpl.New(logger) - templ.Lookup("").Funcs(tweetFuncMap) + p, _ := pageFromString(simplePage, "simple.md", func(templ tpl.Template) error { + templ.Funcs(instagramFuncMap) + return nil + }) - p, _ := pageFromString(simplePage, "simple.md") cacheFileID := viper.GetString("cacheDir") + url.QueryEscape("https://api.instagram.com/oembed/?url=https://instagram.com/p/BMokmydjG-M/&hidecaption="+this.hidecaption) defer os.Remove(cacheFileID) - output, err := HandleShortcodes(this.in, p, templ) + output, err := HandleShortcodes(this.in, p) if err != nil { t.Fatalf("[%d] Failed to render shortcodes", i) |