diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2016-03-24 14:11:04 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2016-03-24 14:11:04 +0100 |
commit | c2c73c2bd21090173135b9dbfdc89400450c4837 (patch) | |
tree | 278abdc6caba693ca9f481de5a5088b01ac6eeb8 /hugolib/shortcode.go | |
parent | 218fceac358ad3c76482ff009be7ccf4df6ce988 (diff) |
hugolib: Some more GoLint fixes
Diffstat (limited to 'hugolib/shortcode.go')
-rw-r--r-- | hugolib/shortcode.go | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/hugolib/shortcode.go b/hugolib/shortcode.go index b81c95394..782f0e21a 100644 --- a/hugolib/shortcode.go +++ b/hugolib/shortcode.go @@ -30,6 +30,7 @@ import ( jww "github.com/spf13/jwalterweatherman" ) +// ShortcodeWithPage is the "." context in a shortcode template. type ShortcodeWithPage struct { Params interface{} Inner template.HTML @@ -39,18 +40,23 @@ type ShortcodeWithPage struct { scratch *Scratch } +// Site returns information about the current site. func (scp *ShortcodeWithPage) Site() *SiteInfo { return scp.Page.Site } +// Ref is a shortcut to the Ref method on Page. func (scp *ShortcodeWithPage) Ref(ref string) (string, error) { return scp.Page.Ref(ref) } +// RelRef is a shortcut to the RelRef method on Page. func (scp *ShortcodeWithPage) RelRef(ref string) (string, error) { return scp.Page.RelRef(ref) } +// Scratch returns a scratch-pad scoped for this shortcode. This can be used +// as a temporary storage for variables, counters etc. func (scp *ShortcodeWithPage) Scratch() *Scratch { if scp.scratch == nil { scp.scratch = newScratch() @@ -58,6 +64,7 @@ func (scp *ShortcodeWithPage) Scratch() *Scratch { return scp.scratch } +// Get is a convenience method to look up shortcode parameters by its key. func (scp *ShortcodeWithPage) Get(key interface{}) interface{} { if reflect.ValueOf(scp.Params).Len() == 0 { return nil @@ -154,9 +161,8 @@ func HandleShortcodes(stringToParse string, page *Page, t tpl.Template) (string, if err != nil { return "", fmt.Errorf("Fail to replace short code tokens in %s:\n%s", page.BaseFileName(), err.Error()) - } else { - return string(tmpContentWithTokensReplaced), nil } + return string(tmpContentWithTokensReplaced), nil } return tmpContent, nil @@ -303,7 +309,7 @@ func renderShortcodes(shortcodes map[string]shortcode, p *Page, t tpl.Template) return renderedShortcodes } -var shortCodeIllegalState = errors.New("Illegal shortcode state") +var errShortCodeIllegalState = errors.New("Illegal shortcode state") // pageTokens state: // - before: positioned just before the shortcode start @@ -395,7 +401,7 @@ Loop: if params, ok := sc.params.(map[string]string); ok { params[currItem.val] = pt.next().val } else { - return sc, shortCodeIllegalState + return sc, errShortCodeIllegalState } } @@ -410,7 +416,7 @@ Loop: params = append(params, currItem.val) sc.params = params } else { - return sc, shortCodeIllegalState + return sc, errShortCodeIllegalState } } |