From 1b7f38a5bda991e424712fdb8ba462549c639e43 Mon Sep 17 00:00:00 2001 From: Ruben Hoenle Date: Mon, 4 May 2026 12:39:01 +0200 Subject: [PATCH 1/2] feat(templates): add prefix and suffix string template functions relates to #591 --- internal/provider/template.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/provider/template.go b/internal/provider/template.go index 43e785dc..1ddf205c 100644 --- a/internal/provider/template.go +++ b/internal/provider/template.go @@ -112,6 +112,8 @@ func newTemplate(providerDir, name, text string) (*template.Template, error) { tmpl.Funcs(map[string]interface{}{ "codefile": codeFile(providerDir), + "hasPrefix": strings.HasPrefix, + "hasSuffix": strings.HasSuffix, "lower": strings.ToLower, "plainmarkdown": mdplain.PlainMarkdown, "prefixlines": tmplfuncs.PrefixLines, From fc7be84774c87f3424a24ef4ffed101f32d8373f Mon Sep 17 00:00:00 2001 From: Ruben Hoenle Date: Fri, 15 May 2026 13:33:02 +0200 Subject: [PATCH 2/2] add to readme --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4728a927..3f2fa694 100644 --- a/README.md +++ b/README.md @@ -408,6 +408,8 @@ using the following data fields and functions: | Function | Example | Description | |-----------------|--------------------------------------------------|---------------------------------------------------------------------------------------------------| | `codefile` | `{{codefile "shell" "path/to/file.sh"}}` | Create a Markdown code block with the content of a file. Path is relative to the repository root. | +| `hasPrefix` | `{{if hasPrefix "FOO BAR" "FOO"}}` | Equivalent to [`strings.HasPrefix`](https://pkg.go.dev/strings#HasPrefix). | +| `hasSuffix` | `{{if hasSuffix "FOO BAR" "BAR"}}` | Equivalent to [`strings.HasSuffix`](https://pkg.go.dev/strings#HasSuffix). | | `lower` | `{{"EXAMPLE STRING" \| lower}}` | Equivalent to [`strings.ToLower`](https://pkg.go.dev/strings#ToLower). | | `plainmarkdown` | `{{"*example markdown*" \| plainmarkdown }}` | Render Markdown content as plaintext. | | `prefixlines` | `{{"example string" \| prefixlines "prefix: "}}` | Add a prefix to all (newline-separated) lines in a string. | @@ -489,4 +491,4 @@ cmp stdout expected-output.txt # compares stdout from binary with the golden fi cmp docs/index.md expected-index.md # compares the generated docs with the golden file in the text archive below cmp docs/data-sources/example.md expected-datasource.md # compares the generated docs with the golden file in the text archive below cmp docs/resources/example.md expected-resource.md # compares the generated docs with the golden file in the text archive below -``` \ No newline at end of file +```