Permalink
Browse files

Fix incorrect Windows directory path extraction.

  • Loading branch information...
1 parent be56beb commit 8ec364ea8b27eec2c2b1b4e1542aa930f6cfa33e @cliffano committed Aug 15, 2012
Showing with 34 additions and 6 deletions.
  1. +1 −1 CHANGELOG.md
  2. +1 −1 lib/engine.js
  3. +32 −4 test/engine.js
View
@@ -1,5 +1,5 @@
### 0.0.6 (SNAPSHOT)
-* Fix incorrect URL path on Windows
+* Fix incorrect URL path and directory path on Windows
### 0.0.5
* Fix params.js reloading in watch mode
View
@@ -112,7 +112,7 @@ Engine.prototype.merge = function (dir, templates, params, cb) {
}
function _writePage(cb) {
- f.mkdirs(p.join(dir, page).replace(/\/[^\/]+$/, ''), '0755', function (err) {
+ f.mkdirs(p.join(dir, page).replace(/(\/[^\/]+$|\\[^\\]+$)/, ''), '0755', function (err) {
if (!err) {
fs.writeFile(p.join(dir, page), pageContent, 'utf8', function (err) {
if (!err) {
View
@@ -107,7 +107,7 @@ describe('engine', function () {
},
file: {
mkdirs: function (dir, mode, cb) {
- checks.file_walkSync_dir = dir;
+ checks.file_mkdirs_dir = dir;
mode.should.equal('0755');
cb(mocks.file_mkdirs_err);
}
@@ -198,13 +198,14 @@ describe('engine', function () {
foo: 'bar'
};
engine = new (create(checks, mocks))('html');
- engine.merge('someoutputdir', templates, params, function (err, result) {
+ engine.merge('some/output/dir', templates, params, function (err, result) {
checks.engine_compile_err = err;
checks.engine_compile_result = result;
done();
});
checks.console_log_messages.length.should.equal(1);
- checks.console_log_messages[0].should.equal('+ creating someoutputdir/page.html');
+ checks.console_log_messages[0].should.equal('+ creating some/output/dir/page.html');
+ checks.file_mkdirs_dir.should.equal('some/output/dir');
});
it('should pass error to callback when directory cannot be created', function (done) {
@@ -223,12 +224,39 @@ describe('engine', function () {
foo: 'bar'
};
engine = new (create(checks, mocks))('html');
- engine.merge('someoutputdir', templates, params, function (err, result) {
+ engine.merge('some/output/dir', templates, params, function (err, result) {
checks.engine_compile_err = err;
checks.engine_compile_result = result;
done();
});
checks.engine_compile_err.message.should.equal('someerror');
+ checks.file_mkdirs_dir.should.equal('some/output/dir');
+ });
+
+ it('should create dir with *nix and Windows paths', function () {
+ mocks.file_mkdirs_err = new Error('someerror');
+ var templates = {
+ partials: {
+ },
+ pages: {
+ 'page.html': jazz.compile('Some content with param {foo}')
+ },
+ layouts: {
+ 'default.html': jazz.compile('{content}')
+ }
+ },
+ params = {
+ foo: 'bar'
+ };
+ engine = new (create(checks, mocks))('html');
+
+ engine.merge('some/output/dir', templates, params, function (err, result) {
+ });
+ checks.file_mkdirs_dir.should.equal('some/output/dir');
+
+ engine.merge('some\\output\\dir', templates, params, function (err, result) {
+ });
+ checks.file_mkdirs_dir.should.equal('some\\output');
});
});
});

0 comments on commit 8ec364e

Please sign in to comment.