Wrap comments helpers package to fit 80-column width

Add an initial space after `//` where appropriate.
Minor copyediting.
This commit is contained in:
Anthony Fok 2014-12-26 08:07:03 -07:00
parent fbf8bcacc4
commit f5a3fb149f
5 changed files with 71 additions and 52 deletions

View file

@ -11,8 +11,10 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
//Package helpers implements general utility functions that work with and on content. The helper functions defined here // Package helpers implements general utility functions that work with
//lay down the foundation of how Hugo works with files, filepaths and does string operations on content. // and on content. The helper functions defined here lay down the
// foundation of how Hugo works with files and filepaths, and perform
// string operations on content.
package helpers package helpers
import ( import (
@ -212,7 +214,8 @@ func RemoveSummaryDivider(content []byte) []byte {
return bytes.Replace(content, SummaryDivider, []byte(""), -1) return bytes.Replace(content, SummaryDivider, []byte(""), -1)
} }
//TruncateWords takes content and na int and shortens down the number of words in the content down to the number of int. // TruncateWords takes content and an int and shortens down the number
// of words in the content down to the number of int.
func TruncateWords(s string, max int) string { func TruncateWords(s string, max int) string {
words := strings.Fields(s) words := strings.Fields(s)
if max > len(words) { if max > len(words) {
@ -222,7 +225,8 @@ func TruncateWords(s string, max int) string {
return strings.Join(words[:max], " ") return strings.Join(words[:max], " ")
} }
//TruncateWordsToWholeSentence takes content and an int and returns entire sentences from content, delimited by the int. // TruncateWordsToWholeSentence takes content and an int
// and returns entire sentences from content, delimited by the int.
func TruncateWordsToWholeSentence(s string, max int) string { func TruncateWordsToWholeSentence(s string, max int) string {
words := strings.Fields(s) words := strings.Fields(s)
if max > len(words) { if max > len(words) {
@ -241,6 +245,8 @@ func TruncateWordsToWholeSentence(s string, max int) string {
return strings.Join(words[:max], " ") return strings.Join(words[:max], " ")
} }
// GetRstContent calls the Python script rst2html as an external helper
// to convert reStructuredText content to HTML.
func GetRstContent(content []byte) string { func GetRstContent(content []byte) string {
cleanContent := bytes.Replace(content, SummaryDivider, []byte(""), 1) cleanContent := bytes.Replace(content, SummaryDivider, []byte(""), 1)

View file

@ -40,7 +40,8 @@ func FindAvailablePort() (*net.TCPAddr, error) {
return nil, err return nil, err
} }
// InStringArray checks if a string is an element of a slice of strings and returns a boolean value. // InStringArray checks if a string is an element of a slice of strings
// and returns a boolean value.
func InStringArray(arr []string, el string) bool { func InStringArray(arr []string, el string) bool {
for _, v := range arr { for _, v := range arr {
if v == el { if v == el {
@ -64,7 +65,8 @@ func GuessType(in string) string {
return "unknown" return "unknown"
} }
//ReaderToBytes takes an io.Reader argument, reads from it and returns bytes. // ReaderToBytes takes an io.Reader argument, reads from it
// and returns bytes.
func ReaderToBytes(lines io.Reader) []byte { func ReaderToBytes(lines io.Reader) []byte {
b := new(bytes.Buffer) b := new(bytes.Buffer)
b.ReadFrom(lines) b.ReadFrom(lines)
@ -88,7 +90,7 @@ func BytesToReader(in []byte) io.Reader {
return bytes.NewReader(in) return bytes.NewReader(in)
} }
// sliceToLower goes through the source slice and lowers all values. // SliceToLower goes through the source slice and lowers all values.
func SliceToLower(s []string) []string { func SliceToLower(s []string) []string {
if s == nil { if s == nil {
return nil return nil
@ -102,7 +104,7 @@ func SliceToLower(s []string) []string {
return l return l
} }
//Md5String takes a string and returns a MD5 Hash of it. // Md5String takes a string and returns its MD5 hash.
func Md5String(f string) string { func Md5String(f string) string {
h := md5.New() h := md5.New()
h.Write([]byte(f)) h.Write([]byte(f))

View file

@ -28,15 +28,16 @@ import (
var sanitizeRegexp = regexp.MustCompile("[^a-zA-Z0-9./_-]") var sanitizeRegexp = regexp.MustCompile("[^a-zA-Z0-9./_-]")
// Take a string with any characters and replace it so the string could be used in a path. // MakePath takes a string with any characters and replace it
// MakePath creates a Unicode sanitized string, with the spaces replaced, whilst // so the string could be used in a path.
// preserving the original casing of the string. // It does so by creating a Unicode-sanitized string, with the spaces replaced,
// whilst preserving the original casing of the string.
// E.g. Social Media -> Social-Media // E.g. Social Media -> Social-Media
func MakePath(s string) string { func MakePath(s string) string {
return UnicodeSanitize(strings.Replace(strings.TrimSpace(s), " ", "-", -1)) return UnicodeSanitize(strings.Replace(strings.TrimSpace(s), " ", "-", -1))
} }
// MakePathToLower creates a Unicode santized string, with the spaces replaced, // MakePathToLower creates a Unicode-sanitized string, with the spaces replaced,
// and transformed to lower case. // and transformed to lower case.
// E.g. Social Media -> social-media // E.g. Social Media -> social-media
func MakePathToLower(s string) string { func MakePathToLower(s string) string {
@ -65,7 +66,8 @@ func UnicodeSanitize(s string) string {
return string(target) return string(target)
} }
//ReplaceExtension takes a path and an extension, strips the old extension and returns the path with the new extension. // ReplaceExtension takes a path and an extension, strips the old extension
// and returns the path with the new extension.
func ReplaceExtension(path string, newExt string) string { func ReplaceExtension(path string, newExt string) string {
f, _ := FileAndExt(path) f, _ := FileAndExt(path)
return f + "." + newExt return f + "." + newExt
@ -83,7 +85,7 @@ func DirExists(path string, fs afero.Fs) (bool, error) {
return false, err return false, err
} }
//IsDir check if a given path is a directory. // IsDir checks if a given path is a directory.
func IsDir(path string, fs afero.Fs) (bool, error) { func IsDir(path string, fs afero.Fs) (bool, error) {
fi, err := fs.Stat(path) fi, err := fs.Stat(path)
if err != nil { if err != nil {
@ -154,7 +156,8 @@ func MakePathRelative(inPath string, possibleDirectories ...string) (string, err
return inPath, errors.New("Can't extract relative path, unknown prefix") return inPath, errors.New("Can't extract relative path, unknown prefix")
} }
//Filename takes a path, strips out the extension and returns the name of the file. // Filename takes a path, strips out the extension,
// and returns the name of the file.
func Filename(in string) (name string) { func Filename(in string) (name string) {
name, _ = FileAndExt(in) name, _ = FileAndExt(in)
return return
@ -162,14 +165,18 @@ func Filename(in string) (name string) {
// FileAndExt returns the filename and any extension of a file path as // FileAndExt returns the filename and any extension of a file path as
// two separate strings. // two separate strings.
// If path, in, contains a directory name ending in a slash then //
// both name and ext will be empty strings. // If the path, in, contains a directory name ending in a slash,
// then both name and ext will be empty strings.
//
// If the path, in, is either the current directory, the parent // If the path, in, is either the current directory, the parent
// directory or the root directory, or an empty string, then both // directory or the root directory, or an empty string,
// name and ext will be empty strings. // then both name and ext will be empty strings.
// If the path, in, represents the path of a file without an extension //
// If the path, in, represents the path of a file without an extension,
// then name will be the name of the file and ext will be an empty string. // then name will be the name of the file and ext will be an empty string.
// If the path, in, represents a filename with an extension then //
// If the path, in, represents a filename with an extension,
// then name will be the filename minus any extension - including the dot // then name will be the filename minus any extension - including the dot
// and ext will contain the extension - minus the dot. // and ext will contain the extension - minus the dot.
func FileAndExt(in string) (name string, ext string) { func FileAndExt(in string) (name string, ext string) {
@ -216,8 +223,9 @@ func GetRelativePath(path, base string) (final string, err error) {
return name, nil return name, nil
} }
// Given a source path, determine the section // Given a source path, determine the section.
// A section is the part between the root slash and the second slash or before the first slash // A section is the part between the root slash and the second slash
// or before the first slash.
func GuessSection(in string) string { func GuessSection(in string) string {
parts := strings.Split(in, FilePathSeparator) parts := strings.Split(in, FilePathSeparator)
// This will include an empty entry before and after paths with leading and trailing slashes // This will include an empty entry before and after paths with leading and trailing slashes
@ -258,7 +266,7 @@ func PathPrep(ugly bool, in string) string {
} }
} }
// Same as PrettifyUrlPath() but for paths. // Same as PrettifyUrlPath() but for file paths.
// /section/name.html becomes /section/name/index.html // /section/name.html becomes /section/name/index.html
// /section/name/ becomes /section/name/index.html // /section/name/ becomes /section/name/index.html
// /section/name/index.html becomes /section/name/index.html // /section/name/index.html becomes /section/name/index.html
@ -281,7 +289,8 @@ func PrettifyPath(in string) string {
} }
} }
//FindCWD returns the current working directory from where the Hugo executable is run. // FindCWD returns the current working directory from where the Hugo
// executable is run.
func FindCWD() (string, error) { func FindCWD() (string, error) {
serverFile, err := filepath.Abs(os.Args[0]) serverFile, err := filepath.Abs(os.Args[0])

View file

@ -25,7 +25,8 @@ import (
const pygmentsBin = "pygmentize" const pygmentsBin = "pygmentize"
//HasPygments checks to see if Pygments is installed and available on the system. // HasPygments checks to see if Pygments is installed and available
// on the system.
func HasPygments() bool { func HasPygments() bool {
if _, err := exec.LookPath(pygmentsBin); err != nil { if _, err := exec.LookPath(pygmentsBin); err != nil {
return false return false

View file

@ -111,7 +111,8 @@ func PrettifyUrl(in string) string {
return x return x
} }
//PrettifyUrlPath takes a URL path to a content and converts it to enable pretty URLS. // 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.html becomes /section/name/index.html
// /section/name/ becomes /section/name/index.html // /section/name/ becomes /section/name/index.html
// /section/name/index.html becomes /section/name/index.html // /section/name/index.html becomes /section/name/index.html
@ -134,7 +135,7 @@ func PrettifyUrlPath(in string) string {
} }
} }
//Uglify does the opposite of PrettifyPath(). // Uglify does the opposite of PrettifyUrlPath().
// /section/name/index.html becomes /section/name.html // /section/name/index.html becomes /section/name.html
// /section/name/ becomes /section/name.html // /section/name/ becomes /section/name.html
// /section/name.html becomes /section/name.html // /section/name.html becomes /section/name.html
@ -162,7 +163,7 @@ func Uglify(in string) string {
} }
} }
// Same as FileAndExt, but for Urls // Same as FileAndExt, but for URLs.
func ResourceAndExt(in string) (name string, ext string) { func ResourceAndExt(in string) (name string, ext string) {
ext = path.Ext(in) ext = path.Ext(in)
base := path.Base(in) base := path.Base(in)