Skip to content

Commit

Permalink
fix(hbs2ui5): enables 3 or more levels of inheritance with templates (#…
Browse files Browse the repository at this point in the history
…1593)

- lookup for include statements in the hbs files used to be just
one level above the class.
  • Loading branch information
MapTo0 committed May 12, 2020
1 parent f1f3d4f commit 2a426dd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/tools/lib/hbs2lit/src/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const removeWhiteSpaces = (source) => {
const compileString = async (sInput, config) => {
let sPreprocessed = sInput;

sPreprocessed = await includesReplacer.replace(sPreprocessed, config);
sPreprocessed = includesReplacer.replace(sPreprocessed, config);
sPreprocessed = removeWhiteSpaces(sPreprocessed);

const ast = Handlebars.parse(sPreprocessed);
Expand Down
17 changes: 6 additions & 11 deletions packages/tools/lib/hbs2lit/src/includesReplacer.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
const path = require("path");
const {promisify} = require("util");
const nativeFs = require("fs");

function replaceIncludes(hbs, config) {
const fs = config.fs || nativeFs;
const readFile = promisify(fs.readFile);
const inclRegex = /{{>\s*include\s*["']([a-zA-Z.\/]+)["']}}/g;
let match;

async function replacer(match, p1) {
const includeContent = await readFile(path.join(config.templatesPath, p1), "utf-8");
hbs = hbs.replace(match, includeContent);
while((match = inclRegex.exec(hbs)) !== null) {
inclRegex.lastIndex = 0;
const includeContent = fs.readFileSync(path.join(config.templatesPath, match[1]), "utf-8");
hbs = hbs.replace(match[0], includeContent);
}

let match;
const replacers = [];
while ((match = inclRegex.exec (hbs)) !== null) {
replacers.push(replacer(match[0], match[1]));
}
return Promise.all(replacers).then(() => hbs);
return hbs;
}

module.exports = {
Expand Down

0 comments on commit 2a426dd

Please sign in to comment.