@@ -7,46 +7,79 @@ import (
77 "github.com/codeshelldev/goplater/pkg/templating/modules"
88)
99
10- var Module = modules .NewModule (containerDeleteFunc , containerSetFunc , containerHasFunc , containerIncludesFunc , slicePushFunc , sliceCreateFunc )
10+ var Module = modules .NewModule (containerDeleteFunc , containerSetFunc , containerHasFunc , containerIncludesFunc , slicePushFunc , sliceCreateWithFunc , sliceCreateFunc , mapCreateFunc , mapCreateWithFunc )
1111
1212var containerDeleteFunc = modules .NewFunc ("delete" , delete )
1313
14- func delete (_ * templating.Runtime , _ templating.Context , container any , key any ) any {
14+ func delete (_ * templating.Runtime , _ templating.Context , container * any , key any ) any {
1515 return deleteKey (container , key )
1616}
1717
1818var containerSetFunc = modules .NewFunc ("set" , set )
1919
20- func set (_ * templating.Runtime , _ templating.Context , container any , key any , value any ) any {
20+ func set (_ * templating.Runtime , _ templating.Context , container * any , key any , value any ) any {
2121 return setKey (container , key , value )
2222}
2323
2424var containerHasFunc = modules .NewFunc ("has" , has )
2525
26- func has (_ * templating.Runtime , _ templating.Context , container any , key any ) bool {
26+ func has (_ * templating.Runtime , _ templating.Context , container any , key any ) bool {
2727 return hasKey (container , key )
2828}
2929
3030var containerIncludesFunc = modules .NewFunc ("includes" , includes )
3131
32- func includes (_ * templating.Runtime , _ templating.Context , container any , value any ) bool {
32+ func includes (_ * templating.Runtime , _ templating.Context , container any , value any ) bool {
3333 return hasValue (container , value )
3434}
3535
3636var slicePushFunc = modules .NewFunc ("slicePush" , slicePush )
3737
38- func slicePush (_ * templating.Runtime , _ templating.Context , container []any , value any ) []any {
38+ func slicePush (_ * templating.Runtime , _ templating.Context , container []any , value any ) []any {
3939 return append (container , value )
4040}
4141
42- var sliceCreateFunc = modules .NewFunc ("sliceCreate " , sliceCreate )
42+ var sliceCreateWithFunc = modules .NewFunc ("sliceCreateWith " , sliceCreateWith )
4343
44- func sliceCreate (_ * templating.Runtime , _ templating.Context , value ... any ) []any {
44+ func sliceCreateWith (_ * templating.Runtime , _ templating.Context , value ... any ) []any {
4545 value = modules .UnpackArgs (value ... )
4646
4747 return value
4848}
4949
50+ var sliceCreateFunc = modules .NewFunc ("sliceCreate" , sliceCreate )
51+
52+ func sliceCreate (_ * templating.Runtime , _ templating.Context , value ... any ) []any {
53+ return []any {}
54+ }
55+
56+ var mapCreateWithFunc = modules .NewFunc ("mapCreateWith" , mapCreateWith )
57+
58+ func mapCreateWith (_ * templating.Runtime , _ templating.Context , value ... any ) map [string ]any {
59+ value = modules .UnpackArgs (value ... )
60+
61+ out := map [string ]any {}
62+
63+ for i := 1 ; i < len (value ); i += 2 {
64+ key , ok := value [i - 1 ].(string )
65+
66+ if ! ok {
67+ continue
68+ }
69+
70+ out [key ] = value [i ]
71+ }
72+
73+ return out
74+ }
75+
76+ var mapCreateFunc = modules .NewFunc ("mapCreate" , sliceCreate )
77+
78+ func mapCreate (_ * templating.Runtime , _ templating.Context , value ... any ) map [string ]any {
79+ return map [string ]any {}
80+ }
81+
82+
5083func hasKey (data any , key any ) bool {
5184 val := reflect .ValueOf (data )
5285
0 commit comments