標籤列表javascript
關於文檔的類型 默認是htmlhtml
簡潔文檔類型標記java
You can also use your own literal custom doctype:jquery
默認,每行最開始的(或者在空格以後的(只有空格))表明一個html 標籤 ,能夠嵌入縮進,建立像html 文檔結構的樣式。緩存
ul li Item A li Item B li Item C
<ul> <li>Item A</li> <li>Item B</li> <li>Item C</li> </ul>
jade 也知道那種標籤是能夠本身關閉的。markdown
img
<img/>
jade 提供的支持內聯的嵌入標籤app
a: img
<a><img/></a>
標籤屬性看起來比較像html, 而後它們的值只是規則的javascript.less
a(href='google.com') Google a(class='button', href='google.com') Google
<a href="google.com">Google</a> <a class="button" href="google.com">Google</a>
普通的javascript擴展也能夠使用:ide
- var authenticated = true body(class=authenticated?'authed':'anon')
<body class="authed"></body>
input(type='checkbox', checked) input(type='checkbox', checked=true) input(type='checkbox', checked=false) input(type='checkbox', checked=true.toString())
<input type="checkbox" checked="checked" /> <input type="checkbox" checked="checked" /> <input type="checkbox" /> <input type="checkbox" checked="true" />
input(type='checkbox', checked) input(type='checkbox', checked=true) input(type='checkbox', checked=false) input(type='checkbox', checked=true && 'checked')
<input type="checkbox" checked> <input type="checkbox" checked> <input type="checkbox"> <input type="checkbox" checked="checked">
類屬性只是簡單的字符串、 可是它們能夠表明一系列類名, 它們是從javascript中生成的.ui
- var classes = ['foo', 'bar', 'baz'] a(class=classes) //- the class attribute may also be repeated to merge arrays a.bing(class=classes class=['bing'])
<a class="foo bar baz"></a> <a class="foo bar baz bing"></a>
就是html 標籤中class 屬性的名稱
a.button
<a class="button"></a>
默認的標示是div:
.content
<div class="content"></div>
就是html 標籤中id屬性的名稱
a#main-link
<a id="main-link"></a>
默認是div
#content
<div id="content"></div>
Jade提供了三中方式. 、
使用 |
字符
| Plain text can include <strong>html</strong> p | It must always be on its own line
Plain text can include <strong>html</strong> <p>It must always be on its own line</p>
p Plain text can include <strong>html</strong>
<p>Plain text can include <strong>html</strong></p>
使用. 一個較好的例子就是script 和style. 爲了這樣作,你僅僅使用 .
在一個標籤以後(沒有空格)
script. if (usingJade) console.log('you are awesome') else console.log('use jade')
<script> if (usingJade) console.log('you are awesome') else console.log('use jade') </script>
Jade 能夠進行javascript代碼的編寫.
Unbuffered 代碼以-
開始.
- for (var x = 0; x < 3; x++) li item
<li>item</li> <li>item</li> <li>item</li>
緩存代碼以=
開始
p = 'This code is <escaped>!'
<p>This code is <escaped>!</p>
p= 'This code is' + ' <escaped>!'
<p>This code is <escaped>!</p>
// just some paragraphs p foo p bar
<!-- just some paragraphs --> <p>foo</p> <p>bar</p>
//- will not output within markup p foo p bar
<p>foo</p> <p>bar</p>
body // As much text as you want can go here.
<body> <!-- As much text as you want can go here. --> </body>
進行判斷
- var user = { description: 'foo bar baz' } #user if user.description h2 Description p.description= user.description else h1 Description p.description User has no description
<div id="user"> <h2>Description</h2> <p class="description">foo bar baz</p> </div>
unless user.isAnonymous p You're logged in as #{user.name}
if !user.isAnonymous p You're logged in as #{user.name}
ul each val in [1, 2, 3, 4, 5] li= val
<ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> </ul>
ul each val, index in ['zero', 'one', 'two'] li= index + ': ' + val
<ul> <li>0: zero</li> <li>1: one</li> <li>2: two</li> </ul>
ul each val, index in {1:'one',2:'two',3:'three'} li= index + ': ' + val
<ul> <li>1: one</li> <li>2: two</li> <li>3: three</li> </ul>
- var friends = 10 case friends when 0 p you have no friends when 1 p you have a friend default p you have #{friends} friends
<p>you have 10 friends</p>
- var friends = 0 case friends when 0 when 1 p you have very few default p you have #{friends} friends
<p>you have very few friends</p>
- var friends = 1 case friends when 0: p you have no friends when 1: p you have a friend default: p you have #{friends} friends
<p>you have a friend</p>
:markdown # Markdown I often like including markdown documents. script :coffee console.log 'This is coffee script'
<h1>Markdown</h1> <p>I often like including markdown documents.</p> <script>console.log('This is coffee script')</script>
//- Declaration mixin list ul li foo li bar li baz //- Use +list() +list()
<ul> <li>foo</li> <li>bar</li> <li>baz</li> </ul> <ul> <li>foo</li> <li>bar</li> <li>baz</li> </ul>
mixin pets(pets) ul.pets - each pet in pets li= pet +pets(['cat', 'dog', 'pig'])
<ul class="pets"> <li>cat</li> <li>dog</li> <li>pig</li> </ul>
mixin article(title) .article .article-wrapper h1= title if block block else p No content provided +article('Hello world') +article('Hello world') p This is my p Amazing article
<div class="article"> <div class="article-wrapper"> <h1>Hello world</h1> <p>No content provided</p> </div> </div> <div class="article"> <div class="article-wrapper"> <h1>Hello world</h1> <p>This is my</p> <p>Amazing article</p> </div> </div>
mixin link(href, name) a(class!=attributes.class, href=href)= name +link('/foo', 'foo')(class="btn")
<a class="btn" href="/foo">foo</a>
// index.jade html include includes/head body h1 My Site p Welcome to my super lame site. include includes/foot
// includes/head.jade head title My Site script(src='/javascripts/jquery.js') script(src='/javascripts/app.js')
// includes/foot.jade #footer p Copyright (c) foobar