summaryrefslogtreecommitdiffstats
path: root/hugolib/shortcode.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-04-02 14:20:34 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-04-02 14:20:34 +0200
commit7eb71ee06419f9ceedfd701ab2a27513ef448829 (patch)
tree254ba6c75575e067df76b4abe4e566936619adcb /hugolib/shortcode.go
parentc97dae40d9cd24c467f5b8cfbe2ac06f3cdef1d2 (diff)
Revert "tpl: Rework to handle both text and HTML templates"
Will have to take another stab at this ... This reverts commit 5c5efa03d2512749950b0d05a7d4bde35ecbdc37. Closes #3260
Diffstat (limited to 'hugolib/shortcode.go')
-rw-r--r--hugolib/shortcode.go16
1 files changed, 9 insertions, 7 deletions
diff --git a/hugolib/shortcode.go b/hugolib/shortcode.go
index d72a96faa..d165c778b 100644
--- a/hugolib/shortcode.go
+++ b/hugolib/shortcode.go
@@ -177,7 +177,7 @@ var isInnerShortcodeCache = struct {
// to avoid potential costly look-aheads for closing tags we look inside the template itself
// we could change the syntax to self-closing tags, but that would make users cry
// the value found is cached
-func isInnerShortcode(t tpl.TemplateExecutor) (bool, error) {
+func isInnerShortcode(t *template.Template) (bool, error) {
isInnerShortcodeCache.RLock()
m, ok := isInnerShortcodeCache.m[t.Name()]
isInnerShortcodeCache.RUnlock()
@@ -188,7 +188,10 @@ func isInnerShortcode(t tpl.TemplateExecutor) (bool, error) {
isInnerShortcodeCache.Lock()
defer isInnerShortcodeCache.Unlock()
- match, _ := regexp.MatchString("{{.*?\\.Inner.*?}}", t.Tree())
+ if t.Tree == nil {
+ return false, errors.New("Template failed to compile")
+ }
+ match, _ := regexp.MatchString("{{.*?\\.Inner.*?}}", t.Tree.Root.String())
isInnerShortcodeCache.m[t.Name()] = match
return match, nil
@@ -395,6 +398,8 @@ Loop:
case tScName:
sc.name = currItem.val
tmpl := getShortcodeTemplate(sc.name, p.s.Tmpl)
+ {
+ }
if tmpl == nil {
return sc, fmt.Errorf("Unable to locate template for shortcode %q in page %q", sc.name, p.Path())
}
@@ -565,10 +570,7 @@ func replaceShortcodeTokens(source []byte, prefix string, replacements map[strin
return source, nil
}
-func getShortcodeTemplate(name string, t tpl.TemplateHandler) *tpl.TemplateAdapter {
- isInnerShortcodeCache.RLock()
- defer isInnerShortcodeCache.RUnlock()
-
+func getShortcodeTemplate(name string, t tpl.Template) *template.Template {
if x := t.Lookup("shortcodes/" + name + ".html"); x != nil {
return x
}
@@ -578,7 +580,7 @@ func getShortcodeTemplate(name string, t tpl.TemplateHandler) *tpl.TemplateAdapt
return t.Lookup("_internal/shortcodes/" + name + ".html")
}
-func renderShortcodeWithPage(tmpl tpl.Template, data *ShortcodeWithPage) string {
+func renderShortcodeWithPage(tmpl *template.Template, data *ShortcodeWithPage) string {
buffer := bp.GetBuffer()
defer bp.PutBuffer(buffer)