@mynameiszhangxu
2015-04-13T06:18:56.000000Z
字数 2176
阅读 1876
笔记
section#wrapper
编译后是
<section id="wrapper"></section>
section#wrapper.class-name
编译后是
<section id="wrapper" class="class-name"></section>
pspan
编译后是
<p><span></span></p>
h1 Very important heading
编译后是
<h1>Very important heading</h1>
p| Text can be over| many lines| after a pipe symbol
编译后是
<p>Text can be over many lines after a pipe symbol</p>
- var foo = bar;
变量设置完成可在以后使用
p I wanna learn to use variables.Foo is #{foo}!
- users = ['Sally', 'Joseph', 'Michael', 'Sanjay']- each user in usersp=user
编译后是:
<p>Sally</p><p>Joseph</p><p>Michael</p><p>Sanjay</p>
如果使用for关键字,可以这么写:
for user in usersp= user
也可以使用对象进行迭代
- obj = {first_name:'George', surname:'Ornbo'}- each val, key in objli #{key}: #{val}
编译后是
<li>first_name:George</li><li>Surname:Ornbo</li>
if和else关键字前的 ‘-’ 是可选的
- awake =false- if (awake)p You are awake!Make coffee- elsep You are sleeping
若想内联 JavaScript 代码,声明一个脚块后,在其中加入 JavaScript 代码即可
scriptalert('You can execute inline JavaScript througt jade');
用途:大多数网站都会有在站点的每个页面都重复出现的部分,比如页眉,页脚和边栏
jade 通过include关键字后跟想要包含的模板来支持包含功能
htmlbadyinclude includes/header
上述代码从 views/includes/header.jade 文件中包含代码
app.get('/about', function(req, res){res.send('HELLO from the about route!');});
app.post('/',function(req,res){res.send(req.body);});
h1= titlep Welcome to #{title}h2 Form exampleform(method='post', action='/')fieldsetlegend Add a userplabel First nameinput(name = 'user[first_name]')plabel Last nameinput(name = 'user[last_name]')pinput(type = 'submit', value='Save')
申明一个捕获参数的路由
app.get('/users/:id', function(req, res){res.send('show content for user id' + req.params.id);});
var fs = require('fs'),data = "Some data I want to write to a file";fs.writeFile('file.txt', data, function(err){if(!err){console.log('Worte data to file.txt');}else{throw err;}});
var fs = require('fs');fs.readFile('file.txt', "utf8", function (err,data){if(!err){console.log(data);}else{throw err;}});
如果设置了环境变量 SOMETHING,只需要一行代码就可以将其读出
var = something = process.env.SOMETHING