Skip to content

Commit

Permalink
Updated code style and dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
André König committed Aug 13, 2014
1 parent c1e3530 commit d9b860b
Show file tree
Hide file tree
Showing 22 changed files with 135 additions and 132 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -1 +1,3 @@
node_modules

.zedstate
23 changes: 23 additions & 0 deletions HISTORY.md
@@ -0,0 +1,23 @@
# UNRELEASED

* Possibility to define a function which will generate an own CSS class structure (by [@juice49](https://github.com/juice49)).

# Version 0.2.2 (2014-02-21)

* Added more files to .npmignore.

# Version 0.2.1 (2014-02-17)

* Added `preferGlobal` flag to the `package.json`.

# Version 0.2.0 (2014-02-17)

* Implemented support for passing a vinyl file object to the transform method.

# Version 0.1.1 (2014-02-11)

* Fixed typos in the README.

# Version 0.1.0 (2014-02-11)

* Initial Release. Implemented the core functionality (CLI and API).
25 changes: 1 addition & 24 deletions README.md
Expand Up @@ -105,7 +105,7 @@ imacss
.pipe(process.stdout);
```

#### Passing a function to customise the resulting CSS rule set
#### Passing a function to customize the resulting CSS rule set

```javascript
var imacss = require('imacss');
Expand All @@ -122,29 +122,6 @@ imacss
.pipe(process.stdout);
```
## Changelog
### Version 0.2.2 (20140221)
- Added more files to .npmignore.
### Version 0.2.1 (20140217)
- Added `preferGlobal` flag to the `package.json`.
### Version 0.2.0 (20140217)
- Implemented support for passing a vinyl file object to the transform method.
### Version 0.1.1 (20140211)
- Fixed typos in the README.
### Version 0.1.0 (20140211)
- Initial Release. Implemented the core functionality (CLI and API).
## Author
Copyright 2014, [André König](http://iam.andrekoenig.info) (andre.koenig@posteo.de)
8 changes: 4 additions & 4 deletions gulpfile.js
Expand Up @@ -13,10 +13,10 @@

'use strict';

var gulp = require('gulp'),
jshint = require('gulp-jshint'),
jasmine = require('gulp-jasmine'),
paths = {};
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var jasmine = require('gulp-jasmine');
var paths = {};

paths.sources = ['./lib/**/*.js', './specs/**/*.js', 'gulpfile.js', 'index.js'];
paths.specs = ['./specs/**/*.spec.js'];
Expand Down
11 changes: 6 additions & 5 deletions index.js
Expand Up @@ -13,9 +13,10 @@

'use strict';

var domain = require('domain'),
pipeline = require('./lib'),
pkg = require('./package.json');
var domain = require('domain');

var pipeline = require('./lib');
var pkg = require('./package.json');

/**
* Transforms image files to base64 encoded data URIs and embeds them into CSS files.
Expand All @@ -26,8 +27,8 @@ var domain = require('domain'),
*/
exports.transform = function transform (glob, css) {

var execution = domain.create(),
transformation;
var execution = domain.create();
var transformation;

css = css || pkg.name;

Expand Down
21 changes: 12 additions & 9 deletions lib/cssify.js
Expand Up @@ -13,9 +13,10 @@

'use strict';

var stream = require('stream'),
util = require('util'),
Utilities = require('./utilities');
var stream = require('stream');
var util = require('util');

var Utilities = require('./utilities');

/**
* The stream which will transform the internal image
Expand Down Expand Up @@ -48,12 +49,14 @@ Cssify.prototype._transform = function _transform (image, enc, cb) {
'background-image': 'url(\'' + image.datauri + '\')'
};

if(typeof this.css === 'string') {
this.push(Utilities.getCSSSelector(this.css, image.slug, selector) + '\n');
}

if(this.css instanceof Function) {
this.push(this.css(image) + '\n');
switch (typeof this.css) {
case 'string':
this.push(Utilities.getCSSSelector(this.css, image.slug, selector) + '\n');
break;

case 'function':
this.push(this.css(image) + '\n');
break;
}

cb();
Expand Down
15 changes: 7 additions & 8 deletions lib/index.js
Expand Up @@ -13,14 +13,13 @@

'use strict';

var stream = require('stream'),
through = require('through2'),
vfs = require('vinyl-fs'),
purify = require('./purify'),
slugify = require('./slugify'),
mimeify = require('./mimeify'),
urify = require('./urify'),
cssify = require('./cssify');
var through = require('through2');
var vfs = require('vinyl-fs');
var purify = require('./purify');
var slugify = require('./slugify');
var mimeify = require('./mimeify');
var urify = require('./urify');
var cssify = require('./cssify');

exports.purify = purify;
exports.slugify = slugify;
Expand Down
6 changes: 3 additions & 3 deletions lib/mimeify.js
Expand Up @@ -13,9 +13,9 @@

'use strict';

var stream = require('stream'),
util = require('util'),
Utilities = require('./utilities');
var stream = require('stream');
var util = require('util');
var Utilities = require('./utilities');

/**
* The stream which will determine the respective image MIME type
Expand Down
7 changes: 3 additions & 4 deletions lib/purify.js
Expand Up @@ -13,10 +13,9 @@

'use strict';

var stream = require('stream'),
util = require('util'),
path = require('path'),
slug = require('slug');
var stream = require('stream');
var util = require('util');
var path = require('path');

/**
* The stream which will convert the vinyl file to
Expand Down
8 changes: 4 additions & 4 deletions lib/slugify.js
Expand Up @@ -13,10 +13,10 @@

'use strict';

var stream = require('stream'),
path = require('path'),
util = require('util'),
slug = require('slug');
var stream = require('stream');
var path = require('path');
var util = require('util');
var slug = require('slug');

/**
* The stream which will create a slug based on the
Expand Down
7 changes: 4 additions & 3 deletions lib/urify.js
Expand Up @@ -13,9 +13,10 @@

'use strict';

var stream = require('stream'),
util = require('util'),
Utilities = require('./utilities');
var stream = require('stream');
var util = require('util');

var Utilities = require('./utilities');

/**
* The stream which generate the data URI of the image.
Expand Down
4 changes: 2 additions & 2 deletions lib/utilities/css.js
Expand Up @@ -24,8 +24,8 @@
*
*/
exports.constructSelector = function constructSelector (prefix, name, properties) {
var selector = '',
prop;
var selector = '';
var prop;

// Creating cascade: e.g. .imacss.imacss-foobar {...}
selector = '.' + prefix + '.' + prefix + '-' + name + '{';
Expand Down
10 changes: 5 additions & 5 deletions lib/utilities/index.js
Expand Up @@ -13,10 +13,10 @@

'use strict';

var mime = require('./mime'),
uri = require('./uri'),
css = require('./css');
var mime = require('./mime');
var uri = require('./uri');
var css = require('./css');

exports.getMimeType = mime.detect;
exports.getDataURI = uri.constructDataURI;
exports.getMimeType = mime.detect;
exports.getDataURI = uri.constructDataURI;
exports.getCSSSelector = css.constructSelector;
26 changes: 13 additions & 13 deletions lib/utilities/mime.js
Expand Up @@ -13,11 +13,11 @@

'use strict';

var fs = require('fs'),
filetypes = [
{mime: 'image/jpeg', magicnumber: 'FFD8', extensions: ['jpg', 'jpeg']},
{mime: 'image/png', magicnumber: '89504E470D0A1A0A', extensions: ['png']}
];
var fs = require('fs');
var filetypes = [
{mime: 'image/jpeg', magicnumber: 'FFD8', extensions: ['jpg', 'jpeg']},
{mime: 'image/png', magicnumber: '89504E470D0A1A0A', extensions: ['png']}
];

/**
* Determines the MIME type of the given image.
Expand All @@ -27,21 +27,21 @@ var fs = require('fs'),
*
*/
exports.detect = function detect (image, callback) {
var buffer = image.toString('hex').toUpperCase(),
i = filetypes.length - 1,
filetype,
magic,
mime;
var buffer = image.toString('hex').toUpperCase();
var i = filetypes.length - 1;
var filetype;
var magic;
var mime;

//
// Helper function for checking if a file is a SVG.
// (Thanks to grunticon: https://github.com/filamentgroup/grunticon)
//
function isSVG (data) {

var i = 0,
len = data.length,
snippet;
var i = 0;
var len = data.length;
var snippet;

for (i; i < len; i = i + 1) {
snippet = data.slice(i, i + 2).toString('hex');
Expand Down
14 changes: 7 additions & 7 deletions package.json
Expand Up @@ -33,14 +33,14 @@
},
"homepage": "https://github.com/akoenig/imacss",
"dependencies": {
"vinyl-fs": "0.0.2",
"slug": "~0.4.0",
"through2": "~0.4.1"
"vinyl-fs": "0.3.6",
"slug": "~0.5.0",
"through2": "~1.1.1"
},
"devDependencies": {
"gulp": "~3.5.2",
"gulp-jshint": "~1.4.0",
"gulp-jasmine": "~0.1.3",
"gulp-util": "~2.2.14"
"gulp": "~3.8.7",
"gulp-jshint": "~1.8.4",
"gulp-jasmine": "~0.3.0",
"gulp-util": "~3.0.0"
}
}
32 changes: 15 additions & 17 deletions specs/cssify.spec.js
Expand Up @@ -13,15 +13,15 @@

'use strict';

var helper = require('./helper'),
cssify = require('../lib/cssify');
var helper = require('./helper');
var cssify = require('../lib/cssify');

describe('The "cssification" stream', function () {

it('should generate a CSS selector based on the image data', function (done) {
var image = helper.createImage(),
prefix = 'imacss',
stream = cssify(prefix);
var image = helper.createImage();
var prefix = 'imacss';
var stream = cssify(prefix);

stream.on('data', function (selector) {
expect(selector).toBeDefined();
Expand All @@ -37,19 +37,17 @@ describe('The "cssification" stream', function () {

it('should generate a custom CSS rule set if a function is passed instead of a prefix string', function(done) {

var image = helper.createImage(),
generateCss = function generateCss(image) { return image.name; },
stream = cssify(generateCss);
var image = helper.createImage();
var generateCss = function generateCss(image) { return image.name; };
var stream = cssify(generateCss);

stream.on('data', function(ruleset) {
expect(ruleset).toBeDefined();
expect(ruleset).toBe(image.name + '\n');
done();
});
stream.on('data', function(ruleset) {
expect(ruleset).toBeDefined();
expect(ruleset).toBe(image.name + '\n');
done();
});

stream.write(image);
stream.end();

stream.write(image);
stream.end();
});

});
10 changes: 5 additions & 5 deletions specs/helper.js
Expand Up @@ -13,9 +13,9 @@

'use strict';

var fs = require('fs'),
path = require('path'),
gutil = require('gulp-util');
var fs = require('fs');
var path = require('path');
var gutil = require('gulp-util');

/**
* Creates a vinyl based file description.
Expand All @@ -41,8 +41,8 @@ exports.createImageFile = function createImageFile () {
*
*/
exports.createImage = function createImage () {
var file = this.createImageFile(),
image = {};
var file = this.createImageFile();
var image = {};

image.name = path.basename(file.path);
image.contents = file.contents;
Expand Down

0 comments on commit d9b860b

Please sign in to comment.