@@ -11,42 +11,41 @@ bloggers. It's up to your imagination.
11
11
12
12
13
13
## Examples
14
- ** Fill configuration files from environment variables **
14
+ ** Substituting from STDIN **
15
15
``` bash
16
+ $ echo ' Hi, my name is {{FIRST}} {{LAST}}' | templ FIRST=John LAST=Doe -
17
+ Hi, my name is John Doe
18
+ ```
19
+
20
+ ** Substitute big files, no need to worry about escaping them for ` templ ` **
21
+ ``` bash
22
+ $ echo ' big.txt: {{CONTENTS}}' | templ CONTENTS=" $( curl https://norvig.com/big.txt) " -
23
+ big.txt: The Project Gutenberg EBook of The Adventures of Sherlock Holmes
24
+ by Sir Arthur Conan Doyle
25
+ ...
26
+ ```
27
+
28
+ ** Using template files**
29
+ ``` bash
30
+ # NOTE Templates should end with `.in`
16
31
$ ls /etc/spark-conf
17
32
core-site.xml.in yarn-site.xml.in spark-defaults.conf.in
33
+
34
+ # NOTE This is injecting `SPARK` and `HADOOP` related env vars into the template
18
35
$ DESTROYSRC=1 templ $( SPARK=foo env | grep -E ' SPARK|HADOOP' ) /etc/spark-conf
36
+
37
+ # NOTE The DELETESRC variable removed the original templates after substitution
38
+ $ ls /etc/spark-conf
39
+ core-site.xml yarn-site.xml spark-defaults.conf
19
40
```
20
41
21
- ** Automate Emails! **
42
+ ** Configurable delimiters and delimiter sequence lengths **
22
43
``` bash
23
- $ cat sorry.txt.in
24
- Subject: Can' t go...
25
- I' m so sorry I can' t make it to your party {{NAME}}! I told {{LIE}} I' d go to his...
26
-
27
- $ cat contacts.tsv
28
- Joe joe@a.com
29
- Jon jon@b.com
30
- Vic vic@c.com
31
-
32
- $ LIES=" $( join -j 42 -o {1,2}.1 contacts.tsv{,} | awk ' $1 != $2 {print $1, $2}' ) "
33
-
34
- $ LIES=" $( sort -u -k1,1 <<< " $LIES" | join -j 1 - contacts.tsv) "
35
-
36
- $ echo " $LIES "
37
- Joe Jon joe@a.com
38
- Jon Joe jon@b.com
39
- Vic Joe vic@c.com
40
-
41
- $ xargs -n 3 sh -c ' cat sorry.txt | templ NAME=$0 LIE=$1 - | sendmail $2' <<< " $LIES"
42
- Subject: Can' t go...
43
- I' m so sorry I can' t make it to your party Joe! I told Jon I' d go to his...
44
- SENT
45
- Subject: Can' t go...
46
- I' m so sorry I can' t make it to your party Jon! I told Joe I' d go to his...
47
- SENT
48
- Subject: Can' t go...
49
- I' m so sorry I can' t make it to your party Vic! I told Joe I' d go to his...
50
- SENT
51
- ```
44
+ # NOTE The SEQN env variable configures how many delimiters to use for the substitution
45
+ $echo ' {{{{FIRST}}}} {{LAST}}' | SEQN=4 templ FIRST=John LAST=Doe -
46
+ Hi, my name is John {{LAST}}
52
47
48
+ # NOTE The LHS and RHS env vars respectively set the left and right delimiter characters
49
+ $ echo ' %%FOO%%' | LHS=' %' RHS=' %' templ FOO=bar -
50
+ bar
51
+ ```
0 commit comments