[ADD] Added clone template in QWeb2 (t-name & t-extend)

bzr revid: fme@openerp.com-20110509121901-kmpcn7n6gsrjx6bl
This commit is contained in:
Fabien Meghazi
2011-05-09 14:19:01 +02:00
parent d6bf99ff90
commit 84c0e981ec
3 changed files with 16 additions and 0 deletions
@@ -24,4 +24,9 @@
<t t-extend="jquery-extend">
<t t-jquery="footer" t-operation="inner"><b>END</b></t>
</t>
<t t-name="jquery-extend-clone" t-extend="jquery-extend">
<t t-jquery="ul" t-operation="append"><li>CLONED TEMPLATE</li></t>
</t>
</templates>
@@ -251,6 +251,8 @@
test("jQuery extend", function () {
equals(render('jquery-extend', {}), '<hr/><ul class="main"><li>1</li><li>2</li><li>3</li></ul><footer><b>END</b></footer>',
"Extend template with jQuery");
equals(render('jquery-extend-clone', {}), '<ul><li>one</li><li>CLONED TEMPLATE</li></ul>',
"Clone template");
});
});
</script>
+9
View File
@@ -216,6 +216,15 @@ QWeb2.Engine = (function() {
}
var name = node.getAttribute(this.prefix + '-name');
var extend = node.getAttribute(this.prefix + '-extend');
if (name && extend) {
// Clone template and extend it
if (!this.templates[extend]) {
return this.tools.exception("Can't clone undefined template " + extend);
}
this.templates[name] = this.templates[extend].cloneNode(true);
extend = name;
name = undefined;
}
if (name) {
this.templates[name] = node;
} else if (extend) {