Skip to content
This repository has been archived by the owner on Nov 27, 2018. It is now read-only.

Commit

Permalink
pass the path to generator hooks even if the file is not modified
Browse files Browse the repository at this point in the history
  • Loading branch information
laktek committed Nov 10, 2012
1 parent eec1752 commit 0f136f2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
9 changes: 7 additions & 2 deletions lib/generator_hooks/console_output.js
@@ -1,8 +1,13 @@
module.exports = {

run: function(file_path, complete, callback) {
if (file_path) {
run: function(file_path, options, callback) {
var modified = options.modified || false;
var finished = options.finished || false;

if (file_path && modified) {
console.log("Created " + file_path);
} else if (file_path && !modified) {
console.log("Not modified " + file_path);
}

return callback();
Expand Down
12 changes: 6 additions & 6 deletions lib/site_generator.js
Expand Up @@ -159,18 +159,18 @@ module.exports = {

var options = {};

var store_if_modified = function(rendered_obj){
var store_if_modified = function(rendered_obj) {
if(rendered_obj.modified){
self.cacheStore.update(request_basename, file_extension, rendered_obj, options, function(err) {
if (err) {
// we do nothing here.
// maybe log the failure?
}

return callback(request_path);
return callback(request_path, true);
});
} else {
return callback();
return callback(request_path, false);
}
};

Expand All @@ -185,8 +185,8 @@ module.exports = {

var move_to_next_path = function() {
if (paths.length) {
return self.renderPath(paths.pop(), function(rendered_path) {
return self.runGeneratorHooks(rendered_path, false, move_to_next_path);
return self.renderPath(paths.pop(), function(rendered_path, modified) {
return self.runGeneratorHooks(rendered_path, { modified: true }, move_to_next_path);
});
} else {
return callback();
Expand Down Expand Up @@ -244,7 +244,7 @@ module.exports = {
return steps.shift().apply(self, method_args);
} else {
var run_generator_hooks = function(complete) {
return self.runGeneratorHooks(null, true, complete);
return self.runGeneratorHooks(null, { finished: true }, complete);
};

return run_generator_hooks(complete);
Expand Down
2 changes: 1 addition & 1 deletion spec/site_generator.spec.js
Expand Up @@ -208,7 +208,7 @@ describe("generate site", function() {
var spyCallback = jasmine.createSpy();
site_generator.generate(spyCallback);

expect(site_generator.runGeneratorHooks).toHaveBeenCalledWith(null, true, spyCallback);
expect(site_generator.runGeneratorHooks).toHaveBeenCalledWith(null, { finished: true }, spyCallback);
});

it("call the user provided callback", function() {
Expand Down

0 comments on commit 0f136f2

Please sign in to comment.