Skip to content

Commit

Permalink
added example site
Browse files Browse the repository at this point in the history
  • Loading branch information
Caolan McMahon committed May 1, 2010
1 parent 5c9f6e8 commit 27831cd
Show file tree
Hide file tree
Showing 16 changed files with 344 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
example/www
17 changes: 17 additions & 0 deletions example/build.js
@@ -0,0 +1,17 @@
#!/usr/local/bin/node

require.paths.push(__dirname);
require.paths.push(__dirname + '/../lib');
require.paths.push(__dirname + '/../deps');
require.paths.push(__dirname + '/../deps/json-template/lib');
require.paths.push(__dirname + '/../deps/markdown-js/lib');

var buildrunner = require('buildrunner');

buildrunner.run({
data_dir: __dirname + '/data',
view_dir: __dirname + '/views',
template_dir: __dirname + '/templates',
output_dir: __dirname + '/www',
media_dirs: [__dirname + '/media']
});
11 changes: 11 additions & 0 deletions example/data/article_one.md
@@ -0,0 +1,11 @@
date: Sat, 11 Jul 2009 18:43:50 +0100
tags: monkeys, penguins

# Article One

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
16 changes: 16 additions & 0 deletions example/data/article_three.md
@@ -0,0 +1,16 @@
date: Thu, 29 Apr 2010 20:00:00 +0100
tags: monkeys, elephants, penguins

# Article Three

_Italic_, Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit
esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

__Bold text__: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat.
18 changes: 18 additions & 0 deletions example/data/article_two.md
@@ -0,0 +1,18 @@
date: Thu, 29 Apr 2010 18:00:00 +0100
tags: monkeys, ducks

# Article Two

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
52 changes: 52 additions & 0 deletions example/media/style.css
@@ -0,0 +1,52 @@
body {
font-size: 16px;
line-height: 24px;
background: #f0f0f0;
color: #252525;
font-family: "Palatino Linotype", "Book Antiqua", Palatino, FreeSerif, serif;
}
div.container {
width: 550px;
margin: 50px 0 50px 200px;
}
h1, h2, h3, h4, h5, h6 {
margin-top: 40px;
}
.tags {
font-weight: bold;
}
.tags ul {
font-weight: normal;
list-style-type: none;
display: inline;
margin: 0 0.5em;
padding: 0;
}
.tags ul li {
display: inline;
}
#nav {
border-right: solid #ccc 1px;
font-weight: bold;
float: left;
margin: 0 0 0 50px;
padding: 0;
width: 100px;
list-style-type: none;
}
#nav li {
margin: 0 0 1em 0;
}
#nav ul {
list-style-type: none;
padding: 0;
}
#nav ul li {
margin: 0;
font-weight: normal;
}
ul.articles {
margin: 0;
padding: 0;
list-style-type: none;
}
25 changes: 25 additions & 0 deletions example/templates/article.jsont
@@ -0,0 +1,25 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>{article.heading}</title>
<link rel="stylesheet" type="text/css" href="media/style.css" />
</head>
<body>
{partials.navigation}
<div class="container">
{.section article}
<h1>{heading}</h1>
<div class="tags">
Tags:
<ul>
{.repeated section tags}
<li><a href="{@}.html">{@}</a></li>
{.end}
</ul>
</div>
{html_no_heading}
{.end}
</div>
</body>
</html>
18 changes: 18 additions & 0 deletions example/templates/home.jsont
@@ -0,0 +1,18 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Petrify example site</title>
<link rel="stylesheet" type="text/css" href="media/style.css" />
</head>
<body>
{partials.navigation}
<div class="container">
<h1>Petrify example site</h1>
{.repeated section articles}
<h2><a href="{url}">{heading}</a></h2>
{html_no_heading}
{.end}
</div>
</body>
</html>
21 changes: 21 additions & 0 deletions example/templates/nav.jsont
@@ -0,0 +1,21 @@
<ul id="nav">
<li><a href="index.html">Home</a></li>
{.section years}
<li>Year
<ul>
{.repeated section @}
<li><a href="{@}.html">{@}</a></li>
{.end}
</ul>
</li>
{.end}
{.section tags}
<li>Tags
<ul>
{.repeated section @}
<li><a href="{@}.html">{@}</a></li>
{.end}
</ul>
</li>
{.end}
</ul>
19 changes: 19 additions & 0 deletions example/templates/tag.jsont
@@ -0,0 +1,19 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>{name}</title>
<link rel="stylesheet" type="text/css" href="media/style.css" />
</head>
<body>
{partials.navigation}
<div class="container">
<h1>{name}</h1>
<ul class="articles">
{.repeated section articles}
<li><a href="{url}">{heading}</a></li>
{.end}
</ul>
</div>
</body>
</html>
19 changes: 19 additions & 0 deletions example/templates/year.jsont
@@ -0,0 +1,19 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>{name}</title>
<link rel="stylesheet" type="text/css" href="media/style.css" />
</head>
<body>
{partials.navigation}
<div class="container">
<h1>{name}</h1>
<ul class="articles">
{.repeated section articles}
<li><a href="{url}">{heading}</a></li>
{.end}
</ul>
</div>
</body>
</html>
26 changes: 26 additions & 0 deletions example/views/articles.js
@@ -0,0 +1,26 @@
// wait until the navigation partial is complete
exports.requires = ['navigation'];


exports.run = function(view, context){

// parse meta data - this updates the context.data in-place, so
// other views can make use of these changes
context.data = context.data.map(function(x){
x.tags = x.meta.tags.split(', ');
x.date = new Date(x.meta.date);
x.url = x.filename.replace(/\.md$/, '.html');
return x;
});

// for each article emit the article template
context.data.forEach(function(article){
var html = context.templates['article.jsont'].expand({
article: article,
partials: context.partials
});
view.emit(article.url, html);
});

view.done();
};
15 changes: 15 additions & 0 deletions example/views/home.js
@@ -0,0 +1,15 @@
// wait until the navigation and articles views are complete
exports.requires = ['navigation', 'articles'];


exports.run = function(view, context){

// render the home template
var html = context.templates['home.jsont'].expand({
articles: context.data,
partials: context.partials
});

view.emit('index.html', html);

};
34 changes: 34 additions & 0 deletions example/views/navigation.js
@@ -0,0 +1,34 @@
// returns a unique list of values from an array
var unique = function(arr){
return Object.keys(arr.reduce(function(a, x){a[x] = null; return a;}, {}));
};


exports.run = function(view, context){

// partials is an object for storing processed templates
// and data for later use. The partials object is shared by all views.
var partials = context.partials;

// extract a unique list of 4-digit years from the data
partials.years = unique(context.data.map(function(d){
return new Date(d.meta.date).getFullYear();
}));

// extract a unique list of tags from the data
partials.tags = unique(context.data.reduce(function(a, d){
return a.concat(d.meta.tags.split(', '));
}, []));

// render the naviagtion template and store in context.partials for later
// use in other views
partials.navigation = context.templates['nav.jsont'].expand({
years: partials.years.sort().reverse(),
tags: partials.tags
});

// note: this view did not emit anything, but generated some HTML and data
// for including in other templates.
view.done();

};
26 changes: 26 additions & 0 deletions example/views/tags.js
@@ -0,0 +1,26 @@
// wait until the navigation and articles views are complete
exports.requires = ['navigation', 'articles'];


exports.run = function(view, context){

// use the list of unique tags generated in the naviagtion view
context.partials.tags.forEach(function(tag){

// get the articles with the tag
var articles = context.data.filter(function(d){
return d.tags.some(function(t){return t === tag;});
});

// render the tag template
var html = context.templates['tag.jsont'].expand({
name: tag,
articles: articles,
partials: context.partials
});

view.emit(tag + '.html', html);

});

};
26 changes: 26 additions & 0 deletions example/views/years.js
@@ -0,0 +1,26 @@
// wait until the navigation and articles views are complete
exports.requires = ['navigation', 'articles'];


exports.run = function(view, context){

// use the list of unique years generated in the naviagtion view
context.partials.years.forEach(function(year){

// get the articles in that year
var articles = context.data.filter(function(d){
return d.date.getFullYear() == year;
});

// render the year template
var html = context.templates['year.jsont'].expand({
name: year,
articles: articles,
partials: context.partials
});

view.emit(year + '.html', html);

});

};

0 comments on commit 27831cd

Please sign in to comment.