directory-encoder
Advanced tools
Comparing version 0.3.7 to 0.4.0
@@ -6,2 +6,3 @@ /*global module:true*/ | ||
var fs = require( 'fs' ); | ||
var imgStats = require( 'img-stats' ); | ||
@@ -19,3 +20,19 @@ function DataURIEncoder( path ) { | ||
DataURIEncoder.prototype.stats = function(){ | ||
var data = imgStats.statsSync( this.path ), stats; | ||
if( data.width && data.height ){ | ||
stats = {}; | ||
if( data.width !== "" ){ | ||
stats.width = data.width + "px"; | ||
} | ||
if( data.height !== "" ){ | ||
stats.height = data.height + "px"; | ||
} | ||
} | ||
return stats; | ||
}; | ||
module.exports = DataURIEncoder; | ||
}()); |
@@ -44,11 +44,14 @@ /*global require:true*/ | ||
fs.readdirSync( this.input ).forEach(function( file ) { | ||
var css, datauri, extension = path.extname( file ); | ||
var css, datauri, stats, | ||
filepath = path.join( self.input, file ), | ||
extension = path.extname( file ); | ||
if( extension === ".svg" || extension === ".png" ) { | ||
if( fs.lstatSync( path.join( self.input, file ) ).isFile() ) { | ||
if( fs.lstatSync( filepath ).isFile() ) { | ||
self._checkName(seen, file.replace( extension, '' )); | ||
datauri = self._datauri( path.join(self.input, file) ); | ||
stats = self._stats( filepath ); | ||
datauri = self._datauri( filepath ); | ||
css = self._css( file.replace( extension, '' ), datauri ); | ||
css = self._css( file.replace( extension, '' ), datauri, stats ); | ||
@@ -60,4 +63,9 @@ fs.appendFileSync( self.output, css + "\n\n" ); | ||
}; | ||
DirectoryEncoder.prototype._css = function( name, datauri ) { | ||
var self = this; | ||
DirectoryEncoder.prototype._css = function( name, datauri, stats ) { | ||
var self = this, width, height; | ||
if( stats ){ | ||
width = stats.width; | ||
height = stats.height; | ||
} | ||
this.customselectors = this.customselectors || {}; | ||
@@ -81,2 +89,4 @@ this.prefix = this.prefix || ".icon-"; | ||
datauri: datauri, | ||
width: width, | ||
height: height, | ||
customselectors: this.customselectors[ name ] | ||
@@ -102,2 +112,14 @@ }, css = ""; | ||
DirectoryEncoder.prototype._stats = function( file ){ | ||
var encoder, extension = path.extname( file ); | ||
if( typeof DirectoryEncoder.encoders[extension.replace(".", "")] === "undefined" ){ | ||
throw new Error( "Encoder does not recognize file type: " + file ); | ||
} | ||
encoder = new DirectoryEncoder.encoders[extension.replace(".", "")]( file ); | ||
return encoder.stats(); | ||
}; | ||
DirectoryEncoder.prototype._datauri = function( file ) { | ||
@@ -127,3 +149,3 @@ var encoder, extension = path.extname( file ); | ||
if( templateFile && fs.existsSync( templateFile ) && fs.statSync( templateFile ).isFile() ){ | ||
if( templateFile && fs.existsSync( templateFile ) && fs.lstatSync( templateFile ).isFile() ){ | ||
var source = fs.readFileSync( templateFile ).toString( 'utf-8' ); | ||
@@ -130,0 +152,0 @@ tmpl = Handlebars.compile(source); |
@@ -15,2 +15,6 @@ /*global require:true*/ | ||
PngURIEncoder.prototype.stats = function(){ | ||
return DataURIEncoder.prototype.stats.call( this ); | ||
}; | ||
PngURIEncoder.prototype.encode = function( options ) { | ||
@@ -17,0 +21,0 @@ var datauri = PngURIEncoder.prefix + DataURIEncoder.prototype.encode.call(this); |
@@ -15,2 +15,6 @@ /*global require:true*/ | ||
SvgURIEncoder.prototype.stats = function(){ | ||
return DataURIEncoder.prototype.stats.call( this ); | ||
}; | ||
SvgURIEncoder.prototype.encode = function() { | ||
@@ -17,0 +21,0 @@ var fileData = fs.readFileSync( this.path ); |
{ | ||
"name": "directory-encoder", | ||
"description": "Encode a directory of images to CSS", | ||
"version": "0.3.7", | ||
"version": "0.4.0", | ||
"homepage": "https://github.com/filamentgroup/directory-encoder", | ||
@@ -33,3 +33,4 @@ "author": { | ||
"handlebars": "1.1.2", | ||
"lodash":"2.4.0" | ||
"lodash":"2.4.0", | ||
"img-stats": "0.4.2" | ||
}, | ||
@@ -36,0 +37,0 @@ "devDependencies": { |
@@ -35,3 +35,3 @@ /*global require:true*/ | ||
setUp: function( done ) { | ||
this.encoder = new Constructor( "test/files/bear.png" ); | ||
this.encoder = new Constructor( "test/files/cat.png" ); | ||
done(); | ||
@@ -55,2 +55,18 @@ }, | ||
exports['stats'] = { | ||
setUp: function( done ) { | ||
this.encoder = new Constructor( "test/files/cat.png" ); | ||
this.encoder2 = new Constructor( "test/files/bear.svg" ); | ||
done(); | ||
}, | ||
stats: function( test ) { | ||
test.equal( this.encoder.stats().width, '100px', "Width should match" ); | ||
test.equal( this.encoder.stats().height, '100px', "Height should match on png" ); | ||
test.equal( this.encoder2.stats().width, '100px', "Width should match" ); | ||
test.equal( this.encoder2.stats().height, '62.905px', "Height should match on svg" ); | ||
test.done(); | ||
} | ||
}; | ||
exports['SvgURIEncoder'] = { | ||
@@ -74,3 +90,3 @@ setUp: function( done ) { | ||
setUp: function( done ) { | ||
this.encoder = new PngURIEncoder( "test/files/bear.png" ); | ||
this.encoder = new PngURIEncoder( "test/files/cat.png" ); | ||
this.encode = _.clone( Constructor.prototype.encode ); | ||
@@ -102,3 +118,3 @@ done(); | ||
test.equal( this.encoder.encode({ pngfolder: "foo" }), 'foo/bear.png' ); | ||
test.equal( this.encoder.encode({ pngfolder: "foo" }), 'foo/cat.png' ); | ||
test.done(); | ||
@@ -109,4 +125,3 @@ } | ||
setUp: function( done ) { | ||
this.encoder = new PngURIEncoder( "test/files/bear.png" ); | ||
this.encoder2 = new PngURIEncoder( "test/files/bear copy.png" ); | ||
this.encoder = new PngURIEncoder( "test/files/cat.png" ); | ||
done(); | ||
@@ -123,4 +138,3 @@ }, | ||
test.equal( this.encoder.encode(options), 'bar/bear.png' ); | ||
test.equal( this.encoder2.encode(options), 'bar/bear copy.png' ); | ||
test.equal( this.encoder.encode(options), 'bar/cat.png' ); | ||
test.done(); | ||
@@ -127,0 +141,0 @@ } |
@@ -9,4 +9,4 @@ /*global require:true*/ | ||
var outputFileData = '\n.what-bear copy {\n\tbackground-image: url(\'bear copy.png\');\n\tbackground-repeat: no-repeat;\n}\n\n\n\n.icon-2,\n\n.what-bear {\n\tbackground-image: url(\'data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22100%22%20height%3D%2262.905px%22%3E%3Cpath%20d%3D%22M11.068%2C34.558c-1.585-2.365-2.595-5.098-2.939-8.106c-0.344%2C0.092-0.666%2C0.161-1.033%2C0.161%20c-2.342%2C0-4.248-1.906-4.248-4.248c0-1.47%2C0.758-2.756%2C1.883-3.514l12.147-8.45c2.549-1.562%2C5.534-2.526%2C8.749-2.641l30.149%2C0.092%20L77.819%2C4.34c0-0.115%2C0-0.229%2C0-0.345C77.819%2C1.791%2C79.586%2C0%2C81.791%2C0c2.205%2C0%2C3.996%2C1.791%2C3.996%2C3.995%20c0%2C0.345-0.046%2C0.712-0.138%2C1.034l2.043%2C0.275c2.365%2C0.459%2C4.156%2C2.549%2C4.156%2C5.052c0%2C0.161%2C0%2C0.298-0.022%2C0.436l6.544%2C3.536%20c0.941%2C0.368%2C1.63%2C1.309%2C1.63%2C2.388c0%2C0.367-0.068%2C0.689-0.206%2C1.01l-1.631%2C3.697c-0.804%2C1.309-2.181%2C2.228-3.788%2C2.411%20l-15.041%2C1.791L65.787%2C41.527l7.738%2C13.363l5.098%2C2.365c0.803%2C0.552%2C1.354%2C1.493%2C1.354%2C2.549c0%2C1.699-1.378%2C3.078-3.101%2C3.078%20l-9.805%2C0.022c-2.525%2C0-4.707-1.424-5.809-3.49l-8.382-15.155l-18.92%2C0.023l6.682%2C10.287l4.937%2C2.25%20c0.919%2C0.551%2C1.516%2C1.538%2C1.516%2C2.664c0%2C1.699-1.378%2C3.076-3.077%2C3.076l-9.828%2C0.023c-2.388%2C0-4.5-1.286-5.649-3.215l-9.208-14.627%20l-6.429%2C6.246l-0.528%2C4.087l2.158%2C1.423c0.368%2C0.184%2C0.689%2C0.438%2C0.965%2C0.758c1.056%2C1.332%2C0.872%2C3.284-0.459%2C4.34%20c-0.574%2C0.482-1.286%2C0.713-1.975%2C0.689l-4.317%2C0.023c-1.194-0.139-2.273-0.758-2.962-1.677l-5.029-8.68C0.275%2C51.033%2C0%2C50%2C0%2C48.898%20c0-1.676%2C0.62-3.215%2C1.676-4.387L11.068%2C34.558z%22%2F%3E%3C%2Fsvg%3E\');\n\tbackground-repeat: no-repeat;\n}\n\n\n\n.what-dog {\n\tbackground-image: url(\'dog.png\');\n\tbackground-repeat: no-repeat;\n}\n\n\n'; | ||
var outputFileData2 = '\n.icon-bear copy:before,\n\n.icon-bear copy:after,\n\n.what-bear copy {\n\tbackground-image: url(\'bear copy.png\');\n\tbackground-repeat: no-repeat;\n}\n\n\n\n.icon-2,\n\n.icon-bear:before,\n\n.icon-bear:after,\n\n.what-bear {\n\tbackground-image: url(\'data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22100%22%20height%3D%2262.905px%22%3E%3Cpath%20d%3D%22M11.068%2C34.558c-1.585-2.365-2.595-5.098-2.939-8.106c-0.344%2C0.092-0.666%2C0.161-1.033%2C0.161%20c-2.342%2C0-4.248-1.906-4.248-4.248c0-1.47%2C0.758-2.756%2C1.883-3.514l12.147-8.45c2.549-1.562%2C5.534-2.526%2C8.749-2.641l30.149%2C0.092%20L77.819%2C4.34c0-0.115%2C0-0.229%2C0-0.345C77.819%2C1.791%2C79.586%2C0%2C81.791%2C0c2.205%2C0%2C3.996%2C1.791%2C3.996%2C3.995%20c0%2C0.345-0.046%2C0.712-0.138%2C1.034l2.043%2C0.275c2.365%2C0.459%2C4.156%2C2.549%2C4.156%2C5.052c0%2C0.161%2C0%2C0.298-0.022%2C0.436l6.544%2C3.536%20c0.941%2C0.368%2C1.63%2C1.309%2C1.63%2C2.388c0%2C0.367-0.068%2C0.689-0.206%2C1.01l-1.631%2C3.697c-0.804%2C1.309-2.181%2C2.228-3.788%2C2.411%20l-15.041%2C1.791L65.787%2C41.527l7.738%2C13.363l5.098%2C2.365c0.803%2C0.552%2C1.354%2C1.493%2C1.354%2C2.549c0%2C1.699-1.378%2C3.078-3.101%2C3.078%20l-9.805%2C0.022c-2.525%2C0-4.707-1.424-5.809-3.49l-8.382-15.155l-18.92%2C0.023l6.682%2C10.287l4.937%2C2.25%20c0.919%2C0.551%2C1.516%2C1.538%2C1.516%2C2.664c0%2C1.699-1.378%2C3.076-3.077%2C3.076l-9.828%2C0.023c-2.388%2C0-4.5-1.286-5.649-3.215l-9.208-14.627%20l-6.429%2C6.246l-0.528%2C4.087l2.158%2C1.423c0.368%2C0.184%2C0.689%2C0.438%2C0.965%2C0.758c1.056%2C1.332%2C0.872%2C3.284-0.459%2C4.34%20c-0.574%2C0.482-1.286%2C0.713-1.975%2C0.689l-4.317%2C0.023c-1.194-0.139-2.273-0.758-2.962-1.677l-5.029-8.68C0.275%2C51.033%2C0%2C50%2C0%2C48.898%20c0-1.676%2C0.62-3.215%2C1.676-4.387L11.068%2C34.558z%22%2F%3E%3C%2Fsvg%3E\');\n\tbackground-repeat: no-repeat;\n}\n\n\n\n.icon-dog:before,\n\n.icon-dog:after,\n\n.what-dog {\n\tbackground-image: url(\'dog.png\');\n\tbackground-repeat: no-repeat;\n}\n\n\n'; | ||
var outputFileData = '\n.icon-2,\n\n.what-bear {\n\tbackground-image: url(\'data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22100%22%20height%3D%2262.905px%22%3E%3Cpath%20d%3D%22M11.068%2C34.558c-1.585-2.365-2.595-5.098-2.939-8.106c-0.344%2C0.092-0.666%2C0.161-1.033%2C0.161%20c-2.342%2C0-4.248-1.906-4.248-4.248c0-1.47%2C0.758-2.756%2C1.883-3.514l12.147-8.45c2.549-1.562%2C5.534-2.526%2C8.749-2.641l30.149%2C0.092%20L77.819%2C4.34c0-0.115%2C0-0.229%2C0-0.345C77.819%2C1.791%2C79.586%2C0%2C81.791%2C0c2.205%2C0%2C3.996%2C1.791%2C3.996%2C3.995%20c0%2C0.345-0.046%2C0.712-0.138%2C1.034l2.043%2C0.275c2.365%2C0.459%2C4.156%2C2.549%2C4.156%2C5.052c0%2C0.161%2C0%2C0.298-0.022%2C0.436l6.544%2C3.536%20c0.941%2C0.368%2C1.63%2C1.309%2C1.63%2C2.388c0%2C0.367-0.068%2C0.689-0.206%2C1.01l-1.631%2C3.697c-0.804%2C1.309-2.181%2C2.228-3.788%2C2.411%20l-15.041%2C1.791L65.787%2C41.527l7.738%2C13.363l5.098%2C2.365c0.803%2C0.552%2C1.354%2C1.493%2C1.354%2C2.549c0%2C1.699-1.378%2C3.078-3.101%2C3.078%20l-9.805%2C0.022c-2.525%2C0-4.707-1.424-5.809-3.49l-8.382-15.155l-18.92%2C0.023l6.682%2C10.287l4.937%2C2.25%20c0.919%2C0.551%2C1.516%2C1.538%2C1.516%2C2.664c0%2C1.699-1.378%2C3.076-3.077%2C3.076l-9.828%2C0.023c-2.388%2C0-4.5-1.286-5.649-3.215l-9.208-14.627%20l-6.429%2C6.246l-0.528%2C4.087l2.158%2C1.423c0.368%2C0.184%2C0.689%2C0.438%2C0.965%2C0.758c1.056%2C1.332%2C0.872%2C3.284-0.459%2C4.34%20c-0.574%2C0.482-1.286%2C0.713-1.975%2C0.689l-4.317%2C0.023c-1.194-0.139-2.273-0.758-2.962-1.677l-5.029-8.68C0.275%2C51.033%2C0%2C50%2C0%2C48.898%20c0-1.676%2C0.62-3.215%2C1.676-4.387L11.068%2C34.558z%22%2F%3E%3C%2Fsvg%3E\');\n\tbackground-repeat: no-repeat;\n\twidth: 100px;\n\theight: 62.905px;\n}\n\n\n\n.what-dog {\n\tbackground-image: url(\'dog.png\');\n\tbackground-repeat: no-repeat;\n\twidth: 100px;\n\theight: 62.905px;\n}\n\n\n'; | ||
var outputFileData2 = '\n.icon-2,\n\n.icon-bear:before,\n\n.icon-bear:after,\n\n.what-bear {\n\tbackground-image: url(\'data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22100%22%20height%3D%2262.905px%22%3E%3Cpath%20d%3D%22M11.068%2C34.558c-1.585-2.365-2.595-5.098-2.939-8.106c-0.344%2C0.092-0.666%2C0.161-1.033%2C0.161%20c-2.342%2C0-4.248-1.906-4.248-4.248c0-1.47%2C0.758-2.756%2C1.883-3.514l12.147-8.45c2.549-1.562%2C5.534-2.526%2C8.749-2.641l30.149%2C0.092%20L77.819%2C4.34c0-0.115%2C0-0.229%2C0-0.345C77.819%2C1.791%2C79.586%2C0%2C81.791%2C0c2.205%2C0%2C3.996%2C1.791%2C3.996%2C3.995%20c0%2C0.345-0.046%2C0.712-0.138%2C1.034l2.043%2C0.275c2.365%2C0.459%2C4.156%2C2.549%2C4.156%2C5.052c0%2C0.161%2C0%2C0.298-0.022%2C0.436l6.544%2C3.536%20c0.941%2C0.368%2C1.63%2C1.309%2C1.63%2C2.388c0%2C0.367-0.068%2C0.689-0.206%2C1.01l-1.631%2C3.697c-0.804%2C1.309-2.181%2C2.228-3.788%2C2.411%20l-15.041%2C1.791L65.787%2C41.527l7.738%2C13.363l5.098%2C2.365c0.803%2C0.552%2C1.354%2C1.493%2C1.354%2C2.549c0%2C1.699-1.378%2C3.078-3.101%2C3.078%20l-9.805%2C0.022c-2.525%2C0-4.707-1.424-5.809-3.49l-8.382-15.155l-18.92%2C0.023l6.682%2C10.287l4.937%2C2.25%20c0.919%2C0.551%2C1.516%2C1.538%2C1.516%2C2.664c0%2C1.699-1.378%2C3.076-3.077%2C3.076l-9.828%2C0.023c-2.388%2C0-4.5-1.286-5.649-3.215l-9.208-14.627%20l-6.429%2C6.246l-0.528%2C4.087l2.158%2C1.423c0.368%2C0.184%2C0.689%2C0.438%2C0.965%2C0.758c1.056%2C1.332%2C0.872%2C3.284-0.459%2C4.34%20c-0.574%2C0.482-1.286%2C0.713-1.975%2C0.689l-4.317%2C0.023c-1.194-0.139-2.273-0.758-2.962-1.677l-5.029-8.68C0.275%2C51.033%2C0%2C50%2C0%2C48.898%20c0-1.676%2C0.62-3.215%2C1.676-4.387L11.068%2C34.558z%22%2F%3E%3C%2Fsvg%3E\');\n\tbackground-repeat: no-repeat;\n\twidth: 100px;\n\theight: 62.905px;\n}\n\n\n\n.icon-dog:before,\n\n.icon-dog:after,\n\n.what-dog {\n\tbackground-image: url(\'dog.png\');\n\tbackground-repeat: no-repeat;\n\twidth: 100px;\n\theight: 62.905px;\n}\n\n\n'; | ||
var encoder, output = "test/output/encoded.css"; | ||
@@ -62,2 +62,5 @@ | ||
Constructor.encoders.svg = function(){}; | ||
Constructor.encoders.svg.prototype.stats = function(){ | ||
return {}; | ||
}; | ||
Constructor.encoders.svg.prototype.encode = function() { | ||
@@ -68,2 +71,5 @@ return "foo"; | ||
Constructor.encoders.png = function(){}; | ||
Constructor.encoders.png.prototype.stats = function(){ | ||
return {}; | ||
}; | ||
Constructor.encoders.png.prototype.encode = function() { | ||
@@ -70,0 +76,0 @@ return "bar"; |
Sorry, the diff of this file is not supported yet
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
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
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
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
33027
588
4
20
+ Addedimg-stats@0.4.2
+ Addedimg-stats@0.4.2(transitive)
+ Addedxmldom@0.1.16(transitive)