Skip to content

Commit

Permalink
Improves README with real information about how to use this tool.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwynforthewyn committed Feb 4, 2024
1 parent 54fe136 commit cbf8b8a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
33 changes: 26 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,43 @@
# Templ
A tool to render templates, and download and update repositories of templates.
A tool to render go text templates. The sweetness is that you can store your text templates in a git repository,
and use templ to download and use that repository of templates.

Update templates with your text editor, commit to git with your usual workflow, then `templ -u` to download the updates.

Want to check that your templates are written and parsed correctly before committing them to git? Awesome, templ can be
piped into:

cat foo.tmpl | templ VAR=VALUE

![logo](.github/images/templ-logo-smaller.png)

# Environment variables
TEMPL_DIR - Defaults to ~/.config/templ. Directory that stores template git repositories. You run lists against this dir.

# Uses
`templ -fetch https://github.com/PlayTechniuque/templ-templates.git` - download a github repository to your templates directory
## Retrieve Templates Stored in a Git Repository
`templ -f https://github.com/PlayTechniuque/templ-templates.git` - download a github repository to your templates directory.
You can set the templates directory with an environment variable TEMPL_DIR or use the default (currently ~/.config/templ)

`templ -list` - list all available templates
## List your templates
`templ -l` - list all downloaded templates
`templ templatename` - display the contents of a template file to stdout. It's like cat, but it has partial file matching,
so if you have a template file in a directory structure `foo/bar/bam.yaml` then you can use `templ foo` or `templ bam.yaml`
or `templ bar/bam`.

`templ templatename` - display the contents of a template file to stdout.
If you have two files `foo/bar/bam.yaml` and `zee/zye/bam.yaml`, then `templ bam` will show both of the `bam.yaml` files.

`templ templatename=variablesfile.yaml` - hydrate a template file using variablesfile.yaml.
## Rendering templates
You have two options for rendering templates. The first and simplest is to put the template file on
stdout and then pipe that template through templ itself, replacing variables with values:
`templ templatename | templ KEY=VALUE` - pipeline a render operation! You do not need a config file, you can pipe through
templ itself. This is best suited for replacing simple variables, not using template logic

`templ templatename=variablesfile.yaml` - hydrate a template file using variablesfile.yaml. This gives you more
flexibility in composing more complex templates.

```variablesfile.yaml
---
Variable: value
OtherVariable: othervalue
```

`templ templatename | templ KEY=VALUE` - pipeline a render operation! You do not need a config file, you can pipe through templ itself.
7 changes: 6 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ func main() {
"will populate the template file's variables. If no variables file is provided, the utility"+
"operates like 'cat' on the file, printing it to stdout.\n\n"+
"This utility can also be called in a pipeline as %s templatename | %s FOO=BAR BAM=BAS, for folks who"+
"prefer not to have a variables file.\n\n",
"prefer not to have a variables file.\n\n"+
"Templates can be stored in a git repository and downloaded with `templ -f https://path/to/git/repository.git`."+
"git repository download support is provided by the awesome https://github.com/go-git/, and all protocols are supported."+
"Only a `git pull` operation is supported - edit your templates with a text editor, commit to git, and"+
" run `templ -u` to update your templates.\n\n"+
"templ also supports project layouts. Supply a yaml file listing template names and template definition files.\n",
filepath.Base(os.Args[0]), filepath.Base(os.Args[0]), filepath.Base(os.Args[0]))

flag.Usage = func() { fmt.Println(usage); flag.PrintDefaults(); return }
Expand Down

0 comments on commit cbf8b8a

Please sign in to comment.