Skip to content

Commit fa7d37f

Browse files
authored
tpl: Add missing functions to init files
Closes #14249
1 parent fae49a2 commit fa7d37f

File tree

24 files changed

+819
-375
lines changed

24 files changed

+819
-375
lines changed

‎docs/data/docs.yaml‎

Lines changed: 315 additions & 153 deletions
Large diffs are not rendered by default.

‎tpl/cast/init.go‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ func init() {
3131
Context: func(cctx context.Context, args ...any) (any, error) { return ctx, nil },
3232
}
3333

34+
ns.AddMethodMapping(ctx.ToFloat,
35+
[]string{"float"},
36+
[][2]string{
37+
{`{{ "1234" | float | printf "%T" }}`, `float64`},
38+
},
39+
)
40+
3441
ns.AddMethodMapping(ctx.ToInt,
3542
[]string{"int"},
3643
[][2]string{
@@ -45,13 +52,6 @@ func init() {
4552
},
4653
)
4754

48-
ns.AddMethodMapping(ctx.ToFloat,
49-
[]string{"float"},
50-
[][2]string{
51-
{`{{ "1234" | float | printf "%T" }}`, `float64`},
52-
},
53-
)
54-
5555
return ns
5656
}
5757

‎tpl/collections/init.go‎

Lines changed: 64 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ func init() {
3636
[][2]string{},
3737
)
3838

39+
ns.AddMethodMapping(ctx.Append,
40+
[]string{"append"},
41+
[][2]string{},
42+
)
43+
3944
ns.AddMethodMapping(ctx.Apply,
4045
[]string{"apply"},
4146
[][2]string{},
@@ -48,11 +53,9 @@ func init() {
4853
},
4954
)
5055

51-
ns.AddMethodMapping(ctx.SymDiff,
52-
[]string{"symdiff"},
53-
[][2]string{
54-
{`{{ slice 1 2 3 | symdiff (slice 3 4) }}`, `[1 2 4]`},
55-
},
56+
ns.AddMethodMapping(ctx.D,
57+
nil,
58+
[][2]string{},
5659
)
5760

5861
ns.AddMethodMapping(ctx.Delimit,
@@ -72,11 +75,9 @@ func init() {
7275
[][2]string{},
7376
)
7477

75-
ns.AddMethodMapping(ctx.KeyVals,
76-
[]string{"keyVals"},
77-
[][2]string{
78-
{`{{ keyVals "key" "a" "b" }}`, `key: [a b]`},
79-
},
78+
ns.AddMethodMapping(ctx.Group,
79+
[]string{"group"},
80+
[][2]string{},
8081
)
8182

8283
ns.AddMethodMapping(ctx.In,
@@ -101,11 +102,43 @@ func init() {
101102
[][2]string{},
102103
)
103104

105+
ns.AddMethodMapping(ctx.KeyVals,
106+
[]string{"keyVals"},
107+
[][2]string{
108+
{`{{ keyVals "key" "a" "b" }}`, `key: [a b]`},
109+
},
110+
)
111+
104112
ns.AddMethodMapping(ctx.Last,
105113
[]string{"last"},
106114
[][2]string{},
107115
)
108116

117+
ns.AddMethodMapping(ctx.Merge,
118+
[]string{"merge"},
119+
[][2]string{
120+
{
121+
`{{ dict "title" "Hugo Rocks!" | collections.Merge (dict "title" "Default Title" "description" "Yes, Hugo Rocks!") | sort }}`,
122+
`[Yes, Hugo Rocks! Hugo Rocks!]`,
123+
},
124+
{
125+
`{{ merge (dict "title" "Default Title" "description" "Yes, Hugo Rocks!") (dict "title" "Hugo Rocks!") | sort }}`,
126+
`[Yes, Hugo Rocks! Hugo Rocks!]`,
127+
},
128+
{
129+
`{{ merge (dict "title" "Default Title" "description" "Yes, Hugo Rocks!") (dict "title" "Hugo Rocks!") (dict "extra" "For reals!") | sort }}`,
130+
`[Yes, Hugo Rocks! For reals! Hugo Rocks!]`,
131+
},
132+
},
133+
)
134+
135+
ns.AddMethodMapping(ctx.NewScratch,
136+
[]string{"newScratch"},
137+
[][2]string{
138+
{`{{ $scratch := newScratch }}{{ $scratch.Add "b" 2 }}{{ $scratch.Add "b" 2 }}{{ $scratch.Get "b" }}`, `4`},
139+
},
140+
)
141+
109142
ns.AddMethodMapping(ctx.Querify,
110143
[]string{"querify"},
111144
[][2]string{
@@ -124,56 +157,46 @@ func init() {
124157
},
125158
)
126159

127-
ns.AddMethodMapping(ctx.Shuffle,
128-
[]string{"shuffle"},
160+
ns.AddMethodMapping(ctx.Reverse,
161+
nil,
129162
[][2]string{},
130163
)
131164

132-
ns.AddMethodMapping(ctx.Slice,
133-
[]string{"slice"},
165+
ns.AddMethodMapping(ctx.Seq,
166+
[]string{"seq"},
134167
[][2]string{
135-
{`{{ slice "B" "C" "A" | sort }}`, `[A B C]`},
168+
{`{{ seq 3 }}`, `[1 2 3]`},
136169
},
137170
)
138171

139-
ns.AddMethodMapping(ctx.Sort,
140-
[]string{"sort"},
172+
ns.AddMethodMapping(ctx.Shuffle,
173+
[]string{"shuffle"},
141174
[][2]string{},
142175
)
143176

144-
ns.AddMethodMapping(ctx.Union,
145-
[]string{"union"},
177+
ns.AddMethodMapping(ctx.Slice,
178+
[]string{"slice"},
146179
[][2]string{
147-
{`{{ union (slice 1 2 3) (slice 3 4 5) }}`, `[1 2 3 4 5]`},
180+
{`{{ slice "B" "C" "A" | sort }}`, `[A B C]`},
148181
},
149182
)
150183

151-
ns.AddMethodMapping(ctx.Where,
152-
[]string{"where"},
153-
[][2]string{},
154-
)
155-
156-
ns.AddMethodMapping(ctx.Append,
157-
[]string{"append"},
158-
[][2]string{},
159-
)
160-
161-
ns.AddMethodMapping(ctx.Group,
162-
[]string{"group"},
184+
ns.AddMethodMapping(ctx.Sort,
185+
[]string{"sort"},
163186
[][2]string{},
164187
)
165188

166-
ns.AddMethodMapping(ctx.Seq,
167-
[]string{"seq"},
189+
ns.AddMethodMapping(ctx.SymDiff,
190+
[]string{"symdiff"},
168191
[][2]string{
169-
{`{{ seq 3 }}`, `[1 2 3]`},
192+
{`{{ slice 1 2 3 | symdiff (slice 3 4) }}`, `[1 2 4]`},
170193
},
171194
)
172195

173-
ns.AddMethodMapping(ctx.NewScratch,
174-
[]string{"newScratch"},
196+
ns.AddMethodMapping(ctx.Union,
197+
[]string{"union"},
175198
[][2]string{
176-
{`{{ $scratch := newScratch }}{{ $scratch.Add "b" 2 }}{{ $scratch.Add "b" 2 }}{{ $scratch.Get "b" }}`, `4`},
199+
{`{{ union (slice 1 2 3) (slice 3 4 5) }}`, `[1 2 3 4 5]`},
177200
},
178201
)
179202

@@ -184,22 +207,9 @@ func init() {
184207
},
185208
)
186209

187-
ns.AddMethodMapping(ctx.Merge,
188-
[]string{"merge"},
189-
[][2]string{
190-
{
191-
`{{ dict "title" "Hugo Rocks!" | collections.Merge (dict "title" "Default Title" "description" "Yes, Hugo Rocks!") | sort }}`,
192-
`[Yes, Hugo Rocks! Hugo Rocks!]`,
193-
},
194-
{
195-
`{{ merge (dict "title" "Default Title" "description" "Yes, Hugo Rocks!") (dict "title" "Hugo Rocks!") | sort }}`,
196-
`[Yes, Hugo Rocks! Hugo Rocks!]`,
197-
},
198-
{
199-
`{{ merge (dict "title" "Default Title" "description" "Yes, Hugo Rocks!") (dict "title" "Hugo Rocks!") (dict "extra" "For reals!") | sort }}`,
200-
`[Yes, Hugo Rocks! For reals! Hugo Rocks!]`,
201-
},
202-
},
210+
ns.AddMethodMapping(ctx.Where,
211+
[]string{"where"},
212+
[][2]string{},
203213
)
204214

205215
return ns

‎tpl/compare/init.go‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ func init() {
3737
Context: func(cctx context.Context, args ...any) (any, error) { return ctx, nil },
3838
}
3939

40+
ns.AddMethodMapping(ctx.Conditional,
41+
[]string{"cond"},
42+
[][2]string{
43+
{`{{ cond (eq (add 2 2) 4) "2+2 is 4" "what?" | safeHTML }}`, `2+2 is 4`},
44+
},
45+
)
46+
4047
ns.AddMethodMapping(ctx.Default,
4148
[]string{"default"},
4249
[][2]string{
@@ -74,16 +81,15 @@ func init() {
7481
[][2]string{},
7582
)
7683

77-
ns.AddMethodMapping(ctx.Ne,
78-
[]string{"ne"},
84+
// For internal use only.
85+
ns.AddMethodMapping(ctx.LtCollate,
86+
nil,
7987
[][2]string{},
8088
)
8189

82-
ns.AddMethodMapping(ctx.Conditional,
83-
[]string{"cond"},
84-
[][2]string{
85-
{`{{ cond (eq (add 2 2) 4) "2+2 is 4" "what?" | safeHTML }}`, `2+2 is 4`},
86-
},
90+
ns.AddMethodMapping(ctx.Ne,
91+
[]string{"ne"},
92+
[][2]string{},
8793
)
8894

8995
return ns

‎tpl/crypto/init.go‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ func init() {
3131
Context: func(cctx context.Context, args ...any) (any, error) { return ctx, nil },
3232
}
3333

34+
// Deprecated. Use hash.FNV32a instead.
35+
ns.AddMethodMapping(ctx.FNV32a,
36+
nil,
37+
[][2]string{},
38+
)
39+
40+
ns.AddMethodMapping(ctx.HMAC,
41+
[]string{"hmac"},
42+
[][2]string{
43+
{`{{ hmac "sha256" "Secret key" "Hello world, gophers!" }}`, `b6d11b6c53830b9d87036272ca9fe9d19306b8f9d8aa07b15da27d89e6e34f40`},
44+
},
45+
)
46+
3447
ns.AddMethodMapping(ctx.MD5,
3548
[]string{"md5"},
3649
[][2]string{
@@ -53,13 +66,6 @@ func init() {
5366
},
5467
)
5568

56-
ns.AddMethodMapping(ctx.HMAC,
57-
[]string{"hmac"},
58-
[][2]string{
59-
{`{{ hmac "sha256" "Secret key" "Hello world, gophers!" }}`, `b6d11b6c53830b9d87036272ca9fe9d19306b8f9d8aa07b15da27d89e6e34f40`},
60-
},
61-
)
62-
6369
return ns
6470
}
6571

‎tpl/css/css.go‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,28 @@ func init() {
162162
Context: func(cctx context.Context, args ...any) (any, error) { return ctx, nil },
163163
}
164164

165+
ns.AddMethodMapping(ctx.PostCSS,
166+
[]string{"postCSS"},
167+
[][2]string{},
168+
)
169+
170+
ns.AddMethodMapping(ctx.Quoted,
171+
nil,
172+
[][2]string{},
173+
)
174+
165175
ns.AddMethodMapping(ctx.Sass,
166176
[]string{"toCSS"},
167177
[][2]string{},
168178
)
169179

170-
ns.AddMethodMapping(ctx.PostCSS,
171-
[]string{"postCSS"},
180+
ns.AddMethodMapping(ctx.TailwindCSS,
181+
nil,
182+
[][2]string{},
183+
)
184+
185+
ns.AddMethodMapping(ctx.Unquoted,
186+
nil,
172187
[][2]string{},
173188
)
174189

‎tpl/data/init.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ func init() {
3131
Context: func(cctx context.Context, args ...any) (any, error) { return ctx, nil },
3232
}
3333

34+
// Deprecated. Use resources.GetRemote instead.
3435
ns.AddMethodMapping(ctx.GetCSV,
3536
[]string{"getCSV"},
3637
[][2]string{},
3738
)
3839

40+
// Deprecated. Use resources.GetRemote instead.
3941
ns.AddMethodMapping(ctx.GetJSON,
4042
[]string{"getJSON"},
4143
[][2]string{},

‎tpl/debug/init.go‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,34 @@ func init() {
4040
},
4141
)
4242

43+
// For internal use only. Used in tests.
44+
ns.AddMethodMapping(ctx.TestDeprecationErr,
45+
nil,
46+
[][2]string{},
47+
)
48+
49+
// For internal use only. Used in tests.
50+
ns.AddMethodMapping(ctx.TestDeprecationInfo,
51+
nil,
52+
[][2]string{},
53+
)
54+
55+
// For internal use only. Used in tests.
56+
ns.AddMethodMapping(ctx.TestDeprecationWarn,
57+
nil,
58+
[][2]string{},
59+
)
60+
61+
ns.AddMethodMapping(ctx.Timer,
62+
nil,
63+
[][2]string{},
64+
)
65+
66+
ns.AddMethodMapping(ctx.VisualizeSpaces,
67+
nil,
68+
[][2]string{},
69+
)
70+
4371
return ns
4472
}
4573

‎tpl/diagrams/init.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ func init() {
3434
Context: func(cctx context.Context, args ...any) (any, error) { return ctx, nil },
3535
}
3636

37+
ns.AddMethodMapping(ctx.Goat,
38+
nil,
39+
[][2]string{},
40+
)
41+
3742
return ns
3843
}
3944

0 commit comments

Comments
 (0)