mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-30 00:53:28 -05:00
menu: make receiver name on Page methods consistent
Apply some Golint rules on Menu, esp. making the method receiver names consistent.
This commit is contained in:
parent
e24a775962
commit
5759007874
2 changed files with 17 additions and 19 deletions
|
@ -136,12 +136,11 @@ func (by MenuEntryBy) Sort(menu Menu) {
|
||||||
sort.Stable(ms)
|
sort.Stable(ms)
|
||||||
}
|
}
|
||||||
|
|
||||||
var DefaultMenuEntrySort = func(m1, m2 *MenuEntry) bool {
|
var defaultMenuEntrySort = func(m1, m2 *MenuEntry) bool {
|
||||||
if m1.Weight == m2.Weight {
|
if m1.Weight == m2.Weight {
|
||||||
return m1.Name < m2.Name
|
return m1.Name < m2.Name
|
||||||
} else {
|
|
||||||
return m1.Weight < m2.Weight
|
|
||||||
}
|
}
|
||||||
|
return m1.Weight < m2.Weight
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ms *MenuSorter) Len() int { return len(ms.menu) }
|
func (ms *MenuSorter) Len() int { return len(ms.menu) }
|
||||||
|
@ -150,30 +149,29 @@ func (ms *MenuSorter) Swap(i, j int) { ms.menu[i], ms.menu[j] = ms.menu[j], ms.m
|
||||||
// Less is part of sort.Interface. It is implemented by calling the "by" closure in the sorter.
|
// Less is part of sort.Interface. It is implemented by calling the "by" closure in the sorter.
|
||||||
func (ms *MenuSorter) Less(i, j int) bool { return ms.by(ms.menu[i], ms.menu[j]) }
|
func (ms *MenuSorter) Less(i, j int) bool { return ms.by(ms.menu[i], ms.menu[j]) }
|
||||||
|
|
||||||
func (p Menu) Sort() {
|
func (m Menu) Sort() {
|
||||||
MenuEntryBy(DefaultMenuEntrySort).Sort(p)
|
MenuEntryBy(defaultMenuEntrySort).Sort(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p Menu) Limit(n int) Menu {
|
func (m Menu) Limit(n int) Menu {
|
||||||
if len(p) < n {
|
if len(m) < n {
|
||||||
return p[0:n]
|
return m[0:n]
|
||||||
} else {
|
|
||||||
return p
|
|
||||||
}
|
}
|
||||||
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p Menu) ByWeight() Menu {
|
func (m Menu) ByWeight() Menu {
|
||||||
MenuEntryBy(DefaultMenuEntrySort).Sort(p)
|
MenuEntryBy(defaultMenuEntrySort).Sort(m)
|
||||||
return p
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p Menu) ByName() Menu {
|
func (m Menu) ByName() Menu {
|
||||||
title := func(m1, m2 *MenuEntry) bool {
|
title := func(m1, m2 *MenuEntry) bool {
|
||||||
return m1.Name < m2.Name
|
return m1.Name < m2.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuEntryBy(title).Sort(p)
|
MenuEntryBy(title).Sort(m)
|
||||||
return p
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m Menu) Reverse() Menu {
|
func (m Menu) Reverse() Menu {
|
||||||
|
|
|
@ -399,7 +399,7 @@ func (ts testMenuState) findTestMenuEntryByName(mn string, id string) *MenuEntry
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts testMenuState) findTestMenuEntry(mn string, id string, matcher func(me *MenuEntry, id string) bool) *MenuEntry {
|
func (ts testMenuState) findTestMenuEntry(mn string, id string, matcher func(me *MenuEntry, id string) bool) *MenuEntry {
|
||||||
var found *MenuEntry = nil
|
var found *MenuEntry
|
||||||
if menu, ok := ts.site.Menus[mn]; ok {
|
if menu, ok := ts.site.Menus[mn]; ok {
|
||||||
for _, me := range *menu {
|
for _, me := range *menu {
|
||||||
|
|
||||||
|
@ -423,7 +423,7 @@ func (ts testMenuState) findTestMenuEntry(mn string, id string, matcher func(me
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts testMenuState) findDescendantTestMenuEntry(parent *MenuEntry, id string, matcher func(me *MenuEntry, id string) bool) *MenuEntry {
|
func (ts testMenuState) findDescendantTestMenuEntry(parent *MenuEntry, id string, matcher func(me *MenuEntry, id string) bool) *MenuEntry {
|
||||||
var found *MenuEntry = nil
|
var found *MenuEntry
|
||||||
if parent.HasChildren() {
|
if parent.HasChildren() {
|
||||||
for _, child := range parent.Children {
|
for _, child := range parent.Children {
|
||||||
|
|
||||||
|
@ -500,7 +500,7 @@ func testSiteSetup(s *Site, t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func tomlToMap(s string) (map[string]interface{}, error) {
|
func tomlToMap(s string) (map[string]interface{}, error) {
|
||||||
var data map[string]interface{} = make(map[string]interface{})
|
var data = make(map[string]interface{})
|
||||||
if _, err := toml.Decode(s, &data); err != nil {
|
if _, err := toml.Decode(s, &data); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue