-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtest.pug
579 lines (436 loc) · 12 KB
/
test.pug
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
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
//--------------------------------------------------
// Attributes
//--------------------------------------------------
a(href='google.com') Google
a(class='button' href='google.com') Google
a(class='button', href='google.com') Google
- var authenticated = true
body(class=authenticated ? 'authed' : 'anon')
//--------------------------------------------------
// Multiline Attributes
input(
type='checkbox'
name='agreement'
checked
)
input(data-json=`
{
"very-long": "piece of ",
"data": true
}
`)
//--------------------------------------------------
// Quoted Attributes
div(class='div-class', (click)='play()')
div(class='div-class' '(click)'='play()')
//--------------------------------------------------
// Attribute Interpolation
- var btnType = 'info'
- var btnSize = 'lg'
button(type='button' class='btn btn-' + btnType + ' btn-' + btnSize)
button(type='button' class=`btn btn-${btnType} btn-${btnSize}`)
//--------------------------------------------------
// Unescaped Attributes
div(escaped="<code>")
div(unescaped!="<code>")
//--------------------------------------------------
// Boolean Attributes
input(type='checkbox' checked)
input(type='checkbox' checked=true)
input(type='checkbox' checked=false)
input(type='checkbox' checked=true.toString())
input(type='checkbox' checked=true && 'checked')
//--------------------------------------------------
// Style Attributes
a(style={color: 'red', background: 'green'})
//--------------------------------------------------
// Class Attributes
- var classes = ['foo', 'bar', 'baz']
a(class=classes)
a.bang(class=classes class=['bing'])
- var currentUrl = '/about'
a(class={active: currentUrl === '/'} href='/') Home
a(class={active: currentUrl === '/about'} href='/about') About
//--------------------------------------------------
// Class Literal
a.button
.content
//--------------------------------------------------
// ID Literal
a#main-link
#content
//--------------------------------------------------
// &attributes
div#foo(data-bar="foo")&attributes({'data-foo': 'bar'})
- var attributes = {};
- attributes.class = 'baz';
div#foo(data-bar="foo")&attributes(attributes)
//--------------------------------------------------
// Case
//--------------------------------------------------
- var friends = 10
case friends
when 0
p you have no friends
when 1
p you have a friend
default
p you have #{friends} friends
//--------------------------------------------------
// Case Fall Through
- var friends = 0
case friends
when 0
when 1
p you have very few friends
default
p you have #{friends} friends
- var friends = 0
case friends
when 0
- break
when 1
p you have very few friends
default
p you have #{friends} friends
//--------------------------------------------------
// Block Expansion
- var friends = 1
case friends
when 0: p you have no friends
when 1: p you have a friend
default: p you have #{friends} friends
//--------------------------------------------------
// Code
//--------------------------------------------------
- for (var x = 0; x < 3; x++)
li item
-
var list = ["Uno", "Dos", "Tres",
"Cuatro", "Cinco", "Seis"]
each item in list
li= item
//--------------------------------------------------
// Buffered Code
p
= 'This code is <escaped>!'
p= 'This code is' + ' <escaped>!'
//--------------------------------------------------
// Unescaped Buffered Code
p
!= 'This code is <strong>not</strong> escaped!'
p!= 'This code is' + ' <strong>not</strong> escaped!'
//--------------------------------------------------
// Comments
// just some paragraphs
p foo
p bar
//- will not output within markup
p foo
p bar
body
//
As much text as you want
can go here.
// All lines beginning with < are treated as plain text
<!--[if IE 8]>
<html lang="en" class="lt-ie9">
<![endif]-->
<!--[if gt IE 8]><!-->
<html lang="en">
<!--<![endif]-->
//--------------------------------------------------
// Conditionals
//--------------------------------------------------
- var user = { description: 'foo bar baz' }
- var authorised = false
#user
if user.description
h2.green Description
p.description= user.description
else if authorised
h2.blue Description
p.description.
User has no description,
why not add one...
else
h2.red Description
p.description User has no description
unless user.isAnonymous
p You're logged in as #{user.name}
//--------------------------------------------------
// Doctype
//--------------------------------------------------
doctype html
//--------------------------------------------------
// Doctype Shortcuts
<!DOCTYPE html>
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
//--------------------------------------------------
// Custom Doctypes
doctype html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN"
//--------------------------------------------------
// Extends—Template Inheritance
//--------------------------------------------------
//- index.pug
extends layout.pug
block title
title Article Title
block content
h1 My Article
//- layout.pug
doctype html
html
head
block title
title Default title
body
block content
//--------------------------------------------------
// Filters
//--------------------------------------------------
:markdown-it(linkify langPrefix='highlight-')
# Markdown
Markdown document with http://links.com and
```js
var codeBlocks;
```
script
:coffee-script
console.log 'This is coffee script'
//--------------------------------------------------
// Inline Syntax
p
:markdown-it(inline) **BOLD TEXT**
p.
In the midst of a large amount of plain
text, suddenly a wild #[:markdown-it(inline) *Markdown*]
appeared.
//--------------------------------------------------
// Nested Filters
script
:cdata-js:babel(presets=['es2015'])
const myFunc = () => `This is ES2015 in a CD${'ATA'}`;
//--------------------------------------------------
// Custom Filters
p
:my-own-filter(addStart addEnd)
Filter
Body
//--------------------------------------------------
// Includes
//--------------------------------------------------
//- index.pug
doctype html
html
include includes/head.pug
body
h1 My Site
p Welcome to my super lame site.
include includes/foot.pug
//- includes/head.pug
head
title My Site
script(src='/javascripts/jquery.js')
script(src='/javascripts/app.js')
//- includes/foot.pug
footer#footer
p Copyright (c) foobar
//--------------------------------------------------
// Including Plain Text
//--------------------------------------------------
doctype html
html
head
style
include style.css
body
h1 My Site
p Welcome to my super lame site.
script
include script.js
//--------------------------------------------------
// Including Filtered Tex
doctype html
html
head
title An Article
body
include:markdown-it article.md
//--------------------------------------------------
// Template Inheritance
//--------------------------------------------------
html
head
title My Site - #{title}
block scripts
script(src='/jquery.js')
body
block content
block foot
#footer
p some footer content
extends layout.pug
block scripts
script(src='/jquery.js')
script(src='/pets.js')
block content
h1= title
- var pets = ['cat', 'dog']
each petName in pets
include pet.pug
//--------------------------------------------------
// Block append / prepend
extends layout.pug
block append head
script(src='/vendor/three.js')
script(src='/game.js')
extends layout
append head
script(src='/vendor/three.js')
script(src='/game.js')
//--------------------------------------------------
// Interpolation
//--------------------------------------------------
- var title = "On Dogs: Man's Best Friend";
- var author = "enlore";
- var theGreat = "<span>escape!</span>";
h1= title
p Written with love by #{author}
p This will be safe: #{theGreat}
- var msg = "not my inside voice";
p This is #{msg.toUpperCase()}
p No escaping for #{'}'}!
p Escaping works with \#{interpolation}
p Interpolation works with #{'#{interpolation}'} too!
//--------------------------------------------------
// String Interpolation—Unescaped
- var riskyBusiness = "<em>Some of the girls are wearing my mother's clothing.</em>";
.quote
p Joel: !{riskyBusiness}
//--------------------------------------------------
// Tag Interpolation
p.
This is a very long and boring paragraph that spans multiple lines.
Suddenly there is a #[strong strongly worded phrase] that cannot be
#[em ignored].
//--------------------------------------------------
// Whitespace Control
p
| If I don't write the paragraph with tag interpolation, tags like
strong strong
| and
em em
| might produce unexpected results.
p.
If I do, whitespace is #[strong respected] and #[em everybody] is happy.
//--------------------------------------------------
// Iteration
//--------------------------------------------------
ul
each val in [1, 2, 3, 4, 5]
li= val
ul
each val, index in ['zero', 'one', 'two']
li= index + ': ' + val
ul
each val, index in {1:'one',2:'two',3:'three'}
li= index + ': ' + val
ul
each val in values.length ? values : ['There are no values']
li= val
ul
each val in values
li= val
else
li There are no values
ul
while n < 4
li= n++
//--------------------------------------------------
// Mixins
//--------------------------------------------------
//- Declaration
mixin list
ul
li foo
li bar
li baz
//- Use
+list
+list
mixin pet(name)
li.pet= name
ul
+pet('cat')
+pet('dog')
+pet('pig')
//--------------------------------------------------
// Mixin Blocks
mixin article(title)
.article
.article-wrapper
h1= title
if block
block
else
p No content provided
+article('Hello world')
+article('Hello world')
p This is my
p Amazing article
//--------------------------------------------------
// Mixin Attributes
mixin link(href, name)
//- attributes == {class: "btn"}
a(class!=attributes.class href=href)= name
+link('/foo', 'foo')(class="btn")
mixin link(href, name)
a(href=href)&attributes(attributes)= name
+link('/foo', 'foo')(class="btn")
//--------------------------------------------------
// Rest Arguments
mixin list(id, ...items)
ul(id=id)
each item in items
li= item
+list('my-list', 1, 2, 3, 4)
//--------------------------------------------------
// Plain Text
//--------------------------------------------------
| Plain text can include <strong>html</strong>
p
| It must always be on its own line
//--------------------------------------------------
// Inline in a Tag
p Plain text can include <strong>html</strong>
//--------------------------------------------------
// Block in a Tag
script.
if (usingPug)
console.log('you are awesome')
else
console.log('use pug')
//--------------------------------------------------
// Tags
//--------------------------------------------------
ul
li Item A
li Item B
li Item C
img
//--------------------------------------------------
// Block Expansion
a: img
//--------------------------------------------------
// Self Closing Tags
// (when they are not selfclosed automatically)
foo/
foo(bar='baz')/