mirror of
https://github.com/gohugoio/hugo.git
synced 2025-03-21 06:11:05 +00:00
hugolib: Some more GoLint fixes
This commit is contained in:
parent
218fceac35
commit
c2c73c2bd2
3 changed files with 15 additions and 9 deletions
|
@ -27,8 +27,8 @@ func TestPageCache(t *testing.T) {
|
||||||
p[0].Description = "changed"
|
p[0].Description = "changed"
|
||||||
}
|
}
|
||||||
|
|
||||||
var o1 uint64 = 0
|
var o1 uint64
|
||||||
var o2 uint64 = 0
|
var o2 uint64
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ import (
|
||||||
jww "github.com/spf13/jwalterweatherman"
|
jww "github.com/spf13/jwalterweatherman"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ShortcodeWithPage is the "." context in a shortcode template.
|
||||||
type ShortcodeWithPage struct {
|
type ShortcodeWithPage struct {
|
||||||
Params interface{}
|
Params interface{}
|
||||||
Inner template.HTML
|
Inner template.HTML
|
||||||
|
@ -39,18 +40,23 @@ type ShortcodeWithPage struct {
|
||||||
scratch *Scratch
|
scratch *Scratch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Site returns information about the current site.
|
||||||
func (scp *ShortcodeWithPage) Site() *SiteInfo {
|
func (scp *ShortcodeWithPage) Site() *SiteInfo {
|
||||||
return scp.Page.Site
|
return scp.Page.Site
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ref is a shortcut to the Ref method on Page.
|
||||||
func (scp *ShortcodeWithPage) Ref(ref string) (string, error) {
|
func (scp *ShortcodeWithPage) Ref(ref string) (string, error) {
|
||||||
return scp.Page.Ref(ref)
|
return scp.Page.Ref(ref)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RelRef is a shortcut to the RelRef method on Page.
|
||||||
func (scp *ShortcodeWithPage) RelRef(ref string) (string, error) {
|
func (scp *ShortcodeWithPage) RelRef(ref string) (string, error) {
|
||||||
return scp.Page.RelRef(ref)
|
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 {
|
func (scp *ShortcodeWithPage) Scratch() *Scratch {
|
||||||
if scp.scratch == nil {
|
if scp.scratch == nil {
|
||||||
scp.scratch = newScratch()
|
scp.scratch = newScratch()
|
||||||
|
@ -58,6 +64,7 @@ func (scp *ShortcodeWithPage) Scratch() *Scratch {
|
||||||
return scp.scratch
|
return scp.scratch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get is a convenience method to look up shortcode parameters by its key.
|
||||||
func (scp *ShortcodeWithPage) Get(key interface{}) interface{} {
|
func (scp *ShortcodeWithPage) Get(key interface{}) interface{} {
|
||||||
if reflect.ValueOf(scp.Params).Len() == 0 {
|
if reflect.ValueOf(scp.Params).Len() == 0 {
|
||||||
return nil
|
return nil
|
||||||
|
@ -154,9 +161,8 @@ func HandleShortcodes(stringToParse string, page *Page, t tpl.Template) (string,
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("Fail to replace short code tokens in %s:\n%s", page.BaseFileName(), err.Error())
|
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
|
return tmpContent, nil
|
||||||
|
@ -303,7 +309,7 @@ func renderShortcodes(shortcodes map[string]shortcode, p *Page, t tpl.Template)
|
||||||
return renderedShortcodes
|
return renderedShortcodes
|
||||||
}
|
}
|
||||||
|
|
||||||
var shortCodeIllegalState = errors.New("Illegal shortcode state")
|
var errShortCodeIllegalState = errors.New("Illegal shortcode state")
|
||||||
|
|
||||||
// pageTokens state:
|
// pageTokens state:
|
||||||
// - before: positioned just before the shortcode start
|
// - before: positioned just before the shortcode start
|
||||||
|
@ -395,7 +401,7 @@ Loop:
|
||||||
if params, ok := sc.params.(map[string]string); ok {
|
if params, ok := sc.params.(map[string]string); ok {
|
||||||
params[currItem.val] = pt.next().val
|
params[currItem.val] = pt.next().val
|
||||||
} else {
|
} else {
|
||||||
return sc, shortCodeIllegalState
|
return sc, errShortCodeIllegalState
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -410,7 +416,7 @@ Loop:
|
||||||
params = append(params, currItem.val)
|
params = append(params, currItem.val)
|
||||||
sc.params = params
|
sc.params = params
|
||||||
} else {
|
} else {
|
||||||
return sc, shortCodeIllegalState
|
return sc, errShortCodeIllegalState
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ import (
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
const SITE_INFO_PARAM_TEMPLATE = `{{ .Site.Params.MyGlobalParam }}`
|
const siteInfoParamTemplate = `{{ .Site.Params.MyGlobalParam }}`
|
||||||
|
|
||||||
func TestSiteInfoParams(t *testing.T) {
|
func TestSiteInfoParams(t *testing.T) {
|
||||||
viper.Reset()
|
viper.Reset()
|
||||||
|
@ -34,7 +34,7 @@ func TestSiteInfoParams(t *testing.T) {
|
||||||
t.Errorf("Unable to set site.Info.Param")
|
t.Errorf("Unable to set site.Info.Param")
|
||||||
}
|
}
|
||||||
|
|
||||||
s.prepTemplates("template", SITE_INFO_PARAM_TEMPLATE)
|
s.prepTemplates("template", siteInfoParamTemplate)
|
||||||
|
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue