mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
small qweb cleanup
This commit is contained in:
+6
-12
@@ -18,7 +18,7 @@ export class Context {
|
||||
code: string[] = [];
|
||||
variables: { [key: string]: any } = {};
|
||||
escaping: boolean = false;
|
||||
parentNode: string | undefined;
|
||||
parentNode: string;
|
||||
indentLevel: number = 0;
|
||||
rootContext: Context;
|
||||
caller: Element | undefined;
|
||||
@@ -27,6 +27,7 @@ export class Context {
|
||||
constructor() {
|
||||
this.rootContext = this;
|
||||
this.fragmentID = this.generateID();
|
||||
this.parentNode = this.fragmentID;
|
||||
}
|
||||
|
||||
generateID(): string {
|
||||
@@ -68,11 +69,7 @@ export class Context {
|
||||
}
|
||||
|
||||
addNode(nodeID: string) {
|
||||
if (this.parentNode) {
|
||||
this.addLine(`${this.parentNode}.appendChild(${nodeID})`);
|
||||
} else {
|
||||
this.addLine(`${this.fragmentID}.appendChild(${nodeID})`);
|
||||
}
|
||||
this.addLine(`${this.parentNode}.appendChild(${nodeID})`);
|
||||
}
|
||||
addLine(line: string) {
|
||||
const prefix = new Array(this.indentLevel).join("\t");
|
||||
@@ -80,6 +77,9 @@ export class Context {
|
||||
const suffix = lastChar !== "}" && lastChar !== "{" ? ";" : "";
|
||||
this.code.push(prefix + line + suffix);
|
||||
}
|
||||
getValue(val: any): any {
|
||||
return val in this.variables ? this.getValue(this.variables[val]) : val;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -298,12 +298,6 @@ export default class QWeb {
|
||||
}
|
||||
}
|
||||
|
||||
_getValue(val: any, ctx: Context): any {
|
||||
if (val in ctx.variables) {
|
||||
return this._getValue(ctx.variables[val], ctx);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
_compileChildren(node: ChildNode, ctx: Context) {
|
||||
if (node.childNodes.length > 0) {
|
||||
for (let child of Array.from(node.childNodes)) {
|
||||
|
||||
@@ -61,7 +61,7 @@ const ifDirective: Directive = {
|
||||
name: "if",
|
||||
priority: 20,
|
||||
atNodeEncounter({ node, qweb, ctx }): boolean {
|
||||
let cond = qweb._getValue(node.getAttribute("t-if")!, ctx);
|
||||
let cond = ctx.getValue(node.getAttribute("t-if")!);
|
||||
ctx.addLine(`if (${qweb._formatExpression(cond)}) {`);
|
||||
ctx.indent();
|
||||
return false;
|
||||
@@ -76,7 +76,7 @@ const elifDirective: Directive = {
|
||||
name: "elif",
|
||||
priority: 30,
|
||||
atNodeEncounter({ node, qweb, ctx }): boolean {
|
||||
let cond = qweb._getValue(node.getAttribute("t-elif")!, ctx);
|
||||
let cond = ctx.getValue(node.getAttribute("t-elif")!);
|
||||
ctx.addLine(`else if (${qweb._formatExpression(cond)}) {`);
|
||||
ctx.indent();
|
||||
return false;
|
||||
@@ -180,7 +180,7 @@ const escDirective: Directive = {
|
||||
let nodeID = qweb._compileGenericNode(node, ctx);
|
||||
ctx = ctx.withParent(nodeID);
|
||||
}
|
||||
let value = qweb._getValue(node.getAttribute("t-esc")!, ctx);
|
||||
let value = ctx.getValue(node.getAttribute("t-esc")!);
|
||||
compileValueNode(value, node, qweb, ctx.withEscaping());
|
||||
return true;
|
||||
}
|
||||
@@ -194,7 +194,7 @@ const rawDirective: Directive = {
|
||||
let nodeID = qweb._compileGenericNode(node, ctx);
|
||||
ctx = ctx.withParent(nodeID);
|
||||
}
|
||||
let value = qweb._getValue(node.getAttribute("t-raw")!, ctx);
|
||||
let value = ctx.getValue(node.getAttribute("t-raw")!);
|
||||
compileValueNode(value, node, qweb, ctx);
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user