REFACTOR: Support bundling our admin section as an ember addon

This commit is contained in:
Robin Ward
2020-09-22 14:18:47 -04:00
parent cfb3f4db13
commit ce3fe2f4c4
448 changed files with 130 additions and 29 deletions
+26 -19
View File
@@ -22,7 +22,7 @@ function sexpValue(value) {
function pairsToObj(pairs) {
let result = [];
pairs.forEach(p => {
pairs.forEach((p) => {
result.push(`"${p.key}": ${sexpValue(p.value)}`);
});
@@ -47,7 +47,7 @@ function sexp(value) {
if (value.path.original === "concat") {
let result = [];
value.params.forEach(p => {
value.params.forEach((p) => {
result.push(sexpValue(p));
});
return result.join(" + ");
@@ -86,9 +86,11 @@ function mustacheValue(node, state) {
switch (path) {
case "attach":
let widgetName = argValue(node.hash.pairs.find(p => p.key === "widget"));
let widgetName = argValue(
node.hash.pairs.find((p) => p.key === "widget")
);
let attrs = node.hash.pairs.find(p => p.key === "attrs");
let attrs = node.hash.pairs.find((p) => p.key === "attrs");
if (attrs) {
return `this.attach(${widgetName}, ${argValue(attrs)})`;
}
@@ -102,9 +104,13 @@ function mustacheValue(node, state) {
return i18n(node);
break;
case "avatar":
let template = argValue(node.hash.pairs.find(p => p.key === "template"));
let username = argValue(node.hash.pairs.find(p => p.key === "username"));
let size = argValue(node.hash.pairs.find(p => p.key === "size"));
let template = argValue(
node.hash.pairs.find((p) => p.key === "template")
);
let username = argValue(
node.hash.pairs.find((p) => p.key === "username")
);
let size = argValue(node.hash.pairs.find((p) => p.key === "size"));
return `${useHelper(
state,
"avatar"
@@ -149,7 +155,7 @@ class Compiler {
this.state = {
helpersUsed: {},
helperNumber: 0
helperNumber: 0,
};
}
@@ -163,7 +169,8 @@ class Compiler {
switch (node.type) {
case "Program":
node.body.forEach(bodyNode => {
case "Template":
node.body.forEach((bodyNode) => {
instructions = instructions.concat(
this.processNode(parentAcc, bodyNode)
);
@@ -172,7 +179,7 @@ class Compiler {
case "ElementNode":
innerAcc = this.newAcc();
instructions.push(`var ${innerAcc} = [];`);
node.children.forEach(child => {
node.children.forEach((child) => {
instructions = instructions.concat(this.processNode(innerAcc, child));
});
@@ -180,7 +187,7 @@ class Compiler {
let attributes = [];
let properties = [];
node.attributes.forEach(a => {
node.attributes.forEach((a) => {
const name = a.name;
const value =
a.value.type === "MustacheStatement"
@@ -227,7 +234,7 @@ class Compiler {
instructions.push(
`if (${negate}${resolve(node.params[0].original)}) {`
);
node.program.body.forEach(child => {
node.program.body.forEach((child) => {
instructions = instructions.concat(
this.processNode(parentAcc, child)
);
@@ -235,7 +242,7 @@ class Compiler {
if (node.inverse) {
instructions.push(`} else {`);
node.inverse.body.forEach(child => {
node.inverse.body.forEach((child) => {
instructions = instructions.concat(
this.processNode(parentAcc, child)
);
@@ -249,7 +256,7 @@ class Compiler {
instructions.push(
` ${collection}.forEach(${node.program.blockParams[0]} => {`
);
node.program.body.forEach(child => {
node.program.body.forEach((child) => {
instructions = instructions.concat(
this.processNode(parentAcc, child)
);
@@ -281,7 +288,7 @@ function compile(template) {
let imports = "";
Object.keys(compiler.state.helpersUsed).forEach(h => {
Object.keys(compiler.state.helpersUsed).forEach((h) => {
let id = compiler.state.helpersUsed[h];
imports += `var __h${id} = __widget_helpers.${h}; `;
});
@@ -298,7 +305,7 @@ function error(path, state, msg) {
);
}
exports.WidgetHbsCompiler = function(babel) {
exports.WidgetHbsCompiler = function (babel) {
let t = babel.types;
return {
visitor: {
@@ -342,7 +349,7 @@ exports.WidgetHbsCompiler = function(babel) {
}
let template = path.node.quasi.quasis
.map(quasi => quasi.value.cooked)
.map((quasi) => quasi.value.cooked)
.join("");
try {
@@ -350,7 +357,7 @@ exports.WidgetHbsCompiler = function(babel) {
} catch (e) {
return error(path, state, e.toString());
}
}
}
},
},
};
};