mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[IMP] qweb: add support for template strings
in inline expressions, such as t-esc or t-value. closes #746
This commit is contained in:
@@ -1236,6 +1236,55 @@ exports[`static templates empty div 1`] = `
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`static templates inline template string in t-esc 1`] = `
|
||||
"function anonymous(context, extra
|
||||
) {
|
||||
// Template name: \\"test\\"
|
||||
let scope = Object.create(context);
|
||||
let result;
|
||||
let h = this.h;
|
||||
let _1 = \`text\`;
|
||||
if (_1 != null) {
|
||||
let vn2 = {text: _1};
|
||||
result = vn2
|
||||
}
|
||||
return result;
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`static templates inline template string with content in t-esc 1`] = `
|
||||
"function anonymous(context, extra
|
||||
) {
|
||||
// Template name: \\"test\\"
|
||||
let scope = Object.create(context);
|
||||
let result;
|
||||
let h = this.h;
|
||||
scope.v = 1;
|
||||
let _1 = \`text\${scope.v}\`;
|
||||
if (_1 != null) {
|
||||
let vn2 = {text: _1};
|
||||
result = vn2
|
||||
}
|
||||
return result;
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`static templates inline template string with variable in context 1`] = `
|
||||
"function anonymous(context, extra
|
||||
) {
|
||||
// Template name: \\"test\\"
|
||||
let scope = Object.create(context);
|
||||
let result;
|
||||
let h = this.h;
|
||||
let _1 = \`text \${scope['v']}\`;
|
||||
if (_1 != null) {
|
||||
let vn2 = {text: _1};
|
||||
result = vn2
|
||||
}
|
||||
return result;
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`static templates properly handle comments 1`] = `
|
||||
"function anonymous(context, extra
|
||||
) {
|
||||
|
||||
@@ -31,6 +31,21 @@ describe("static templates", () => {
|
||||
expect(renderToString(qweb, "test", { text: "hello vdom" })).toBe("hello vdom");
|
||||
});
|
||||
|
||||
test("inline template string in t-esc", () => {
|
||||
qweb.addTemplate("test", '<t><t t-esc="`text`"/></t>');
|
||||
expect(renderToString(qweb, "test")).toBe("text");
|
||||
});
|
||||
|
||||
test("inline template string with content in t-esc", () => {
|
||||
qweb.addTemplate("test", '<t><t t-set="v" t-value="1"/><t t-esc="`text${v}`"/></t>');
|
||||
expect(renderToString(qweb, "test")).toBe("text1");
|
||||
});
|
||||
|
||||
test("inline template string with variable in context", () => {
|
||||
qweb.addTemplate("test", '<t><t t-esc="`text ${v}`"/></t>');
|
||||
expect(renderToString(qweb, "test", { v: "from context" })).toBe("text from context");
|
||||
});
|
||||
|
||||
test("simple string, with some dynamic value", () => {
|
||||
qweb.addTemplate("test", '<t>hello <t t-esc="text"/></t>');
|
||||
expect(renderToString(qweb, "test", { text: "vdom" })).toBe("hello vdom");
|
||||
|
||||
@@ -206,4 +206,10 @@ describe("expression evaluation", () => {
|
||||
expect(compileExpr("{a,b}", {})).toBe("{a:scope['a'],b:scope['b']}");
|
||||
expect(compileExpr("{a,b:3,c}", {})).toBe("{a:scope['a'],b:3,c:scope['c']}");
|
||||
});
|
||||
|
||||
test("template strings", () => {
|
||||
expect(compileExpr("`hey`", {})).toBe("`hey`");
|
||||
expect(compileExpr("`hey ${you}`", {})).toBe("`hey ${scope['you']}`");
|
||||
expect(compileExpr("`hey ${1 + 2}`", {})).toBe("`hey ${1+2}`");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user