forked from fetch/node-sass-asset-functions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (51 loc) · 1.98 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
51
52
53
54
var sass = require('node-sass');
var Processor = require('./lib/processor');
module.exports = function(options) {
var opts = options || {};
var processor = new Processor(opts);
return {
'image-url($filename, $only_path: false)': function(filename, only_path, done) {
processor.image_url(filename.getValue(), function(url) {
if(!only_path.getValue()) url = 'url(\'' + url + '\')';
done(new sass.types.String(url));
});
},
'inline-image($filename, $mime_type: null)': function(filename, mime_type, done) {
mime_type = mime_type instanceof sass.types.Null ? null : mime_type.getValue();
processor.inline_image(filename.getValue(), mime_type, function(dataUrl) {
done(new sass.types.String('url(\'' + dataUrl + '\')'));
});
},
'image-width($filename)': function(filename, done) {
processor.image_width(filename.getValue(), function(image_width) {
done(new sass.types.Number(image_width, 'px'));
});
},
'image-height($filename)': function(filename, done) {
processor.image_height(filename.getValue(), function(image_height) {
done(new sass.types.Number(image_height, 'px'));
});
},
'font-url($filename, $only-path: false)': function(filename, only_path, done) {
processor.font_url(filename.getValue(), function(url) {
if(!only_path.getValue()) url = 'url(\'' + url + '\')';
done(new sass.types.String(url));
});
},
'font-files($filenames...)': function(list, done) {
var len = list.getLength(), i = 0, filenames = [];
for(; i < len; ++i) {
filenames[i] = list.getValue(i).getValue();
}
processor.font_files(filenames, function(files) {
len = files.length;
i = 0;
list = new sass.types.List(len);
for (; i < len; ++i) {
list.setValue(i, new sass.types.String('url(\'' + files[i].url + '\') format(\'' + files[i].type + '\')'));
}
done(list);
});
}
};
};