mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-29 22:29:56 +02:00
Correct initialisms as suggested by golint
First step to use initialisms that golint suggests, for example: Line 116: func GetHtmlRenderer should be GetHTMLRenderer as see on http://goreportcard.com/report/spf13/hugo Thanks to @bep for the idea! Note that command-line flags (cobra and pflag) as well as struct fields like .BaseUrl and .Url that are used in Go HTML templates need more work to maintain backward-compatibility, and thus are NOT yet dealt with in this commit. First step in fixing #959.
This commit is contained in:
@@ -58,7 +58,7 @@ type templateErr struct {
|
||||
err error
|
||||
}
|
||||
|
||||
type GoHtmlTemplate struct {
|
||||
type GoHTMLTemplate struct {
|
||||
template.Template
|
||||
errors []*templateErr
|
||||
}
|
||||
@@ -81,7 +81,7 @@ func InitializeT() Template {
|
||||
// Return a new Hugo Template System
|
||||
// With all the additional features, templates & functions
|
||||
func New() Template {
|
||||
var templates = &GoHtmlTemplate{
|
||||
var templates = &GoHTMLTemplate{
|
||||
Template: *template.New(""),
|
||||
errors: make([]*templateErr, 0),
|
||||
}
|
||||
@@ -934,21 +934,21 @@ func DateFormat(layout string, v interface{}) (string, error) {
|
||||
return t.Format(layout), nil
|
||||
}
|
||||
|
||||
func SafeHtml(text string) template.HTML {
|
||||
func SafeHTML(text string) template.HTML {
|
||||
return template.HTML(text)
|
||||
}
|
||||
|
||||
// "safeHtmlAttr" is currently disabled, pending further discussion
|
||||
// on its use case. 2015-01-19
|
||||
func SafeHtmlAttr(text string) template.HTMLAttr {
|
||||
func SafeHTMLAttr(text string) template.HTMLAttr {
|
||||
return template.HTMLAttr(text)
|
||||
}
|
||||
|
||||
func SafeCss(text string) template.CSS {
|
||||
func SafeCSS(text string) template.CSS {
|
||||
return template.CSS(text)
|
||||
}
|
||||
|
||||
func SafeUrl(text string) template.URL {
|
||||
func SafeURL(text string) template.URL {
|
||||
return template.URL(text)
|
||||
}
|
||||
|
||||
@@ -1151,12 +1151,12 @@ func ExecuteTemplateToHTML(context interface{}, layouts ...string) template.HTML
|
||||
return template.HTML(b.String())
|
||||
}
|
||||
|
||||
func (t *GoHtmlTemplate) LoadEmbedded() {
|
||||
func (t *GoHTMLTemplate) LoadEmbedded() {
|
||||
t.EmbedShortcodes()
|
||||
t.EmbedTemplates()
|
||||
}
|
||||
|
||||
func (t *GoHtmlTemplate) AddInternalTemplate(prefix, name, tpl string) error {
|
||||
func (t *GoHTMLTemplate) AddInternalTemplate(prefix, name, tpl string) error {
|
||||
if prefix != "" {
|
||||
return t.AddTemplate("_internal/"+prefix+"/"+name, tpl)
|
||||
} else {
|
||||
@@ -1164,11 +1164,11 @@ func (t *GoHtmlTemplate) AddInternalTemplate(prefix, name, tpl string) error {
|
||||
}
|
||||
}
|
||||
|
||||
func (t *GoHtmlTemplate) AddInternalShortcode(name, content string) error {
|
||||
func (t *GoHTMLTemplate) AddInternalShortcode(name, content string) error {
|
||||
return t.AddInternalTemplate("shortcodes", name, content)
|
||||
}
|
||||
|
||||
func (t *GoHtmlTemplate) AddTemplate(name, tpl string) error {
|
||||
func (t *GoHTMLTemplate) AddTemplate(name, tpl string) error {
|
||||
_, err := t.New(name).Parse(tpl)
|
||||
if err != nil {
|
||||
t.errors = append(t.errors, &templateErr{name: name, err: err})
|
||||
@@ -1176,7 +1176,7 @@ func (t *GoHtmlTemplate) AddTemplate(name, tpl string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (t *GoHtmlTemplate) AddTemplateFile(name, path string) error {
|
||||
func (t *GoHTMLTemplate) AddTemplateFile(name, path string) error {
|
||||
// get the suffix and switch on that
|
||||
ext := filepath.Ext(path)
|
||||
switch ext {
|
||||
@@ -1221,7 +1221,7 @@ func (t *GoHtmlTemplate) AddTemplateFile(name, path string) error {
|
||||
|
||||
}
|
||||
|
||||
func (t *GoHtmlTemplate) GenerateTemplateNameFrom(base, path string) string {
|
||||
func (t *GoHTMLTemplate) GenerateTemplateNameFrom(base, path string) string {
|
||||
name, _ := filepath.Rel(base, path)
|
||||
return filepath.ToSlash(name)
|
||||
}
|
||||
@@ -1234,7 +1234,7 @@ func isBackupFile(path string) bool {
|
||||
return path[len(path)-1] == '~'
|
||||
}
|
||||
|
||||
func (t *GoHtmlTemplate) loadTemplates(absPath string, prefix string) {
|
||||
func (t *GoHTMLTemplate) loadTemplates(absPath string, prefix string) {
|
||||
walker := func(path string, fi os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return nil
|
||||
@@ -1277,15 +1277,15 @@ func (t *GoHtmlTemplate) loadTemplates(absPath string, prefix string) {
|
||||
filepath.Walk(absPath, walker)
|
||||
}
|
||||
|
||||
func (t *GoHtmlTemplate) LoadTemplatesWithPrefix(absPath string, prefix string) {
|
||||
func (t *GoHTMLTemplate) LoadTemplatesWithPrefix(absPath string, prefix string) {
|
||||
t.loadTemplates(absPath, prefix)
|
||||
}
|
||||
|
||||
func (t *GoHtmlTemplate) LoadTemplates(absPath string) {
|
||||
func (t *GoHTMLTemplate) LoadTemplates(absPath string) {
|
||||
t.loadTemplates(absPath, "")
|
||||
}
|
||||
|
||||
func (t *GoHtmlTemplate) PrintErrors() {
|
||||
func (t *GoHTMLTemplate) PrintErrors() {
|
||||
for _, e := range t.errors {
|
||||
jww.ERROR.Println(e.err)
|
||||
}
|
||||
@@ -1293,8 +1293,9 @@ func (t *GoHtmlTemplate) PrintErrors() {
|
||||
|
||||
func init() {
|
||||
funcMap = template.FuncMap{
|
||||
"urlize": helpers.Urlize,
|
||||
"sanitizeurl": helpers.SanitizeUrl,
|
||||
"urlize": helpers.URLize,
|
||||
"sanitizeURL": helpers.SanitizeURL,
|
||||
"sanitizeurl": helpers.SanitizeURL,
|
||||
"eq": Eq,
|
||||
"ne": Ne,
|
||||
"gt": Gt,
|
||||
@@ -1303,11 +1304,15 @@ func init() {
|
||||
"le": Le,
|
||||
"in": In,
|
||||
"intersect": Intersect,
|
||||
"isSet": IsSet,
|
||||
"isset": IsSet,
|
||||
"echoParam": ReturnWhenSet,
|
||||
"safeHtml": SafeHtml,
|
||||
"safeCss": SafeCss,
|
||||
"safeUrl": SafeUrl,
|
||||
"safeHTML": SafeHTML,
|
||||
"safeHtml": SafeHTML,
|
||||
"safeCSS": SafeCSS,
|
||||
"safeCss": SafeCSS,
|
||||
"safeURL": SafeURL,
|
||||
"safeUrl": SafeURL,
|
||||
"markdownify": Markdownify,
|
||||
"first": First,
|
||||
"where": Where,
|
||||
@@ -1331,8 +1336,10 @@ func init() {
|
||||
"replace": Replace,
|
||||
"trim": Trim,
|
||||
"dateFormat": DateFormat,
|
||||
"getJson": GetJson,
|
||||
"getCsv": GetCsv,
|
||||
"getJSON": GetJSON,
|
||||
"getJson": GetJSON,
|
||||
"getCSV": GetCSV,
|
||||
"getCsv": GetCSV,
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -18,7 +18,7 @@ type Tmpl struct {
|
||||
Data string
|
||||
}
|
||||
|
||||
func (t *GoHtmlTemplate) EmbedShortcodes() {
|
||||
func (t *GoHTMLTemplate) EmbedShortcodes() {
|
||||
t.AddInternalShortcode("ref.html", `{{ .Get 0 | ref .Page }}`)
|
||||
t.AddInternalShortcode("relref.html", `{{ .Get 0 | relref .Page }}`)
|
||||
t.AddInternalShortcode("highlight.html", `{{ .Get 0 | highlight .Inner }}`)
|
||||
@@ -43,7 +43,7 @@ func (t *GoHtmlTemplate) EmbedShortcodes() {
|
||||
<!-- image -->`)
|
||||
}
|
||||
|
||||
func (t *GoHtmlTemplate) EmbedTemplates() {
|
||||
func (t *GoHTMLTemplate) EmbedTemplates() {
|
||||
|
||||
t.AddInternalTemplate("_default", "rss.xml", `<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
||||
<channel>
|
||||
|
@@ -31,7 +31,7 @@ import (
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var remoteUrlLock = &remoteLock{m: make(map[string]*sync.Mutex)}
|
||||
var remoteURLLock = &remoteLock{m: make(map[string]*sync.Mutex)}
|
||||
|
||||
type remoteLock struct {
|
||||
sync.RWMutex
|
||||
@@ -39,7 +39,7 @@ type remoteLock struct {
|
||||
}
|
||||
|
||||
// resLock locks an URL during download
|
||||
func (l *remoteLock) UrlLock(url string) {
|
||||
func (l *remoteLock) URLLock(url string) {
|
||||
l.Lock()
|
||||
if _, ok := l.m[url]; !ok {
|
||||
l.m[url] = &sync.Mutex{}
|
||||
@@ -49,7 +49,7 @@ func (l *remoteLock) UrlLock(url string) {
|
||||
}
|
||||
|
||||
// resUnlock unlocks an URL when the download has been finished. Use only in defer calls.
|
||||
func (l *remoteLock) UrlUnlock(url string) {
|
||||
func (l *remoteLock) URLUnlock(url string) {
|
||||
l.RLock()
|
||||
defer l.RUnlock()
|
||||
if um, ok := l.m[url]; ok {
|
||||
@@ -111,8 +111,8 @@ func resGetRemote(url string, fs afero.Fs, hc *http.Client) ([]byte, error) {
|
||||
}
|
||||
|
||||
// avoid race condition with locks, block other goroutines if the current url is processing
|
||||
remoteUrlLock.UrlLock(url)
|
||||
defer func() { remoteUrlLock.UrlUnlock(url) }()
|
||||
remoteURLLock.URLLock(url)
|
||||
defer func() { remoteURLLock.URLUnlock(url) }()
|
||||
|
||||
// avoid multiple locks due to calling resGetCache twice
|
||||
c, err = resGetCache(url, fs, viper.GetBool("IgnoreCache"))
|
||||
@@ -176,7 +176,7 @@ func resGetResource(url string) ([]byte, error) {
|
||||
// GetJson expects one or n-parts of a URL to a resource which can either be a local or a remote one.
|
||||
// If you provide multiple parts they will be joined together to the final URL.
|
||||
// GetJson returns nil or parsed JSON to use in a short code.
|
||||
func GetJson(urlParts ...string) interface{} {
|
||||
func GetJSON(urlParts ...string) interface{} {
|
||||
url := strings.Join(urlParts, "")
|
||||
c, err := resGetResource(url)
|
||||
if err != nil {
|
||||
@@ -194,7 +194,7 @@ func GetJson(urlParts ...string) interface{} {
|
||||
}
|
||||
|
||||
// parseCsv parses bytes of csv data into a slice slice string or an error
|
||||
func parseCsv(c []byte, sep string) ([][]string, error) {
|
||||
func parseCSV(c []byte, sep string) ([][]string, error) {
|
||||
if len(sep) != 1 {
|
||||
return nil, errors.New("Incorrect length of csv separator: " + sep)
|
||||
}
|
||||
@@ -211,14 +211,14 @@ func parseCsv(c []byte, sep string) ([][]string, error) {
|
||||
// The data separator can be a comma, semi-colon, pipe, etc, but only one character.
|
||||
// If you provide multiple parts for the URL they will be joined together to the final URL.
|
||||
// GetCsv returns nil or a slice slice to use in a short code.
|
||||
func GetCsv(sep string, urlParts ...string) [][]string {
|
||||
func GetCSV(sep string, urlParts ...string) [][]string {
|
||||
url := strings.Join(urlParts, "")
|
||||
c, err := resGetResource(url)
|
||||
if err != nil {
|
||||
jww.ERROR.Printf("Failed to get csv resource %s with error message %s", url, err)
|
||||
return nil
|
||||
}
|
||||
d, err := parseCsv(c, sep)
|
||||
d, err := parseCSV(c, sep)
|
||||
if err != nil {
|
||||
jww.ERROR.Printf("Failed to read csv resource %s with error message %s", url, err)
|
||||
return nil
|
||||
|
@@ -157,7 +157,7 @@ func TestScpGetRemote(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseCsv(t *testing.T) {
|
||||
func TestParseCSV(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
csv []byte
|
||||
@@ -173,7 +173,7 @@ func TestParseCsv(t *testing.T) {
|
||||
{[]byte("z|y|c\nd|e|f"), "|", "zycdef", false},
|
||||
}
|
||||
for _, test := range tests {
|
||||
csv, err := parseCsv(test.csv, test.sep)
|
||||
csv, err := parseCSV(test.csv, test.sep)
|
||||
if test.err && err == nil {
|
||||
t.Error("Expecting an error")
|
||||
}
|
||||
|
@@ -972,7 +972,7 @@ func TestDateFormat(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSafeHtml(t *testing.T) {
|
||||
func TestSafeHTML(t *testing.T) {
|
||||
for i, this := range []struct {
|
||||
str string
|
||||
tmplStr string
|
||||
@@ -997,7 +997,7 @@ func TestSafeHtml(t *testing.T) {
|
||||
}
|
||||
|
||||
buf.Reset()
|
||||
err = tmpl.Execute(buf, SafeHtml(this.str))
|
||||
err = tmpl.Execute(buf, SafeHTML(this.str))
|
||||
if err != nil {
|
||||
t.Errorf("[%d] execute template with an escaped string value by SafeHtml returns unexpected error: %s", i, err)
|
||||
}
|
||||
@@ -1007,7 +1007,7 @@ func TestSafeHtml(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSafeHtmlAttr(t *testing.T) {
|
||||
func TestSafeHTMLAttr(t *testing.T) {
|
||||
for i, this := range []struct {
|
||||
str string
|
||||
tmplStr string
|
||||
@@ -1032,7 +1032,7 @@ func TestSafeHtmlAttr(t *testing.T) {
|
||||
}
|
||||
|
||||
buf.Reset()
|
||||
err = tmpl.Execute(buf, SafeHtmlAttr(this.str))
|
||||
err = tmpl.Execute(buf, SafeHTMLAttr(this.str))
|
||||
if err != nil {
|
||||
t.Errorf("[%d] execute template with an escaped string value by SafeHtmlAttr returns unexpected error: %s", i, err)
|
||||
}
|
||||
@@ -1042,7 +1042,7 @@ func TestSafeHtmlAttr(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSafeCss(t *testing.T) {
|
||||
func TestSafeCSS(t *testing.T) {
|
||||
for i, this := range []struct {
|
||||
str string
|
||||
tmplStr string
|
||||
@@ -1067,7 +1067,7 @@ func TestSafeCss(t *testing.T) {
|
||||
}
|
||||
|
||||
buf.Reset()
|
||||
err = tmpl.Execute(buf, SafeCss(this.str))
|
||||
err = tmpl.Execute(buf, SafeCSS(this.str))
|
||||
if err != nil {
|
||||
t.Errorf("[%d] execute template with an escaped string value by SafeCss returns unexpected error: %s", i, err)
|
||||
}
|
||||
@@ -1077,7 +1077,7 @@ func TestSafeCss(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSafeUrl(t *testing.T) {
|
||||
func TestSafeURL(t *testing.T) {
|
||||
for i, this := range []struct {
|
||||
str string
|
||||
tmplStr string
|
||||
@@ -1102,7 +1102,7 @@ func TestSafeUrl(t *testing.T) {
|
||||
}
|
||||
|
||||
buf.Reset()
|
||||
err = tmpl.Execute(buf, SafeUrl(this.str))
|
||||
err = tmpl.Execute(buf, SafeURL(this.str))
|
||||
if err != nil {
|
||||
t.Errorf("[%d] execute template with an escaped string value by SafeUrl returns unexpected error: %s", i, err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user