@bookshop/eleventy-engine
Advanced tools
Comparing version
@@ -1,1 +0,1 @@ | ||
{"processes":{"37ec9ca1-92e2-416e-8410-066664937c6b":{"parent":"52634d9d-8ea6-4f98-b4c2-614ceb8acae4","children":[]},"4c651e70-fafb-4a59-866a-406ba037d258":{"parent":"52634d9d-8ea6-4f98-b4c2-614ceb8acae4","children":[]},"52634d9d-8ea6-4f98-b4c2-614ceb8acae4":{"parent":null,"children":["37ec9ca1-92e2-416e-8410-066664937c6b","4c651e70-fafb-4a59-866a-406ba037d258","c8e52f11-9a6a-48f2-b386-d5b9fbb3da91"]},"c8e52f11-9a6a-48f2-b386-d5b9fbb3da91":{"parent":"52634d9d-8ea6-4f98-b4c2-614ceb8acae4","children":[]}},"files":{},"externalIds":{}} | ||
{"processes":{"0b518de3-879a-4b51-8694-0c47c98c1392":{"parent":null,"children":["5ca85da4-b9e4-433a-b7f1-60803e0f8cb8","e0b1556a-d17b-4fc9-abcb-4924c466dce1","f92b6327-7c67-476c-929d-13ab1bb63434"]},"5ca85da4-b9e4-433a-b7f1-60803e0f8cb8":{"parent":"0b518de3-879a-4b51-8694-0c47c98c1392","children":[]},"e0b1556a-d17b-4fc9-abcb-4924c466dce1":{"parent":"0b518de3-879a-4b51-8694-0c47c98c1392","children":[]},"f92b6327-7c67-476c-929d-13ab1bb63434":{"parent":"0b518de3-879a-4b51-8694-0c47c98c1392","children":[]}},"files":{},"externalIds":{}} |
import { Tokenizer } from 'liquidjs'; | ||
const rewriteTag = function(token, src, liveMarkup) { | ||
// Put quotes around rewritten dynamic values. | ||
// Assuming that if this code is running, the Eleventy build succeeded. | ||
// A _bookshop_{{val}} include without quotes __will__ break in liquidjs, | ||
// but seems to work in Eleventy? | ||
const quoteDynamicNames = (raw) => { | ||
return raw.replace( | ||
/\s_bookshop_(include_)?{{(.+)}}\s/, | ||
(_, include, innards) => { | ||
return ` "_bookshop_${include || ''}{{${innards}}}" ` | ||
} | ||
); | ||
} | ||
const rewriteTag = function (token, src, liveMarkup) { | ||
let raw = token.getText(); | ||
@@ -10,7 +23,7 @@ | ||
if (liveMarkup && token.name && token.name === 'for'){ | ||
if (liveMarkup && token.name && token.name === 'for') { | ||
raw = `${raw}{% loop_context ${token.args} %}` | ||
} | ||
if (liveMarkup && token.name && (token.name === 'assign' || token.name === 'local')){ | ||
if (liveMarkup && token.name && (token.name === 'assign' || token.name === 'local')) { | ||
let identifier = token.args.split('=').shift().trim(); | ||
@@ -25,8 +38,10 @@ raw = `${raw}<!--bookshop-live context(${identifier}="{{${identifier}}}")-->` | ||
raw = raw.replace( | ||
/bookshop_include ('|")?(\S+)/, | ||
(_, quote, component) => { | ||
componentName = component.replace(/('|")$/, ''); | ||
return `include ${quote||''}_bookshop_include_${component}` | ||
} | ||
/bookshop_include ('|")?(\S+)/, | ||
(_, quote, component) => { | ||
componentName = component.replace(/('|")$/, ''); | ||
return `include ${quote || ''}_bookshop_include_${component}` | ||
} | ||
); | ||
raw = quoteDynamicNames(raw); | ||
if (liveMarkup) { | ||
@@ -44,8 +59,10 @@ let params = token.args.split(' '); | ||
raw = raw.replace( | ||
/bookshop ('|")?(\S+)/, | ||
(_, quote, component) => { | ||
componentName = component.replace(/('|")$/, ''); | ||
return `include ${quote||''}_bookshop_${component}` | ||
} | ||
/bookshop ('|")?(\S+)/, | ||
(_, quote, component) => { | ||
componentName = component.replace(/('|")$/, ''); | ||
return `include ${quote || ''}_bookshop_${component}` | ||
} | ||
); | ||
raw = quoteDynamicNames(raw); | ||
if (liveMarkup) { | ||
@@ -65,3 +82,3 @@ let params = token.args.split(' '); | ||
export default function(text, opts) { | ||
export default function (text, opts) { | ||
opts = { | ||
@@ -68,0 +85,0 @@ expandBindSyntax: true, |
@@ -13,3 +13,3 @@ import test from 'ava'; | ||
const expected = `{% include _bookshop_component prop: page.item %}`; | ||
t.is(translateLiquid(input, {expandBindSyntax: false, liveMarkup: false}), expected); | ||
t.is(translateLiquid(input, { expandBindSyntax: false, liveMarkup: false }), expected); | ||
}); | ||
@@ -20,9 +20,28 @@ | ||
const expected = `{% include "_bookshop_component" prop: page.item %}`; | ||
t.is(translateLiquid(input, {expandBindSyntax: false, liveMarkup: false}), expected); | ||
t.is(translateLiquid(input, { expandBindSyntax: false, liveMarkup: false }), expected); | ||
}); | ||
test("rewrite dynamic bookshop tags", t => { | ||
const input = `{% bookshop "{{ _bookshop_name }}" prop: page.item %}`; | ||
const expected = `{% include "_bookshop_{{ _bookshop_name }}" prop: page.item %}`; | ||
t.is(translateLiquid(input, { expandBindSyntax: false, liveMarkup: false }), expected); | ||
}); | ||
test("rewrite unquoted dynamic bookshop tags", t => { | ||
const input = `{% bookshop {{ _bookshop_name }} prop: page.item %}`; | ||
const expected = `{% include "_bookshop_{{ _bookshop_name }}" prop: page.item %}`; | ||
t.is(translateLiquid(input, { expandBindSyntax: false, liveMarkup: false }), expected); | ||
}); | ||
test("rewrite unquoted dynamic bookshop include tags", t => { | ||
const input = `{% bookshop_include {{ _bookshop_name }} prop: page.item %}`; | ||
const expected = `{% include "_bookshop_include_{{ _bookshop_name }}" prop: page.item %}`; | ||
t.is(translateLiquid(input, { expandBindSyntax: false, liveMarkup: false }), expected); | ||
}); | ||
test("rewrite bookshop_include tags", t => { | ||
const input = `{% bookshop_include "helper" prop: page.item %}`; | ||
const expected = `{% include "_bookshop_include_helper" prop: page.item %}`; | ||
t.is(translateLiquid(input, {expandBindSyntax: false, liveMarkup: false}), expected); | ||
t.is(translateLiquid(input, { expandBindSyntax: false, liveMarkup: false }), expected); | ||
}); | ||
@@ -32,3 +51,3 @@ | ||
const input = `<div><h1>{{ title | default: "Hello World" }}</h1></div>`; | ||
t.is(translateLiquid(input, {expandBindSyntax: false, liveMarkup: false}), input); | ||
t.is(translateLiquid(input, { expandBindSyntax: false, liveMarkup: false }), input); | ||
}); | ||
@@ -39,3 +58,3 @@ | ||
const expected = `<!--bookshop-live name(component) params(prop: page.item)-->{% include "_bookshop_component" prop: page.item %}<!--bookshop-live end-->`; | ||
t.is(translateLiquid(input, {expandBindSyntax: false}), expected); | ||
t.is(translateLiquid(input, { expandBindSyntax: false }), expected); | ||
}); | ||
@@ -46,3 +65,3 @@ | ||
const expected = `<!--bookshop-live name(helper) params(prop: page.item)-->{% include "_bookshop_include_helper" prop: page.item %}<!--bookshop-live end-->`; | ||
t.is(translateLiquid(input, {expandBindSyntax: false}), expected); | ||
t.is(translateLiquid(input, { expandBindSyntax: false }), expected); | ||
}); | ||
@@ -53,3 +72,3 @@ | ||
const expected = `{% assign a=b %}<!--bookshop-live context(a="{{a}}")-->`; | ||
t.is(translateLiquid(input, {expandBindSyntax: false}), expected); | ||
t.is(translateLiquid(input, { expandBindSyntax: false }), expected); | ||
}); | ||
@@ -60,3 +79,3 @@ | ||
const expected = `{% local a=b %}<!--bookshop-live context(a="{{a}}")-->`; | ||
t.is(translateLiquid(input, {expandBindSyntax: false}), expected); | ||
t.is(translateLiquid(input, { expandBindSyntax: false }), expected); | ||
}); | ||
@@ -67,3 +86,3 @@ | ||
const expected = `{% for a in b %}{% loop_context a in b %}`; | ||
t.is(translateLiquid(input, {expandBindSyntax: false}), expected); | ||
t.is(translateLiquid(input, { expandBindSyntax: false }), expected); | ||
}); |
{ | ||
"name": "@bookshop/eleventy-engine", | ||
"packageManager": "yarn@3.0.0", | ||
"version": "2.0.10-editorlinks.2", | ||
"version": "2.0.10-editorlinks.3", | ||
"description": "Bookshop frontend Eleventy renderer", | ||
@@ -26,4 +26,4 @@ "type": "module", | ||
"dependencies": { | ||
"@bookshop/helpers": "2.0.10-editorlinks.2", | ||
"esbuild": "^0.11.23", | ||
"@bookshop/helpers": "2.0.10-editorlinks.3", | ||
"esbuild": "^0.13.10", | ||
"liquidjs": "9.28.0", | ||
@@ -30,0 +30,0 @@ "slugify": "^1.5.3" |
19983
8.36%408
7.65%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
Updated