@bookshop/hugo-engine 3.3.3 → 3.4.0-alpha.4

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 (100) hide show
  1. package/.nyc_output/{25f8c04a-7fe3-4d10-b99e-0688e18203ec.json → 22bb8575-684b-4abd-a7da-a126ef609bfa.json} +0 -0
  2. package/.nyc_output/{2c3e7d19-6b44-48be-857a-ceba6bb9bf99.json → 51e132a2-0039-4273-bbea-09f6f8377759.json} +0 -0
  3. package/.nyc_output/{5429d932-0ea0-4757-b731-0a647f4adc5f.json → 5810b308-22d3-45cf-b7e4-53661081d6fa.json} +0 -0
  4. package/.nyc_output/{723f5a1e-49f4-48c2-8a96-069bb758bb7f.json → 6d65e1ae-d74f-4c1f-8055-2f6e78ff5297.json} +0 -0
  5. package/.nyc_output/{e4df4511-7e66-4fa6-84ed-6bd96e3027fe.json → 768753f4-837c-4445-815d-f95e7b72b4a3.json} +0 -0
  6. package/.nyc_output/processinfo/22bb8575-684b-4abd-a7da-a126ef609bfa.json +1 -0
  7. package/.nyc_output/processinfo/51e132a2-0039-4273-bbea-09f6f8377759.json +1 -0
  8. package/.nyc_output/processinfo/5810b308-22d3-45cf-b7e4-53661081d6fa.json +1 -0
  9. package/.nyc_output/processinfo/6d65e1ae-d74f-4c1f-8055-2f6e78ff5297.json +1 -0
  10. package/.nyc_output/processinfo/768753f4-837c-4445-815d-f95e7b72b4a3.json +1 -0
  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/25f8c04a-7fe3-4d10-b99e-0688e18203ec.json +0 -1
  37. package/.nyc_output/processinfo/2c3e7d19-6b44-48be-857a-ceba6bb9bf99.json +0 -1
  38. package/.nyc_output/processinfo/5429d932-0ea0-4757-b731-0a647f4adc5f.json +0 -1
  39. package/.nyc_output/processinfo/723f5a1e-49f4-48c2-8a96-069bb758bb7f.json +0 -1
  40. package/.nyc_output/processinfo/e4df4511-7e66-4fa6-84ed-6bd96e3027fe.json +0 -1
  41. package/hugo-renderer/build.sh +0 -66
  42. package/hugo-renderer/deps/bookshop_modified_deps.go +0 -6
  43. package/hugo-renderer/go.mod +0 -19
  44. package/hugo-renderer/helpers/bookshop_modified_content.go +0 -98
  45. package/hugo-renderer/helpers/bookshop_modified_general.go +0 -33
  46. package/hugo-renderer/helpers/emoji.go +0 -96
  47. package/hugo-renderer/hugo_renderer.wasm +0 -0
  48. package/hugo-renderer/hugo_renderer.wasm.gz +0 -0
  49. package/hugo-renderer/main.go +0 -42
  50. package/hugo-renderer/tpl/bookshop_engine/bookshop_func_importer.go +0 -35
  51. package/hugo-renderer/tpl/bookshop_engine/bookshop_render.go +0 -64
  52. package/hugo-renderer/tpl/bookshop_library/bookshop_components.go +0 -129
  53. package/hugo-renderer/tpl/bookshop_library/bookshop_data.go +0 -53
  54. package/hugo-renderer/tpl/cast/cast.go +0 -63
  55. package/hugo-renderer/tpl/cast/init.go +0 -57
  56. package/hugo-renderer/tpl/collections/append.go +0 -37
  57. package/hugo-renderer/tpl/collections/apply.go +0 -131
  58. package/hugo-renderer/tpl/collections/collections.go +0 -768
  59. package/hugo-renderer/tpl/collections/complement.go +0 -55
  60. package/hugo-renderer/tpl/collections/index.go +0 -133
  61. package/hugo-renderer/tpl/collections/init.go +0 -214
  62. package/hugo-renderer/tpl/collections/merge.go +0 -126
  63. package/hugo-renderer/tpl/collections/reflect_helpers.go +0 -216
  64. package/hugo-renderer/tpl/collections/sort.go +0 -183
  65. package/hugo-renderer/tpl/collections/symdiff.go +0 -68
  66. package/hugo-renderer/tpl/collections/where.go +0 -517
  67. package/hugo-renderer/tpl/compare/compare.go +0 -324
  68. package/hugo-renderer/tpl/compare/init.go +0 -85
  69. package/hugo-renderer/tpl/crypto/crypto.go +0 -109
  70. package/hugo-renderer/tpl/crypto/init.go +0 -65
  71. package/hugo-renderer/tpl/debug/debug.go +0 -40
  72. package/hugo-renderer/tpl/debug/init.go +0 -45
  73. package/hugo-renderer/tpl/encoding/encoding.go +0 -90
  74. package/hugo-renderer/tpl/encoding/init.go +0 -59
  75. package/hugo-renderer/tpl/fmt/fmt.go +0 -66
  76. package/hugo-renderer/tpl/fmt/init.go +0 -77
  77. package/hugo-renderer/tpl/inflect/inflect.go +0 -79
  78. package/hugo-renderer/tpl/inflect/init.go +0 -60
  79. package/hugo-renderer/tpl/internal/bookshop_modified_templatefuncsRegistry.go +0 -88
  80. package/hugo-renderer/tpl/math/init.go +0 -134
  81. package/hugo-renderer/tpl/math/math.go +0 -164
  82. package/hugo-renderer/tpl/math/round.go +0 -61
  83. package/hugo-renderer/tpl/partials/init.go +0 -55
  84. package/hugo-renderer/tpl/partials/partials.go +0 -88
  85. package/hugo-renderer/tpl/path/init.go +0 -60
  86. package/hugo-renderer/tpl/path/path.go +0 -159
  87. package/hugo-renderer/tpl/reflect/init.go +0 -51
  88. package/hugo-renderer/tpl/reflect/reflect.go +0 -36
  89. package/hugo-renderer/tpl/safe/init.go +0 -80
  90. package/hugo-renderer/tpl/safe/safe.go +0 -72
  91. package/hugo-renderer/tpl/site/bookshop_site.go +0 -67
  92. package/hugo-renderer/tpl/site/init.go +0 -41
  93. package/hugo-renderer/tpl/strings/init.go +0 -229
  94. package/hugo-renderer/tpl/strings/regexp.go +0 -125
  95. package/hugo-renderer/tpl/strings/strings.go +0 -500
  96. package/hugo-renderer/tpl/strings/truncate.go +0 -157
  97. package/hugo-renderer/tpl/transform/bookshop_unmarshal.go +0 -39
  98. package/hugo-renderer/tpl/transform/init.go +0 -113
  99. package/hugo-renderer/tpl/transform/transform.go +0 -116
  100. 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
- }