@bookshop/hugo-engine 2.4.0-hugo.4 → 2.4.0
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/.nyc_output/{5ff8dc15-11f5-4e63-9582-916657a3e8ba.json → 46dcfe75-3bbf-4f92-a6b3-8145e351ae24.json} +0 -0
- package/.nyc_output/{7054beca-6b99-4dd2-a8c7-4aec983815fe.json → 67223940-25e4-4ca5-88f7-2427417305e6.json} +0 -0
- package/.nyc_output/{727fa7a6-f028-4392-b4d1-0b0ec68f3077.json → 8cad51f7-2d53-4aad-9ac6-583d26278617.json} +0 -0
- package/.nyc_output/{7e79dc9e-2fd1-45e0-8a5a-d743898cb2ab.json → b0aa8748-7b49-40c3-a46a-4c4b89756480.json} +0 -0
- package/.nyc_output/{a528b45c-4264-43cd-bf2c-ace2d3f3528d.json → f64c5820-5f85-4cca-a4b8-197da73a4918.json} +0 -0
- package/.nyc_output/processinfo/{7054beca-6b99-4dd2-a8c7-4aec983815fe.json → 46dcfe75-3bbf-4f92-a6b3-8145e351ae24.json} +1 -1
- package/.nyc_output/processinfo/{727fa7a6-f028-4392-b4d1-0b0ec68f3077.json → 67223940-25e4-4ca5-88f7-2427417305e6.json} +1 -1
- package/.nyc_output/processinfo/{7e79dc9e-2fd1-45e0-8a5a-d743898cb2ab.json → 8cad51f7-2d53-4aad-9ac6-583d26278617.json} +1 -1
- package/.nyc_output/processinfo/{a528b45c-4264-43cd-bf2c-ace2d3f3528d.json → b0aa8748-7b49-40c3-a46a-4c4b89756480.json} +1 -1
- package/.nyc_output/processinfo/f64c5820-5f85-4cca-a4b8-197da73a4918.json +1 -0
- package/.nyc_output/processinfo/index.json +1 -1
- package/lib/translateTextTemplate.js +12 -6
- package/lib/translateTextTemplate.test.js +24 -12
- package/package.json +2 -2
- package/.nyc_output/processinfo/5ff8dc15-11f5-4e63-9582-916657a3e8ba.json +0 -1
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"parent":"
|
|
1
|
+
{"parent":"f64c5820-5f85-4cca-a4b8-197da73a4918","pid":23488,"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":1643594173677,"ppid":23484,"coverageFilename":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/46dcfe75-3bbf-4f92-a6b3-8145e351ae24.json","externalId":"","uuid":"46dcfe75-3bbf-4f92-a6b3-8145e351ae24","files":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"parent":"
|
|
1
|
+
{"parent":"f64c5820-5f85-4cca-a4b8-197da73a4918","pid":23487,"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":1643594173669,"ppid":23484,"coverageFilename":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/67223940-25e4-4ca5-88f7-2427417305e6.json","externalId":"","uuid":"67223940-25e4-4ca5-88f7-2427417305e6","files":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"parent":"
|
|
1
|
+
{"parent":"f64c5820-5f85-4cca-a4b8-197da73a4918","pid":23486,"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":1643594173664,"ppid":23484,"coverageFilename":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/8cad51f7-2d53-4aad-9ac6-583d26278617.json","externalId":"","uuid":"8cad51f7-2d53-4aad-9ac6-583d26278617","files":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"parent":"
|
|
1
|
+
{"parent":"f64c5820-5f85-4cca-a4b8-197da73a4918","pid":23485,"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":1643594173660,"ppid":23484,"coverageFilename":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/b0aa8748-7b49-40c3-a46a-4c4b89756480.json","externalId":"","uuid":"b0aa8748-7b49-40c3-a46a-4c4b89756480","files":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"parent":null,"pid":23484,"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":1643594173128,"ppid":23483,"coverageFilename":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/f64c5820-5f85-4cca-a4b8-197da73a4918.json","externalId":"","uuid":"f64c5820-5f85-4cca-a4b8-197da73a4918","files":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"processes":{"
|
|
1
|
+
{"processes":{"46dcfe75-3bbf-4f92-a6b3-8145e351ae24":{"parent":"f64c5820-5f85-4cca-a4b8-197da73a4918","children":[]},"67223940-25e4-4ca5-88f7-2427417305e6":{"parent":"f64c5820-5f85-4cca-a4b8-197da73a4918","children":[]},"8cad51f7-2d53-4aad-9ac6-583d26278617":{"parent":"f64c5820-5f85-4cca-a4b8-197da73a4918","children":[]},"b0aa8748-7b49-40c3-a46a-4c4b89756480":{"parent":"f64c5820-5f85-4cca-a4b8-197da73a4918","children":[]},"f64c5820-5f85-4cca-a4b8-197da73a4918":{"parent":null,"children":["46dcfe75-3bbf-4f92-a6b3-8145e351ae24","67223940-25e4-4ca5-88f7-2427417305e6","8cad51f7-2d53-4aad-9ac6-583d26278617","b0aa8748-7b49-40c3-a46a-4c4b89756480"]}},"files":{},"externalIds":{}}
|
|
@@ -5,10 +5,11 @@ const tokens = {
|
|
|
5
5
|
BEGIN: /{{\s*(if)/,
|
|
6
6
|
BEGIN_SCOPED: /{{\s*(range|with|define|block|template)/,
|
|
7
7
|
LOOP: /{{\s*range\s+(.+?)\s*}}/,
|
|
8
|
+
INDEX_LOOP: /{{\s*range\s+(\$.+), \$.+ := (.+?)\s*}}/,
|
|
8
9
|
ASSIGN: /{{\s*(\$\S+)\s+:=\s+(.+?)\s*}}/,
|
|
9
10
|
WITH: /{{\s*with\s+(.+?)\s*}}/,
|
|
10
|
-
BOOKSHOP: /{{\s*partial\s+"bookshop
|
|
11
|
-
BOOKSHOP_SCOPED: /{{\s*partial\s+"bookshop
|
|
11
|
+
BOOKSHOP: /{{\s*partial\s+"bookshop"\s+\(\s*slice\s+"(.+?)" (.+?)\s*\)\s*}}/,
|
|
12
|
+
BOOKSHOP_SCOPED: /{{\s*partial\s+"bookshop"\s+\(?\s*\.\s*\)?\s*}}/,
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
/**
|
|
@@ -40,7 +41,12 @@ const rewriteTag = function (token, src, endTags, liveMarkup) {
|
|
|
40
41
|
matchingEnd.text = `{{ \`<!--bookshop-live unstack-->\` | safeHTML }}${matchingEnd.text}`;
|
|
41
42
|
}
|
|
42
43
|
|
|
43
|
-
if (liveMarkup && tokens.
|
|
44
|
+
if (liveMarkup && tokens.INDEX_LOOP.test(raw)) {
|
|
45
|
+
let [, index_variable, iterator] = raw.match(tokens.INDEX_LOOP);
|
|
46
|
+
outputToken.text = [`${outputToken.text}`,
|
|
47
|
+
`{{ (printf \`<!--bookshop-live context(.: (index (${iterator}) %d))-->\` ${index_variable}) | safeHTML }}`
|
|
48
|
+
].join('')
|
|
49
|
+
} else if (liveMarkup && tokens.LOOP.test(raw)) {
|
|
44
50
|
let [, iterator] = raw.match(tokens.LOOP);
|
|
45
51
|
outputToken.text = [`{{ $bookshop__live__iterator := 0 }}`,
|
|
46
52
|
`${outputToken.text}`,
|
|
@@ -49,13 +55,13 @@ const rewriteTag = function (token, src, endTags, liveMarkup) {
|
|
|
49
55
|
].join('')
|
|
50
56
|
} else if (liveMarkup && tokens.ASSIGN.test(raw)) {
|
|
51
57
|
let [, identifier, value] = raw.match(tokens.ASSIGN);
|
|
52
|
-
outputToken.text = `${outputToken.text}{{ \`<!--bookshop-live context(${identifier}: ${value})-->\` | safeHTML }}`
|
|
58
|
+
outputToken.text = `${outputToken.text}{{ \`<!--bookshop-live context(${identifier}: (${value}))-->\` | safeHTML }}`
|
|
53
59
|
} else if (liveMarkup && tokens.WITH.test(raw)) {
|
|
54
60
|
let [, value] = raw.match(tokens.WITH);
|
|
55
|
-
outputToken.text = `${outputToken.text}{{ \`<!--bookshop-live context(.: ${value})-->\` | safeHTML }}`
|
|
61
|
+
outputToken.text = `${outputToken.text}{{ \`<!--bookshop-live context(.: (${value}))-->\` | safeHTML }}`
|
|
56
62
|
} else if (liveMarkup && tokens.BOOKSHOP.test(raw)) {
|
|
57
63
|
let [, name, params] = raw.match(tokens.BOOKSHOP);
|
|
58
|
-
outputToken.text = `{{ \`<!--bookshop-live name(${name}) params(.: ${params})-->\` | safeHTML }}${outputToken.text}{{ \`<!--bookshop-live end-->\` | safeHTML }}`
|
|
64
|
+
outputToken.text = `{{ \`<!--bookshop-live name(${name}) params(.: (${params}))-->\` | safeHTML }}${outputToken.text}{{ \`<!--bookshop-live end-->\` | safeHTML }}`
|
|
59
65
|
} else if (liveMarkup && tokens.BOOKSHOP_SCOPED.test(raw)) {
|
|
60
66
|
outputToken.text = [`{{ if reflect.IsSlice . }}{{ (printf \`<!--bookshop-live name(%s) params(.: .)-->\` (index . 0)) | safeHTML }}`,
|
|
61
67
|
`{{- else if reflect.IsMap . -}}{{ (printf \`<!--bookshop-live name(%s) params(.: .)-->\` ._bookshop_name) | safeHTML }}{{ end }}`,
|
|
@@ -4,7 +4,7 @@ import translateTextTemplate from './translateTextTemplate.js';
|
|
|
4
4
|
test("add live markup to bookshop tags", t => {
|
|
5
5
|
const input = `{{ partial "bookshop" (slice "content" (dict "content_html" .Params.note_html "type" "note")) }}`;
|
|
6
6
|
const expected = [
|
|
7
|
-
`{{ \`<!--bookshop-live name(content) params(.: (dict "content_html" .Params.note_html "type" "note"))-->\` | safeHTML }}`,
|
|
7
|
+
`{{ \`<!--bookshop-live name(content) params(.: ((dict "content_html" .Params.note_html "type" "note")))-->\` | safeHTML }}`,
|
|
8
8
|
`{{ partial "bookshop" (slice "content" (dict "content_html" .Params.note_html "type" "note")) }}`,
|
|
9
9
|
`{{ \`<!--bookshop-live end-->\` | safeHTML }}`
|
|
10
10
|
].join('');
|
|
@@ -22,19 +22,19 @@ test("add live markup to scoped bookshop tags", t => {
|
|
|
22
22
|
t.is(translateTextTemplate(input, {}), expected);
|
|
23
23
|
});
|
|
24
24
|
|
|
25
|
-
test("add live markup to bookshop_partial tags", t => {
|
|
25
|
+
test("don't add live markup to bookshop_partial tags", t => {
|
|
26
26
|
const input = `{{ partial "bookshop_partial" (slice "helper" (dict "text" "input")) }}`;
|
|
27
|
-
const expected =
|
|
28
|
-
`{{ \`<!--bookshop-live name(helper) params(.: (dict "text" "input"))-->\` | safeHTML }}`,
|
|
29
|
-
`{{ partial "bookshop_partial" (slice "helper" (dict "text" "input")) }}`,
|
|
30
|
-
`{{ \`<!--bookshop-live end-->\` | safeHTML }}`
|
|
31
|
-
].join('');
|
|
27
|
+
const expected = `{{ partial "bookshop_partial" (slice "helper" (dict "text" "input")) }}`;
|
|
32
28
|
t.is(translateTextTemplate(input, {}), expected);
|
|
33
29
|
});
|
|
34
30
|
|
|
35
31
|
test("add live markup to assigns", t => {
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
let input = `{{ $a := .b }}`;
|
|
33
|
+
let expected = `{{ $a := .b }}{{ \`<!--bookshop-live context($a: (.b))-->\` | safeHTML }}`;
|
|
34
|
+
t.is(translateTextTemplate(input, {}), expected);
|
|
35
|
+
|
|
36
|
+
input = `{{ $a := .b | chomp }}`;
|
|
37
|
+
expected = `{{ $a := .b | chomp }}{{ \`<!--bookshop-live context($a: (.b | chomp))-->\` | safeHTML }}`;
|
|
38
38
|
t.is(translateTextTemplate(input, {}), expected);
|
|
39
39
|
});
|
|
40
40
|
|
|
@@ -42,7 +42,7 @@ test("add live markup to withs", t => {
|
|
|
42
42
|
const input = `{{ with .b }}<p>{{.}}</p>{{ end }}`;
|
|
43
43
|
const expected = [`{{ with .b }}`,
|
|
44
44
|
`{{ \`<!--bookshop-live stack-->\` | safeHTML }}`,
|
|
45
|
-
`{{ \`<!--bookshop-live context(.: .b)-->\` | safeHTML }}`,
|
|
45
|
+
`{{ \`<!--bookshop-live context(.: (.b))-->\` | safeHTML }}`,
|
|
46
46
|
`<p>{{.}}</p>`,
|
|
47
47
|
`{{ \`<!--bookshop-live unstack-->\` | safeHTML }}`,
|
|
48
48
|
`{{ end }}`
|
|
@@ -64,6 +64,18 @@ test("add live markup to loops", t => {
|
|
|
64
64
|
t.is(translateTextTemplate(input, {}), expected);
|
|
65
65
|
});
|
|
66
66
|
|
|
67
|
+
test("add live markup to loops with iterators", t => {
|
|
68
|
+
const input = `{{range $loop_index, $element := .columns}}<p>{{$element}}</p>{{ end }}`;
|
|
69
|
+
const expected = [`{{range $loop_index, $element := .columns}}`,
|
|
70
|
+
`{{ \`<!--bookshop-live stack-->\` | safeHTML }}`,
|
|
71
|
+
`{{ (printf \`<!--bookshop-live context(.: (index (.columns) %d))-->\` $loop_index) | safeHTML }}`,
|
|
72
|
+
`<p>{{$element}}</p>`,
|
|
73
|
+
`{{ \`<!--bookshop-live unstack-->\` | safeHTML }}`,
|
|
74
|
+
`{{ end }}`
|
|
75
|
+
].join('');
|
|
76
|
+
t.is(translateTextTemplate(input, {}), expected);
|
|
77
|
+
});
|
|
78
|
+
|
|
67
79
|
test("add live markup to complex end structures", t => {
|
|
68
80
|
const input = `
|
|
69
81
|
{{ range .items }}
|
|
@@ -84,14 +96,14 @@ test("add live markup to complex end structures", t => {
|
|
|
84
96
|
const expected = `
|
|
85
97
|
{{ $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
98
|
|
|
87
|
-
{{with .text}}{{ \`<!--bookshop-live stack-->\` | safeHTML }}{{ \`<!--bookshop-live context(.: .text)-->\` | safeHTML }}
|
|
99
|
+
{{with .text}}{{ \`<!--bookshop-live stack-->\` | safeHTML }}{{ \`<!--bookshop-live context(.: (.text))-->\` | safeHTML }}
|
|
88
100
|
<p>{{ . }}</p>
|
|
89
101
|
{{ \`<!--bookshop-live unstack-->\` | safeHTML }}{{ end }}
|
|
90
102
|
|
|
91
103
|
{{ if .subtitle }}
|
|
92
104
|
<h2>{{ .subtitle }}</h2>
|
|
93
105
|
{{ else }}
|
|
94
|
-
{{ with .excerpt }}{{ \`<!--bookshop-live stack-->\` | safeHTML }}{{ \`<!--bookshop-live context(.: .excerpt)-->\` | safeHTML }}
|
|
106
|
+
{{ with .excerpt }}{{ \`<!--bookshop-live stack-->\` | safeHTML }}{{ \`<!--bookshop-live context(.: (.excerpt))-->\` | safeHTML }}
|
|
95
107
|
<p>{{ . }}</p>
|
|
96
108
|
{{ \`<!--bookshop-live unstack-->\` | safeHTML }}{{end}}
|
|
97
109
|
{{ end }}
|
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
|
|
4
|
+
"version": "2.4.0",
|
|
5
5
|
"description": "Bookshop frontend Hugo renderer",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"sideEffects": false,
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"nyc": "^15.1.0"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@bookshop/helpers": "2.4.0
|
|
32
|
+
"@bookshop/helpers": "2.4.0",
|
|
33
33
|
"esbuild": "^0.13.10",
|
|
34
34
|
"liquidjs": "9.28.0"
|
|
35
35
|
},
|
|
@@ -1 +0,0 @@
|
|
|
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":[]}
|