metalsmith
Advanced tools
Comparing version 0.0.2 to 0.0.4
0.0.4 - February 5, 2013 | ||
------------------------ | ||
* fix corrupted non-utf8 files | ||
0.0.3 - February 5, 2013 | ||
------------------------ | ||
* expose `files` dictionary to `build` callback | ||
0.0.2 - February 5, 2013 | ||
@@ -3,0 +11,0 @@ ------------------------ |
@@ -9,2 +9,3 @@ | ||
var readdir = require('recursive-readdir'); | ||
var utf8 = require('is-utf8'); | ||
var Ware = require('ware'); | ||
@@ -111,3 +112,5 @@ | ||
if (err) return fn(err); | ||
self.write(files, fn); | ||
self.write(files, function(err){ | ||
fn(err, files); | ||
}); | ||
}); | ||
@@ -136,8 +139,13 @@ }); | ||
function read(file, done){ | ||
fs.readFile(file, 'utf8', function(err, str){ | ||
var name = path.relative(dir, file); | ||
fs.readFile(file, function(err, buffer){ | ||
if (err) return done(err); | ||
var name = path.relative(dir, file); | ||
var parsed = front(str); | ||
files[name] = parsed.attributes; | ||
files[name].body = parsed.body.trim(); | ||
if (utf8(buffer)) { | ||
var parsed = front(buffer.toString()); | ||
files[name] = parsed.attributes; | ||
files[name].body = parsed.body.trim(); | ||
} else { | ||
files[name] = {}; | ||
files[name].body = buffer; | ||
} | ||
done(); | ||
@@ -144,0 +152,0 @@ }); |
{ | ||
"name": "metalsmith", | ||
"repository": "git://github.com/segmentio/metalsmith.git", | ||
"version": "0.0.2", | ||
"version": "0.0.4", | ||
"license": "MIT", | ||
@@ -32,3 +32,4 @@ "description": "An extremely simple, pluggable static site generator.", | ||
"fs-extra": "~0.8.1", | ||
"defaults": "~1.0.0" | ||
"defaults": "~1.0.0", | ||
"is-utf8": "~0.2.0" | ||
}, | ||
@@ -40,4 +41,5 @@ "devDependencies": { | ||
"metalsmith-templates": "0.0.2", | ||
"swig": "~1.3.2" | ||
"swig": "~1.3.2", | ||
"assert-dir-equal": "~0.1.0" | ||
} | ||
} | ||
} |
var assert = require('assert'); | ||
var equal = require('assert-dir-equal'); | ||
var exec = require('child_process').exec; | ||
@@ -96,5 +97,6 @@ var fs = require('fs'); | ||
Metalsmith('test/fixtures/basic') | ||
.build(function(err){ | ||
.build(function(err, files){ | ||
if (err) return done(err); | ||
equal('basic/build', 'basic/expected'); | ||
assert.equal('object', typeof files); | ||
equal('test/fixtures/basic/build', 'test/fixtures/basic/expected'); | ||
done(); | ||
@@ -104,2 +106,12 @@ }); | ||
it('should preserve binary files', function(done){ | ||
Metalsmith('test/fixtures/basic-images') | ||
.build(function(err, files){ | ||
if (err) return done(err); | ||
assert.equal('object', typeof files); | ||
equal('test/fixtures/basic-images/build', 'test/fixtures/basic-images/expected'); | ||
done(); | ||
}); | ||
}); | ||
it('should apply a plugin', function(done){ | ||
@@ -116,3 +128,3 @@ Metalsmith('test/fixtures/basic-plugin') | ||
if (err) return done(err); | ||
equal('basic-plugin/build', 'basic-plugin/expected'); | ||
equal('test/fixtures/basic-plugin/build', 'test/fixtures/basic-plugin/expected'); | ||
done(); | ||
@@ -131,3 +143,3 @@ }); | ||
if (err) return done(err); | ||
equal('cli-basic/build', 'cli-basic/expected'); | ||
equal('test/fixtures/cli-basic/build', 'test/fixtures/cli-basic/expected'); | ||
done(); | ||
@@ -140,3 +152,3 @@ }); | ||
if (err) return done(err); | ||
equal('cli-json/destination', 'cli-json/expected'); | ||
equal('test/fixtures/cli-json/destination', 'test/fixtures/cli-json/expected'); | ||
done(); | ||
@@ -149,3 +161,3 @@ }); | ||
if (err) return done(err); | ||
equal('cli-config/destination', 'cli-config/expected'); | ||
equal('test/fixtures/cli-config/destination', 'test/fixtures/cli-config/expected'); | ||
done(); | ||
@@ -158,3 +170,3 @@ }); | ||
if (err) return done(err); | ||
equal('cli-source/destination', 'cli-source/expected'); | ||
equal('test/fixtures/cli-source/destination', 'test/fixtures/cli-source/expected'); | ||
done(); | ||
@@ -167,3 +179,3 @@ }); | ||
if (err) return done(err); | ||
equal('cli-destination/overriden', 'cli-destination/expected'); | ||
equal('test/fixtures/cli-destination/overriden', 'test/fixtures/cli-destination/expected'); | ||
done(); | ||
@@ -176,3 +188,3 @@ }); | ||
if (err) return done(err); | ||
equal('cli-templates/build', 'cli-templates/expected'); | ||
equal('test/fixtures/cli-templates/build', 'test/fixtures/cli-templates/expected'); | ||
done(); | ||
@@ -182,21 +194,2 @@ }); | ||
}); | ||
}); | ||
/** | ||
* Assert a fixture build matches its expected contents. | ||
* | ||
* @param {String} one | ||
* @param {String} two | ||
*/ | ||
function equal(one, two){ | ||
one = 'test/fixtures/' + one; | ||
two = 'test/fixtures/' + two; | ||
readdir(one).forEach(function(rel){ | ||
var file = path.resolve(one, rel); | ||
var other = path.resolve(two, rel); | ||
file = fs.readFileSync(file, 'utf8'); | ||
other = fs.readFileSync(other, 'utf8'); | ||
assert.equal(file, other); | ||
}); | ||
} | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4195092
46
371
7
6
+ Addedis-utf8@~0.2.0
+ Addedis-utf8@0.2.1(transitive)