mirror of
https://github.com/beego/bee.git
synced 2025-07-04 21:50:18 +00:00
Removes the use of template/html
This uses the template/text instead because template/html does not escape quotes and replaces them with their HTML codes. Added two more util functions to make it easy to use bold and colored text in the command long description.
This commit is contained in:
25
util.go
25
util.go
@ -15,6 +15,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
@ -24,6 +25,7 @@ import (
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -281,3 +283,26 @@ func __LINE__() int {
|
||||
_, _, line, _ := runtime.Caller(1)
|
||||
return line
|
||||
}
|
||||
|
||||
// BeeFuncMap returns a FuncMap of functions used in different templates.
|
||||
func BeeFuncMap() template.FuncMap {
|
||||
return template.FuncMap{
|
||||
"trim": strings.TrimSpace,
|
||||
"bold": bold,
|
||||
"headline": MagentaBold,
|
||||
"endline": EndLine,
|
||||
"tmpltostr": TmplToString,
|
||||
}
|
||||
}
|
||||
|
||||
// TmplToString parses a text template and return the result as a string.
|
||||
func TmplToString(tmpl string, data interface{}) string {
|
||||
t := template.New("tmpl").Funcs(BeeFuncMap())
|
||||
template.Must(t.Parse(tmpl))
|
||||
|
||||
var doc bytes.Buffer
|
||||
err := t.Execute(&doc, data)
|
||||
MustCheck(err)
|
||||
|
||||
return doc.String()
|
||||
}
|
||||
|
Reference in New Issue
Block a user