[![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).
## 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 (using the _!!! 5_ 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
- :sass must have [sass.js](http://github.com/visionmedia/sass.js) installed
- :less must have [less.js](http://github.com/cloudhead/less.js) installed
- :markdown must have [markdown-js](http://github.com/evilstreak/markdown-js) installed or [node-discount](http://github.com/visionmedia/node-discount)
- :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)
- [Screencasts](http://tjholowaychuk.com/post/1004255394/jade-screencast-template-engine-for-nodejs)
- [html2jade](https://github.com/donpark/html2jade) converter
## 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)
## Installation
via npm:
npm install jade
## Browser Support
To compile jade to a single file compatible for client-side use simply execute:
$ 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.
$ 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
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("");
}
```
## Public API
```javascript
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
## Syntax
### Line Endings
**CRLF** and **CR** are converted to **LF** before parsing.
### Tags
A tag is simply a leading word:
html
for example is converted to `<html></html>`
tags can also have ids:
div#container
which would render `<div id="container"></div>`
how about some classes?
div.user-details
renders `<div class="user-details"></div>`
multiple classes? _and_ an id? sure:
div#foo.bar.baz
renders `<div id="foo" class="bar baz"></div>`
div div div sure is annoying, how about:
#foo
.bar
which is syntactic sugar for what we have already been doing, and outputs:
`<div id="foo"></div><div class="bar"></div>`
### Tag Text
Simply place some content after the tag:
p wahoo!
renders `<p>wahoo!</p>`.
well cool, but how about large bodies of text:
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:
#user #{name} <#{email}>
outputs `<div id="user">tj <tj@vision-media.ca></div>`
Actually want `#{}` for some reason? escape it!
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:
- var html = "<script></script>"
| !{html}
Nested tags that also contain text can optionally use a text block:
label
| Username:
input(name='user[name]')
or immediate tag text:
label Username:
input(name='user[name]')
Tags that accept _only_ text such as `script` and `style` do not
need the leading `|` character, for example:
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:
p.
foo asdf
asdf
asdfasdfaf
asdf
asd.
outputs:
<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:
p .
outputs:
<p>.</p>
It should be noted that text blocks should be doubled escaped. For example if you desire the following output.
</p>foo\bar</p>
use:
p.
foo\\bar
### Comments
Single line comments currently look the same as JavaScript comments,
aka "//" and must be placed on their own line:
// just some paragraphs
p foo
p bar
would output
<!-- just some paragraphs -->
<p>foo</p>
<p>bar</p>
Jade also supports unbuffered comments, by simply adding a hyphen:
//- will not output within markup
p foo
p bar
outputting
<p>foo</p>
<p>bar</p>
### Block Comments
A block comment is legal as well:
body
//
#content
h1 Example
outputting
<body>
<!--
<div id="content">
<h1>Example</h1>
</div>
-->
</body>
Jade supports conditional-comments as well, for example:
head
//if lt IE 8
script(src='/ie-sucks.js')
outputs:
<body>
<!--[if lt IE 8]>
<script src="/ie-sucks.js"></script>
<![endif]-->
</body>
### Nesting
Jade supports nesting to define the tags in a natural way:
ul
li.first
a(href
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
【项目资源】: 包含前端、后端、移动开发、操作系统、人工智能、物联网、信息化管理、数据库、硬件开发、大数据、课程资源、音视频、网站开发等各种技术项目的源码。 包括STM32、ESP8266、PHP、QT、Linux、iOS、C++、Java、python、web、C#、EDA、proteus、RTOS等项目的源码。 【项目质量】: 所有源码都经过严格测试,可以直接运行。 功能在确认正常工作后才上传。 【适用人群】: 适用于希望学习不同技术领域的小白或进阶学习者。 可作为毕设项目、课程设计、大作业、工程实训或初期项目立项。 【附加价值】: 项目具有较高的学习借鉴价值,也可直接拿来修改复刻。 对于有一定基础或热衷于研究的人来说,可以在这些基础代码上进行修改和扩展,实现其他功能。 【沟通交流】: 有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 鼓励下载和使用,并欢迎大家互相学习,共同进步。
资源推荐
资源详情
资源评论
收起资源包目录
基于Node.js+socket.io+express做的简单的web在线聊天例子-WebTalk.zip (1065个子文件)
00 388B
MozillaRootCertificates.as 216KB
AESKey.as 114KB
AESKeyTest.as 52KB
BigInteger.as 31KB
TLSEngine.as 30KB
BlowFishKey.as 19KB
WebSocket.as 15KB
MD5.as 14KB
DESKey.as 14KB
SHA1Test.as 13KB
TLSSocket.as 11KB
SSLSecurityParameters.as 11KB
RSAKey.as 9KB
HMACTest.as 9KB
Base64.as 7KB
RFC2817Socket.as 7KB
Crypto.as 7KB
TLSSecurityParameters.as 7KB
MD5.as 7KB
X509Certificate.as 6KB
CBCModeTest.as 6KB
DER.as 6KB
ECBModeTest.as 6KB
TLSTest.as 6KB
CipherSuites.as 5KB
WebSocketMain.as 5KB
SSLConnectionState.as 4KB
TLSConnectionState.as 4KB
CTRModeTest.as 4KB
MD2.as 4KB
OFBModeTest.as 3KB
BulkCiphers.as 3KB
CFBModeTest.as 3KB
BlowFishKeyTest.as 3KB
RSAKeyTest.as 3KB
MAC.as 3KB
PEM.as 3KB
SHA256.as 3KB
TLSPRF.as 3KB
DESKeyTest.as 3KB
CFB8ModeTest.as 3KB
Random.as 3KB
IVMode.as 2KB
SHA1.as 2KB
ObjectIdentifier.as 2KB
XTeaKey.as 2KB
TLSConfig.as 2KB
TripleDESKey.as 2KB
Type.as 2KB
ECBMode.as 2KB
HMAC.as 2KB
SHA256Test.as 2KB
Sequence.as 2KB
MontgomeryReduction.as 2KB
XTeaKeyTest.as 2KB
ARC4.as 2KB
TLSError.as 2KB
SHA224Test.as 2KB
BarrettReduction.as 2KB
TripleDESKeyTest.as 2KB
CFBMode.as 1KB
TLSPRFTest.as 1KB
CFB8Mode.as 1KB
MD5Test.as 1KB
Hex.as 1KB
MD2Test.as 1KB
X509CertificateCollection.as 1KB
SHABase.as 1KB
ARC4Test.as 1KB
SimpleIVMode.as 1KB
OID.as 1KB
CBCMode.as 1KB
UTCTime.as 1KB
SSLPad.as 1KB
CTRMode.as 1KB
TLSPad.as 1KB
OFBMode.as 1KB
ISecurityParameters.as 1KB
PKCS5.as 1013B
ISymmetricKey.as 956B
BigIntegerTest.as 941B
WebSocketEvent.as 907B
PrintableString.as 893B
MACs.as 884B
Integer.as 850B
ByteString.as 849B
TestCase.as 824B
ClassicReduction.as 761B
TLSEvent.as 700B
TLSSocketEvent.as 686B
SSLEvent.as 654B
KeyExchanges.as 641B
IPad.as 623B
Memory.as 589B
SHA224.as 577B
Set.as 576B
IHMAC.as 573B
NullPad.as 548B
NullReduction.as 537B
共 1065 条
- 1
- 2
- 3
- 4
- 5
- 6
- 11
资源评论
妄北y
- 粉丝: 1w+
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功