@bookshop/hugo-engine 2.4.0-hugo.0 → 2.4.0-hugo.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.
- package/.npmrc +1 -0
- package/.nyc_output/{50eb2ebd-c797-4d3f-8df7-a707c1b211eb.json → 5ff8dc15-11f5-4e63-9582-916657a3e8ba.json} +0 -0
- package/.nyc_output/{86f85916-4f58-43da-8c32-c1ec29ca783e.json → 7054beca-6b99-4dd2-a8c7-4aec983815fe.json} +0 -0
- package/.nyc_output/{a27680c8-8858-4ede-921d-6e6617f42a0b.json → 727fa7a6-f028-4392-b4d1-0b0ec68f3077.json} +0 -0
- package/.nyc_output/{b5f86652-cbe8-44f9-a36c-d5721dfe5bbe.json → 7e79dc9e-2fd1-45e0-8a5a-d743898cb2ab.json} +0 -0
- package/.nyc_output/{ecca87c1-5774-4962-864a-2e4537aa9915.json → a528b45c-4264-43cd-bf2c-ace2d3f3528d.json} +0 -0
- package/.nyc_output/processinfo/5ff8dc15-11f5-4e63-9582-916657a3e8ba.json +1 -0
- package/.nyc_output/processinfo/{50eb2ebd-c797-4d3f-8df7-a707c1b211eb.json → 7054beca-6b99-4dd2-a8c7-4aec983815fe.json} +1 -1
- package/.nyc_output/processinfo/{86f85916-4f58-43da-8c32-c1ec29ca783e.json → 727fa7a6-f028-4392-b4d1-0b0ec68f3077.json} +1 -1
- package/.nyc_output/processinfo/{a27680c8-8858-4ede-921d-6e6617f42a0b.json → 7e79dc9e-2fd1-45e0-8a5a-d743898cb2ab.json} +1 -1
- package/.nyc_output/processinfo/{ecca87c1-5774-4962-864a-2e4537aa9915.json → a528b45c-4264-43cd-bf2c-ace2d3f3528d.json} +1 -1
- package/.nyc_output/processinfo/index.json +1 -1
- package/bookshop-hugo-engine-2.3.1.tgz +0 -0
- package/hugo-renderer/hugo_renderer.wasm +0 -0
- package/hugo-renderer/tpl/bookshop_engine/bookshop_render.go +4 -4
- package/lib/engine.js +12 -2
- package/lib/hugoIdentifierParser.js +7 -1
- package/lib/hugoIdentifierParser.test.js +21 -2
- package/lib/translateTextTemplate.js +45 -18
- package/lib/translateTextTemplate.test.js +63 -1
- package/package.json +10 -3
- package/.nyc_output/processinfo/b5f86652-cbe8-44f9-a36c-d5721dfe5bbe.json +0 -1
package/.npmrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
engine-strict = true
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"parent":null,"pid":64953,"argv":["/Users/liambigelow/.nvm/versions/node/v14.16.0/bin/node","/Users/liambigelow/Projects/CC/bookshop/javascript-modules/node_modules/ava/cli.js","-v"],"execArgv":[],"cwd":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine","time":1643573514056,"ppid":64952,"coverageFilename":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/5ff8dc15-11f5-4e63-9582-916657a3e8ba.json","externalId":"","uuid":"5ff8dc15-11f5-4e63-9582-916657a3e8ba","files":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"parent":"
|
|
1
|
+
{"parent":"5ff8dc15-11f5-4e63-9582-916657a3e8ba","pid":64957,"argv":["/Users/liambigelow/.nvm/versions/node/v14.16.0/bin/node","/Users/liambigelow/Projects/CC/bookshop/javascript-modules/node_modules/ava/lib/worker/subprocess.js"],"execArgv":[],"cwd":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine","time":1643573514565,"ppid":64953,"coverageFilename":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/7054beca-6b99-4dd2-a8c7-4aec983815fe.json","externalId":"","uuid":"7054beca-6b99-4dd2-a8c7-4aec983815fe","files":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"parent":"
|
|
1
|
+
{"parent":"5ff8dc15-11f5-4e63-9582-916657a3e8ba","pid":64955,"argv":["/Users/liambigelow/.nvm/versions/node/v14.16.0/bin/node","/Users/liambigelow/Projects/CC/bookshop/javascript-modules/node_modules/ava/lib/worker/subprocess.js"],"execArgv":[],"cwd":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine","time":1643573514552,"ppid":64953,"coverageFilename":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/727fa7a6-f028-4392-b4d1-0b0ec68f3077.json","externalId":"","uuid":"727fa7a6-f028-4392-b4d1-0b0ec68f3077","files":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"parent":"
|
|
1
|
+
{"parent":"5ff8dc15-11f5-4e63-9582-916657a3e8ba","pid":64956,"argv":["/Users/liambigelow/.nvm/versions/node/v14.16.0/bin/node","/Users/liambigelow/Projects/CC/bookshop/javascript-modules/node_modules/ava/lib/worker/subprocess.js"],"execArgv":[],"cwd":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine","time":1643573514562,"ppid":64953,"coverageFilename":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/7e79dc9e-2fd1-45e0-8a5a-d743898cb2ab.json","externalId":"","uuid":"7e79dc9e-2fd1-45e0-8a5a-d743898cb2ab","files":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"parent":"
|
|
1
|
+
{"parent":"5ff8dc15-11f5-4e63-9582-916657a3e8ba","pid":64954,"argv":["/Users/liambigelow/.nvm/versions/node/v14.16.0/bin/node","/Users/liambigelow/Projects/CC/bookshop/javascript-modules/node_modules/ava/lib/worker/subprocess.js"],"execArgv":[],"cwd":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine","time":1643573514548,"ppid":64953,"coverageFilename":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/a528b45c-4264-43cd-bf2c-ace2d3f3528d.json","externalId":"","uuid":"a528b45c-4264-43cd-bf2c-ace2d3f3528d","files":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"processes":{"
|
|
1
|
+
{"processes":{"5ff8dc15-11f5-4e63-9582-916657a3e8ba":{"parent":null,"children":["7054beca-6b99-4dd2-a8c7-4aec983815fe","727fa7a6-f028-4392-b4d1-0b0ec68f3077","7e79dc9e-2fd1-45e0-8a5a-d743898cb2ab","a528b45c-4264-43cd-bf2c-ace2d3f3528d"]},"7054beca-6b99-4dd2-a8c7-4aec983815fe":{"parent":"5ff8dc15-11f5-4e63-9582-916657a3e8ba","children":[]},"727fa7a6-f028-4392-b4d1-0b0ec68f3077":{"parent":"5ff8dc15-11f5-4e63-9582-916657a3e8ba","children":[]},"7e79dc9e-2fd1-45e0-8a5a-d743898cb2ab":{"parent":"5ff8dc15-11f5-4e63-9582-916657a3e8ba","children":[]},"a528b45c-4264-43cd-bf2c-ace2d3f3528d":{"parent":"5ff8dc15-11f5-4e63-9582-916657a3e8ba","children":[]}},"files":{},"externalIds":{}}
|
|
Binary file
|
|
Binary file
|
|
@@ -38,10 +38,10 @@ func createFuncMap(d *deps.Deps) map[string]interface{} {
|
|
|
38
38
|
// as well as a JSON blob of its data,
|
|
39
39
|
// and renders it.
|
|
40
40
|
func RenderHugo(templateString string, props string) interface{} {
|
|
41
|
-
var parsedProps
|
|
41
|
+
var parsedProps interface{}
|
|
42
42
|
err := json.Unmarshal([]byte(props), &parsedProps)
|
|
43
43
|
if err != nil {
|
|
44
|
-
buf := bytes.NewBufferString(fmt.Sprintf("bad json unmarshal: %s", err.Error()))
|
|
44
|
+
buf := bytes.NewBufferString(fmt.Sprintf("BKSHERR: bad json unmarshal: %s", err.Error()))
|
|
45
45
|
return buf.String()
|
|
46
46
|
}
|
|
47
47
|
|
|
@@ -50,14 +50,14 @@ func RenderHugo(templateString string, props string) interface{} {
|
|
|
50
50
|
|
|
51
51
|
templ, err := template.New("").Funcs(funcMap).Parse(templateString)
|
|
52
52
|
if err != nil {
|
|
53
|
-
buf := bytes.NewBufferString(fmt.Sprintf("bad template parse: %s", err.Error()))
|
|
53
|
+
buf := bytes.NewBufferString(fmt.Sprintf("BKSHERR: bad template parse: %s", err.Error()))
|
|
54
54
|
return buf.String()
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
buf := bytes.NewBufferString("")
|
|
58
58
|
err = templ.Execute(buf, parsedProps)
|
|
59
59
|
if err != nil {
|
|
60
|
-
buf := bytes.NewBufferString(fmt.Sprintf("bad template render: %s", err.Error()))
|
|
60
|
+
buf := bytes.NewBufferString(fmt.Sprintf("BKSHERR: bad template render: %s", err.Error()))
|
|
61
61
|
return buf.String()
|
|
62
62
|
}
|
|
63
63
|
return buf.String()
|
package/lib/engine.js
CHANGED
|
@@ -94,13 +94,20 @@ export class Engine {
|
|
|
94
94
|
source = translateTextTemplate(source, {});
|
|
95
95
|
if (!globals || typeof globals !== "object") globals = {};
|
|
96
96
|
props = { ...globals, ...props };
|
|
97
|
+
|
|
98
|
+
// If we have assigned a root scope we need to pass that in as the context
|
|
99
|
+
if (props["."]) props = props["."];
|
|
97
100
|
const output = window.renderHugo(source, JSON.stringify(props));
|
|
98
|
-
|
|
101
|
+
if (/BKSHERR/.test(output)) {
|
|
102
|
+
console.error(output);
|
|
103
|
+
} else {
|
|
104
|
+
target.innerHTML = output;
|
|
105
|
+
}
|
|
99
106
|
}
|
|
100
107
|
|
|
101
108
|
async eval(str, props = [{}]) {
|
|
102
109
|
while (!window.renderHugo) await sleep(10);
|
|
103
|
-
|
|
110
|
+
let props_obj = props.reduce((a, b) => { return { ...a, ...b } });
|
|
104
111
|
|
|
105
112
|
// We're capable of looking up a simple variable
|
|
106
113
|
// (and it's hard to pass to wasm since we store variables on the context)
|
|
@@ -108,6 +115,9 @@ export class Engine {
|
|
|
108
115
|
return props_obj[str] ?? null;
|
|
109
116
|
}
|
|
110
117
|
|
|
118
|
+
// If we have assigned a root scope we need to pass that in as the context
|
|
119
|
+
if (props_obj["."]) props_obj = props_obj["."];
|
|
120
|
+
|
|
111
121
|
// Rewrite array.0 into index array 0
|
|
112
122
|
str = str.replace(/(.*)\.(\d+)$/, (_, obj, index) => {
|
|
113
123
|
return `index (${obj}) ${index}`;
|
|
@@ -22,6 +22,13 @@ export class IdentifierParser {
|
|
|
22
22
|
|
|
23
23
|
// Some short-circuits for easy to regex patterns to skip the parser
|
|
24
24
|
tryShortCircuit() {
|
|
25
|
+
// change an index of . to be only the index
|
|
26
|
+
const indexDotFunc = /^\s*\(\s*index\s+(?:\(\s*\.\s*\)|\.)\s+(\d+)\s*\)\s*$/
|
|
27
|
+
if (indexDotFunc.test(this.input)) {
|
|
28
|
+
const [, index] = this.input.match(indexDotFunc);
|
|
29
|
+
return `${index}`;
|
|
30
|
+
}
|
|
31
|
+
|
|
25
32
|
// change the index function into Bookshop dot notation
|
|
26
33
|
const indexFunc = /^\s*\(\s*index\s+\(?\.?(.+?)\)?\s+(\d+)\s*\)\s*$/
|
|
27
34
|
if (indexFunc.test(this.input)) {
|
|
@@ -30,7 +37,6 @@ export class IdentifierParser {
|
|
|
30
37
|
}
|
|
31
38
|
|
|
32
39
|
// strip the leading . from basic variable references
|
|
33
|
-
const variableDot = /^\s*\.([^\.\s])/;
|
|
34
40
|
if (/^\s*\./.test(this.input)) {
|
|
35
41
|
return this.input.replace(/^\s*\.([^\.\s])/, '$1');
|
|
36
42
|
}
|
|
@@ -66,7 +66,26 @@ test(`Nested dicts and slices`, async t => {
|
|
|
66
66
|
});
|
|
67
67
|
|
|
68
68
|
test(`Converts an index into dot notation`, async t => {
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
let ident = `(index (.items) 5)`;
|
|
70
|
+
let output = (new IdentifierParser(ident)).build();
|
|
71
71
|
t.deepEqual(output, `items.5`);
|
|
72
|
+
|
|
73
|
+
ident = `(index .array 5)`;
|
|
74
|
+
output = (new IdentifierParser(ident)).build();
|
|
75
|
+
t.deepEqual(output, `array.5`);
|
|
76
|
+
|
|
77
|
+
ident = `(index $variable 5)`;
|
|
78
|
+
output = (new IdentifierParser(ident)).build();
|
|
79
|
+
t.deepEqual(output, `$variable.5`);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
test(`Converts a dot index into a JS object property`, async t => {
|
|
84
|
+
let ident = `(index (.) 5)`;
|
|
85
|
+
let output = (new IdentifierParser(ident)).build();
|
|
86
|
+
t.deepEqual(output, `5`);
|
|
87
|
+
|
|
88
|
+
ident = `(index . 1234)`;
|
|
89
|
+
output = (new IdentifierParser(ident)).build();
|
|
90
|
+
t.deepEqual(output, `1234`);
|
|
72
91
|
});
|
|
@@ -2,9 +2,13 @@ import { Tokenizer } from 'liquidjs';
|
|
|
2
2
|
|
|
3
3
|
const tokens = {
|
|
4
4
|
END: /{{\s*end\s*}}/,
|
|
5
|
+
BEGIN: /{{\s*(if)/,
|
|
6
|
+
BEGIN_SCOPED: /{{\s*(range|with|define|block|template)/,
|
|
5
7
|
LOOP: /{{\s*range\s+(.+?)\s*}}/,
|
|
6
8
|
ASSIGN: /{{\s*(\$\S+)\s+:=\s+(.+?)\s*}}/,
|
|
9
|
+
WITH: /{{\s*with\s+(.+?)\s*}}/,
|
|
7
10
|
BOOKSHOP: /{{\s*partial\s+"bookshop(?:_partial)?"\s+\(\s*slice\s+"(.+?)" (.+?)\s*\)\s*}}/,
|
|
11
|
+
BOOKSHOP_SCOPED: /{{\s*partial\s+"bookshop(?:_partial)?"\s+\(?\s*\.\s*\)?\s*}}/,
|
|
8
12
|
}
|
|
9
13
|
|
|
10
14
|
/**
|
|
@@ -12,33 +16,55 @@ const tokens = {
|
|
|
12
16
|
* that we already have in the bundle.
|
|
13
17
|
* All go templating tags will come through as value tokens.
|
|
14
18
|
*/
|
|
15
|
-
const rewriteTag = function (token, src, liveMarkup) {
|
|
19
|
+
const rewriteTag = function (token, src, endTags, liveMarkup) {
|
|
16
20
|
let raw = token.getText();
|
|
21
|
+
let outputToken = {
|
|
22
|
+
text: raw
|
|
23
|
+
}
|
|
17
24
|
|
|
18
25
|
// Skip non-value tags
|
|
19
|
-
if (token.kind !== 8) return
|
|
20
|
-
if (tokens.END.test(raw))
|
|
26
|
+
if (token.kind !== 8) return outputToken;
|
|
27
|
+
if (tokens.END.test(raw)) {
|
|
28
|
+
endTags.push(outputToken);
|
|
29
|
+
return outputToken;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (tokens.BEGIN.test(raw)) {
|
|
33
|
+
endTags.pop();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (tokens.BEGIN_SCOPED.test(raw)) {
|
|
37
|
+
outputToken.text = `${outputToken.text}{{ \`<!--bookshop-live stack-->\` | safeHTML }}`;
|
|
38
|
+
|
|
39
|
+
let matchingEnd = endTags.pop();
|
|
40
|
+
matchingEnd.text = `{{ \`<!--bookshop-live unstack-->\` | safeHTML }}${matchingEnd.text}`;
|
|
41
|
+
}
|
|
21
42
|
|
|
22
43
|
if (liveMarkup && tokens.LOOP.test(raw)) {
|
|
23
44
|
let [, iterator] = raw.match(tokens.LOOP);
|
|
24
|
-
|
|
25
|
-
`${
|
|
45
|
+
outputToken.text = [`{{ $bookshop__live__iterator := 0 }}`,
|
|
46
|
+
`${outputToken.text}`,
|
|
26
47
|
`{{ (printf \`<!--bookshop-live context(.: (index (${iterator}) %d))-->\` $bookshop__live__iterator) | safeHTML }}`,
|
|
27
48
|
`{{ $bookshop__live__iterator = (add $bookshop__live__iterator 1) }}`
|
|
28
49
|
].join('')
|
|
29
50
|
} else if (liveMarkup && tokens.ASSIGN.test(raw)) {
|
|
30
51
|
let [, identifier, value] = raw.match(tokens.ASSIGN);
|
|
31
|
-
|
|
52
|
+
outputToken.text = `${outputToken.text}{{ \`<!--bookshop-live context(${identifier}: ${value})-->\` | safeHTML }}`
|
|
53
|
+
} else if (liveMarkup && tokens.WITH.test(raw)) {
|
|
54
|
+
let [, value] = raw.match(tokens.WITH);
|
|
55
|
+
outputToken.text = `${outputToken.text}{{ \`<!--bookshop-live context(.: ${value})-->\` | safeHTML }}`
|
|
32
56
|
} else if (liveMarkup && tokens.BOOKSHOP.test(raw)) {
|
|
33
57
|
let [, name, params] = raw.match(tokens.BOOKSHOP);
|
|
34
|
-
|
|
58
|
+
outputToken.text = `{{ \`<!--bookshop-live name(${name}) params(.: ${params})-->\` | safeHTML }}${outputToken.text}{{ \`<!--bookshop-live end-->\` | safeHTML }}`
|
|
59
|
+
} else if (liveMarkup && tokens.BOOKSHOP_SCOPED.test(raw)) {
|
|
60
|
+
outputToken.text = [`{{ if reflect.IsSlice . }}{{ (printf \`<!--bookshop-live name(%s) params(.: .)-->\` (index . 0)) | safeHTML }}`,
|
|
61
|
+
`{{- else if reflect.IsMap . -}}{{ (printf \`<!--bookshop-live name(%s) params(.: .)-->\` ._bookshop_name) | safeHTML }}{{ end }}`,
|
|
62
|
+
`${outputToken.text}`,
|
|
63
|
+
`{{ \`<!--bookshop-live end-->\` | safeHTML }}`
|
|
64
|
+
].join('');
|
|
35
65
|
}
|
|
36
66
|
|
|
37
|
-
return
|
|
38
|
-
src.substr(0, token.begin),
|
|
39
|
-
raw,
|
|
40
|
-
src.substr(token.end)
|
|
41
|
-
].join('');
|
|
67
|
+
return outputToken;
|
|
42
68
|
}
|
|
43
69
|
|
|
44
70
|
export default function (text, opts) {
|
|
@@ -46,13 +72,14 @@ export default function (text, opts) {
|
|
|
46
72
|
liveMarkup: true,
|
|
47
73
|
...opts
|
|
48
74
|
}
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
const output =
|
|
75
|
+
const tokenizer = new Tokenizer(text.toString());
|
|
76
|
+
const tokens = tokenizer.readTopLevelTokens();
|
|
77
|
+
const output = [];
|
|
78
|
+
const endTags = [];
|
|
52
79
|
|
|
53
|
-
|
|
54
|
-
|
|
80
|
+
tokens.reverse().forEach(tag => {
|
|
81
|
+
output.unshift(rewriteTag(tag, text, endTags, opts.liveMarkup));
|
|
55
82
|
});
|
|
56
83
|
|
|
57
|
-
return text;
|
|
84
|
+
return output.map(t => t.text).join('');
|
|
58
85
|
};
|
|
@@ -11,6 +11,17 @@ test("add live markup to bookshop tags", t => {
|
|
|
11
11
|
t.is(translateTextTemplate(input, {}), expected);
|
|
12
12
|
});
|
|
13
13
|
|
|
14
|
+
test("add live markup to scoped bookshop tags", t => {
|
|
15
|
+
const input = `{{ partial "bookshop" . }}`;
|
|
16
|
+
const expected = [
|
|
17
|
+
`{{ if reflect.IsSlice . }}{{ (printf \`<!--bookshop-live name(%s) params(.: .)-->\` (index . 0)) | safeHTML }}`,
|
|
18
|
+
`{{- else if reflect.IsMap . -}}{{ (printf \`<!--bookshop-live name(%s) params(.: .)-->\` ._bookshop_name) | safeHTML }}{{ end }}`,
|
|
19
|
+
`{{ partial "bookshop" . }}`,
|
|
20
|
+
`{{ \`<!--bookshop-live end-->\` | safeHTML }}`
|
|
21
|
+
].join('');
|
|
22
|
+
t.is(translateTextTemplate(input, {}), expected);
|
|
23
|
+
});
|
|
24
|
+
|
|
14
25
|
test("add live markup to bookshop_partial tags", t => {
|
|
15
26
|
const input = `{{ partial "bookshop_partial" (slice "helper" (dict "text" "input")) }}`;
|
|
16
27
|
const expected = [
|
|
@@ -27,13 +38,64 @@ test("add live markup to assigns", t => {
|
|
|
27
38
|
t.is(translateTextTemplate(input, {}), expected);
|
|
28
39
|
});
|
|
29
40
|
|
|
41
|
+
test("add live markup to withs", t => {
|
|
42
|
+
const input = `{{ with .b }}<p>{{.}}</p>{{ end }}`;
|
|
43
|
+
const expected = [`{{ with .b }}`,
|
|
44
|
+
`{{ \`<!--bookshop-live stack-->\` | safeHTML }}`,
|
|
45
|
+
`{{ \`<!--bookshop-live context(.: .b)-->\` | safeHTML }}`,
|
|
46
|
+
`<p>{{.}}</p>`,
|
|
47
|
+
`{{ \`<!--bookshop-live unstack-->\` | safeHTML }}`,
|
|
48
|
+
`{{ end }}`
|
|
49
|
+
].join('');
|
|
50
|
+
t.is(translateTextTemplate(input, {}), expected);
|
|
51
|
+
});
|
|
52
|
+
|
|
30
53
|
test("add live markup to loops", t => {
|
|
31
54
|
const input = `{{ range .items }}<p>{{ . }}</p>{{ end }}`;
|
|
32
55
|
const expected = [`{{ $bookshop__live__iterator := 0 }}`,
|
|
33
56
|
`{{ range .items }}`,
|
|
57
|
+
`{{ \`<!--bookshop-live stack-->\` | safeHTML }}`,
|
|
34
58
|
`{{ (printf \`<!--bookshop-live context(.: (index (.items) %d))-->\` $bookshop__live__iterator) | safeHTML }}`,
|
|
35
59
|
`{{ $bookshop__live__iterator = (add $bookshop__live__iterator 1) }}`,
|
|
36
|
-
`<p>{{ . }}</p
|
|
60
|
+
`<p>{{ . }}</p>`,
|
|
61
|
+
`{{ \`<!--bookshop-live unstack-->\` | safeHTML }}`,
|
|
62
|
+
`{{ end }}`
|
|
37
63
|
].join('');
|
|
38
64
|
t.is(translateTextTemplate(input, {}), expected);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("add live markup to complex end structures", t => {
|
|
68
|
+
const input = `
|
|
69
|
+
{{ range .items }}
|
|
70
|
+
|
|
71
|
+
{{with .text}}
|
|
72
|
+
<p>{{ . }}</p>
|
|
73
|
+
{{ end }}
|
|
74
|
+
|
|
75
|
+
{{ if .subtitle }}
|
|
76
|
+
<h2>{{ .subtitle }}</h2>
|
|
77
|
+
{{ else }}
|
|
78
|
+
{{ with .excerpt }}
|
|
79
|
+
<p>{{ . }}</p>
|
|
80
|
+
{{end}}
|
|
81
|
+
{{ end }}
|
|
82
|
+
|
|
83
|
+
{{ end }}`;
|
|
84
|
+
const expected = `
|
|
85
|
+
{{ $bookshop__live__iterator := 0 }}{{ range .items }}{{ \`<!--bookshop-live stack-->\` | safeHTML }}{{ (printf \`<!--bookshop-live context(.: (index (.items) %d))-->\` $bookshop__live__iterator) | safeHTML }}{{ $bookshop__live__iterator = (add $bookshop__live__iterator 1) }}
|
|
86
|
+
|
|
87
|
+
{{with .text}}{{ \`<!--bookshop-live stack-->\` | safeHTML }}{{ \`<!--bookshop-live context(.: .text)-->\` | safeHTML }}
|
|
88
|
+
<p>{{ . }}</p>
|
|
89
|
+
{{ \`<!--bookshop-live unstack-->\` | safeHTML }}{{ end }}
|
|
90
|
+
|
|
91
|
+
{{ if .subtitle }}
|
|
92
|
+
<h2>{{ .subtitle }}</h2>
|
|
93
|
+
{{ else }}
|
|
94
|
+
{{ with .excerpt }}{{ \`<!--bookshop-live stack-->\` | safeHTML }}{{ \`<!--bookshop-live context(.: .excerpt)-->\` | safeHTML }}
|
|
95
|
+
<p>{{ . }}</p>
|
|
96
|
+
{{ \`<!--bookshop-live unstack-->\` | safeHTML }}{{end}}
|
|
97
|
+
{{ end }}
|
|
98
|
+
|
|
99
|
+
{{ \`<!--bookshop-live unstack-->\` | safeHTML }}{{ end }}`;
|
|
100
|
+
t.is(translateTextTemplate(input, {}), expected);
|
|
39
101
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bookshop/hugo-engine",
|
|
3
3
|
"packageManager": "yarn@3.0.0",
|
|
4
|
-
"version": "2.4.0-hugo.
|
|
4
|
+
"version": "2.4.0-hugo.4",
|
|
5
5
|
"description": "Bookshop frontend Hugo renderer",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"sideEffects": false,
|
|
@@ -10,6 +10,12 @@
|
|
|
10
10
|
".": "./main.js",
|
|
11
11
|
"./build": "./build.js"
|
|
12
12
|
},
|
|
13
|
+
"files": [
|
|
14
|
+
"*.js",
|
|
15
|
+
"lib/*.js",
|
|
16
|
+
"!**/*.test.js",
|
|
17
|
+
"hugo-renderer/hugo_renderer.wasm"
|
|
18
|
+
],
|
|
13
19
|
"scripts": {
|
|
14
20
|
"test": "nyc ava -v"
|
|
15
21
|
},
|
|
@@ -23,8 +29,9 @@
|
|
|
23
29
|
"nyc": "^15.1.0"
|
|
24
30
|
},
|
|
25
31
|
"dependencies": {
|
|
26
|
-
"@bookshop/helpers": "2.4.0-hugo.
|
|
27
|
-
"esbuild": "^0.13.10"
|
|
32
|
+
"@bookshop/helpers": "2.4.0-hugo.4",
|
|
33
|
+
"esbuild": "^0.13.10",
|
|
34
|
+
"liquidjs": "9.28.0"
|
|
28
35
|
},
|
|
29
36
|
"engines": {
|
|
30
37
|
"node": ">=14.16"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"parent":null,"pid":88149,"argv":["/Users/liambigelow/.nvm/versions/node/v14.16.0/bin/node","/Users/liambigelow/Projects/CC/bookshop/javascript-modules/node_modules/ava/cli.js","-v"],"execArgv":[],"cwd":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine","time":1643327931302,"ppid":88148,"coverageFilename":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/b5f86652-cbe8-44f9-a36c-d5721dfe5bbe.json","externalId":"","uuid":"b5f86652-cbe8-44f9-a36c-d5721dfe5bbe","files":[]}
|