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

Commit

Permalink
Don't check for the sub-directory availability, let the exceptions to…
Browse files Browse the repository at this point in the history
… trigger
  • Loading branch information
laktek committed Apr 2, 2012
1 parent 0c26956 commit 96c479e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 47 deletions.
16 changes: 10 additions & 6 deletions lib/punch.js
Expand Up @@ -303,12 +303,16 @@ module.exports = {
var output_path = path.split("/");
output_path[0] = config.output_dir;

fs.stat(config.output_dir, function(err, stats){
if(err || !stats.isDirectory()){
// Create the output directory
fs.mkdirSync(output_path.join("/"));
}
});
try {
// Create the output directory
fs.mkdirSync(output_path.join("/"));
}
catch(err){
// we can ignore the errors
// since failing to create a directory means
// it already exists.
// or destination is not writeable.
}
}

files.forEach(function(file){
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -2,7 +2,7 @@
"name": "punch"
, "description": "Generate static sites with mustache templates & json"
, "keywords": ["static", "sites", "mustache", "json", "markdown"]
, "version": "0.0.6-beta"
, "version": "0.0.7-beta"
, "homepage": "https://github.com/laktek/punch"
, "author": "Lakshan Perera <lakshan@web2media.net> (http://laktek.com)"
, "licenses" : ["MIT"]
Expand Down
45 changes: 5 additions & 40 deletions spec/punch.spec.js
Expand Up @@ -95,11 +95,8 @@ describe("traversing templates", function() {
callback(null, ["sub.mustache"]);
}
});

spyOn(fs, 'stat').andCallFake(function(path, callback){
callback(null, {isDirectory: function(){ return true }} );
});

spyOn(fs, 'mkdirSync');
spyOn(punch, "fetchAndRender");

punch.traverseTemplates(config);
Expand All @@ -111,10 +108,6 @@ describe("traversing templates", function() {
it("creates sub-directories in the output path", function(){
var config = {"template_dir": "templates", "output_dir": "public"};

spyOn(fs, 'stat').andCallFake(function(path, callback){
callback(null, {isDirectory: function(){ return false }} );
});

spyOn(fs, 'mkdirSync');
spyOn(punch, "fetchAndRender");

Expand All @@ -132,30 +125,6 @@ describe("traversing templates", function() {

});

it("will skip creating already existing sub-directories in the output path", function(){
var config = {"template_dir": "templates", "output_dir": "public"};

spyOn(fs, 'stat').andCallFake(function(path, callback){
callback(null, {isDirectory: function(){ return true }} );
});

spyOn(fs, 'mkdirSync');
spyOn(punch, "fetchAndRender");

spyOn(fs, 'readdir').andCallFake(function(path, callback){
if(fs.readdir.mostRecentCall.args[0] === "templates"){
callback(null, ["index.mustache", "sub_dir"]);
} else {
callback(null, ["sub.mustache"]);
}
});

punch.traverseTemplates(config);

expect(fs.mkdirSync).not.toHaveBeenCalled();

});

it("calls to render content when a template is found", function(){
var config = {"template_dir": "templates"};

Expand All @@ -167,10 +136,7 @@ describe("traversing templates", function() {
}
});

spyOn(fs, 'stat').andCallFake(function(path, callback){
callback(null, {isDirectory: function(){ return true }} );
});

spyOn(fs, 'mkdirSync');
spyOn(punch, "fetchAndRender");

punch.traverseTemplates(config);
Expand All @@ -190,10 +156,7 @@ describe("traversing templates", function() {
}
});

spyOn(fs, 'stat').andCallFake(function(path, callback){
callback(null, {isDirectory: function(){ return true }} );
});

spyOn(fs, 'mkdirSync');
spyOn(punch, "fetchAndRender");

punch.traverseTemplates(config);
Expand All @@ -214,6 +177,7 @@ describe("traversing templates", function() {
}
});

spyOn(fs, 'mkdirSync');
spyOn(punch, "staticFileHandler");

punch.traverseTemplates(config);
Expand All @@ -222,6 +186,7 @@ describe("traversing templates", function() {

});


});

describe("handling static files", function(){
Expand Down

0 comments on commit 96c479e

Please sign in to comment.