@bookshop/hugo-engine 3.3.2 → 3.4.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/.nyc_output/{396c364e-fec4-4f27-9ff2-8b236061ef8f.json → 0f70a16f-6a79-48c7-8b16-3b4665e247b2.json} +0 -0
  2. package/.nyc_output/{4ef43740-059b-4329-96cd-0643fd8fe8d8.json → 6285d5fa-be3d-49e4-8f2f-82157d95dcd8.json} +0 -0
  3. package/.nyc_output/{656275f4-66d6-4d27-bfab-c2f7a3087670.json → 8b5e1314-6e86-4197-a3ae-3c40e4c2f39e.json} +0 -0
  4. package/.nyc_output/{6aec5420-0b83-4260-b300-4d595dfd0660.json → c5490eb0-70c0-468f-a43f-e58c75dd34c8.json} +0 -0
  5. package/.nyc_output/{874bd79b-45da-4726-9afc-1f6cab44be1f.json → ee1a9bec-d318-4aea-af93-7269debcf6df.json} +0 -0
  6. package/.nyc_output/processinfo/{396c364e-fec4-4f27-9ff2-8b236061ef8f.json → 0f70a16f-6a79-48c7-8b16-3b4665e247b2.json} +1 -1
  7. package/.nyc_output/processinfo/6285d5fa-be3d-49e4-8f2f-82157d95dcd8.json +1 -0
  8. package/.nyc_output/processinfo/{4ef43740-059b-4329-96cd-0643fd8fe8d8.json → 8b5e1314-6e86-4197-a3ae-3c40e4c2f39e.json} +1 -1
  9. package/.nyc_output/processinfo/{656275f4-66d6-4d27-bfab-c2f7a3087670.json → c5490eb0-70c0-468f-a43f-e58c75dd34c8.json} +1 -1
  10. package/.nyc_output/processinfo/{874bd79b-45da-4726-9afc-1f6cab44be1f.json → ee1a9bec-d318-4aea-af93-7269debcf6df.json} +1 -1
  11. package/.nyc_output/processinfo/index.json +1 -1
  12. package/bookshop-hugo-templates/bookshop.html +56 -0
  13. package/bookshop-hugo-templates/bookshop_bindings.html +29 -0
  14. package/bookshop-hugo-templates/bookshop_component_browser.html +30 -0
  15. package/bookshop-hugo-templates/bookshop_partial.html +42 -0
  16. package/bookshop-hugo-templates/bookshop_scss.html +9 -0
  17. package/bookshop-hugo-templates/errors/bad_bookshop_tag.html +39 -0
  18. package/bookshop-hugo-templates/errors/err.html +6 -0
  19. package/bookshop-hugo-templates/helpers/component.html +25 -0
  20. package/bookshop-hugo-templates/helpers/component_key.html +11 -0
  21. package/bookshop-hugo-templates/helpers/partial.html +25 -0
  22. package/bookshop-hugo-templates/helpers/partial_key.html +9 -0
  23. package/full-hugo-renderer/build.sh +34 -0
  24. package/full-hugo-renderer/go.mod +87 -0
  25. package/{hugo-renderer → full-hugo-renderer}/go.sum +204 -12
  26. package/full-hugo-renderer/hugo_renderer.wasm +0 -0
  27. package/full-hugo-renderer/hugo_renderer.wasm.gz +0 -0
  28. package/full-hugo-renderer/main.go +215 -0
  29. package/{hugo-renderer → full-hugo-renderer}/wasm_exec.js +6 -2
  30. package/lib/builder.js +2 -2
  31. package/lib/engine.js +109 -42
  32. package/lib/hugoIdentifierParser.js +5 -0
  33. package/lib/translateTextTemplate.js +3 -0
  34. package/lib/translateTextTemplate.test.js +22 -16
  35. package/package.json +4 -4
  36. package/.nyc_output/processinfo/6aec5420-0b83-4260-b300-4d595dfd0660.json +0 -1
  37. package/hugo-renderer/build.sh +0 -66
  38. package/hugo-renderer/deps/bookshop_modified_deps.go +0 -6
  39. package/hugo-renderer/go.mod +0 -19
  40. package/hugo-renderer/helpers/bookshop_modified_content.go +0 -98
  41. package/hugo-renderer/helpers/bookshop_modified_general.go +0 -33
  42. package/hugo-renderer/helpers/emoji.go +0 -96
  43. package/hugo-renderer/hugo_renderer.wasm +0 -0
  44. package/hugo-renderer/hugo_renderer.wasm.gz +0 -0
  45. package/hugo-renderer/main.go +0 -42
  46. package/hugo-renderer/tpl/bookshop_engine/bookshop_func_importer.go +0 -35
  47. package/hugo-renderer/tpl/bookshop_engine/bookshop_render.go +0 -64
  48. package/hugo-renderer/tpl/bookshop_library/bookshop_components.go +0 -129
  49. package/hugo-renderer/tpl/bookshop_library/bookshop_data.go +0 -53
  50. package/hugo-renderer/tpl/cast/cast.go +0 -63
  51. package/hugo-renderer/tpl/cast/init.go +0 -57
  52. package/hugo-renderer/tpl/collections/append.go +0 -37
  53. package/hugo-renderer/tpl/collections/apply.go +0 -131
  54. package/hugo-renderer/tpl/collections/collections.go +0 -768
  55. package/hugo-renderer/tpl/collections/complement.go +0 -55
  56. package/hugo-renderer/tpl/collections/index.go +0 -133
  57. package/hugo-renderer/tpl/collections/init.go +0 -214
  58. package/hugo-renderer/tpl/collections/merge.go +0 -126
  59. package/hugo-renderer/tpl/collections/reflect_helpers.go +0 -216
  60. package/hugo-renderer/tpl/collections/sort.go +0 -183
  61. package/hugo-renderer/tpl/collections/symdiff.go +0 -68
  62. package/hugo-renderer/tpl/collections/where.go +0 -517
  63. package/hugo-renderer/tpl/compare/compare.go +0 -324
  64. package/hugo-renderer/tpl/compare/init.go +0 -85
  65. package/hugo-renderer/tpl/crypto/crypto.go +0 -109
  66. package/hugo-renderer/tpl/crypto/init.go +0 -65
  67. package/hugo-renderer/tpl/debug/debug.go +0 -40
  68. package/hugo-renderer/tpl/debug/init.go +0 -45
  69. package/hugo-renderer/tpl/encoding/encoding.go +0 -90
  70. package/hugo-renderer/tpl/encoding/init.go +0 -59
  71. package/hugo-renderer/tpl/fmt/fmt.go +0 -66
  72. package/hugo-renderer/tpl/fmt/init.go +0 -77
  73. package/hugo-renderer/tpl/inflect/inflect.go +0 -79
  74. package/hugo-renderer/tpl/inflect/init.go +0 -60
  75. package/hugo-renderer/tpl/internal/bookshop_modified_templatefuncsRegistry.go +0 -88
  76. package/hugo-renderer/tpl/math/init.go +0 -134
  77. package/hugo-renderer/tpl/math/math.go +0 -164
  78. package/hugo-renderer/tpl/math/round.go +0 -61
  79. package/hugo-renderer/tpl/partials/init.go +0 -55
  80. package/hugo-renderer/tpl/partials/partials.go +0 -88
  81. package/hugo-renderer/tpl/path/init.go +0 -60
  82. package/hugo-renderer/tpl/path/path.go +0 -159
  83. package/hugo-renderer/tpl/reflect/init.go +0 -51
  84. package/hugo-renderer/tpl/reflect/reflect.go +0 -36
  85. package/hugo-renderer/tpl/safe/init.go +0 -80
  86. package/hugo-renderer/tpl/safe/safe.go +0 -72
  87. package/hugo-renderer/tpl/site/bookshop_site.go +0 -67
  88. package/hugo-renderer/tpl/site/init.go +0 -41
  89. package/hugo-renderer/tpl/strings/init.go +0 -229
  90. package/hugo-renderer/tpl/strings/regexp.go +0 -125
  91. package/hugo-renderer/tpl/strings/strings.go +0 -500
  92. package/hugo-renderer/tpl/strings/truncate.go +0 -157
  93. package/hugo-renderer/tpl/transform/bookshop_unmarshal.go +0 -39
  94. package/hugo-renderer/tpl/transform/init.go +0 -113
  95. package/hugo-renderer/tpl/transform/transform.go +0 -116
  96. package/hugo-renderer/update-from-hugo.sh +0 -19
@@ -1,63 +0,0 @@
1
- // Copyright 2017 The Hugo Authors. All rights reserved.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- // http://www.apache.org/licenses/LICENSE-2.0
7
- //
8
- // Unless required by applicable law or agreed to in writing, software
9
- // distributed under the License is distributed on an "AS IS" BASIS,
10
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- // See the License for the specific language governing permissions and
12
- // limitations under the License.
13
-
14
- // Package cast provides template functions for data type conversions.
15
- package cast
16
-
17
- import (
18
- "html/template"
19
-
20
- _cast "github.com/spf13/cast"
21
- )
22
-
23
- // New returns a new instance of the cast-namespaced template functions.
24
- func New() *Namespace {
25
- return &Namespace{}
26
- }
27
-
28
- // Namespace provides template functions for the "cast" namespace.
29
- type Namespace struct {
30
- }
31
-
32
- // ToInt converts the given value to an int.
33
- func (ns *Namespace) ToInt(v interface{}) (int, error) {
34
- v = convertTemplateToString(v)
35
- return _cast.ToIntE(v)
36
- }
37
-
38
- // ToString converts the given value to a string.
39
- func (ns *Namespace) ToString(v interface{}) (string, error) {
40
- return _cast.ToStringE(v)
41
- }
42
-
43
- // ToFloat converts the given value to a float.
44
- func (ns *Namespace) ToFloat(v interface{}) (float64, error) {
45
- v = convertTemplateToString(v)
46
- return _cast.ToFloat64E(v)
47
- }
48
-
49
- func convertTemplateToString(v interface{}) interface{} {
50
- switch vv := v.(type) {
51
- case template.HTML:
52
- v = string(vv)
53
- case template.CSS:
54
- v = string(vv)
55
- case template.HTMLAttr:
56
- v = string(vv)
57
- case template.JS:
58
- v = string(vv)
59
- case template.JSStr:
60
- v = string(vv)
61
- }
62
- return v
63
- }
@@ -1,57 +0,0 @@
1
- // Copyright 2017 The Hugo Authors. All rights reserved.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- // http://www.apache.org/licenses/LICENSE-2.0
7
- //
8
- // Unless required by applicable law or agreed to in writing, software
9
- // distributed under the License is distributed on an "AS IS" BASIS,
10
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- // See the License for the specific language governing permissions and
12
- // limitations under the License.
13
-
14
- package cast
15
-
16
- import (
17
- "hugo-renderer/deps"
18
- "hugo-renderer/tpl/internal"
19
- )
20
-
21
- const name = "cast"
22
-
23
- func init() {
24
- f := func(d *deps.Deps) *internal.TemplateFuncsNamespace {
25
- ctx := New()
26
-
27
- ns := &internal.TemplateFuncsNamespace{
28
- Name: name,
29
- Context: func(args ...interface{}) (interface{}, error) { return ctx, nil },
30
- }
31
-
32
- ns.AddMethodMapping(ctx.ToInt,
33
- []string{"int"},
34
- [][2]string{
35
- {`{{ "1234" | int | printf "%T" }}`, `int`},
36
- },
37
- )
38
-
39
- ns.AddMethodMapping(ctx.ToString,
40
- []string{"string"},
41
- [][2]string{
42
- {`{{ 1234 | string | printf "%T" }}`, `string`},
43
- },
44
- )
45
-
46
- ns.AddMethodMapping(ctx.ToFloat,
47
- []string{"float"},
48
- [][2]string{
49
- {`{{ "1234" | float | printf "%T" }}`, `float64`},
50
- },
51
- )
52
-
53
- return ns
54
- }
55
-
56
- internal.AddTemplateFuncsNamespace(f)
57
- }
@@ -1,37 +0,0 @@
1
- // Copyright 2018 The Hugo Authors. All rights reserved.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- // http://www.apache.org/licenses/LICENSE-2.0
7
- //
8
- // Unless required by applicable law or agreed to in writing, software
9
- // distributed under the License is distributed on an "AS IS" BASIS,
10
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- // See the License for the specific language governing permissions and
12
- // limitations under the License.
13
-
14
- package collections
15
-
16
- import (
17
- "errors"
18
-
19
- "github.com/gohugoio/hugo/common/collections"
20
- )
21
-
22
- // Append appends the arguments up to the last one to the slice in the last argument.
23
- // This construct allows template constructs like this:
24
- // {{ $pages = $pages | append $p2 $p1 }}
25
- // Note that with 2 arguments where both are slices of the same type,
26
- // the first slice will be appended to the second:
27
- // {{ $pages = $pages | append .Site.RegularPages }}
28
- func (ns *Namespace) Append(args ...interface{}) (interface{}, error) {
29
- if len(args) < 2 {
30
- return nil, errors.New("need at least 2 arguments to append")
31
- }
32
-
33
- to := args[len(args)-1]
34
- from := args[:len(args)-1]
35
-
36
- return collections.Append(to, from...)
37
- }
@@ -1,131 +0,0 @@
1
- // Copyright 2017 The Hugo Authors. All rights reserved.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- // http://www.apache.org/licenses/LICENSE-2.0
7
- //
8
- // Unless required by applicable law or agreed to in writing, software
9
- // distributed under the License is distributed on an "AS IS" BASIS,
10
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- // See the License for the specific language governing permissions and
12
- // limitations under the License.
13
-
14
- package collections
15
-
16
- import (
17
- "errors"
18
- "fmt"
19
- "reflect"
20
- )
21
-
22
- // Apply takes a map, array, or slice and returns a new slice with the function fname applied over it.
23
- func (ns *Namespace) Apply(seq interface{}, fname string, args ...interface{}) (interface{}, error) {
24
- if seq == nil {
25
- return make([]interface{}, 0), nil
26
- }
27
-
28
- if fname == "apply" {
29
- return nil, errors.New("can't apply myself (no turtles allowed)")
30
- }
31
-
32
- seqv := reflect.ValueOf(seq)
33
- seqv, isNil := indirect(seqv)
34
- if isNil {
35
- return nil, errors.New("can't iterate over a nil value")
36
- }
37
-
38
- fnv, found := ns.lookupFunc(fname)
39
- if !found {
40
- return nil, errors.New("can't find function " + fname)
41
- }
42
-
43
- // fnv := reflect.ValueOf(fn)
44
-
45
- switch seqv.Kind() {
46
- case reflect.Array, reflect.Slice:
47
- r := make([]interface{}, seqv.Len())
48
- for i := 0; i < seqv.Len(); i++ {
49
- vv := seqv.Index(i)
50
-
51
- vvv, err := applyFnToThis(fnv, vv, args...)
52
- if err != nil {
53
- return nil, err
54
- }
55
-
56
- r[i] = vvv.Interface()
57
- }
58
-
59
- return r, nil
60
- default:
61
- return nil, fmt.Errorf("can't apply over %v", seq)
62
- }
63
- }
64
-
65
- func applyFnToThis(fn, this reflect.Value, args ...interface{}) (reflect.Value, error) {
66
- n := make([]reflect.Value, len(args))
67
- for i, arg := range args {
68
- if arg == "." {
69
- n[i] = this
70
- } else {
71
- n[i] = reflect.ValueOf(arg)
72
- }
73
- }
74
-
75
- num := fn.Type().NumIn()
76
-
77
- if fn.Type().IsVariadic() {
78
- num--
79
- }
80
-
81
- // TODO(bep) see #1098 - also see template_tests.go
82
- /*if len(args) < num {
83
- return reflect.ValueOf(nil), errors.New("Too few arguments")
84
- } else if len(args) > num {
85
- return reflect.ValueOf(nil), errors.New("Too many arguments")
86
- }*/
87
-
88
- for i := 0; i < num; i++ {
89
- // AssignableTo reports whether xt is assignable to type targ.
90
- if xt, targ := n[i].Type(), fn.Type().In(i); !xt.AssignableTo(targ) {
91
- return reflect.ValueOf(nil), errors.New("called apply using " + xt.String() + " as type " + targ.String())
92
- }
93
- }
94
-
95
- res := fn.Call(n)
96
-
97
- if len(res) == 1 || res[1].IsNil() {
98
- return res[0], nil
99
- }
100
- return reflect.ValueOf(nil), res[1].Interface().(error)
101
- }
102
-
103
- func (ns *Namespace) lookupFunc(fname string) (reflect.Value, bool) {
104
- // TODO(bookshop): NYI
105
- return reflect.Value{}, false
106
- }
107
-
108
- // indirect is borrowed from the Go stdlib: 'text/template/exec.go'
109
- func indirect(v reflect.Value) (rv reflect.Value, isNil bool) {
110
- for ; v.Kind() == reflect.Ptr || v.Kind() == reflect.Interface; v = v.Elem() {
111
- if v.IsNil() {
112
- return v, true
113
- }
114
- if v.Kind() == reflect.Interface && v.NumMethod() > 0 {
115
- break
116
- }
117
- }
118
- return v, false
119
- }
120
-
121
- func indirectInterface(v reflect.Value) (rv reflect.Value, isNil bool) {
122
- for ; v.Kind() == reflect.Interface; v = v.Elem() {
123
- if v.IsNil() {
124
- return v, true
125
- }
126
- if v.Kind() == reflect.Interface && v.NumMethod() > 0 {
127
- break
128
- }
129
- }
130
- return v, false
131
- }