This repository has been archived by the owner on Aug 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
demo.html
159 lines (146 loc) · 3.81 KB
/
demo.html
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Demo</title>
<style>
#content div {
border: 1px solid #ddd;
padding: 30px;
margin: 30px;
}
</style>
</head>
<body>
<div id="content">
</div>
<script type="module">
import pug, {html, escape, unescape, map, scat, el, elpug, elhtml} from '/ttl-pug/ttl-pug.js';
const links = [
{ name: 'MARPPLE', url: 'https://marpple.com', is_app: true },
{ name: 'abym', url: 'https://abym.co.kr', is_app: true },
{ name: 'blog', url: 'https://marpple.github.io' },
{ name: 'GitHub', url: 'https://github.com/marpple' }
];
// 1: plain javascript
let demo1 = document.createElement('div');
demo1.setAttribute('id', 'demo1');
demo1.innerHTML = `
<h1>1: Link</h1>
<ul class="list">
${links.map(link =>
`<li><a href="${link.url}">${link.name}</a></li>`
).join('')}
</ul>
`;
document.querySelector('#content').appendChild(demo1);
// 2: with html
let demo2 = document.createElement('div');
demo2.setAttribute('id', 'demo2');
demo2.innerHTML = html`
<h1>2: Link</h1>
<ul class="list">
${links.map(link =>
`<li><a href="${link.url}">${link.name}</a></li>`
)}
</ul>
`;
document.querySelector('#content').appendChild(demo2);
// 3: html, el
var str = html`
<div id="demo3">
<h1>3: Link</h1>
<ul class="list">
${links.map(link =>
`<li><a href="${link.url}">${link.name}</a></li>`
)}
</ul>
</div>
`;
var element = el(str);
document.querySelector('#content').appendChild(element);
// 4: elhtml
document
.querySelector('#content')
.appendChild(elhtml`
<div id="demo4">
<h1>4: Link</h1>
<ul class="list">
${links.map(link =>
`<li><a href="${link.url}">${link.name}</a></li>`
)}
</ul>
</div>
`);
// 5: pug, el
var str = pug`
#demo5
h1 5: Link
ul.list
${links.map(link => pug`
li
a[href="${link.url}"] ${link.name}`
)}
`;
var element = el(str);
document.querySelector('#content').appendChild(element);
// 6: elpug
document
.querySelector('#content')
.appendChild(elpug`
#demo6
h1 6: Link
ul.list
${links
.filter(link => link.is_app)
.map(link => pug`
li
a[href="${link.url}"] ${link.name}`
)}
`);
// 7: elpug, map(support array, array-like, Object, Set, Map, typeof list[Symbol.iterator] == 'function')
var links2 = new Set(links);
document
.querySelector('#content')
.appendChild(elpug`
#demo7
h1 7: Link
ul.list
${map(links2, link => pug`
li
a[href="${link.url}"] ${link.name}`
)}
`);
// 8: plain, el, scat(support array, array-like, Object, Set, Map, typeof list[Symbol.iterator] == 'function')
var links3 = {
MARPPLE: { name: 'MARPPLE', url: 'https://marpple.com', is_app: true },
abym: { name: 'abym', url: 'https://abym.co.kr', is_app: true },
blog: { name: 'blog', url: 'https://marpple.github.io' },
GitHub: { name: 'GitHub', url: 'https://github.com/marpple' }
};
document
.querySelector('#content')
.appendChild(el(`
<div id="demo8">
<h1>8: Link</h1>
<ul class="list">
${scat(links3, link =>
`<li><a href="${link.url}">${link.name}</a></li>`
)}
</ul>
</div>
`));
// 9: escape, unescape
var str = '<ul class="test"><li>hi</li></ul>';
document
.querySelector('#content')
.appendChild(el(`
<div id="demo9">
<h1>9: escape, unescape</h1>
<div>${escape(str)}</div>
<div>${unescape(escape(str))}</div>
</div>
`));
</script>
</body>
</html>