add a data-uri function

as described in a comment on #775
This commit is contained in:
Jay Adkisson
2012-12-23 00:59:13 -08:00
committed by Luke Page
parent d56e0a476d
commit 24e41081ef
4 changed files with 22 additions and 0 deletions

View File

@@ -1,3 +1,5 @@
var fs = require('fs');
(function (tree) {
tree.functions = {
@@ -345,6 +347,18 @@ tree.functions = {
},
shade: function(color, amount) {
return this.mix(this.rgb(0, 0, 0), color, amount);
},
"data-uri": function(mimetype, path) {
var data = fs.readFileSync(path.value);
mimetype = mimetype.value;
if (/;base64$/.test(mimetype)) {
data = (new Buffer(data)).toString('base64');
}
var contents = new(tree.Anonymous)('data:'+mimetype+','+data);
return new(tree.URL)(contents);
}
};