[ADD] qweb-js: jinja-style interpolation pattern
This commit is contained in:
parent
35f5fb46e7
commit
4fb49a67f3
|
@ -25,4 +25,17 @@
|
|||
<t t-name="format-multiple">
|
||||
<div t-attf-foo="a #{value1} is #{value2} of #{value3} ]"/>
|
||||
</t>
|
||||
|
||||
<t t-name="format2-literal">
|
||||
<div t-attf-foo="bar"/>
|
||||
</t>
|
||||
<t t-name="format2-value">
|
||||
<div t-attf-foo="b{{value}}r"/>
|
||||
</t>
|
||||
<t t-name="format2-expression">
|
||||
<div t-attf-foo="{{value + 37}}"/>
|
||||
</t>
|
||||
<t t-name="format2-multiple">
|
||||
<div t-attf-foo="a {{value1}} is {{value2}} of {{value3}} ]"/>
|
||||
</t>
|
||||
</templates>
|
||||
|
|
|
@ -165,6 +165,23 @@
|
|||
'<div foo="a 0 is 1 of 2 ]"></div>',
|
||||
"each format string should be evaluated independently");
|
||||
});
|
||||
QUnit.test('Fixed name, jinja-formatted', function (assert) {
|
||||
assert.equal(render('format2-literal', {}), '<div foo="bar"></div>',
|
||||
"Literal format");
|
||||
assert.equal(render('format2-value', {value:'a'}), '<div foo="bar"></div>',
|
||||
"Valued format");
|
||||
assert.equal(
|
||||
render('format2-expression', {value: 5}),
|
||||
'<div foo="42"></div>',
|
||||
"Format strings are evaluated expressions");
|
||||
assert.equal(render('format2-multiple', {
|
||||
value1: 0,
|
||||
value2: 1,
|
||||
value3: 2,
|
||||
}),
|
||||
'<div foo="a 0 is 1 of 2 ]"></div>',
|
||||
"each format string should be evaluated independently");
|
||||
});
|
||||
|
||||
QUnit.module("Template calling (including)", {
|
||||
setup: function () {
|
||||
|
|
|
@ -609,12 +609,12 @@ QWeb2.Element = (function() {
|
|||
s && r.push(_this.engine.tools.js_escape(s));
|
||||
}
|
||||
|
||||
var re = /#{(.*?)}/g, start = 0, r = [], m;
|
||||
var re = /(?:#{(.+?)}|{{(.+?)}})/g, start = 0, r = [], m;
|
||||
while (m = re.exec(s)) {
|
||||
// extract literal string between previous and current match
|
||||
append_literal(s.slice(start, re.lastIndex - m[0].length));
|
||||
// extract matched expression
|
||||
r.push('(' + this.format_expression(m[1]) + ')');
|
||||
r.push('(' + this.format_expression(m[2] || m[1]) + ')');
|
||||
// update position of new matching
|
||||
start = re.lastIndex;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue