Skip to content

Commit f34937b

Browse files
Ivan De Marinodetro
authored andcommitted
Adding lower, upper and title functions
1 parent 1998ecc commit f34937b

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,14 @@ using the following data fields and functions:
164164
| Function | Description |
165165
|-----------------|---------------------------------------------------------------------------------------------------|
166166
| `codefile` | Create a Markdown code block with the content of a file. Path is relative to the repository root. |
167+
| `lower` | Equivalent to [`strings.ToLower`](https://pkg.go.dev/strings#ToLower). |
167168
| `plainmarkdown` | Render Markdown content as plaintext. |
168169
| `prefixlines` | Add a prefix to all (newline-separated) lines in a string. |
169170
| `split` | Split string into sub-strings, by a given separator (ex. `split .Name "_"`). |
171+
| `title` | Equivalent to [`strings.ToLower`](https://pkg.go.dev/strings#ToTitle). |
170172
| `tffile` | A special case of the `codefile` function, designed for Terraform files (i.e. `.tf`). |
171173
| `trimspace` | Equivalent to [`strings.TrimSpace`](https://pkg.go.dev/strings#TrimSpace). |
174+
| `upper` | Equivalent to [`strings.ToLower`](https://pkg.go.dev/strings#ToUpper). |
172175

173176
## Disclaimer
174177

internal/provider/template.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ type (
3232
func newTemplate(name, text string) (*template.Template, error) {
3333
tmpl := template.New(name)
3434

35-
tmpl.Funcs(template.FuncMap(map[string]interface{}{
35+
tmpl.Funcs(map[string]interface{}{
3636
"codefile": tmplfuncs.CodeFile,
37+
"lower": strings.ToLower,
3738
"plainmarkdown": mdplain.PlainMarkdown,
3839
"prefixlines": tmplfuncs.PrefixLines,
39-
"tffile": func(file string) (string, error) {
40-
// TODO: omit comment handling
41-
return tmplfuncs.CodeFile("terraform", file)
42-
},
43-
"trimspace": strings.TrimSpace,
44-
"split": strings.Split,
45-
}))
40+
"split": strings.Split,
41+
"tffile": terraformCodeFile,
42+
"title": strings.ToTitle,
43+
"trimspace": strings.TrimSpace,
44+
"upper": strings.ToUpper,
45+
})
4646

4747
var err error
4848
tmpl, err = tmpl.Parse(text)
@@ -53,6 +53,11 @@ func newTemplate(name, text string) (*template.Template, error) {
5353
return tmpl, nil
5454
}
5555

56+
func terraformCodeFile(file string) (string, error) {
57+
// TODO: omit comment handling
58+
return tmplfuncs.CodeFile("terraform", file)
59+
}
60+
5661
func renderTemplate(name string, text string, out io.Writer, data interface{}) error {
5762
tmpl, err := newTemplate(name, text)
5863
if err != nil {

0 commit comments

Comments
 (0)