[IMP] app, compiler: introduce t-out

t-out automatically escaped content when it is a string not marked
with the `markup` function

t-out renders the raw content if it is a Block, or if it has been marked
with the `markup` funtion.

t-esc has been kept since it is safe and is optimized to render text nodes.

all t-raw calls are in fact the same as t-out.
This commit is contained in:
Lucas Perais (lpe)
2021-11-15 15:01:56 +01:00
committed by Aaron Bohy
parent 1761af9c24
commit b902edc1be
62 changed files with 1780 additions and 1306 deletions
+11 -7
View File
@@ -1,6 +1,7 @@
import { App, Component, mount, status, useState } from "../../src";
import { xml } from "../../src/tags";
import { makeTestFixture, nextTick, snapshotEverything } from "../helpers";
import { markup } from "../../src/utils";
let fixture: HTMLElement;
@@ -965,31 +966,34 @@ describe("support svg components", () => {
});
});
describe("t-raw in components", () => {
describe("t-out in components", () => {
test("update properly on state changes", async () => {
class Test extends Component {
static template = xml`<div><t t-raw="state.value"/></div>`;
state = useState({ value: "<b>content</b>" });
static template = xml`<div><t t-out="state.value"/></div>`;
state = useState({ value: markup("<b>content</b>") });
}
const component = await mount(Test, fixture);
markup("prout");
expect(fixture.innerHTML).toBe("<div><b>content</b></div>");
component.state.value = "<span>other content</span>";
component.state.value = markup("<span>other content</span>");
await nextTick();
expect(fixture.innerHTML).toBe("<div><span>other content</span></div>");
});
test("can render list of t-raw ", async () => {
test("can render list of t-out ", async () => {
class Test extends Component {
static template = xml`
<div>
<t t-foreach="state.items" t-as="item" t-key="item">
<t t-esc="item"/>
<t t-raw="item"/>
<t t-out="item"/>
</t>
</div>`;
state = useState({ items: ["<b>one</b>", "<b>two</b>", "<b>tree</b>"] });
state = useState({
items: [markup("<b>one</b>"), markup("<b>two</b>"), markup("<b>tree</b>")],
});
}
await mount(Test, fixture);