imp: qweb engine can be initialized with templates

This commit is contained in:
Géry Debongnie
2019-03-29 16:40:59 +01:00
parent e6b0d06e3e
commit d6e61c2203
3 changed files with 26 additions and 1 deletions
+5 -1
View File
@@ -182,7 +182,7 @@ export class QWeb {
templates: { [name: string]: CompiledTemplate<VNode> } = {};
directives: Directive[] = [];
constructor() {
constructor(data?: string) {
[
forEachDirective,
escDirective,
@@ -196,6 +196,10 @@ export class QWeb {
refDirective,
widgetDirective
].forEach(d => this.addDirective(d));
if (data) {
this.loadTemplates(data);
}
}
utils = {
+11
View File
@@ -464,6 +464,17 @@ exports[`foreach iterate, position 1`] = `
}"
`;
exports[`loading templates can initialize qweb with a string 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
c1.push({text: \`jupiler\`});
return vn1;
}"
`;
exports[`loading templates can load a few templates from a xml string 1`] = `
"function anonymous(context,extra
) {
+10
View File
@@ -878,6 +878,16 @@ describe("t-ref", () => {
});
describe("loading templates", () => {
test("can initialize qweb with a string", () => {
const data = `
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<div t-name="hey">jupiler</div>
</templates>`;
const qweb = new QWeb(data);
expect(renderToString(qweb, "hey")).toBe("<div>jupiler</div>");
});
test("can load a few templates from a xml string", () => {
const data = `
<?xml version="1.0" encoding="UTF-8"?>