HTMLをPugで書くメリット
- 閉じタグを書かなくて良い
- header、footerなど共通部分を別ファイルで管理できる
- 変数や条件分岐ができる
- jsが書ける
HTMLをPugで書くデメリット
- HTML => Pugに変換する環境が必要(Gulpを使えば簡単。もしくはGUI変換ならPreprosで出来るらしい)
実際にどのくらい記述差があるのか?
<!DOCTYPE html>
<html lang="en">
<head>
<title>Pug</title>
<script type="text/javascript">
foo = true;
bar = function() {};
if (foo) {
bar(1 + 5);
}
</script>
</head>
<body>
<h1>Pug - node template engine</h1>
<div class="col" id="container">
<p>You are amazing</p>
<p>Pug is a terse and simple templating language with a strong focus on
performance and powerful features.</p>
<ul>
<li>item 0</li>
<li>item 1</li>
<li>item 2</li>
</ul>
</div>
</body>
</html>
doctype html
html(lang="en")
head
title Pug
script(type="text/javascript").
foo = true;
bar = function () {};
if (foo) {
bar(1 + 5);
}
body
h1 Pug - node template engine
#container.col
p You are amazing
p
| Pug is a terse and simple templating language with a strong focus on
| performance and powerful features.
ul
- for (var x = 0; x < 3; x++)
li item #{x}