/
cssify.js
67 lines (51 loc) · 1.3 KB
/
cssify.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* imacss
*
* Copyright(c) 2014 André König <andre.koenig@posteo.de>
* MIT Licensed
*
*/
/**
* @author André König <andre.koenig@posteo.de>
*
*/
'use strict';
var stream = require('stream');
var util = require('util');
var Utilities = require('./utilities');
/**
* The stream which will transform the internal image
* data structure into a CSS selector with the embedded file.
*
* @param {string | function} css The CSS class which will be used as a prefix, or a function to generate the CSS rule set.
* @param {object} options Stream options.
*
*/
function Cssify (css, options) {
this.css = css;
options = options || {};
options.objectMode = true;
stream.Transform.call(this, options);
}
util.inherits(Cssify, stream.Transform);
/**
* The transformation process.
*
*/
Cssify.prototype._transform = function _transform (image, enc, cb) {
var selector = {
'background-image': 'url(\'' + image.datauri + '\')'
};
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();
};
module.exports = function (css) {
return new Cssify(css);
};