shithub: hugo

Download patch

ref: 44d57fdc0ce6743a92a8ad8b73566e344762cc24
parent: 10c7cf29424b6c230ae9df14de41656e97ea85c8
author: spf13 <steve.francia@gmail.com>
date: Thu Dec 5 04:29:41 EST 2013

Reorganize helpers

--- /dev/null
+++ b/helpers/templates.go
@@ -1,0 +1,29 @@
+// Copyright © 2013 Steve Francia <spf@spf13.com>.
+//
+// Licensed under the Simple Public License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+// http://opensource.org/licenses/Simple-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package helpers
+
+import (
+	"regexp"
+	"strings"
+)
+
+var sanitizeRegexp = regexp.MustCompile("[^a-zA-Z0-9./_-]")
+
+func Urlize(url string) string {
+	return Sanitize(strings.ToLower(strings.Replace(strings.TrimSpace(url), " ", "-", -1)))
+}
+
+func Sanitize(s string) string {
+	return sanitizeRegexp.ReplaceAllString(s, "")
+}
--- a/hugolib/index.go
+++ b/hugolib/index.go
@@ -14,7 +14,7 @@
 package hugolib
 
 import (
-	"github.com/spf13/hugo/template"
+	"github.com/spf13/hugo/helpers"
 	"sort"
 )
 
@@ -50,7 +50,7 @@
 
 // KeyPrep... Indexes should be case insensitive. Can make it easily conditional later.
 func kp(in string) string {
-	return template.Urlize(in)
+	return helpers.Urlize(in)
 }
 
 func (i Index) Get(key string) IndexedPages { return i[kp(key)] }
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -18,8 +18,8 @@
 	"errors"
 	"fmt"
 	"github.com/BurntSushi/toml"
+	"github.com/spf13/hugo/helpers"
 	"github.com/spf13/hugo/parser"
-	helper "github.com/spf13/hugo/template"
 	"github.com/spf13/hugo/template/bundle"
 	"github.com/theplant/blackfriday"
 	"html/template"
@@ -366,12 +366,12 @@
 		case "description":
 			page.Description = interfaceToString(v)
 		case "slug":
-			page.Slug = helper.Urlize(interfaceToString(v))
+			page.Slug = helpers.Urlize(interfaceToString(v))
 		case "url":
 			if url := interfaceToString(v); strings.HasPrefix(url, "http://") || strings.HasPrefix(url, "https://") {
 				return fmt.Errorf("Only relative urls are supported, %v provided", url)
 			}
-			page.Url = helper.Urlize(interfaceToString(v))
+			page.Url = helpers.Urlize(interfaceToString(v))
 		case "type":
 			page.contentType = interfaceToString(v)
 		case "keywords":
--- a/hugolib/permalinks.go
+++ b/hugolib/permalinks.go
@@ -6,7 +6,7 @@
 	"strconv"
 	"strings"
 
-	helper "github.com/spf13/hugo/template"
+	"github.com/spf13/hugo/helpers"
 )
 
 // PathPattern represents a string which builds up a URL from attributes
@@ -117,7 +117,7 @@
 func pageToPermalinkTitle(p *Page, _ string) (string, error) {
 	// Page contains Node which has Title
 	// (also contains UrlPath which has Slug, sometimes)
-	return helper.Urlize(p.Title), nil
+	return helpers.Urlize(p.Title), nil
 }
 
 // if the page has a slug, return the slug, else return the title
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -17,9 +17,9 @@
 	"bitbucket.org/pkg/inflect"
 	"bytes"
 	"fmt"
+	"github.com/spf13/hugo/helpers"
 	"github.com/spf13/hugo/source"
 	"github.com/spf13/hugo/target"
-	helpers "github.com/spf13/hugo/template"
 	"github.com/spf13/hugo/template/bundle"
 	"github.com/spf13/hugo/transform"
 	"github.com/spf13/nitro"
--- a/target/htmlredirect.go
+++ b/target/htmlredirect.go
@@ -2,7 +2,7 @@
 
 import (
 	"bytes"
-	helpers "github.com/spf13/hugo/template"
+	"github.com/spf13/hugo/helpers"
 	"html/template"
 	"path"
 	"strings"
--- a/template/bundle/template.go
+++ b/template/bundle/template.go
@@ -3,7 +3,7 @@
 import (
 	"errors"
 	"github.com/eknkc/amber"
-	helpers "github.com/spf13/hugo/template"
+	"github.com/spf13/hugo/helpers"
 	"html/template"
 	"io"
 	"io/ioutil"
--- a/template/helpers.go
+++ /dev/null
@@ -1,29 +1,0 @@
-// Copyright © 2013 Steve Francia <spf@spf13.com>.
-//
-// Licensed under the Simple Public License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-// http://opensource.org/licenses/Simple-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package template
-
-import (
-	"regexp"
-	"strings"
-)
-
-var sanitizeRegexp = regexp.MustCompile("[^a-zA-Z0-9./_-]")
-
-func Urlize(url string) string {
-	return Sanitize(strings.ToLower(strings.Replace(strings.TrimSpace(url), " ", "-", -1)))
-}
-
-func Sanitize(s string) string {
-	return sanitizeRegexp.ReplaceAllString(s, "")
-}
--