From c0b93d7ebdfd27badbb41eb62ca0bd77b0252308 Mon Sep 17 00:00:00 2001 From: Dave Henderson Date: Sun, 29 May 2022 15:03:51 -0400 Subject: Support URLs for nested templates Signed-off-by: Dave Henderson --- docs/content/config.md | 14 +++++++++++++- docs/content/usage.md | 24 ++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) (limited to 'docs/content') diff --git a/docs/content/config.md b/docs/content/config.md index 01a21324..9e488e8a 100644 --- a/docs/content/config.md +++ b/docs/content/config.md @@ -406,7 +406,19 @@ suppressEmpty: true See [`--template`/`-t`](../usage/#template-t). -An array of template references. Can be just a path or an alias and a path: +```yaml +templates: + t: + url: file:///foo/bar/helloworld.tmpl + remote: + url: https://example.com/api/v1/someremotetemplate + header: + Authorization: ["Basic aGF4MHI6c3dvcmRmaXNoCg=="] + dir: foo/bar/ +``` + +_(Deprecated)_ Can also be an array of template references. Can be just a path, +or an alias and a path: ```yaml templates: diff --git a/docs/content/usage.md b/docs/content/usage.md index e51181bd..1a918791 100644 --- a/docs/content/usage.md +++ b/docs/content/usage.md @@ -189,10 +189,30 @@ Use `--left-delim`/`--right-delim` or set `$GOMPLATE_LEFT_DELIM`/`$GOMPLATE_RIGH ### `--template`/`-t` -Add a nested template that can be referenced by the main input template(s) with the [`template`](https://golang.org/pkg/text/template/#hdr-Actions) built-in or the functions in the [`tmpl`](../functions/tmpl/) namespace. Specify multiple times to add multiple template references. +Add a nested template or directory of templates that can be referenced by the +main input template(s) with the [`template`](https://golang.org/pkg/text/template/#hdr-Actions) +built-in or the functions in the [`tmpl`](../functions/tmpl/) namespace. Specify +multiple times to add multiple template references. -A few different forms are valid: +Similar to data sources, the value is a `alias=url` pair, where `alias` is the +template name and `url` is an optionally-relative URL to the template file or +directory. Note that currently only `file:` URLs are supported. + +In addition to the `alias=url` form, in certain cases the alias may be omitted, +in which case the `url` will be used as the `alias`. When referencing a +directory, all files in the directory will be included, available to be +referenced as `alias/`. + +Some examples: + +- `--template foo=file:///tmp/foo.tmpl` + - References a file `/tmp/foo.tmpl` + - It will be available as a template named `foo`: + ```console + $ gomplate --template foo=file:///tmp/foo.tmpl -i 'here are the contents of the template: [ {{ template "foo" }} ]' + here are the contents of the template: [ hello, world! ] + ``` - `--template mytemplate.t` - References a file `mytemplate.t` in the current working directory. - It will be available as a template named `mytemplate.t`: -- cgit v1.2.3