UCDD II class's effort to re-implement the jade template engine
$ npm install
var jaded = require('./lib/jaded')
var tree = {
"type": "Block",
"children": [{
"type": "Tag",
"name": "h1",
"text": "Welcome to Jaded"
}]
}
jaded.render(tree)
// --> <h1>Welcome to Jaded</h1>
lib/jaded.js
: main library that provides therender()
functionlib/[tag-name].js
: a generator function for a HTML tag. For example,lib/h1.js
is a generator function forh1
lib/a.js
is a generator function fora
$ node test.js
In templates/
, there are several jade template files (.jade) for testing.
In this assignment, you don't need to worry about parsing the template file into a workable format. This has been done for you. Each template file has been parsed and converted into a tree structure, which is stored as a JSON file in the same directory.
Take test3
as an example, the Jade template file is templates/test3.jade
div
h1.title UCDD 2 Spring 2015
A tree data structure obtained by parsing test3.jade
is saved as templates/test3.json
{
"type": "Block",
"children": [
{
"type": "Tag",
"name": "div",
"children": [
{
"type": "Tag",
"name": "h1",
"attrs": [
{
"name": "class",
"val": "'title'"
}
],
"text": "UCDD 2 Spring 2015"
}
]
}
]
}