Skip to content

Commit

Permalink
ONWARD
Browse files Browse the repository at this point in the history
  • Loading branch information
aconbere committed May 14, 2011
1 parent d9eaf68 commit 23868b6
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 17 deletions.
4 changes: 2 additions & 2 deletions bin/boxer.js
Expand Up @@ -2,8 +2,8 @@

var sys = require('sys')
var options = require('./options').options
var PostProcessor = require("../lib/post_processor").PostProcessor
var PreProcessor = require("../lib/pre_processor").PreProcessor
var PostProcessor = require("../lib/boxer/post_processor").PostProcessor
var PreProcessor = require("../lib/boxer/pre_processor").PreProcessor
var Collector = require('../lib/boxer/collector').Collector

var collector = new Collector( options.input
Expand Down
6 changes: 4 additions & 2 deletions lib/boxer.js
@@ -1,2 +1,4 @@
exports.Collector = require("./boxer/collector").Collector;
exports.Item = require("./boxer/item").Item;
exports.Collector = require("./boxer/collector").Collector
exports.Item = require("./boxer/item").Item
exports.PreProcessor = require("./boxer/pre_processor").PreProcessor
exports.PostProcesor = require("./boxer/pre_processor").PostProcesor
38 changes: 26 additions & 12 deletions lib/boxer/collector.js
Expand Up @@ -3,10 +3,11 @@ var file = require('file')
var Item = require('./item').Item

var Collector = function (inputPath, outputPath, PreProcessor, PostProcessor, options) {

this.inputPath = inputPath
this.outputPath = outputPath
this.preProcessor = new PreProcessor(this)
this.postProcessor = new PostProcessor(this)
this.preProcessor = PreProcessor ? new PreProcessor(this) : {}
this.postProcessor = PostProcessor ? new PostProcessor(this) : {}
this.options = options || {}

this.context = {}
Expand All @@ -15,32 +16,45 @@ var Collector = function (inputPath, outputPath, PreProcessor, PostProcessor, op
if (this.options.verbose) sys.puts("processing: " + inputPath)
}

Collector.prototype.preProcess = function (item) {
this.preProcessor[item.label](item)
}

Collector.prototype.ignoredName = function (name) {
// Files with filenames that start with . or _ are not processed
return (name[0] == "." || name[0] == "_")
}

Collector.prototype.buildItem = function (name, startDir) {
var filePath = file.path.join(startDir, name)
console.log(Item)
var item = new Item(this.inputPath, filePath, { verbose: this.options.verbose })
item.parseFile()
that.preProcess(item)
return item
}

Collector.prototype.filterIgnoredNames = function (names) {
var that = this;
return names.filter(function (name) {
return !that.ignoredName(name)
})
}

Collector.prototype.collectFile = function (startDir, fileNames) {
var that = this;
this.filterIgnoredNames(fileNames).forEach(function (name) {
that.items.push(that.buildItem(name, startDir))
})
}

Collector.prototype.collect = function () {
if (this.options.verbose) sys.puts("running collect")

var that = this

file.walkSync(this.inputPath, function (startDir, dirs, fileNames) {

fileNames.filter(function (name) {
return !that.ignoredName(name)
}).forEach(function (name) {
var item = that.buildItem(name, startDir)
item.parseFile()
this.preProcessor[item.label](item)
that.items.push(item)
})
file.walkSync(this.inputPath, function (startDir, _dirs, fileNames) {
that.collectFile(startDir, fileNames)
})
}

Expand Down
2 changes: 1 addition & 1 deletion lib/boxer/item.js
Expand Up @@ -9,7 +9,7 @@ var LABEL_IDENTIFIER = "_"
var CURRENT_DIRECTORY = "."

var Item = function (inputPath, filePath, options) {
this.inputPath = origin
this.inputPath = inputPath
this.filePath = filePath
this.options = options || {}

Expand Down
68 changes: 68 additions & 0 deletions tests/collector/test_collector.js
@@ -0,0 +1,68 @@
var fake = require("fake")
var file = require("file")
var item = require("../lib/boxer/item")

item.Item = function () { console.log("BLARGH") }
var Collector = require("../lib/boxer/collector").Collector

var collector = new Collector()

exports.test_collector_ignored_name = function (test) {
test.equal(true, collector.ignoredName("."))
test.equal(true, collector.ignoredName("_"))
test.done()
}

exports.test_collector_buildItem = function (test) {
object = {}
var itemFake = fake.create()
itemFake.expect(object, "parseFile")

//var ItemConstructorFake = fake.create()
//ItemConstructorFake.expect(item, "Item")
// .andReturn(itemFake)

var collectorFake = fake.create()
collectorFake.expect(collector, "preProcess")

collector.buildItem("n", "/test")

itemFake.verify()
ItemFake.verify()
collectorFake.verify()

test.done()
}

exports.test_collector_collectFile = function (test) {
var names = ["a", "b", "c"]
var startDir = "/test"
var collectorFake = fake.create()
collectorFake.expect(collector, "filterIgnoredNames")
.andReturn(names)

collectorFake.expect(collector, "buildItem")
.times(3)

collector.collectFile(startDir, names)

collectorFake.verify()
test.done()
}

exports.test_collector_collect = function (test) {
fileFake = fake.create()
fileFake.expect(file, "walkSync")
.times(1)
collector.collect()
fileFake.verify()
test.done()
}
//
//exports.test_collector_transformItem = function (test) {
// test.done()
//}
//
//exports.test_collector_processFiles = function (test) {
// test.done()
//}
Empty file removed tests/test_collector.js
Empty file.

0 comments on commit 23868b6

Please sign in to comment.