• Stars
    star
    21,482
  • Rank 1,071 (Top 0.03 %)
  • Language
    JavaScript
  • Created almost 14 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Pug – robust, elegant, feature rich template engine for Node.js

Pug

Full documentation is at pugjs.org

Pug is a high-performance template engine heavily influenced by Haml and implemented with JavaScript for Node.js and browsers. For bug reports, feature requests and questions, open an issue. For discussion join the chat room.

You can test drive Pug online here.

Professionally supported pug is now available

Build Status Rolling Versions NPM version Join Gitter Chat

Packages

Package Name Version
pug NPM version
pug-attrs NPM version
pug-code-gen NPM version
pug-error NPM version
pug-filters NPM version
pug-lexer NPM version
pug-linker NPM version
pug-load NPM version
pug-parser NPM version
pug-runtime NPM version
pug-strip-comments NPM version
pug-walk NPM version

Rename from "Jade"

This project was formerly known as "Jade". However, it was revealed to us that "Jade" is a registered trademark; as a result, a rename was needed. After some discussion among the maintainers, "Pug" was chosen as the new name for this project. As of version 2, "pug" is the official package name.

If your package or app currently uses jade, don't worry: we have secured permissions to continue to occupy that package name, although all new versions will be released under pug.

Before the renaming, work had already begun on “Jade 2.0.0”. Therefore, the rename to Pug coincided with the major version bump. As a result, upgrading from Jade to Pug will be the same process as upgrading any other package with a major version bump.

The syntax of Pug has several differences, deprecations, and removals compared to its predecessor. These differences are documented in #2305.

The website and documentation for Pug are still being updated. But if you are new to Pug, you should get started with the new syntax and install the Pug package from npm.

Installation

Package

To use Pug in your own JavaScript projects:

$ npm install pug

Command Line

After installing the latest version of Node.js, install with:

$ npm install pug-cli -g

and run with

$ pug --help

Syntax

Pug 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.

Pug transforms the above to:

<!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>

API

For full API, see pugjs.org/api/reference.html

var pug = require('pug');

// compile
var fn = pug.compile('string of pug', options);
var html = fn(locals);

// render
var html = pug.render('string of pug', merge(options, locals));

// renderFile
var html = pug.renderFile('filename.pug', merge(options, locals));

Options

  • filename Used in exceptions, and required when using includes
  • compileDebug When false no debug instrumentation is compiled
  • pretty Add pretty-indentation whitespace to output (false by default)

Browser Support

The latest version of pug can be downloaded for the browser in standalone form. It only supports the very latest browsers, though, and is a large file. It is recommended that you pre-compile your pug templates to JavaScript.

To compile a template for use on the client using the command line, do:

$ pug --client --no-debug filename.pug

which will produce filename.js containing the compiled template.

Tutorials

Implementations in other languages

Ports in other languages

Ports to other languages, with very close syntax:

Equivalents in other languages

Templates engines for other languages with a different syntax, but a similar philosophy:

Framework implementations/adapters

Embedded view engines for frameworks:

CMS plugins

Additional Resources

Backers

Support us with a monthly donation and help us continue our activities. [Become a backer]

Sponsors

Become a sponsor and get your logo on our README on GitHub with a link to your site. [Become a sponsor]

License

MIT

More Repositories

1

babel-plugin-transform-react-pug

A plugin for transpiling pug templates to jsx
JavaScript
806
star
2

react-jade

DEPRECATED, see
JavaScript
552
star
3

pug-loader

Pug loader module for Webpack
JavaScript
425
star
4

pug-cli

Pug's CLI interface
JavaScript
255
star
5

pug-lint

An unopinionated and configurable linter and style checker for Pug
JavaScript
227
star
6

babel-walk

Lightweight Babylon AST traversal tools.
TypeScript
44
star
7

then-pug

**EXPERIMENTAL** Async promise based Jade
JavaScript
42
star
8

pug-lexer

The pug lexer (converts a string into an array of tokens)
JavaScript
41
star
9

pug-zh-cn

The Simplified Chinese documentation for Pug.
32
star
10

with

Compile time `with` for strict mode JavaScript
TypeScript
28
star
11

pug-parser

JavaScript
26
star
12

void-elements

Object of "void elements" as defined by the WHATWG HTML Standard.
JavaScript
24
star
13

js-stringify

Stringify an object so it can be safely inlined in JavaScript code
JavaScript
19
star
14

constantinople

Determine whether a JavaScript expression evaluates to a constant (using Acorn)
TypeScript
18
star
15

pug-www

The website for Pug.
CSS
14
star
16

pug-en

The English documentation for Pug.
13
star
17

token-stream

Take an array of token and produce a more useful API to give to a parser
JavaScript
11
star
18

pug-logo

Pug logo and branding materials
10
star
19

pug-walk

10
star
20

doctypes

Shorthands for commonly used doctypes
JavaScript
10
star
21

pug-runtime

The runtime for the Pug compiler
JavaScript
10
star
22

pug-ast-spec

Specification of the Pug AST
10
star
23

is-expression

Validates a string as a JavaScript expression
JavaScript
9
star
24

pug-code-gen

7
star
25

babel-plugin-transform-with

Babel plugin to convert "with" statements into strict mode-compatible JavaScript.
JavaScript
7
star
26

pug-source-gen

Generate Pug source from a Pug AST.
JavaScript
6
star
27

pug-filters

6
star
28

pug-load

The Pug loader is responsible for loading the dependencies of a given Pug file.
JavaScript
5
star
29

pug-plugin-dynamic-include

WIP, UNPUBLISHED. Pug plugin adding support for dynamic inclusion.
JavaScript
4
star
30

pug-attrs

3
star
31

pug-linker

2
star
32

pug-plugin-debug-line

WIP, UNPUBLISHED. Add location information to all tags.
JavaScript
2
star
33

brjade

Inline jade templates when browserifying
JavaScript
2
star
34

pug-fr

French documentation for Pug
1
star
35

pug-lint-config-migration-v2

pug-lint configuration to help migrate projects to Pug 2.0.0.
JavaScript
1
star
36

pug-error

Standard error objects for pug
JavaScript
1
star
37

pug-strip-comments

1
star