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
|
---
language: Pug
contributors:
- ["Michael Warner", "https://github.com/MichaelJGW"]
filename: index.pug
---
## Getting Started with Pug
Pug is a little language that compiles into the HTML. It has cleaner syntax
with additional features like if statements and loops. It can also be used
as a server side templating language for server languages like NodeJS.
### The Language
```pug
//- Single Line Comment
//- Multi Line
Comment
//- ---TAGS---
//- Basic
div
//- <div></div>
h1
//- <h1></h1>
my-customTag
//- <my-customTag></my-customTag>
//- Sibling
div
div
//- <div></div>
<div></div>
//- Child
div
div
//- <div>
<div></div>
</div>
//- Text
h1 Hello there
//- <h1>Hello there</h1>
//- Multi Line Text
div.
Hello
There
//- <div>
Hello
There
</div>
//- ---ATTRIBUTES---
div(class="my-class" id="my-id" my-custom-attrs="data" enabled)
//- <div class="my-class" id="my-id" my-custom-attrs="data" enabled></div>
//- Short Hand
span.my-class
//- <span class="my-class"></span>
.my-class
//- <div class="my-class"></div>
div#my-id
//- <div id="my-id"></div>
div#my-id.my-class
//- <div class="my-class" id="my-id"></div>
//- ---JS---
- const lang = "pug";
//- Multi Line JS
-
const lang = "pug";
const awesome = true;
//- JS Classes
- const myClass = ['class1', 'class2', 'class3']
div(class=myClass)
//- <div class="class1 class2 class3"></div>
//- JS Styles
- const myStyles = {'color':'white', 'background-color':'blue'}
div(styles=myStyles)
//- <div styles="{"color":"white","background-color":"blue"}"></div>
//- JS Attributes
- const myAttributes = {"src": "photo.png", "alt": "My Photo"}
img&attributes(myAttributes)
//- <img src="photo.png" alt="My Photo">
- let disabled = false
input(type="text" disabled=disabled)
//- <input type="text">
- disabled = true
input(type="text" disabled=disabled)
//- <input type="text" disabled>
//- JS Templating
- const name = "Bob";
h1 Hi #{name}
h1= name
//- <h1>Hi Bob</h1>
//- <h1>Bob</h1>
//- ---LOOPS---
//- 'each' and 'for' do the same thing we will use 'each' only.
each value, i in [1,2,3]
p=value
//-
<p>1</p>
<p>2</p>
<p>3</p>
each value, index in [1,2,3]
p=value + '-' + index
//-
<p>1-0</p>
<p>2-1</p>
<p>3-2</p>
each value in []
p=value
//-
each value in []
p=value
else
p No Values are here
//- <p>No Values are here</p>
//- ---CONDITIONALS---
- const number = 5
if number < 5
p number is less then 5
else if number > 5
p number is greater then 5
else
p number is 5
//- <p>number is 5</p>
- const orderStatus = "Pending";
case orderStatus
when "Pending"
p.warn Your order is pending
when "Completed"
p.success Order is Completed.
when -1
p.error Error Occurred
default
p No Order Record Found
//- <p class="warn">Your order is pending</p>
//- --INCLUDE--
//- File path -> "includes/nav.pug"
h1 Company Name
nav
a(href="index.html") Home
a(href="about.html") About Us
//- File path -> "index.pug"
html
body
include includes/nav.pug
//-
<html>
<body>
<h1>Company Name</h1>
<nav><a href="index.html">Home</a><a href="about.html">About Us</a></nav>
</body>
</html>
//- Importing JS and CSS
script
include scripts/index.js
style
include styles/theme.css
//- ---MIXIN---
mixin basic
div Hello
+basic
//- <div>Hello</div>
mixin comment(name, comment)
div
span.comment-name= name
div.comment-text= comment
+comment("Bob", "This is Awesome")
//-
<div>
<span class="comment-name">Bob</span>
<div class="comment-text">This is Awesome</div>
</div>
```
### Additional Resources
- [The Site](https://pugjs.org/)
- [The Docs](https://pugjs.org/api/getting-started.html)
- [Github Repo](https://github.com/pugjs/pug)
|