[REF] qweb: rename loadTemplates into addTemplates

This commit is contained in:
Géry Debongnie
2019-05-15 10:55:39 +02:00
parent 04eb720619
commit 9556696fa8
4 changed files with 69 additions and 21 deletions
+18 -17
View File
@@ -134,7 +134,7 @@ export class QWeb {
constructor(data?: string) {
if (data) {
this.loadTemplates(data);
this.addTemplates(data);
}
this.addTemplate("default", "<div></div>");
}
@@ -167,6 +167,23 @@ export class QWeb {
this._addTemplate(name, <Element>doc.firstChild);
}
/**
* Load templates from a xml (as a string). This will look up for the first
* <templates> tag, and will consider each child of this as a template, with
* the name given by the t-name attribute.
*/
addTemplates(xmlstr: string) {
const doc = parseXML(xmlstr);
const templates = doc.getElementsByTagName("templates")[0];
if (!templates) {
return;
}
for (let elem of <any>templates.children) {
const name = elem.getAttribute("t-name");
this._addTemplate(name, elem);
}
}
_addTemplate(name: string, elem: Element) {
if (name in this.templates) {
throw new Error(`Template ${name} already defined`);
@@ -224,22 +241,6 @@ export class QWeb {
}
}
}
/**
* Load templates from a xml (as a string). This will look up for the first
* <templates> tag, and will consider each child of this as a template, with
* the name given by the t-name attribute.
*/
loadTemplates(xmlstr: string) {
const doc = parseXML(xmlstr);
const templates = doc.getElementsByTagName("templates")[0];
if (!templates) {
return;
}
for (let elem of <any>templates.children) {
const name = elem.getAttribute("t-name");
this._addTemplate(name, elem);
}
}
/**
* Render a template
*