Pug (old name is Jade) is a clean, whitespace sensitive syntax for writing HTML. Here is a simple example:
doctype html
html(lang="en")
head
title= pageTitle
script(type='text/javascript').
if (foo) bar(1 + 5)
body
h1 Pug - node template engine
#container.col
if youAreUsingPug
p You are amazing
else
p Get on it!
p.
Pug is a terse and simple templating language with a
strong focus on performance and powerful features.
Produces following output as HTML
<!DOCTYPE html>
<html lang="en">
<head>
<title>Pug</title>
<script type="text/javascript">
if (foo) bar(1 + 5)
</script>
</head>
<body>
<h1>Pug - node template engine</h1>
<div id="container" class="col">
<p>You are amazing</p>
<p>Pug is a terse and simple templating language with a strong focus on performance and powerful features.</p>
</div>
</body>
</html>
Here are the rules to render Pug to HTML code:
< and >. Attributes are places between round brackets.// or <!-- -->. Comments with //- are not visible in the rendered HTML.#{ } will an offered model generated: #{header} #{user.username}.# (hashtag) without braces will a div element created with the text as ID. Example #myID will be rendered as <div id="myID"></div>.. (point) will a div generated with a class attribute. Example: .myClass will be rendered as <div class="myClass"></div>= (equality sign followed by a space), a variable will be retrieved. Exaple: h1= title!= (not equal to) retrieved a variable without escaping.- (hyphen) allows you to write JavaScript. Example: - console.log("foo");script(src="/js/chat.js")script..extends ../layout.layout.pug happens the inserting by using block content!= partial(template file name/options).include ../includes/footerextend. This allows from a page "html block parts" to send to a layout page for example: extend layout+ (plus) or # (hashtag) char. The plus is used at JavaScript code. The hashtag in HTML and renders the content: `p The name is: #{myName}