Skip to content

Commit

Permalink
More initialism corrections (golint)
Browse files Browse the repository at this point in the history
Thanks to @bep's new, brilliant helpers.Deprecated() function,
the following functions or variables are transitioned to their
new names, preserving backward compatibility for v0.14
and warning the user of upcoming obsolescence in v0.15:

 * .Url → .URL (for node, menu and paginator)
 * .Site.BaseUrl → .Site.BaseURL
 * .Site.Indexes → .Site.Taxonomies
 * .Site.Recent → .Site.Pages
 * getJson → getJSON
 * getCsv → getCSV
 * safeHtml → safeHTML
 * safeCss → safeCSS
 * safeUrl → safeURL

Also fix related initialisms in strings and comments.

Continued effort in fixing gohugoio#959.
  • Loading branch information
anthonyfok committed Mar 18, 2015
1 parent ca69cad commit 6cdf539
Show file tree
Hide file tree
Showing 20 changed files with 184 additions and 129 deletions.
4 changes: 2 additions & 2 deletions commands/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func serve(port int) {
}
}

// fixUrl massages the BaseUrl into a form needed for serving
// fixURL massages the BaseURL into a form needed for serving
// all pages correctly.
func fixURL(s string) (string, error) {
useLocalhost := false
Expand Down Expand Up @@ -164,7 +164,7 @@ func fixURL(s string) (string, error) {
if strings.Contains(host, ":") {
host, _, err = net.SplitHostPort(u.Host)
if err != nil {
return "", fmt.Errorf("Failed to split BaseUrl hostpost: %s", err)
return "", fmt.Errorf("Failed to split BaseURL hostpost: %s", err)
}
}
u.Host = fmt.Sprintf("%s:%d", host, serverPort)
Expand Down
2 changes: 1 addition & 1 deletion helpers/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func PathPrep(ugly bool, in string) string {
return PrettifyPath(in)
}

// Same as PrettifyUrlPath() but for file paths.
// Same as PrettifyURLPath() but for file paths.
// /section/name.html becomes /section/name/index.html
// /section/name/ becomes /section/name/index.html
// /section/name/index.html becomes /section/name/index.html
Expand Down
14 changes: 7 additions & 7 deletions helpers/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func sanitizeURLWithFlags(in string, f purell.NormalizationFlags) string {
// in issues #157, #622, etc., without forcing
// relative URLs to begin with '/'.
// Once the fixes are in, let's remove this kludge
// and restore SanitizeUrl() to the way it was.
// and restore SanitizeURL() to the way it was.
// -- @anthonyfok, 2015-02-16
//
// Begin temporary kludge
Expand All @@ -87,12 +87,12 @@ func sanitizeURLWithFlags(in string, f purell.NormalizationFlags) string {

}

// SanitizeUrl sanitizes the input URL string.
// SanitizeURL sanitizes the input URL string.
func SanitizeURL(in string) string {
return sanitizeURLWithFlags(in, purell.FlagsSafe|purell.FlagRemoveTrailingSlash|purell.FlagRemoveDotSegments|purell.FlagRemoveDuplicateSlashes|purell.FlagRemoveUnnecessaryHostDots|purell.FlagRemoveEmptyPortSeparator)
}

// SanitizeUrlKeepTrailingSlash is the same as SanitizeUrl, but will keep any trailing slash.
// SanitizeURLKeepTrailingSlash is the same as SanitizeURL, but will keep any trailing slash.
func SanitizeURLKeepTrailingSlash(in string) string {
return sanitizeURLWithFlags(in, purell.FlagsSafe|purell.FlagRemoveDotSegments|purell.FlagRemoveDuplicateSlashes|purell.FlagRemoveUnnecessaryHostDots|purell.FlagRemoveEmptyPortSeparator)
}
Expand Down Expand Up @@ -147,7 +147,7 @@ func MakePermalink(host, plink string) *url.URL {

// AddContextRoot adds the context root to an URL if it's not already set.
// For relative URL entries on sites with a base url with a context root set (i.e. http://example.com/mysite),
// relative URLs must not include the context root if canonifyUrls is enabled. But if it's disabled, it must be set.
// relative URLs must not include the context root if canonifyURLs is enabled. But if it's disabled, it must be set.
func AddContextRoot(baseURL, relativePath string) string {

url, err := url.Parse(baseURL)
Expand Down Expand Up @@ -185,7 +185,7 @@ func URLPrep(ugly bool, in string) string {
return url
}

// PrettifyUrl takes a URL string and returns a semantic, clean URL.
// PrettifyURL takes a URL string and returns a semantic, clean URL.
func PrettifyURL(in string) string {
x := PrettifyURLPath(in)

Expand All @@ -200,7 +200,7 @@ func PrettifyURL(in string) string {
return x
}

// PrettifyUrlPath takes a URL path to a content and converts it
// PrettifyURLPath takes a URL path to a content and converts it
// to enable pretty URLs.
// /section/name.html becomes /section/name/index.html
// /section/name/ becomes /section/name/index.html
Expand All @@ -209,7 +209,7 @@ func PrettifyURLPath(in string) string {
return PrettiyPath(in, pathBridge)
}

// Uglify does the opposite of PrettifyUrlPath().
// Uglify does the opposite of PrettifyURLPath().
// /section/name/index.html becomes /section/name.html
// /section/name/ becomes /section/name.html
// /section/name.html becomes /section/name.html
Expand Down
6 changes: 3 additions & 3 deletions helpers/url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"
)

func TestUrlize(t *testing.T) {
func TestURLize(t *testing.T) {
tests := []struct {
input string
expected string
Expand All @@ -26,7 +26,7 @@ func TestUrlize(t *testing.T) {
}
}

func TestSanitizeUrl(t *testing.T) {
func TestSanitizeURL(t *testing.T) {
tests := []struct {
input string
expected string
Expand Down Expand Up @@ -76,7 +76,7 @@ func TestMakePermalink(t *testing.T) {
}
}

func TestUrlPrep(t *testing.T) {
func TestURLPrep(t *testing.T) {
type test struct {
ugly bool
input string
Expand Down
21 changes: 14 additions & 7 deletions hugolib/menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ import (
"strings"

"github.com/spf13/cast"
"github.com/spf13/hugo/helpers"
)

type MenuEntry struct {
Url string
URL string
Name string
Menu string
Identifier string
Expand All @@ -37,6 +38,12 @@ type Menu []*MenuEntry
type Menus map[string]*Menu
type PageMenus map[string]*MenuEntry

// Url is deprecated. Will be removed in 0.15.
func (me *MenuEntry) Url() string {
helpers.Deprecated("MenuEntry", ".Url", ".URL")
return me.URL
}

func (me *MenuEntry) AddChild(child *MenuEntry) {
me.Children = append(me.Children, child)
me.Children.Sort()
Expand All @@ -53,30 +60,30 @@ func (me *MenuEntry) KeyName() string {
return me.Name
}

func (me *MenuEntry) hopefullyUniqueId() string {
func (me *MenuEntry) hopefullyUniqueID() string {
if me.Identifier != "" {
return me.Identifier
} else if me.Url != "" {
return me.Url
} else if me.URL != "" {
return me.URL
} else {
return me.Name
}
}

func (me *MenuEntry) IsEqual(inme *MenuEntry) bool {
return me.hopefullyUniqueId() == inme.hopefullyUniqueId() && me.Parent == inme.Parent
return me.hopefullyUniqueID() == inme.hopefullyUniqueID() && me.Parent == inme.Parent
}

func (me *MenuEntry) IsSameResource(inme *MenuEntry) bool {
return me.Url != "" && inme.Url != "" && me.Url == inme.Url
return me.URL != "" && inme.URL != "" && me.URL == inme.URL
}

func (me *MenuEntry) MarshallMap(ime map[string]interface{}) {
for k, v := range ime {
loki := strings.ToLower(k)
switch loki {
case "url":
me.Url = cast.ToString(v)
me.URL = cast.ToString(v)
case "weight":
me.Weight = cast.ToInt(v)
case "name":
Expand Down
20 changes: 10 additions & 10 deletions hugolib/menu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ func doTestPageMenuWithIdentifier(t *testing.T, menuPageSources []source.ByteSou
assert.NotNil(t, me1)
assert.NotNil(t, me2)

assert.True(t, strings.Contains(me1.Url, "doc1"))
assert.True(t, strings.Contains(me2.Url, "doc2"))
assert.True(t, strings.Contains(me1.URL, "doc1"))
assert.True(t, strings.Contains(me2.URL, "doc2"))

}

Expand Down Expand Up @@ -216,8 +216,8 @@ func doTestPageMenuWithDuplicateName(t *testing.T, menuPageSources []source.Byte
assert.NotNil(t, me1)
assert.NotNil(t, me2)

assert.True(t, strings.Contains(me1.Url, "doc1"))
assert.True(t, strings.Contains(me2.Url, "doc2"))
assert.True(t, strings.Contains(me1.URL, "doc1"))
assert.True(t, strings.Contains(me2.URL, "doc2"))

}

Expand Down Expand Up @@ -275,7 +275,7 @@ func TestMenuWithHashInURL(t *testing.T) {

assert.NotNil(t, me)

assert.Equal(t, "/Zoo/resource/#anchor", me.Url)
assert.Equal(t, "/Zoo/resource/#anchor", me.URL)
}

// issue #719
Expand Down Expand Up @@ -309,7 +309,7 @@ func doTestMenuWithUnicodeURLs(t *testing.T, canonifyURLs, uglyURLs bool) {
expected = expectedBase + "/"
}

assert.Equal(t, expected, unicodeRussian.Url, "uglyURLs[%t]", uglyURLs)
assert.Equal(t, expected, unicodeRussian.URL, "uglyURLs[%t]", uglyURLs)
}

func TestTaxonomyNodeMenu(t *testing.T) {
Expand All @@ -329,7 +329,7 @@ func TestTaxonomyNodeMenu(t *testing.T) {
{"tax", taxRenderInfo{key: "key", singular: "one", plural: "two"},
ts.findTestMenuEntryByID("tax", "2"), true, false},
{"tax", taxRenderInfo{key: "key", singular: "one", plural: "two"},
&MenuEntry{Name: "Somewhere else", Url: "/somewhereelse"}, false, false},
&MenuEntry{Name: "Somewhere else", URL: "/somewhereelse"}, false, false},
} {

n, _ := ts.site.newTaxonomyNode(this.taxInfo)
Expand All @@ -349,7 +349,7 @@ func TestTaxonomyNodeMenu(t *testing.T) {

menuEntryXML := ts.findTestMenuEntryByID("tax", "xml")

if strings.HasSuffix(menuEntryXML.Url, "/") {
if strings.HasSuffix(menuEntryXML.URL, "/") {
t.Error("RSS menu item should not be padded with trailing slash")
}
}
Expand All @@ -359,7 +359,7 @@ func TestHomeNodeMenu(t *testing.T) {
defer resetMenuTestState(ts)

home := ts.site.newHomeNode()
homeMenuEntry := &MenuEntry{Name: home.Title, Url: home.Url}
homeMenuEntry := &MenuEntry{Name: home.Title, URL: home.URL}

for i, this := range []struct {
menu string
Expand All @@ -369,7 +369,7 @@ func TestHomeNodeMenu(t *testing.T) {
}{
{"main", homeMenuEntry, true, false},
{"doesnotexist", homeMenuEntry, false, false},
{"main", &MenuEntry{Name: "Somewhere else", Url: "/somewhereelse"}, false, false},
{"main", &MenuEntry{Name: "Somewhere else", URL: "/somewhereelse"}, false, false},
{"grandparent", ts.findTestMenuEntryByID("grandparent", "grandparentId"), false, false},
{"grandparent", ts.findTestMenuEntryByID("grandparent", "parentId"), false, true},
{"grandparent", ts.findTestMenuEntryByID("grandparent", "grandchildId"), true, false},
Expand Down
17 changes: 12 additions & 5 deletions hugolib/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"html/template"
"sync"
"time"
"github.com/spf13/hugo/helpers"
)

type Node struct {
Expand All @@ -30,7 +31,7 @@ type Node struct {
Params map[string]interface{}
Date time.Time
Sitemap Sitemap
UrlPath
URLPath
paginator *pager
paginatorInit sync.Once
scratch *Scratch
Expand All @@ -42,7 +43,7 @@ func (n *Node) Now() time.Time {

func (n *Node) HasMenuCurrent(menuID string, inme *MenuEntry) bool {
if inme.HasChildren() {
me := MenuEntry{Name: n.Title, Url: n.Url}
me := MenuEntry{Name: n.Title, URL: n.URL}

for _, child := range inme.Children {
if me.IsSameResource(child) {
Expand All @@ -56,7 +57,7 @@ func (n *Node) HasMenuCurrent(menuID string, inme *MenuEntry) bool {

func (n *Node) IsMenuCurrent(menuID string, inme *MenuEntry) bool {

me := MenuEntry{Name: n.Title, Url: n.Url}
me := MenuEntry{Name: n.Title, URL: n.URL}
if !me.IsSameResource(inme) {
return false
}
Expand Down Expand Up @@ -119,13 +120,19 @@ func (n *Node) RelRef(ref string) (string, error) {
return n.Site.RelRef(ref, nil)
}

type UrlPath struct {
Url string
type URLPath struct {
URL string
Permalink template.HTML
Slug string
Section string
}

// Url is deprecated. Will be removed in 0.15.
func (n *Node) Url() string {
helpers.Deprecated("Node", ".Url", ".URL")
return n.URL
}

// Scratch returns the writable context associated with this Node.
func (n *Node) Scratch() *Scratch {
if n.scratch == nil {
Expand Down
24 changes: 12 additions & 12 deletions hugolib/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,10 @@ func (p *Page) analyzePage() {
}

func (p *Page) permalink() (*url.URL, error) {
baseURL := string(p.Site.BaseUrl)
baseURL := string(p.Site.BaseURL)
dir := strings.TrimSpace(filepath.ToSlash(p.Source.Dir()))
pSlug := strings.TrimSpace(p.Slug)
pURL := strings.TrimSpace(p.Url)
pURL := strings.TrimSpace(p.URL)
var permalink string
var err error

Expand Down Expand Up @@ -420,9 +420,9 @@ func (p *Page) RelPermalink() (string, error) {
}

if viper.GetBool("CanonifyURLs") {
// replacements for relpermalink with baseUrl on the form http://myhost.com/sub/ will fail later on
// have to return the Url relative from baseUrl
relpath, err := helpers.GetRelativePath(link.String(), string(p.Site.BaseUrl))
// replacements for relpermalink with baseURL on the form http://myhost.com/sub/ will fail later on
// have to return the URL relative from baseURL
relpath, err := helpers.GetRelativePath(link.String(), string(p.Site.BaseURL))
if err != nil {
return "", err
}
Expand Down Expand Up @@ -455,9 +455,9 @@ func (p *Page) update(f interface{}) error {
p.Slug = helpers.URLize(cast.ToString(v))
case "url":
if url := cast.ToString(v); strings.HasPrefix(url, "http://") || strings.HasPrefix(url, "https://") {
return fmt.Errorf("Only relative urls are supported, %v provided", url)
return fmt.Errorf("Only relative URLs are supported, %v provided", url)
}
p.Url = helpers.URLize(cast.ToString(v))
p.URL = helpers.URLize(cast.ToString(v))
case "type":
p.contentType = cast.ToString(v)
case "extension", "ext":
Expand Down Expand Up @@ -588,7 +588,7 @@ func (p *Page) Menus() PageMenus {
if ms, ok := p.Params["menu"]; ok {
link, _ := p.RelPermalink()

me := MenuEntry{Name: p.LinkTitle(), Weight: p.Weight, Url: link}
me := MenuEntry{Name: p.LinkTitle(), Weight: p.Weight, URL: link}

// Could be the name of the menu to attach it to
mname, err := cast.ToStringE(ms)
Expand Down Expand Up @@ -618,7 +618,7 @@ func (p *Page) Menus() PageMenus {
}

for name, menu := range menus {
menuEntry := MenuEntry{Name: p.LinkTitle(), Url: link, Weight: p.Weight, Menu: name}
menuEntry := MenuEntry{Name: p.LinkTitle(), URL: link, Weight: p.Weight, Menu: name}
jww.DEBUG.Printf("found menu: %q, in %q\n", name, p.Title)

ime, err := cast.ToStringMapE(menu)
Expand Down Expand Up @@ -785,9 +785,9 @@ func (p *Page) FullFilePath() string {

func (p *Page) TargetPath() (outfile string) {

// Always use Url if it's specified
if len(strings.TrimSpace(p.Url)) > 2 {
outfile = strings.TrimSpace(p.Url)
// Always use URL if it's specified
if len(strings.TrimSpace(p.URL)) > 2 {
outfile = strings.TrimSpace(p.URL)

if strings.HasSuffix(outfile, "/") {
outfile = outfile + "index.html"
Expand Down
Loading

0 comments on commit 6cdf539

Please sign in to comment.