NodeJS web 实践 - jade

Jade介绍

http://jade-lang.com/

安装Jade

sudo npm install jade --global

Jade Get Started

http://jade-lang.com/tutorial/
http://jade-lang.com/reference/

Jade Template

touch t.jade
h1
  | Maintainer:
  = ' ' + maintainer.name
table
  tr
    td Twitter
    td= maintainer.twitter
  tr
    td Blog
    td= maintainer.blog

touch j.js
var jade = require('jade'),
    fs = require('fs');

var data = {
  maintainer: {
    name: 'Forbes Lindesay',
    twitter: '@ForbesLindesay',
    blog: 'forbeslindesay.co.uk'
  }
}

fs.readFile('./t.jade', 'utf8', function (err, t) {
    if (err) throw err;
    var fn = jade.compile(t);
    var html = fn(data);
    console.log(html);
});

node j.js > o.html


Reference:
http://stackoverflow.com/questions/13362381/how-to-compile-jade-template-file-to-get-string
发布了386 篇原创文章 · 获赞 19 · 访问量 82万+

猜你喜欢

转载自blog.csdn.net/watson243671/article/details/20442549