diff --git a/.gitignore b/.gitignore index 30bc162..18ba8b5 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -/node_modules \ No newline at end of file +/node_modules +.DS_Store +test/assets/.eyeglass_cache \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..51d201c --- /dev/null +++ b/.travis.yml @@ -0,0 +1,7 @@ +language: node_js +node_js: + - "0.12" + - "4.0" + - "4.1" + - "4.2" + - "5.0" diff --git a/README.md b/README.md index 3c96d0b..51f0881 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ +[![Build Status](https://travis-ci.org/jackw/eyeglass-image-dimensions.svg?branch=master)](https://travis-ci.org/jackw/eyeglass-image-dimensions) +[![NPM Downloads](https://img.shields.io/npm/dm/eyeglass-image-dimensions.svg)](http://npm-stat.com/charts.html?package=eyeglass-image-dimensions&author=&from=&to=) +[![devDependency Status](https://david-dm.org/jackw/eyeglass-image-dimensions/dev-status.svg)](https://david-dm.org/jackw/eyeglass-image-dimensions#info=devDependencies) # eyeglass-image-dimensions -An eyeglass module that provides LibSass the same image dimensions functionality found in ruby compass. +An eyeglass module to give LibSass the same image dimension functionality found in ruby compass. ## Setup diff --git a/eyeglass-exports.js b/eyeglass-exports.js index 4e17992..7548a85 100644 --- a/eyeglass-exports.js +++ b/eyeglass-exports.js @@ -17,20 +17,15 @@ module.exports = function(eyeglass, sass) { function ImageDimensions (assetPath, registeredAssets, callback) { sassUtils.assertType(assetPath, "string"); sassUtils.assertType(registeredAssets, "map"); - var self = this; - var getPath = self.checkImagePath(assetPath.getValue(), registeredAssets); getPath.then(function (success) { - var imageDimensions = self.getDimensions(success); - imageDimensions.then(function (dimensions) { callback(null, dimensions); }, function (err) { callback(err, null); }); - }, function (err) { callback(err, null); }); @@ -43,19 +38,15 @@ module.exports = function(eyeglass, sass) { */ ImageDimensions.prototype.getDimensions = function (assetPath) { return new Promise(function (resolve, reject) { - sizeOf(assetPath, function (err, dimensions) { - if (err) { return reject(err); } - return resolve({ height: new sassUtils.SassDimension(dimensions.height, "px"), width: new sassUtils.SassDimension(dimensions.width, "px") }); }); - }); }; @@ -66,41 +57,30 @@ module.exports = function(eyeglass, sass) { * @return {String | Object} Either the path or the error object */ ImageDimensions.prototype.checkImagePath = function(assetPath, registeredAssets) { - registeredAssets = sassUtils.castToJs(registeredAssets); - return new Promise(function (resolve, reject) { - // Given an absolute path make sure we're looking in the right location. if (path.isAbsolute(assetPath)) { - assetPath = path.join(eyeglass.options.root, assetPath); + assetPath = path.join(eyeglass.options.eyeglass.root, assetPath); } - fs.lstat(assetPath, function(err, stats) { - if (err) { - // can"t find file from path provided so check assets + // can't find file from path provided so check assets if (err.code === "ENOENT") { // loop assets and check for a matching file. registeredAssets.forEach(function(asset) { asset = sassUtils.castToJs(asset); var assetData = asset.coerce.get(assetPath); - if (assetData) { return resolve(assetData.coerce.get("filepath")); } - }); } - return reject(err); } - return resolve(assetPath); }); - }); - }; return { @@ -108,39 +88,32 @@ module.exports = function(eyeglass, sass) { functions: { "eg-image-width($assetPath, $registeredAssets)": function(assetPath, registeredAssets, done) { - - var imageDim = new ImageDimensions(assetPath, registeredAssets, function(err, dimensions) { + new ImageDimensions(assetPath, registeredAssets, function(err, dimensions) { if (err) { done(sass.types.Error(err.message)); } done(sassUtils.castToSass(dimensions.width)); }); - }, "eg-image-height($assetPath, $registeredAssets)": function(assetPath, registeredAssets, done) { - - var imageDim = new ImageDimensions(assetPath, registeredAssets, function(err, dimensions) { + new ImageDimensions(assetPath, registeredAssets, function(err, dimensions) { if (err) { done(sass.types.Error(err.message)); } done(sassUtils.castToSass(dimensions.height)); }); - }, "eg-image-dimensions($assetPath, $registeredAssets)": function(assetPath, registeredAssets, done) { - - var imageDim = new ImageDimensions(assetPath, registeredAssets, function(err, dimensions) { + new ImageDimensions(assetPath, registeredAssets, function(err, dimensions) { if (err) { done(sass.types.Error(err.message)); } dimensions = sassUtils.castToSass([dimensions.width, dimensions.height]); dimensions.setSeparator(false); - done(dimensions); }); - } } }; diff --git a/package.json b/package.json index 28c251a..e7a52c9 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "eyeglass-image-dimensions", "description": "An eyeglass module that provides libsass the same image dimensions functionality found in ruby compass.", - "version": "0.1.1", + "version": "0.2.0", "author": { "name": "Jack Westbrook", "email": "jack.westbrook@gmail.com", @@ -16,26 +16,27 @@ "keywords": [ "sass", "eyeglass-module", - "image dimensions" + "image dimensions", + "image size" ], "eyeglass": { "name": "image-dimensions", "exports": "eyeglass-exports.js", - "needs": "^0.7.0" + "needs": "^0.8.0" }, "devDependencies": { - "eyeglass-dev-eslint": "^1.0.1", + "eyeglass": "^0.8.0", + "eyeglass-dev-eslint": "^2.0.0", "gulp": "^3.9.0", - "gulp-eslint": "^0.15.0", - "gulp-mocha": "^2.1.3", - "node-sass": "^3.2.0", - "should": "^7.0.2" + "gulp-eslint": "^1.1.1", + "gulp-mocha": "^2.2.0", + "node-sass": "^3.4.0", + "should": "^8.2.0" }, "dependencies": { - "eyeglass": "*", - "image-size": "^0.3.5", - "node-sass-utils": "^1.1.1", - "promise": "^7.0.3" + "image-size": "^0.4.0", + "node-sass-utils": "^1.1.0", + "promise": "^7.1.0" }, "scripts": { "test": "./node_modules/.bin/gulp test" diff --git a/test/test_dimensions.js b/test/test_dimensions.js index 98105ce..4059501 100644 --- a/test/test_dimensions.js +++ b/test/test_dimensions.js @@ -3,7 +3,7 @@ var fs = require("fs"); var path = require('path'); var sass = require("node-sass"); -var Eyeglass = require("eyeglass").Eyeglass; +var eyeglass = require("eyeglass"); var assert = require("assert"); @@ -19,13 +19,17 @@ describe("image dimensions module", function () { " background-height: 550px;\n" + " background-width: 400px; }\n"; - var eyeglass = new Eyeglass({ - root: path.join(__dirname, 'assets'), - data: sassInput - }, sass); - - sass.render(eyeglass.sassOptions(), function(error, result) { - // console.log(result.css.toString()); + var options = { + data: sassInput, + eyeglass: { + engines: { + sass: sass + }, + root: path.join(__dirname, 'assets') + } + }; + + sass.render(eyeglass(options), function(error, result) { assert(!error, error && error.message); assert.equal(cssOutput, result.css.toString()); done(); @@ -44,12 +48,17 @@ describe("image dimensions module", function () { " background-height: 300px;\n" + " background-width: 150px; }\n"; - var eyeglass = new Eyeglass({ - root: path.join(__dirname, 'assets'), - data: sassInput - }, sass); - - sass.render(eyeglass.sassOptions(), function(error, result) { + var options = { + data: sassInput, + eyeglass: { + engines: { + sass: sass + }, + root: path.join(__dirname, 'assets') + } + }; + + sass.render(eyeglass(options), function(error, result) { assert(!error, error && error.message); assert.equal(cssOutput, result.css.toString()); done(); @@ -70,14 +79,20 @@ describe("image dimensions module", function () { var rootDir = path.join(__dirname, 'assets'); - var eyeglass = new Eyeglass({ - root: rootDir, - data: sassInput - }, sass); - - eyeglass.assets.addSource(path.join(rootDir, 'images')); - - sass.render(eyeglass.sassOptions(), function(error, result) { + var options = { + data: sassInput, + eyeglass: { + engines: { + sass: sass + }, + root: rootDir, + assets: { + sources: [{directory: path.join(rootDir, 'images')}] + } + } + }; + + sass.render(eyeglass(options), function(error, result) { assert(!error, error && error.message); assert.equal(cssOutput, result.css.toString()); done(); @@ -85,6 +100,4 @@ describe("image dimensions module", function () { }); - - });