-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtemplate.tmpl
33 lines (33 loc) · 1.81 KB
/
template.tmpl
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
------------------------------------------------------------------------------
CSV formatted data:
Employee,Date,val1,val2,val3,SUM,LuaMultiply,linkedText
{{- /* {{- ...}} - minus trim whitespace */}}
{{- range (mustArray .TOP_LEVEL.DATA_LINE)}} {{- /* mustArray - force .DATA_LINE to array even if there is just one record (nil if not exists) */}}
{{index .Employee "-ID"}},{{dateFormat .Trans_Date "2006-01-02" "02.01.2006"}},{{.val1}},{{.val2}},{{.val3}},{{add .val1 .val2}},{{lua "mul" .val1 .val2}},"{{index .Linked_Text "-VALUE"}}"
{{- end}}
------------------------------------------------------------------------------
Count totals:
{{- /* Use variable and iterate over lines to get SUM */}}
{{- $TotalV1 := 0 }}
{{- range .TOP_LEVEL.DATA_LINE}}{{$TotalV1 = lua "sum" $TotalV1 .val1}}{{end}}
{{- $TotalV3 := 0 }}
{{- /* addf - will provide decimal count */}}
{{- range .TOP_LEVEL.DATA_LINE}}{{$TotalV3 = addf $TotalV3 .val3}}{{end}}
Total:
{{- /* if functions and,or,not,eq(equal),lt(lessThen),gt(greatherThen) */}}
Val1: {{$TotalV1}} - {{if gt (toInt $TotalV1) 50}}Over Budget{{else}}Under Buget{{end}}
Val3: {{$TotalV3}}
Created at: {{now "02.01.2006 - 15:04:05"}}
------------------------------------------------------------------------------
JSON formatted data:
{{- $new := "{\"employees\": [" }}
{{- range .TOP_LEVEL.DATA_LINE}}
{{- $new = print $new "{\"employeeID\":\"" (index .Employee "-ID") "\", \"val1\":" .val1 "}," }}
{{- end}}
{{- /* Trim trailing comma, alternatively you can remove last char by "(slice $new 0 (sub (len $new) 1))" */}}
{{- $new = print (trimSuffix $new "," ) "]}"}}
{{$new}}
------------------------------------------------------------------------------
JSON Converted to map and marshal to YAML:
{{toYAML (mapJSON $new) -}}
------------------------------------------------------------------------------