[![Build Status](https://secure.travis-ci.org/visionmedia/jade.png)](http://travis-ci.org/visionmedia/jade)
# Jade - template engine
Jade is a high performance template engine heavily influenced by [Haml](http://haml-lang.com)
and implemented with JavaScript for [node](http://nodejs.org). For discussion join the [Google Group](http://groups.google.com/group/jadejs).
## Test drive
You can test drive Jade online [here](http://naltatis.github.com/jade-syntax-docs).
## README Contents
- [Features](#a1)
- [Implementations](#a2)
- [Installation](#a3)
- [Browser Support](#a4)
- [Public API](#a5)
- [Syntax](#a6)
- [Line Endings](#a6-1)
- [Tags](#a6-2)
- [Tag Text](#a6-3)
- [Comments](#a6-4)
- [Block Comments](#a6-5)
- [Nesting](#a6-6)
- [Block Expansion](#a6-7)
- [Case](#a6-8)
- [Attributes](#a6-9)
- [HTML](#a6-10)
- [Doctypes](#a6-11)
- [Filters](#a7)
- [Code](#a8)
- [Iteration](#a9)
- [Conditionals](#a10)
- [Template inheritance](#a11)
- [Block append / prepend](#a12)
- [Includes](#a13)
- [Mixins](#a14)
- [Generated Output](#a15)
- [Example Makefile](#a16)
- [jade(1)](#a17)
- [Tutorials](#a18)
- [License](#a19)
<a name="a1"/>
## Features
- client-side support
- great readability
- flexible indentation
- block-expansion
- mixins
- static includes
- attribute interpolation
- code is escaped by default for security
- contextual error reporting at compile & run time
- executable for compiling jade templates via the command line
- html 5 mode (the default doctype)
- optional memory caching
- combine dynamic and static tag classes
- parse tree manipulation via _filters_
- template inheritance
- block append / prepend
- supports [Express JS](http://expressjs.com) out of the box
- transparent iteration over objects, arrays, and even non-enumerables via `each`
- block comments
- no tag prefix
- AST filters
- filters
- :stylus must have [stylus](http://github.com/LearnBoost/stylus) installed
- :less must have [less.js](http://github.com/cloudhead/less.js) installed
- :markdown must have [markdown-js](http://github.com/evilstreak/markdown-js), [node-discount](http://github.com/visionmedia/node-discount), or [marked](http://github.com/chjj/marked) installed
- :cdata
- :coffeescript must have [coffee-script](http://jashkenas.github.com/coffee-script/) installed
- [Emacs Mode](https://github.com/brianc/jade-mode)
- [Vim Syntax](https://github.com/digitaltoad/vim-jade)
- [TextMate Bundle](http://github.com/miksago/jade-tmbundle)
- [Coda/SubEtha syntax Mode](https://github.com/aaronmccall/jade.mode)
- [Screencasts](http://tjholowaychuk.com/post/1004255394/jade-screencast-template-engine-for-nodejs)
- [html2jade](https://github.com/donpark/html2jade) converter
<a name="a2"/>
## Implementations
- [php](http://github.com/everzet/jade.php)
- [scala](http://scalate.fusesource.org/versions/snapshot/documentation/scaml-reference.html)
- [ruby](http://github.com/stonean/slim)
- [python](https://github.com/SyrusAkbary/pyjade)
- [java](https://github.com/neuland/jade4j)
<a name="a3"/>
## Installation
via npm:
```bash
$ npm install jade
```
<a name="a4"/>
## Browser Support
To compile jade to a single file compatible for client-side use simply execute:
```bash
$ make jade.js
```
Alternatively, if uglifyjs is installed via npm (`npm install uglify-js`) you may execute the following which will create both files. However each release builds these for you.
```bash
$ make jade.min.js
```
By default Jade instruments templates with line number statements such as `__.lineno = 3` for debugging purposes. When used in a browser it's useful to minimize this boiler plate, you can do so by passing the option `{ compileDebug: false }`. The following template
```jade
p Hello #{name}
```
Can then be as small as the following generated function:
```js
function anonymous(locals, attrs, escape, rethrow) {
var buf = [];
with (locals || {}) {
var interp;
buf.push('\n<p>Hello ' + escape((interp = name) == null ? '' : interp) + '\n</p>');
}
return buf.join("");
}
```
Through the use of Jade's `./runtime.js` you may utilize these pre-compiled templates on the client-side _without_ Jade itself, all you need is the associated utility functions (in runtime.js), which are then available as `jade.attrs`, `jade.escape` etc. To enable this you should pass `{ client: true }` to `jade.compile()` to tell Jade to reference the helper functions
via `jade.attrs`, `jade.escape` etc.
```js
function anonymous(locals, attrs, escape, rethrow) {
var attrs = jade.attrs, escape = jade.escape, rethrow = jade.rethrow;
var buf = [];
with (locals || {}) {
var interp;
buf.push('\n<p>Hello ' + escape((interp = name) == null ? '' : interp) + '\n</p>');
}
return buf.join("");
}
```
<a name="a5"/>
## Public API
```js
var jade = require('jade');
// Compile a function
var fn = jade.compile('string of jade', options);
fn(locals);
```
### Options
- `self` Use a `self` namespace to hold the locals _(false by default)_
- `locals` Local variable object
- `filename` Used in exceptions, and required when using includes
- `debug` Outputs tokens and function body generated
- `compiler` Compiler to replace jade's default
- `compileDebug` When `false` no debug instrumentation is compiled
- `pretty` Add pretty-indentation whitespace to output _(false by default)_
<a name="a6"/>
## Syntax
<a name="a6-1"/>
### Line Endings
**CRLF** and **CR** are converted to **LF** before parsing.
<a name="a6-2"/>
### Tags
A tag is simply a leading word:
```jade
html
```
for example is converted to `<html></html>`
tags can also have ids:
```jade
div#container
```
which would render `<div id="container"></div>`
how about some classes?
```jade
div.user-details
```
renders `<div class="user-details"></div>`
multiple classes? _and_ an id? sure:
```jade
div#foo.bar.baz
```
renders `<div id="foo" class="bar baz"></div>`
div div div sure is annoying, how about:
```jade
#foo
.bar
```
which is syntactic sugar for what we have already been doing, and outputs:
```html
<div id="foo"></div><div class="bar"></div>
```
<a name="a6-3"/>
### Tag Text
Simply place some content after the tag:
```jade
p wahoo!
```
renders `<p>wahoo!</p>`.
well cool, but how about large bodies of text:
```jade
p
| foo bar baz
| rawr rawr
| super cool
| go jade go
```
renders `<p>foo bar baz rawr.....</p>`
interpolation? yup! both types of text can utilize interpolation,
if we passed `{ name: 'tj', email: 'tj@vision-media.ca' }` to the compiled function we can do the following:
```jade
#user #{name} <#{email}>
```
outputs `<div id="user">tj <tj@vision-media.ca></div>`
Actually want `#{}` for some reason? escape it!
```jade
p \#{something}
```
now we have `<p>#{something}</p>`
We can also utilize the unescaped variant `!{html}`, so the following
will result in a literal script tag:
```jade
- var html = "<script></script>"
| !{html}
```
Nested tags that also contain text can optionally use a text block:
```jade
label
| Username:
input(name='user[name]')
```
or immediate tag text:
```jade
label Username:
input(name='user[name]')
```
Tags that accept _only_ text such as `script` and `style` do not
need the leading `|` character, for example:
```jade
html
head
title Example
script
if (foo) {
bar();
} else {
baz();
}
```
Once again as an alternative, we may use a trailing `.` to indicate a text block, for example:
```jade
p.
foo asdf
asdf
asdfasdfaf
asdf
asd.
```
outputs:
```html
<p>foo asdf
asdf
asdfasdfaf
asdf
asd.
</p>
```
This however differs from a trailing `.` followed by a space, which although is ignored by the Jade parser, tells Jade that this period is a literal:
```jade
p .
```
outputs:
```html
<p>.</p>
```
It should be noted that text
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
webrtc.chatdemo.rar_java webrtc_java webrtc de_web rtc_webrtc_we (1077个子文件)
011df13c9fc3735a5bdecd8d3cb505ee906831 2KB
024451c21531f36a7e1e6f0f4857a6b1d110e7 17KB
05b77bfc2ee12a2b0ecb0a453e927ceaecf63a 241B
05bf529df755fbe7ed51b2408a864ac85e9746 949B
0638d05578307f85ac9ee065c72be6aab58bc5 2KB
077856cc7add93c9bb10f7eedbb33c489b831f 71KB
07b0cb805e3cf9f0edceb912fee623a1f9212d 39KB
07f750f4a8057007444c5e293e0bf72b013f27 173B
08e29dd7e8bb53e4484f00d7ce70bedc86a500 177B
0a2baade148f468588da5bdbbdeed6aeb02f0d 2KB
0a64f758bfa2c40f11d0341e7d0e3b3dbae937 11KB
0aa61ad93b72b780fad31d275ff7632110f8aa 256B
0b0c057f50020d7f33d0ed0835e1581beb01ec 1KB
0c1576310ef5e785cc3019b5a949f45aeee2d6 196B
0c3dda0180068e3435f0461f75141bf8a69806 871B
0c4aad0a2b95df51f8bbb45ae2ffcbd590a325 637B
0cbe89570a188a5af51fedd888a099a541aeb5 340B
0cfb352d4a7c60e4986c4b761ecea9778f047e 82B
0d20351498f75e2f3dec9e588bbcbc91645bb6 224B
0e463fd36dfd8c6d22807e236eeff243ef6198 16KB
10f078b1e5bda9497bf83daa51b601401c0111 408B
10ffb3848326714e44aff2c3c6b1c1f1e4fff2 237B
134c506fda66d50af925d47b6fd9c7a9d62111 4KB
14263a76a75f04614c9205a74f373f74012a41 173B
14bf7e1337955c9d1b3b49c59305b0c4d280ed 1KB
157308c8e5901d07ba0de25f64c24120143858 158B
165bdbddb1e9bdb533db12dff28c4ad8654e1f 6KB
16ba001befe567b9c8387276e9cfb4c4343043 21KB
18a0190eba325c13616e60bb8efe3dfff72355 756B
195f1c8096a949bcb087b81a54b2584d8f12b4 1KB
1a508f3ff4c629231dab750b82584519090df5 366B
1a94abb4bdc1715e895f2252ba599693e3178f 297B
1aaf2ff53d42e4cc0d2bdd9a26cebeb7d95ca2 152B
1cbf9e78f1015f3a71feabb217fb83f1fa6102 4KB
1ec1fa332c16045f2b9ef87ce20454ed9159ab 6KB
210096b4024ce8f453c6cb6831c535840e1e4c 4KB
21d77a81c27237b336e58249d728e8c442154c 195B
22666bc07779746d230d2c67e415d0da2f2ddc 82B
230a74cde25a540a79392b2e256fbc927dc21e 543B
242536721154e350578a59865508302ef1a984 328B
243418c6161d28580b18069fbc1f2073013733 463B
24e0e6bec83d22be915733c4a4a46ecc5dc677 658B
25400f8bf07569a410e621c70813babe74bc7a 18KB
255044df48041cfec7c58811aee00e7c355a06 9KB
25df99172ed9a2d8d229832386cc09d89e822f 297B
28baaec6480b889e7a1be13949f219d8327efd 535B
2c5ca69263fb2aafa45549ce382c6d19fe86c4 5KB
2c7f783bd727c415b8dcb4e85a40ec538625ec 2KB
2cd7c2c55bf8788990caaec378382985914039 151B
2d983a6a092e3ba7cb5cbaf44cacc813684d3b 1KB
2da71a44ca6459657c8b579f15845ce9e3f4a0 1KB
2f4e9e9ecf7fc472e267ad6459b99703e33d88 53B
2ff75f263354d169e9e104e7ef9c44855e414e 53B
304780916f8ad4d1d57679bf92697c5ea5bbd5 370B
3523bc8c13992d943175fef2036356aa48db77 323B
3578fdbf2bc4074439b44f926d98a2d73e6264 2KB
35ba6ca23c34b892bec83977277b0d5043ea0b 239B
367f88f17cd2dd8e955717bc0c5565d427f94d 340B
36cca83cfe51cc0a7b5b0da1174734eb2180b6 4KB
36efa30749dd0473434ddfd2ca74f19abbdcd3 156B
375f848ab0bb358ad41af87a8984f30b4d43d8 544B
37aff62bbbaabb783fa7acd89c9850287f1f6a 394B
38f156463c9406b2351eeacafe48b0286df3cf 48KB
398982b04d8706f44141bed3295f2bfc05c56e 122KB
3b459a606a7f9d337370bce444fe95e4776997 814B
3be2a3cf1f2173c066fc1a3b41b669fd2658dc 125B
3d728a0084b6c766c550967c8d4b0c39c390b6 1KB
3d86aeee5d5c06e3c7ca6ffe835775e6b7bf9a 273B
3dc274f991085766c16d5c8e06153ffdf426bd 3KB
3f6c15fe2e55e2d0ec43f3a4c81667601f96b4 409B
415da3ebfd5c143aa07e6a932ba32bbcab777e 132KB
4165be790a2f2fbde9cb768442ba56dabf9ff6 439B
41c0e95af169bb3fe17935963e4daaeb823c25 340B
428e79de6d6e3c13c5873500aa4a13c9c76d64 2KB
42c5c015c27adc6c4e1288fa50f2ebe26c8d52 148B
42f2ac378e5d9ef534948e7fe0dc93a51e51ae 5KB
440abb8eab919fbd04950e9158b2b23100955d 296B
44f8441549a9220321f96cbd9181fd2429cf89 2KB
46d89fad39566c2dd43cb7b199634cb38c258e 294B
4a7d37d921fe7d773a1d0d18b33d3c536d237b 599B
4aeaa878fb77216d6e4583083ed7953795876e 305B
4b4ffdb45acbb991eedc0782a800535e73b051 191B
4d606b33eabe161274a4803e860bbea5d4cb34 21KB
4d82fa66991f65a244961661e6b25af178c451 2KB
4f4863f886b4524d7428a623a50893eaf7971a 116B
5124e904b146162bde26258300e3ab431817ad 116B
519e220009e9277ca53574d82660666b812fd8 23KB
51f64a72918b53d1f80effc63865b29c1103ec 710B
53bd6f8a6b4ece9b5c4058c57beac42fea2cc9 13KB
5623cca5b940eb315c86f9c2d1f9fa348fcd77 2KB
56cd897aaa87c0defa2bc2291dbf266f6b2619 136B
589daa707a25a1fb3e4112075d382e9a1611ab 38KB
58a4ed49aee4e896f102dadc1a2d144465c2df 605B
58b59cd3eb0e2b045f1b8d1f47dd6a0d8476ec 88B
592b3afd6e8eda23d3f838aa1286d9d4f648d7 2KB
59750f2ebb1f79434eed7e029eb15600af660f 283B
5c1239c99f889bb0b38d95fcd14ee9694d4e38 2KB
5d1ca4a37e03c5368adab54530a2afebda1662 1KB
5d3f4a8e85c84654d07de2ceb1b94d8f8dd25d 795B
5ecb6086c7c8204d6d7b365087908d254540ff 1KB
共 1077 条
- 1
- 2
- 3
- 4
- 5
- 6
- 11
资源评论
钱亚锋
- 粉丝: 86
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功