forked from akoenig/imacss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (39 loc) · 1.13 KB
/
index.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
/*
* imacss
*
* Copyright(c) 2014 - 2015 André König <[email protected]>
* MIT Licensed
*
*/
/**
* @author André König <[email protected]>
*
*/
'use strict';
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.
*
* @param {string} glob A globbing expression for matching particular image files.
* @param {string | function} css The CSS class which will be used as a prefix, or a function to generate the CSS rule set.
*
*/
exports.transform = function transform (glob, css) {
var execution = domain.create();
var transformation;
css = css || pkg.name;
execution.on('error', function (err) {
transformation.emit('error', err);
});
execution.run(function () {
transformation = pipeline.createFileStream(glob)
.pipe(pipeline.purify())
.pipe(pipeline.slugify())
.pipe(pipeline.mimeify())
.pipe(pipeline.urify())
.pipe(pipeline.cssify(css));
});
return transformation;
};