mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[REF] qweb: drop support of #{.} string interpolation
We only support the {{.}} syntax.
Part of #128
This commit is contained in:
committed by
Géry Debongnie
parent
e14a4fe338
commit
b14d069ee7
+2
-17
@@ -379,7 +379,7 @@ The `t-widget` directive also accepts dynamic values with string interpolation
|
|||||||
|
|
||||||
```xml
|
```xml
|
||||||
<div t-name="ParentWidget">
|
<div t-name="ParentWidget">
|
||||||
<t t-widget="ChildWidget#{id}"/>
|
<t t-widget="ChildWidget{{id}}"/>
|
||||||
</div>
|
</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
|
**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
|
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.
|
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,
|
`id` set to 44 in the rendering context,
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<div t-ref="widget_#{id}"/>
|
<div t-ref="widget_{{id}}"/>
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
this.refs.widget_44;
|
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
|
### Asynchronous rendering
|
||||||
|
|
||||||
Working with asynchronous code always adds a lot of complexity to a system. Whenever
|
Working with asynchronous code always adds a lot of complexity to a system. Whenever
|
||||||
|
|||||||
@@ -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
|
There is another way to format a string attribute: the `t-attf-` directive. With
|
||||||
it, you get string interpolation:
|
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
|
```xml
|
||||||
<div t-attf-foo="a {{value1}} is {{value2}} of {{value3}} ]"/>
|
<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> -->
|
<!-- result if values are set to 1,2 and 3: <div foo="a 0 is 1 of 2 ]"></div> -->
|
||||||
|
|||||||
+4
-8
@@ -777,15 +777,11 @@ export class Context {
|
|||||||
if (matches && matches[0].length === s.length) {
|
if (matches && matches[0].length === s.length) {
|
||||||
return `(${this.formatExpression(s.slice(2, -2))})`;
|
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(
|
||||||
let r = s
|
/\{\{.*?\}\}/g,
|
||||||
.replace(/\{\{.*?\}\}/g, s => formatter(s.slice(2, -2)))
|
s => "${" + this.formatExpression(s.slice(2, -2)) + "}"
|
||||||
.replace(/\#\{.*?\}/g, s => formatter(s.slice(2, -1)));
|
);
|
||||||
return "`" + r + "`";
|
return "`" + r + "`";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -485,7 +485,7 @@ describe("attributes", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("format expression, other format", () => {
|
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 });
|
const result = renderToString(qweb, "test", { value: 5 });
|
||||||
expect(result).toBe(`<div foo="42"></div>`);
|
expect(result).toBe(`<div foo="42"></div>`);
|
||||||
});
|
});
|
||||||
@@ -530,7 +530,7 @@ describe("attributes", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("class and t-attf-class with ternary operation", () => {
|
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 });
|
const result = renderToString(qweb, "test", { value: true });
|
||||||
expect(result).toBe(`<div class="hello world"></div>`);
|
expect(result).toBe(`<div class="hello world"></div>`);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user