diff --git a/addons/web/static/lib/qweb/qweb-test-call.xml b/addons/web/static/lib/qweb/qweb-test-call.xml index 45a65eabce981c46a22fcc1784df9cb24faeb477..b0c5deb9fe6b57658ae1c994bb41b56d915665de 100644 --- a/addons/web/static/lib/qweb/qweb-test-call.xml +++ b/addons/web/static/lib/qweb/qweb-test-call.xml @@ -57,7 +57,7 @@ </result> <t t-name="basic-caller"> - <t t-call="{{True and '_basic-callee' or 'other'}}"/> + <t t-call="{{1 and '_basic-callee' or 'other'}}"/> </t> <result id="basic-caller">ok</result> </templates> diff --git a/addons/web/static/lib/qweb/qweb-test-global.xml b/addons/web/static/lib/qweb/qweb-test-global.xml index 1db3e5920fb254c973e638c97dfe306e569e74ee..bfcca8c1eba3ffc3e09f2786dcdd7e943c248593 100644 --- a/addons/web/static/lib/qweb/qweb-test-global.xml +++ b/addons/web/static/lib/qweb/qweb-test-global.xml @@ -18,7 +18,7 @@ </t> </t> <t t-call="_callee-asc-toto"/> - <t t-set="toto"><t t-set="truc" t-value="'bbb'"/><i t-att-notruc="not truc" t-att-truc="bool(truc)">i</i></t> + <t t-set="toto"><t t-set="truc" t-value="'bbb'"/><i t-att-notruc="not truc" t-att-truc="truc and 'ok'">i</i></t> <t t-call="_callee-asc-toto"/> </t> @@ -49,6 +49,6 @@ <div>toto default</div> - <div><i truc="True">i</i></div> + <div><i truc="ok">i</i></div> ]]></result> </templates> diff --git a/addons/web/static/lib/qweb/qweb2.js b/addons/web/static/lib/qweb/qweb2.js index c4bb7128e9bec9fadd91f3aa4efe38d762ab4883..8058cb7745f645e9b352ac96c9a6b2f020d48336 100644 --- a/addons/web/static/lib/qweb/qweb2.js +++ b/addons/web/static/lib/qweb/qweb2.js @@ -28,8 +28,10 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. var QWeb2 = { expressions_cache: { }, RESERVED_WORDS: 'true,false,NaN,null,undefined,debugger,console,window,in,instanceof,new,function,return,this,typeof,eval,void,Math,RegExp,Array,Object,Date'.split(','), - ACTIONS_PRECEDENCE: 'foreach,if,elif,else,call,set,esc,raw,js,debug,log'.split(','), + ACTIONS_PRECEDENCE: 'foreach,if,elif,else,call,set,js,debug,log'.split(','), WORD_REPLACEMENT: { + // FUCKING CHM FOR FUCK'S SAKE + 'not': '!', 'and': '&&', 'or': '||', 'gt': '>', @@ -76,9 +78,9 @@ var QWeb2 = { return s; }, gen_attribute: function(o) { - if (o !== null && o !== undefined) { + if (o) { if (o.constructor === Array) { - if (o[1] !== null && o[1] !== undefined) { + if (o[1]) { return this.format_attribute(o[0], o[1]); } } else if (typeof o === 'object') { @@ -718,36 +720,52 @@ QWeb2.Element = (function() { }, compile_element : function() { for (var i = 0, ilen = this.engine.actions_precedence.length; i < ilen; i++) { - var a = this.engine.actions_precedence[i]; - if (a in this.actions) { - var value = this.actions[a]; - var key = 'compile_action_' + a; + var compiled_action = this.engine.actions_precedence[i]; + if (compiled_action in this.actions) { + var value = this.actions[compiled_action]; + var key = 'compile_action_' + compiled_action; if (this[key]) { this[key](value); } else if (this.engine[key]) { this.engine[key].call(this, value); } else { - this.engine.tools.exception("No handler method for action '" + a + "'"); + this.engine.tools.exception("No handler method for action '" + compiled_action + "'"); } } } + function print_contents(self) { + var expr, esc, raw; + if (esc = self.actions['esc']) { + expr = "context.engine.tools.html_escape(" + self.format_str(esc) + ");"; + } else if(raw = self.actions['raw']) { + expr = self.format_str(raw); + } + // print non-empty result of t-esc or t-raw, otherwise + // print/process body + if (expr) { + self.top('var expr_result = ' + expr + ';'); + self.top('if (expr_result) {'); + self.top(' r.push(expr_result);'); + self.top('} else {'); + self.bottom('}'); + } + } if (this.tag.toLowerCase() !== this.engine.prefix) { var tag = "<" + this.tag; - for (var a in this.attributes) { - tag += this.engine.tools.gen_attribute([a, this.attributes[a]]); + for (var att in this.attributes) { + tag += this.engine.tools.gen_attribute([att, this.attributes[att]]); } this.top_string(tag); if (this.actions.att) { - this.top("r.push(context.engine.tools.gen_attribute(" + (this.format_expression(this.actions.att)) + "));"); + } for (var a in this.actions) { - var v = this.actions[a]; - var m = a.match(/att-(.+)/); - if (m) { + var m, v = this.actions[a]; + if (a === 'att') { + this.top("r.push(context.engine.tools.gen_attribute(" + (this.format_expression(v)) + "));"); + } else if (m = a.match(/att-(.+)/)) { this.top("r.push(context.engine.tools.gen_attribute(['" + m[1] + "', (" + (this.format_expression(v)) + ")]));"); - } - var m = a.match(/attf-(.+)/); - if (m) { + } else if (m = a.match(/attf-(.+)/)) { this.top("r.push(context.engine.tools.gen_attribute(['" + m[1] + "', (" + (this.string_interpolation(v)) + ")]));"); } } @@ -755,11 +773,13 @@ QWeb2.Element = (function() { // We do not enforce empty content on void elements // because QWeb rendering is not necessarily html. this.top_string("/>"); + return; // ensure we skip processing content } else { this.top_string(">"); this.bottom_string("</" + this.tag + ">"); } } + print_contents(this); }, compile_action_if : function(value) { this.top("if (" + (this.format_expression(value)) + ") {"); @@ -817,14 +837,6 @@ QWeb2.Element = (function() { } } }, - compile_action_esc : function(value) { - this.top("r.push(context.engine.tools.html_escape(" - + this.format_expression(value) - + "));"); - }, - compile_action_raw : function(value) { - this.top("r.push(" + (this.format_str(value)) + ");"); - }, compile_action_js : function(value) { this.top("(function(" + value + ") {"); this.bottom("})(dict);");