[REF] qweb: drop support of #{.} string interpolation

We only support the {{.}} syntax.

Part of #128
This commit is contained in:
Aaron Bohy
2019-06-07 08:58:02 +02:00
committed by Géry Debongnie
parent e14a4fe338
commit b14d069ee7
4 changed files with 8 additions and 34 deletions
+2 -17
View File
@@ -379,7 +379,7 @@ The `t-widget` directive also accepts dynamic values with string interpolation
```xml
<div t-name="ParentWidget">
<t t-widget="ChildWidget#{id}"/>
<t t-widget="ChildWidget{{id}}"/>
</div>
```
@@ -390,14 +390,6 @@ class ParentWidget {
}
```
Similarly to `t-attf-`, there is an alternate form of string interpolation:
```xml
<div t-name="ParentWidget">
<t t-widget="ChildWidget{{id}}"/>
</div>
```
**CSS and style:** there is some specific support to allow the parent to declare
additional css classes or style for the sub widget: css declared in `class`, `style`, `t-att-class` or `t-att-style` will be added to the
root widget element.
@@ -754,20 +746,13 @@ The `t-ref` directive also accepts dynamic values with string interpolation
`id` set to 44 in the rendering context,
```xml
<div t-ref="widget_#{id}"/>
<div t-ref="widget_{{id}}"/>
```
```js
this.refs.widget_44;
```
Similarly to `t-attf-` and `t-widget`, there is an alternate form of string
interpolation:
```xml
<div t-ref="widget_{{id}}"/>
```
### Asynchronous rendering
Working with asynchronous code always adds a lot of complexity to a system. Whenever
-7
View File
@@ -357,13 +357,6 @@ If an expression evaluates to a falsy value, it will not be set at all:
There is another way to format a string attribute: the `t-attf-` directive. With
it, you get string interpolation:
```xml
<div t-attf-foo="a #{value1} is #{value2} of #{value3} ]"/>
<!-- result if values are set to 1,2 and 3: <div foo="a 0 is 1 of 2 ]"></div> -->
```
For historical reason, there is an alternate form of string interpolation:
```xml
<div t-attf-foo="a {{value1}} is {{value2}} of {{value3}} ]"/>
<!-- result if values are set to 1,2 and 3: <div foo="a 0 is 1 of 2 ]"></div> -->
+4 -8
View File
@@ -777,15 +777,11 @@ export class Context {
if (matches && matches[0].length === s.length) {
return `(${this.formatExpression(s.slice(2, -2))})`;
}
matches = s.match(/\#\{.*?\}/g);
if (matches && matches[0].length === s.length) {
return `(${this.formatExpression(s.slice(2, -1))})`;
}
let formatter = expr => "${" + this.formatExpression(expr) + "}";
let r = s
.replace(/\{\{.*?\}\}/g, s => formatter(s.slice(2, -2)))
.replace(/\#\{.*?\}/g, s => formatter(s.slice(2, -1)));
let r = s.replace(
/\{\{.*?\}\}/g,
s => "${" + this.formatExpression(s.slice(2, -2)) + "}"
);
return "`" + r + "`";
}
}
+2 -2
View File
@@ -485,7 +485,7 @@ describe("attributes", () => {
});
test("format expression, other format", () => {
qweb.addTemplate("test", `<div t-attf-foo="#{value + 37}"/>`);
qweb.addTemplate("test", `<div t-attf-foo="{{value + 37}}"/>`);
const result = renderToString(qweb, "test", { value: 5 });
expect(result).toBe(`<div foo="42"></div>`);
});
@@ -530,7 +530,7 @@ describe("attributes", () => {
});
test("class and t-attf-class with ternary operation", () => {
qweb.addTemplate("test", `<div class="hello" t-attf-class="#{value ? 'world' : ''}"/>`);
qweb.addTemplate("test", `<div class="hello" t-attf-class="{{value ? 'world' : ''}}"/>`);
const result = renderToString(qweb, "test", { value: true });
expect(result).toBe(`<div class="hello world"></div>`);
});