@bookshop/ejs-engine
Advanced tools
Comparing version 1.6.1 to 1.6.2
{ | ||
"name": "@bookshop/ejs-engine", | ||
"version": "1.6.1", | ||
"version": "1.6.2", | ||
"description": "", | ||
@@ -24,3 +24,3 @@ "main": "src/index.js", | ||
}, | ||
"gitHead": "2d429629b50313d39113da07a2392473c4b7b40c" | ||
"gitHead": "32599ab66bf4de6c1e0ac825a462f5bbbd87a13d" | ||
} |
@@ -15,3 +15,4 @@ const ejs = require("./ejs"); | ||
options.renderRoot.innerHTML = ejs.render( | ||
`<% include = window.include %>${fetchComponent( | ||
// Include override (legacy) | ||
`<% include = window.include%>${fetchComponent( | ||
`components/${name}/${lastPart}.ejs` | ||
@@ -26,3 +27,3 @@ )}`, | ||
* | ||
* Storybook handling for `include` | ||
* Storybook handling for including other components | ||
* | ||
@@ -34,11 +35,31 @@ * @param {string} filename | ||
*/ | ||
window.component = (path, props) => { | ||
// Handle that the full path is not provided (just component-name, e.g, component("button")) | ||
const modifiedPathParts = path.split('/'); | ||
const lastPart = modifiedPathParts[modifiedPathParts.length - 1]; | ||
const newPath = `${path.replace('.ejs', '')}/${lastPart}.ejs`; | ||
const ejsComponent = fetchComponent( | ||
`components/${newPath.toLowerCase()}` | ||
); | ||
// include tag is necessary for a new component that imports a legacy component | ||
return ejs.render(`<% include = window.include %>${ejsComponent}`, { props }); | ||
}; | ||
/** | ||
* | ||
* Legacy syntax support | ||
* | ||
* @deprecated | ||
* @param {string} filename | ||
* @param {Record<string, any>} props | ||
* | ||
* @return {string} EJS component string | ||
*/ | ||
window.include = (path, props) => { | ||
const parts = path.split("/"); | ||
const lastPart = parts[parts.length - 1].replace(".ejs", ""); | ||
const ejsComponent = fetchComponent( | ||
`${path.toLowerCase()}` | ||
// path.replace('Components', 'components') | ||
); | ||
return ejs.render(ejsComponent, { props }); | ||
return ejs.render(`<% include = window.include%>${ejsComponent}`, { props }); | ||
}; | ||
@@ -45,0 +66,0 @@ |
49715
1556