Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

make collections work

  • Loading branch information...
commit 07f39de58786bc47f420deff95a7a529d3818781 1 parent 8367f08
@aconbere authored
View
4 example/_templates/posts.html
@@ -7,10 +7,10 @@
</head>
<body>
- {{# items }}
+ {{# posts }}
<div>
{{{ body }}}
</div>
- {{/ items }}
+ {{/ posts }}
</body>
</html>
View
18 lib/boxer/collector.js
@@ -12,14 +12,26 @@ var Collector = function (projectPath, outputPath, PreProcessor, PostProcessor,
this.options = options || {}
this.items = []
+ this._labels = {}
if (this.options.verbose) { sys.puts("processing: " + projectPath) }
}
Collector.ignoredPrefixes = [".", "_"]
+Collector.prototype.labels = function () {
+ return Object.keys(this._labels)
+}
+
Collector.prototype.context = function () {
- return Utils.merge({ items: this.items}, this.options)
+ var context = { items: this.items}
+
+ var that = this
+ this.labels().forEach(function (label) {
+ context[label] = that.findByLabel(label)
+ })
+
+ return Utils.merge(context, this.options)
}
Collector.prototype.preProcess = function (item) {
@@ -44,7 +56,9 @@ Collector.prototype.collect = function () {
Collector.prototype.collectFile = function (currentDir, fileNames) {
var that = this;
this.filterIgnoredNames(fileNames).forEach(function (fileName) {
- that.items.push(that.buildItem(file.path.join(currentDir, fileName)))
+ var item = that.buildItem(file.path.join(currentDir, fileName))
+ that._labels[item.label()] = true
+ that.items.push(item)
})
}
View
14 lib/boxer/post_processor.js
@@ -1,14 +1,8 @@
var sys = require('sys')
-var markdown = require("markdown")
var merge = require("./utils").merge
var PostProcessor = function (collector) {
this.collector = collector
-
- this.markup = {}
- this.markup.mkd = function (data) {
- return markdown.parse(data)
- }
}
PostProcessor.prototype.process = function (item) {
@@ -18,18 +12,10 @@ PostProcessor.prototype.process = function (item) {
return this.default(item)
}
-PostProcessor.prototype.posts = function (item) {
- if (this.markup[item.extension()]) {
- item.body = this.markup[item.extension()](item.body)
- }
- return item
-}
-
// happens after all files are done being collected
PostProcessor.prototype.default = function (item) {
// if it includes a reference to a template
if (item.headers.template) {
- console.log(item.headers.template)
var template = this.collector.findByRelPath("_templates/" + item.headers.template)[0]
if (template) {
View
11 lib/boxer/pre_processor.js
@@ -1,12 +1,21 @@
var path = require('path')
var sys = require('sys')
var mustache = require("mustache")
+var markdown = require("markdown")
var PreProcessor = function (collector) {
this.collector = collector
+ this.markup = { mkd: function (body) {
+ return markdown.parse(body)
+ }
+ }
}
PreProcessor.prototype.process = function (item) {
+ if (this.markup[item.extension()]) {
+ item.body = this.markup[item.extension()](item.body)
+ }
+
if (item.label() && this[item.label()]) {
return this[item.label()](item)
}
@@ -23,8 +32,6 @@ PreProcessor.prototype.templates = function (item) {
// handing back just the item body, we first parse it as mustache
// and transform the contents.
item.render = function (context) {
- console.log(context)
- console.log("body:", this.body)
// context is any extra details passed through the item
// options etc.
return mustache.to_html(this.body, context)
View
9 tests/test_item.js
@@ -2,12 +2,12 @@ var Item = require("../lib/boxer/item").Item
exports.test_Item_extension = function (test) {
var item = new Item("file/path.mkd", "/test")
- test.equal(".mkd", item.extension())
+ test.equal("mkd", item.extension())
test.done()
}
exports.test_Item_mapping_should_return_extension_if_supported = function (test) {
var item = new Item("file/path.mkd", "/test")
- test.equal(".mkd", item.mapping())
+ test.equal("mkd", item.mapping())
test.done()
}
@@ -38,9 +38,8 @@ exports.test_Item_context = function (test) {
}
exports.test_Item_outputFile = function (test) {
- var item = new Item()
- item.outputPath = "test"
- test.equal("/directory/path/test", item.outputFile("/directory/path"))
+ var item = new Item("file/path.mkd", "/input/path/")
+ test.equal("/directory/path/file/path.mkd", item.outputFile("/directory/path"))
test.done()
}
Please sign in to comment.
Something went wrong with that request. Please try again.