diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-01-10 03:36:59 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-10 03:36:59 +0300 |
commit | d6000a208c7687ca3a3efd6961ac941ce325e199 (patch) | |
tree | 9644609a0d19894b46d065faec2cfe2aaeb410bd /hugolib/shortcode.go | |
parent | 4ea4359ac17a3b5304fb0d73773f99a07975ee1e (diff) |
all: Refactor to nonglobal template handling
Updates #2701
Diffstat (limited to 'hugolib/shortcode.go')
-rw-r--r-- | hugolib/shortcode.go | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/hugolib/shortcode.go b/hugolib/shortcode.go index 8e9dc756f..78610d638 100644 --- a/hugolib/shortcode.go +++ b/hugolib/shortcode.go @@ -151,8 +151,8 @@ func (sc shortcode) String() string { // HandleShortcodes does all in one go: extract, render and replace // only used for testing -func HandleShortcodes(stringToParse string, page *Page, t tpl.Template) (string, error) { - tmpContent, tmpShortcodes, err := extractAndRenderShortcodes(stringToParse, page, t) +func HandleShortcodes(stringToParse string, page *Page) (string, error) { + tmpContent, tmpShortcodes, err := extractAndRenderShortcodes(stringToParse, page) if err != nil { return "", err @@ -210,8 +210,8 @@ const innerNewlineRegexp = "\n" const innerCleanupRegexp = `\A<p>(.*)</p>\n\z` const innerCleanupExpand = "$1" -func renderShortcode(sc shortcode, parent *ShortcodeWithPage, p *Page, t tpl.Template) string { - tmpl := getShortcodeTemplate(sc.name, t) +func renderShortcode(sc shortcode, parent *ShortcodeWithPage, p *Page) string { + tmpl := getShortcodeTemplate(sc.name, p.s.tmpl) if tmpl == nil { p.s.log.ERROR.Printf("Unable to locate template for shortcode '%s' in page %s", sc.name, p.BaseFileName()) @@ -230,7 +230,7 @@ func renderShortcode(sc shortcode, parent *ShortcodeWithPage, p *Page, t tpl.Tem case string: inner += innerData.(string) case shortcode: - inner += renderShortcode(innerData.(shortcode), data, p, t) + inner += renderShortcode(innerData.(shortcode), data, p) default: p.s.log.ERROR.Printf("Illegal state on shortcode rendering of '%s' in page %s. Illegal type in inner data: %s ", sc.name, p.BaseFileName(), reflect.TypeOf(innerData)) @@ -280,9 +280,9 @@ func renderShortcode(sc shortcode, parent *ShortcodeWithPage, p *Page, t tpl.Tem return renderShortcodeWithPage(tmpl, data) } -func extractAndRenderShortcodes(stringToParse string, p *Page, t tpl.Template) (string, map[string]func() (string, error), error) { +func extractAndRenderShortcodes(stringToParse string, p *Page) (string, map[string]func() (string, error), error) { - content, shortcodes, err := extractShortcodes(stringToParse, p, t) + content, shortcodes, err := extractShortcodes(stringToParse, p) if err != nil { // try to render what we have whilst logging the error @@ -293,7 +293,7 @@ func extractAndRenderShortcodes(stringToParse string, p *Page, t tpl.Template) ( // TODO(bep) refactor this p.shortcodes = shortcodes - renderedShortcodes := renderShortcodes(shortcodes, p, t) + renderedShortcodes := renderShortcodes(shortcodes, p) return content, renderedShortcodes, err @@ -315,7 +315,7 @@ func executeShortcodeFuncMap(funcs map[string]func() (string, error)) (map[strin return result, nil } -func renderShortcodes(shortcodes map[string]shortcode, p *Page, t tpl.Template) map[string]func() (string, error) { +func renderShortcodes(shortcodes map[string]shortcode, p *Page) map[string]func() (string, error) { renderedShortcodes := make(map[string]func() (string, error)) for key, sc := range shortcodes { @@ -324,7 +324,7 @@ func renderShortcodes(shortcodes map[string]shortcode, p *Page, t tpl.Template) renderedShortcodes[key] = emptyShortcodeFn } else { shorctode := sc - renderedShortcodes[key] = func() (string, error) { return renderShortcode(shorctode, nil, p, t), nil } + renderedShortcodes[key] = func() (string, error) { return renderShortcode(shorctode, nil, p), nil } } } @@ -336,7 +336,7 @@ var errShortCodeIllegalState = errors.New("Illegal shortcode state") // pageTokens state: // - before: positioned just before the shortcode start // - after: shortcode(s) consumed (plural when they are nested) -func extractShortcode(pt *pageTokens, p *Page, t tpl.Template) (shortcode, error) { +func extractShortcode(pt *pageTokens, p *Page) (shortcode, error) { sc := shortcode{} var isInner = false @@ -357,7 +357,7 @@ Loop: if cnt > 0 { // nested shortcode; append it to inner content pt.backup3(currItem, next) - nested, err := extractShortcode(pt, p, t) + nested, err := extractShortcode(pt, p) if err == nil { sc.inner = append(sc.inner, nested) } else { @@ -398,7 +398,7 @@ Loop: sc.inner = append(sc.inner, currItem.val) case tScName: sc.name = currItem.val - tmpl := getShortcodeTemplate(sc.name, t) + tmpl := getShortcodeTemplate(sc.name, p.s.tmpl) if tmpl == nil { return sc, fmt.Errorf("Unable to locate template for shortcode '%s' in page %s", sc.name, p.BaseFileName()) @@ -454,7 +454,7 @@ Loop: return sc, nil } -func extractShortcodes(stringToParse string, p *Page, t tpl.Template) (string, map[string]shortcode, error) { +func extractShortcodes(stringToParse string, p *Page) (string, map[string]shortcode, error) { shortCodes := make(map[string]shortcode) @@ -492,7 +492,7 @@ Loop: case tLeftDelimScWithMarkup, tLeftDelimScNoMarkup: // let extractShortcode handle left delim (will do so recursively) pt.backup() - if currShortcode, err = extractShortcode(pt, p, t); err != nil { + if currShortcode, err = extractShortcode(pt, p); err != nil { return result.String(), shortCodes, err } |