Last active
December 20, 2015 02:09
-
-
Save battlejj/6054619 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fs = require 'fs' | |
hogan = require 'hogan.js' | |
routes = {} | |
templates = {} | |
templates = | |
playout: hogan.compile(fs.readFileSync('./views/partial_layout.hjs').toString()) | |
pindex: hogan.compile(fs.readFileSync('./views/partial_index.hjs').toString()) | |
ptweet: hogan.compile(fs.readFileSync('./views/partial_tweet.hjs').toString()) | |
routes.partial = (req, res)-> | |
page = | |
title: 'Express' | |
someVar: 'test' | |
anArray: [{name:'item1'}, {name:'item2'}] | |
tweets: [ | |
author: "complexcarb" | |
tweet: "lolwut is going on here" | |
, | |
author: "complexcarb" | |
tweet: "oh boy here we go." | |
] | |
partials = | |
template: templates.pindex | |
tweet: templates.ptweet | |
rendered = templates.playout.render(page, partials) | |
res.send(rendered) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{> tweet }} | |
<h1>{{ title }}</h1> | |
<p>Welcome to {{ title }}</p> | |
{{ someVar }} | |
<ul> | |
{{# anArray }} | |
<li>{{ name }}</li> | |
{{/ anArray }} | |
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>{{ title }}</title> | |
<link rel='stylesheet' href='/stylesheets/style.css' /> | |
</head> | |
<body> | |
Hey | |
{{> template }} | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul> | |
{{# tweets }} | |
<li>@{{ author }} - {{ tweet }}</li> | |
{{/ tweets }} | |
</ul> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment