You've already forked go-semantic-release
feat(changelog): add string functions for changelog template
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package changelog
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
@@ -180,6 +181,10 @@ func generateTemplate(text string, values interface{}) (string, error) {
|
||||
|
||||
funcMap := template.FuncMap{
|
||||
"replace": replace,
|
||||
"lower": lower,
|
||||
"upper": upper,
|
||||
"capitalize": capitalize,
|
||||
"addPrefixToLines": addPrefixToLines,
|
||||
}
|
||||
|
||||
var tpl bytes.Buffer
|
||||
@@ -197,3 +202,30 @@ func generateTemplate(text string, values interface{}) (string, error) {
|
||||
func replace(input, from, to string) string {
|
||||
return strings.Replace(input, from, to, -1)
|
||||
}
|
||||
|
||||
func lower(input string) string {
|
||||
return strings.ToLower(input)
|
||||
}
|
||||
|
||||
func upper(input string) string {
|
||||
return strings.ToUpper(input)
|
||||
}
|
||||
|
||||
func capitalize(input string) string {
|
||||
if len(input) > 0 {
|
||||
return strings.ToUpper(string(input[0])) + input[1:]
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// Adds a prefix to each line of the given text block
|
||||
// this can be helpful in rendering correct indentation or bullets for multi-line texts
|
||||
func addPrefixToLines(input, prefix string) string {
|
||||
output := ""
|
||||
scanner := bufio.NewScanner(strings.NewReader(input))
|
||||
for scanner.Scan() {
|
||||
output += prefix + scanner.Text() + "\n"
|
||||
}
|
||||
output = strings.TrimRight(output, "\n")
|
||||
return output
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user