diff options
| author | Xavier Morel <xmo@openerp.com> | 2014-09-08 16:55:46 +0200 |
|---|---|---|
| committer | Xavier Morel <xmo@openerp.com> | 2014-10-06 19:13:42 +0200 |
| commit | bed6b01c53b520591e6f693dbb5c25cc5b772bbc (patch) | |
| tree | e3cfcc8e32e4cdbc10db47c1e9a73334ed8180de /addons/web/static | |
| parent | 4fb49a67f39c5a2c1d56d8c171ab91f81f5cb307 (diff) | |
[ADD] qweb-js: escf, rawf for parity with Python version
Diffstat (limited to 'addons/web/static')
| -rw-r--r-- | addons/web/static/lib/qweb/qweb-test-output.xml | 23 | ||||
| -rw-r--r-- | addons/web/static/lib/qweb/qweb-test.js.html | 11 | ||||
| -rw-r--r-- | addons/web/static/lib/qweb/qweb2.js | 14 |
3 files changed, 46 insertions, 2 deletions
diff --git a/addons/web/static/lib/qweb/qweb-test-output.xml b/addons/web/static/lib/qweb/qweb-test-output.xml index 1135ad9f251..8725bb00a8f 100644 --- a/addons/web/static/lib/qweb/qweb-test-output.xml +++ b/addons/web/static/lib/qweb/qweb-test-output.xml @@ -9,6 +9,19 @@ <t t-name="esc-toescape"> <t t-esc="ok"/> </t> + <!-- formatted esc --> + <t t-name="escf-literal"> + <t t-escf="ok"/> + </t> + <t t-name="escf-variable"> + <t t-escf="{{ ok }}"/> + </t> + <t t-name="escf-toescape"> + <t t-escf="{{ ok }}"/> + </t> + <t t-name="escf-mix"> + <t t-escf="[{{ ok }}]"/> + </t> <!-- raw, evaluates and returns @t-raw directly (no escaping) --> <t t-name="raw-literal"> @@ -20,4 +33,14 @@ <t t-name="raw-notescaped"> <t t-raw="ok"/> </t> + <!-- formatted raw --> + <t t-name="rawf-literal"> + <t t-rawf="ok"/> + </t> + <t t-name="rawf-variable"> + <t t-rawf="{{ ok }}"/> + </t> + <t t-name="rawf-notescaped"> + <t t-rawf="{{ ok }}"/> + </t> </templates> diff --git a/addons/web/static/lib/qweb/qweb-test.js.html b/addons/web/static/lib/qweb/qweb-test.js.html index b768ed9a5a8..e6095a6259a 100644 --- a/addons/web/static/lib/qweb/qweb-test.js.html +++ b/addons/web/static/lib/qweb/qweb-test.js.html @@ -35,11 +35,22 @@ assert.equal(render('esc-variable', {ok: 'ok'}), "ok", "Render a string variable"); assert.equal(render('esc-toescape', {ok: '<ok>'}), "<ok>", "Render a string with data to escape"); }); + QUnit.test("Formatted escaped output", function (assert) { + assert.equal(render('escf-literal', {}), "ok", "Render a literal string"); + assert.equal(render('escf-variable', {ok: 'ok'}), "ok", "Render a string variable"); + assert.equal(render('escf-toescape', {ok: '<ok>'}), "<ok>", "Render a string with data to escape"); + assert.equal(render('escf-mix', {ok: 'ok'}), "[ok]", "Render a string with additions around the format"); + }); QUnit.test("Basic unescaped output", function (assert) { assert.equal(render('raw-literal', {}), "ok", "Render a literal string"); assert.equal(render('raw-variable', {ok: 'ok'}), "ok", "Render a string variable"); assert.equal(render('raw-notescaped', {ok: '<ok>'}), "<ok>", "Render a string with data not escaped"); }); + QUnit.test("Formatted unescaped output", function (assert) { + assert.equal(render('rawf-literal', {}), "ok", "Render a literal string"); + assert.equal(render('rawf-variable', {ok: 'ok'}), "ok", "Render a string variable"); + assert.equal(render('rawf-notescaped', {ok: '<ok>'}), "<ok>", "Render a string with data not escaped"); + }); QUnit.module("Context-setting tests", { setup: function () { diff --git a/addons/web/static/lib/qweb/qweb2.js b/addons/web/static/lib/qweb/qweb2.js index e4a792e856f..08208fbe3a6 100644 --- a/addons/web/static/lib/qweb/qweb2.js +++ b/addons/web/static/lib/qweb/qweb2.js @@ -28,7 +28,7 @@ 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,call,set,esc,raw,js,debug,log'.split(','), + ACTIONS_PRECEDENCE: 'foreach,if,call,set,escf,esc,rawf,raw,js,debug,log'.split(','), WORD_REPLACEMENT: { 'and': '&&', 'or': '||', @@ -739,11 +739,21 @@ QWeb2.Element = (function() { } }, compile_action_esc : function(value) { - this.top("r.push(context.engine.tools.html_escape(" + (this.format_expression(value)) + "));"); + this.top("r.push(context.engine.tools.html_escape(" + + this.format_expression(value) + + "));"); + }, + compile_action_escf : function (value) { + this.top("r.push(context.engine.tools.html_escape(" + + this.string_interpolation(value) + + '));'); }, compile_action_raw : function(value) { this.top("r.push(" + (this.format_expression(value)) + ");"); }, + compile_action_rawf: function (value) { + this.top('r.push(' + this.string_interpolation(value) + ');'); + }, compile_action_js : function(value) { this.top("(function(" + value + ") {"); this.bottom("})(dict);"); |
