-
Notifications
You must be signed in to change notification settings - Fork 4
/
c0039.yml
241 lines (208 loc) · 6.21 KB
/
c0039.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
doc_meta: |
folder: template
title: advanced usage
head: |
Demo usecases of builtin with, block, definition
Also demo the dynamic templating using expand so that you can compose multiple templates
sections:
- title: Demo
log: yes
notes:
goal:
- showcase template usage of "with"
- showcase template block
- showcase template definition
- showcase dynamic template using expand so that you can compose multiple templates
bug:
- due to the viper's lower case all var keys, please use lower case as reference
output: |
dvar> usage_of_with:
" student name: Tom\n school name: Sydney Grammar\n Male\n "
dvar> usage_of_with_else:
" i am somebody "
dvar> template_def_plain:
"\n\n\nONE TWO\"\n"
dvar> template_def_consume:
"\nshow example of how you can define reusable template\nand how you can pass in the parameters\n\n\n\n\nstudent:\n name: ONE: Tom\n gender: TWO: Male\n"
dvar> template_def_consume_dynamic:
"\n\n\n\nstudent:\n name: ONE: Tom\n gender: TWO: Male\n\n"
dvar> template_use_block:
"\n\nstudent:\n name: ONE: Tom\ngender: TWO: Male\n\n"
executing shell commands
cmd( 1):
echo "value\n {{.usage_of_with}}"
value
student name: Tom
school name: Sydney Grammar
Male
cmd( 2):
echo "{{.usage_of_template}}"
None
cmd( 3):
echo "{{.template_def_consume}}"
show example of how you can define reusable template
and how you can pass in the parameters
student:
name: ONE: Tom
gender: TWO: Male
cmd( 4):
echo "{{.template_def_consume_dynamic_t1}}"
{{define T1}}ONE: {{.}}{{end}}
cmd( 5):
echo "{{.template_def_consume_dynamic_t2}}"
{{define T2}}TWO: {{.}}{{end}}
cmd( 6):
echo "{{.template_def_consume_dynamic_t3}}"
{{define T3}}student:
name: {{template T1 .name}}
gender: {{template T2 .gender}}{{end}}
{{template T3 .student}}
cmd( 7):
echo "{{.template_def_consume_dynamic}}"
student:
name: ONE: Tom
gender: TWO: Male
cmd( 8):
echo "{{.template_use_block}}"
student:
name: ONE: Tom
gender: TWO: Male
vars:
ns: prod
pod_name: web_app
ha: true
age: 34
old: 54
nobody:
admins: [tom, jason, alice]
managers:
- tom
- jason
- alice
student:
name: Tom
gender: Male
teachers:
- tom
- jason
- alice
address:
suburb:
name: sydney
postcode: 2000
CBD: yes
school: Sydney Grammar
#due to the viper's lower case all var keys, please use lower case as reference
template_def_consume_dynamic_T1: |
{{define "T1"}}ONE: {{.}}{{end}}
template_def_consume_dynamic_T2: '{{define "T2"}}TWO: {{.}}{{end}}'
template_def_consume_dynamic_T3: |
{{define "T3"}}student:
name: {{template "T1" .name}}
gender: {{template "T2" .gender}}{{end}}
{{template "T3" .student}}
template_def_consume_dynamic_main: |
{{.template_def_consume_dynamic_t1}}
{{.template_def_consume_dynamic_t2}}
{{.template_def_consume_dynamic_t3}}
{{template "T3" .student}}
dvars:
- name: usage_of_with
value: '
{{ with .student }}
student name: {{ println .name}}
{{ with .address}}
school name: {{ println .school}}
{{ end}}
{{ println .gender}}
{{ end}}
'
flags: [vvvv,]
- name: usage_of_with_else
value: '
{{ with .nobody }}
i am nobody
{{else}}
i am somebody
{{ end}}
'
flags: [vvvv,]
- name: template_def_plain
value: |
{{define "T1"}}ONE{{end}}
{{define "T2"}}TWO{{end}}
{{define "T3"}}{{template "T1"}} {{template "T2"}}{{end}}
{{template "T3"}}"
flags: [vvvv,]
- name: template_def_consume
value: |
show example of how you can define reusable template
and how you can pass in the parameters
{{define "T1"}}ONE: {{.}}{{end}}
{{define "T2"}}TWO: {{.}}{{end}}
{{define "T3"}}student:
name: {{template "T1" .name}}
gender: {{template "T2" .gender}}{{end}}
{{template "T3" .student}}
flags: [vvvv,]
# NOTE: this will not work, as the value itself serve as plain text as template rather than
# dynamic rendering, so this reusable definition of template should go to vars section
#-------------------------------------------------------
# - name: template_def_consume_dynamic_T1
# value: |
# {{define "T1"}}ONE: {{.}}{{end}}
# flags: [vvvv,]
#
# - name: template_def_consume_dynamic_T2
# value: |
# {{define "T1"}}ONE: {{.}}{{end}}
# flags: [vvvv,]
#
# - name: template_def_consume_dynamic_T3
# value: |
# {{.template_def_consume_dynamic_T1}}
# {{.template_def_consume_dynamic_T2}}
# {{define "T3"}}student:
# name: {{template "T1" .name}}
# gender: {{template "T2" .gender}}{{end}}
# {{template "T3" .student}}
# flags: [vvvv,]
#-------------------------------------------------------
- name: template_def_consume_dynamic
value: |
{{.template_def_consume_dynamic_main}}
flags: [vvvv,]
expand: 3
- name: template_use_block
desc: |
A block is shorthand for defining a template
{{define "name"}} T1 {{end}}
and then executing it in place
{{template "name" pipeline}}
The typical use is to define a set of root templates that are
then customized by redefining the block templates within.
In this case the define of T3 and execution using template
are merged into one block statement
value: |
{{define "T1"}}ONE: {{.}}{{end}}
{{define "T2"}}TWO: {{.}}{{end}}
{{block "T3" .student}}student:
name: {{template "T1" .name}}
gender: {{template "T2" .gender}}
{{end}}
flags: [vvvv,]
tasks:
-
name: task
task:
-
func: shell
do:
- echo "value\n {{.usage_of_with}}"
- echo "{{.usage_of_template}}"
- echo "{{.template_def_consume}}"
- echo "{{.template_def_consume_dynamic_t1}}"
- echo "{{.template_def_consume_dynamic_t2}}"
- echo "{{.template_def_consume_dynamic_t3}}"
- echo "{{.template_def_consume_dynamic}}"
- echo "{{.template_use_block}}"