-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
39 lines (33 loc) · 1.18 KB
/
example.js
File metadata and controls
39 lines (33 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { html, htmlEncode, htmlRaw } from "./html.js";
customElements.define('x-page', class ExamplePage extends HTMLElement {
article = {
title: 'My Nifty Article',
text: 'Some <em>witty</em> text.',
};
headerTemplate() {
return html`<header>${this.article.title}</header>`;
}
articleTemplate() {
return html`
<main>
<p>Encodes entities by default:<br>${this.article.text}</p>
<p>Use htmlRaw to avoid this:<br>${htmlRaw(this.article.text)}</p>
<p>Use htmlEncode to force this:<br>${htmlRaw(htmlEncode(this.article.text))}</p>
<p>In other words, htmlEncode turns this:</p>
<pre>${htmlEncode(this.article.text)}</pre>
<p>Into this:</p>
<pre>${htmlEncode(String(htmlEncode(this.article.text)))}</pre>
</main>
`;
}
footerTemplate() {
return html`<footer>Just a footer.</footer>`;
}
connectedCallback() {
this.innerHTML = html`
${this.headerTemplate()}
${this.articleTemplate()}
${this.footerTemplate()}
`;
}
});