Permalink
Browse files

Fix bugs

  • Loading branch information...
1 parent df94848 commit bbc480bb6274385361e2ce16e427e6c10ed2a2a4 @pvorb committed Feb 15, 2012
View
24 bake.js
@@ -4,23 +4,18 @@ var props = require('props');
var dive = require('dive');
var ejs = require('ejs');
var async = require('async');
+var clone = require('clone');
+var append = require('append');
// Main function
var bake = function(conf, hooks, cb) {
// File counter
var todo = 0;
- // Ensure `conf` is an object
- if (typeof conf == 'string')
- conf = JSON.parse(conf);
if (typeof conf != 'object')
return cb(new Error('parameter conf must be a valid configuration object'));
- // Ensure `hooks` is an object
- if (typeof hooks != 'object')
- hooks = { };
-
// Set values for `inputDir`, `outputDir` and `tplDir`
var root = conf.root || process.cwd();
var inputDir = conf.directories.input || 'pub';
@@ -69,10 +64,7 @@ var bake = function(conf, hooks, cb) {
// Amend `prop` by properties in `conf.properties` if defined
if (conf.properties)
- for (var key in conf.properties) {
- if (typeof prop[key] == 'undefined')
- prop[key] = conf.properties[key];
- }
+ prop = append(clone(conf.properties), prop);
// Assert that `prop.template` is set
if (typeof prop.template == 'undefined')
@@ -92,16 +84,16 @@ var bake = function(conf, hooks, cb) {
var tasks = {};
// Various property hooks
- for (var key in prop) {(function (key) {
+ for (var key in prop) {(function (prop, key) {
if (hooks[key])
tasks[key] = function (callback) {
- hooks[key](master, prop, callback);
+ return hooks[key](master, prop, callback);
};
else
tasks[key] = function (callback) {
- callback(null, prop.key);
+ return callback(null, prop[key]);
};
- })(key);}
+ })(prop, key);}
// run tasks in parallel
async.parallel(tasks, function (err, prop) {
@@ -110,7 +102,7 @@ var bake = function(conf, hooks, cb) {
// `__propAfter` hook
if (hooks.__propAfter)
- prop = hooks.__propAfter(master, prop, propAfterCB);
+ hooks.__propAfter(master, prop, propAfterCB);
else
propAfterCB(null, prop);

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -21,6 +21,7 @@
"dependencies": {
"append": ">=0.1.1",
"async": ">=0.1.16",
+ "clone": ">=0.0.4",
"dive": ">=0.2.0",
"ejs": ">=0.6.1",
"props": ">=0.2.2"

0 comments on commit bbc480b

Please sign in to comment.