From 27831cd88637361dcb92451680d6d73ee897207c Mon Sep 17 00:00:00 2001 From: Caolan McMahon Date: Sat, 1 May 2010 18:15:41 +0100 Subject: [PATCH] added example site --- .gitignore | 1 + example/build.js | 17 +++++++++++ example/data/article_one.md | 11 +++++++ example/data/article_three.md | 16 ++++++++++ example/data/article_two.md | 18 ++++++++++++ example/media/style.css | 52 +++++++++++++++++++++++++++++++++ example/templates/article.jsont | 25 ++++++++++++++++ example/templates/home.jsont | 18 ++++++++++++ example/templates/nav.jsont | 21 +++++++++++++ example/templates/tag.jsont | 19 ++++++++++++ example/templates/year.jsont | 19 ++++++++++++ example/views/articles.js | 26 +++++++++++++++++ example/views/home.js | 15 ++++++++++ example/views/navigation.js | 34 +++++++++++++++++++++ example/views/tags.js | 26 +++++++++++++++++ example/views/years.js | 26 +++++++++++++++++ 16 files changed, 344 insertions(+) create mode 100644 .gitignore create mode 100755 example/build.js create mode 100644 example/data/article_one.md create mode 100644 example/data/article_three.md create mode 100644 example/data/article_two.md create mode 100644 example/media/style.css create mode 100644 example/templates/article.jsont create mode 100644 example/templates/home.jsont create mode 100644 example/templates/nav.jsont create mode 100644 example/templates/tag.jsont create mode 100644 example/templates/year.jsont create mode 100644 example/views/articles.js create mode 100644 example/views/home.js create mode 100644 example/views/navigation.js create mode 100644 example/views/tags.js create mode 100644 example/views/years.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..37bfe50 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +example/www diff --git a/example/build.js b/example/build.js new file mode 100755 index 0000000..00c4db9 --- /dev/null +++ b/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'] +}); diff --git a/example/data/article_one.md b/example/data/article_one.md new file mode 100644 index 0000000..f826cc2 --- /dev/null +++ b/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. diff --git a/example/data/article_three.md b/example/data/article_three.md new file mode 100644 index 0000000..56003b5 --- /dev/null +++ b/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. diff --git a/example/data/article_two.md b/example/data/article_two.md new file mode 100644 index 0000000..7a19c9b --- /dev/null +++ b/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. diff --git a/example/media/style.css b/example/media/style.css new file mode 100644 index 0000000..789616a --- /dev/null +++ b/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; +} diff --git a/example/templates/article.jsont b/example/templates/article.jsont new file mode 100644 index 0000000..15e90f2 --- /dev/null +++ b/example/templates/article.jsont @@ -0,0 +1,25 @@ + + + + + {article.heading} + + + + {partials.navigation} +
+ {.section article} +

{heading}

+
+ Tags: +
    + {.repeated section tags} +
  • {@}
  • + {.end} +
+
+ {html_no_heading} + {.end} +
+ + diff --git a/example/templates/home.jsont b/example/templates/home.jsont new file mode 100644 index 0000000..a9b06da --- /dev/null +++ b/example/templates/home.jsont @@ -0,0 +1,18 @@ + + + + + Petrify example site + + + + {partials.navigation} +
+

Petrify example site

+ {.repeated section articles} +

{heading}

+ {html_no_heading} + {.end} +
+ + diff --git a/example/templates/nav.jsont b/example/templates/nav.jsont new file mode 100644 index 0000000..421c23b --- /dev/null +++ b/example/templates/nav.jsont @@ -0,0 +1,21 @@ + diff --git a/example/templates/tag.jsont b/example/templates/tag.jsont new file mode 100644 index 0000000..0c165ec --- /dev/null +++ b/example/templates/tag.jsont @@ -0,0 +1,19 @@ + + + + + {name} + + + + {partials.navigation} +
+

{name}

+ +
+ + diff --git a/example/templates/year.jsont b/example/templates/year.jsont new file mode 100644 index 0000000..0c165ec --- /dev/null +++ b/example/templates/year.jsont @@ -0,0 +1,19 @@ + + + + + {name} + + + + {partials.navigation} +
+

{name}

+ +
+ + diff --git a/example/views/articles.js b/example/views/articles.js new file mode 100644 index 0000000..0b63fa9 --- /dev/null +++ b/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(); +}; diff --git a/example/views/home.js b/example/views/home.js new file mode 100644 index 0000000..2ed7b8d --- /dev/null +++ b/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); + +}; diff --git a/example/views/navigation.js b/example/views/navigation.js new file mode 100644 index 0000000..c89d88a --- /dev/null +++ b/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(); + +}; diff --git a/example/views/tags.js b/example/views/tags.js new file mode 100644 index 0000000..ea69ed9 --- /dev/null +++ b/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); + + }); + +}; diff --git a/example/views/years.js b/example/views/years.js new file mode 100644 index 0000000..17859e5 --- /dev/null +++ b/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); + + }); + +};