-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Helper.php
547 lines (490 loc) · 13.2 KB
/
Helper.php
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
<?php
namespace Gt\DomTemplate\Test\Helper;
class Helper {
const HTML_NO_TEMPLATES = <<<HTML
<!doctype html>
<meta charset="utf-8" />
<title>This document has no templates</title>
<main>
<section>
<h1>Hello, World!</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. A aliquam animi
deleniti distinctio dolore doloremque, eius et facilis iure maiores nihil
nisi, nostrum optio perferendis perspiciatis, rerum vitae voluptates.
</p>
<p class="bound-data-test">
My name is <span data-bind:text="name">Example</span>
and I am <span data-bind:text="age">0</span> years old.
</p>
</section>
</main>
HTML;
const HTML_NO_TEMPLATES_BIND_ATTR = <<<HTML
<!doctype html>
<meta charset="utf-8" />
<title>This document has no templates but does have bound attributes</title>
<main>
<section>
<h1>Hello, World!</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. A aliquam animi
deleniti distinctio dolore doloremque, eius et facilis iure maiores nihil
nisi, nostrum optio perferendis perspiciatis, rerum vitae voluptates.
</p>
<p class="bound-data-test">
My name is <span id="name" name="person_id" data-bind:text="@id">Example</span>
and I am <span name="age" data-bind:text="@name">0</span> years old.
</p>
</section>
</main>
HTML;
const HTML_TEMPLATES = <<<HTML
<!doctype html>
<meta charset="utf-8" />
<title>This document has some templates</title>
<main>
<section>
<h1>Hello, World!</h1>
<ul>
<li data-template="list-item">This is a list item</li>
</ul>
<p>
Above this paragraph is an unordered list, with the LI elements templated.
</p>
<dl>
<template id="title-definition">
<dt data-bind:text="title">Title</dt>
<dd data-bind:text="definition">Definition</dd>
</template>
</dl>
<p>
Above this paragraph is a definition list, with a template element wrapping the elements to extract.
</p>
<p>
Below is an ordered list with the LI elements templated.
</p>
<ol>
<li data-template="ordered-list-item">This is an item in the second list</li>
</ol>
</section>
</main>
HTML;
const HTML_COMPONENTS = <<<HTML
<!doctype html>
<meta charset="utf-8" />
<title>This document has some components</title>
<main>
<section>
<h1>Hello, World!</h1>
<ul>
<li data-template="list-item">This is a list item</li>
</ul>
<p>
Above this paragraph is an unordered list, with the LI elements templated.
</p>
<title-definition-list></title-definition-list>
<p>
Above this paragraph is a custom component, which has a nested component within it.
</p>
<p>
Below is another custom component.
</p>
<ordered-list></ordered-list>
</section>
</main>
HTML;
const HTML_COMPONENTS_WITH_NAMED_TEMPLATE = <<<HTML
<!doctype html>
<meta charset="utf-8" />
<title>This document has some components</title>
<main>
<section>
<h1>Hello, World!</h1>
<ul>
<li data-template="list-item">This is a list item</li>
</ul>
<p>
Above this paragraph is an unordered list, with the LI elements templated.
</p>
<title-definition-list data-template="tdlist"></title-definition-list>
<p>
Above this paragraph is a custom component, which has a nested component within it.
</p>
<p>
Below is another custom component.
</p>
<ordered-list></ordered-list>
</section>
</main>
HTML;
const HTML_COMPONENT_WITH_CLASS = <<<HTML
<!doctype html>
<meta charset="utf-8" />
<title>This document has some components</title>
<main>
<section>
<h1>Hello, World!</h1>
<title-definition-list class="source-class"></title-definition-list>
<p>
Above this paragraph is a custom component, which has a nested component within it.
</p>
</section>
</main>
HTML;
const HTML_COMPONENT_WITH_CLASS_ON_PARENT = <<<HTML
<li class="existing-class">This is an item in the list</li>
HTML;
const HTML_TEMPLATE_WITH_NESTED_COMPONENT = <<<HTML
<!doctype html>
<meta charset="utf-8" />
<title>This document has a template with a component inside</title>
<main>
<section>
<outer-nested-thing></outer-nested-thing>
</section>
</main>
HTML;
const COMPONENT_OUTER_NESTED_THING = <<<HTML
<ul>
<li data-template="inner-template-item">
<inner-nested-thing></inner-nested-thing>
</li>
</ul>
HTML;
const COMPONENT_INNER_NESTED_THING = <<<HTML
<p>These two paragraphs are contained within a component, within a template!</p>
<p>The iteration number is: <span class="number">X</span></p>
HTML;
const COMPONENT_TITLE_DEFINITION_LIST = <<<HTML
<dl>
<title-definition data-template="title-definition-item"></title-definition>
</dl>
HTML;
const COMPONENT_TITLE_DEFINITION = <<<HTML
<dt data-template-text="@title">Title</dt>
<dd data-template-text="@definition">Definition</dd>
HTML;
const COMPONENT_ORDERED_LIST = <<<HTML
<ol>
<ordered-list-item></ordered-list-item>
</ol>
HTML;
const COMPONENT_ORDERED_LIST_ITEM = <<<HTML
<li>This is an item in the list</li>
HTML;
const HTML_BIND_UNKNOWN_PROPERTY = <<<HTML
<!doctype html>
<meta charset="utf-8" />
<title>This document has no templates</title>
<main>
<section>
<h1>Hello, World!</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. A aliquam animi
deleniti distinctio dolore doloremque, eius et facilis iure maiores nihil
nisi, nostrum optio perferendis perspiciatis, rerum vitae voluptates.
</p>
<p class="bound-data-test">
My name is <span class="test1" data-bind:unknown="name">Example</span>
and I am <span class="test2" data-bind:text="age">0</span> years old.
</p>
</section>
</main>
HTML;
const HTML_TODO_LIST = <<<HTML
<!doctype html>
<meta charset="utf-8" />
<title>Todo list</title>
<main>
<ul id="todo-list">
<li data-template>
<input name="id" data-bind:value="@name" />
<input name="title" data-bind:value="@name" />
<button name="do" value="complete">Complete</button>
</li>
</ul>
</main>
HTML;
const HTML_TODO_LIST_INLINE_NAMED_TEMPLATE = <<<HTML
<!doctype html>
<meta charset="utf-8" />
<title>Todo list</title>
<main>
<ul id="todo-list">
<li data-template="todo-list-item">
<input name="id" data-bind:value="@name" />
<input name="title" data-bind:value="@name" />
<button name="do" value="complete">Complete</button>
</li>
</ul>
</main>
HTML;
const HTML_TODO_LIST_INLINE_NAMED_TEMPLATE_DOUBLE = <<<HTML
<!doctype html>
<meta charset="utf-8" />
<title>Todo list</title>
<main>
<ul id="todo-list">
<li data-template="todo-list-item">
<input name="id" data-bind:value="@name" />
<input name="title" data-bind:value="@name" />
<button name="do" value="complete">Complete</button>
</li>
</ul>
<ul id="todo-list-2">
<li data-template>
<p>Use the other template instead!</p>
</li>
</ul>
</main>
HTML;
const HTML_TODO_LIST_OPTIONAL_ID = <<<HTML
<!doctype html>
<meta charset="utf-8" />
<title>Todo list</title>
<main>
<ul id="todo-list">
<li data-template>
<input name="id" data-bind:value="?id" />
<input name="title" data-bind:value="@name" />
<button name="do" value="complete">Complete</button>
</li>
</ul>
</main>
HTML;
const HTML_TODO_LIST_OPTIONAL_ID_REFERENCED = <<<HTML
<!doctype html>
<meta charset="utf-8" />
<title>Todo list</title>
<main>
<ul id="todo-list">
<li data-template>
<input name="id" data-bind:value="?@name" />
<input name="title" data-bind:value="@name" />
<button name="do" value="complete">Complete</button>
</li>
</ul>
</main>
HTML;
const HTML_TODO_LIST_BIND_CLASS = <<<HTML
<!doctype html>
<meta charset="utf-8" />
<title>Todo list</title>
<main>
<ul id="todo-list">
<li data-template data-bind:class="complete" class="existing-class">
<input name="id" data-bind:value="@name" />
<input name="title" data-bind:value="@name" />
<button name="do" value="complete">Complete</button>
</li>
</ul>
</main>
HTML;
const HTML_TODO_LIST_BIND_CLASS_COLON = <<<HTML
<!doctype html>
<meta charset="utf-8" />
<title>Todo list</title>
<main>
<ul id="todo-list">
<li data-template data-bind:class="dateTimeCompleted:complete" class="existing-class">
<input name="id" data-bind:value="@name" />
<input name="title" data-bind:value="@name" />
<button name="do" value="complete">Complete</button>
</li>
</ul>
</main>
HTML;
const HTML_TODO_LIST_BIND_CLASS_COLON_MULTIPLE = <<<HTML
<!doctype html>
<meta charset="utf-8" />
<title>Todo list</title>
<main>
<ul id="todo-list">
<li data-template data-bind:class="dateTimeCompleted:complete dateTimeDeleted:deleted" class="existing-class">
<input name="id" data-bind:value="@name" />
<input name="title" data-bind:value="@name" />
<button name="do" value="complete">Complete</button>
</li>
</ul>
</main>
HTML;
const HTML_PARENT_HAS_DATA_BIND_ATTR = <<<HTML
<!doctype html>
<meta charset="utf-8" />
<title>This document has a parent element with a data bind attribute</title>
<main>
<div class="parent">
<label>
<span data-bind:text="outside-scope">This node is outside the scope</span>
<ul>
<li data-template="target-template">
<span data-bind:text="target-key">This node is the target</a>
</li>
</ul>
</label>
</div>
</main>
HTML;
const HTML_DOUBLE_BINDABLE_LIST = <<<HTML
<!doctype html>
<meta charset="utf-8" />
<title>This document has a two bindable lists and other bindable areas</title>
<main>
<h1>Test document name: <span data-bind:text="name">name goes here</span></h1>
<div class="area-1">
<p>Here is a list of numbers from 1 to 10:</p>
<ul>
<li data-template>
<span data-bind:text="number">N</span>
</li>
</ul>
</div>
<div class="area-2">
<p>Here is another list, starting from <span data-bind:text="start">X</span></p>
<ul>
<li data-template="dynamic-list-item">
<span data-bind:text="number">N</span>
</li>
</ul>
</div>
</main>
HTML;
const HTML_DOUBLE_NAMELESS_BIND_LIST = <<<HTML
<!doctype html>
<main>
<h1>List of totalitarian superstates:</h1>
<ul id="list-1">
<li data-template data-bind:text="state-name"></li>
</ul>
<h1>Ministries of Oceana:</h1>
<ul id="list-2">
<li data-template data-bind:text="ministry-name"></li>
</ul>
</main>
HTML;
const HTML_DOUBLE_NAMES_BIND_LIST = <<<HTML
<!doctype html>
<main>
<h1>List of totalitarian superstates:</h1>
<ul id="list-1">
<li data-template="state" data-bind:text="state-name"></li>
</ul>
<h1>Ministries of Oceana:</h1>
<ul id="list-2">
<li data-template="ministry" data-bind:text="ministry-name"></li>
</ul>
</main>
HTML;
const HTML_ATTRIBUTE_PLACEHOLDERS_NO_BIND = <<<HTML
<!doctype html>
<meta charset="utf-8" />
<title>This document has some elements with attribute placeholders</title>
<main>
<h1 id="heading-{userType}-{userId}">This is a test!</h1>
<p><a id="userType-{userType}" href="/user/{userId}">View your account</a></p>
<p>You are logged in.</p>
<p>This is your profile picture:</p>
<img src="/img/profile/{userId}.jpg" alt="{username}'s profile picture" />
</main>
<footer>
<a href="/user.php?id={userId}&type={userType}">Another link in the footer</a>
</footer>
HTML;
const HTML_ATTRIBUTE_PLACEHOLDERS = <<<HTML
<!doctype html>
<meta charset="utf-8" />
<title>This document has some elements with attribute placeholders</title>
<main>
<h1 id="heading-{userType}-{userId}" data-bind-parameters>This is a test!</h1>
<p><a id="userType-{userType}" href="/user/{userId}" data-bind-parameters>View your account</a></p>
<p>You are logged in.</p>
<p>This is your profile picture:</p>
<img src="/img/profile/{userId}.jpg" alt="{username}'s profile picture" data-bind-parameters />
</main>
<footer>
<a href="/user.php?id={userId}&type={userType}" data-bind-parameters>Another link in the footer</a>
</footer>
HTML;
const HTML_MUSIC = <<<HTML
<!doctype html>
<meta charset="utf-8" />
<title>Music list</title>
<main>
<h1>Music list!</h1>
<ul class="artist-list">
<li data-template data-bind:data-artist-name>
<h2 data-bind:text>Artist name</h2>
<ul class="album-list">
<li data-template data-bind:data-album-name>
<h3 data-bind:text>Album name</h3>
<ol class="track-list">
<li data-template data-bind:data-track-name>
<span data-bind:text>Track name</span>
</li>
</ol>
</li>
</ul>
</li>
</ul>
</main>
HTML;
const LIST_MUSIC = [
"A Band From Your Childhood" => [
"This Album is Good" => [
"The Best Song You‘ve Ever Heard",
"Another Cracking Tune",
"Top Notch Music Here",
"The Best Is Left ‘Til Last",
],
"Adequate Collection" => [
"Meh",
"‘sok",
"Sounds Like Every Other Song",
],
],
"Bongo and The Bronks" => [
"Salad" => [
"Tomatoes",
"Song About Cucumber",
"Onions Make Me Cry (but I love them)",
],
"Meat" => [
"Steak",
"Is Chicken Really a Meat?",
"Don‘t Look in the Sausage Factory",
"Stop Horsing Around",
],
"SnaxX" => [
"Crispy Potatoes With Salt",
"Pretzel Song",
"Pork Scratchings Are Skin",
"The Peanut Is Not Actually A Nut",
],
],
"Crayons" => [
"Pastel Colours" => [
"Egg Shell",
"Cotton",
"Frost",
"Periwinkle",
],
"Different Shades of Blue" => [
"Cobalt",
"Slate",
"Indigo",
"Teal",
],
]
];
const HTML_SELECT = <<<HTML
<!doctype html>
<meta charset="utf-8" />
<title>Select test</title>
<body>
<select id="sut">
<option data-template data-bind:text="text" data-bind:value="value" data-bind:disabled="?isDisabled">Test</option>
</select>
</body>
HTML;
}