mirror of
https://github.com/less/less.js.git
synced 2026-02-07 05:25:04 -05:00
Provide fallback 'mime' object that covers 80% case of data-uri usage.
This commit is contained in:
committed by
Luke Page
parent
4e517af093
commit
5325a2e4b4
@@ -387,7 +387,13 @@ tree.functions = {
|
||||
|
||||
// detect the mimetype if not given
|
||||
if (arguments.length < 2) {
|
||||
var mime = require('mime');
|
||||
var mime;
|
||||
try {
|
||||
mime = require('mime');
|
||||
} catch (ex) {
|
||||
mime = tree._mime;
|
||||
}
|
||||
|
||||
path = mimetype;
|
||||
mimetype = mime.lookup(path);
|
||||
|
||||
@@ -410,6 +416,34 @@ tree.functions = {
|
||||
}
|
||||
};
|
||||
|
||||
// these static methods are used as a fallback when the optional 'mime' dependency is missing
|
||||
tree._mime = {
|
||||
// this map is intentionally incomplete
|
||||
// if you want more, install 'mime' dep
|
||||
_types: {
|
||||
'.htm' : 'text/html',
|
||||
'.html': 'text/html',
|
||||
'.gif' : 'image/gif',
|
||||
'.jpg' : 'image/jpeg',
|
||||
'.jpeg': 'image/jpeg',
|
||||
'.png' : 'image/png'
|
||||
},
|
||||
lookup: function (filepath) {
|
||||
var ext = require('path').extname(filepath),
|
||||
type = tree._mime._types[ext];
|
||||
if (type === undefined) {
|
||||
throw new Error('Optional dependency "mime" is required for ' + ext);
|
||||
}
|
||||
return type;
|
||||
},
|
||||
charsets: {
|
||||
lookup: function (type) {
|
||||
// assumes all text types are UTF-8
|
||||
return type && (/^text\//).test(type) ? 'UTF-8' : '';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var mathFunctions = [{name:"ceil"}, {name:"floor"}, {name: "sqrt"}, {name:"abs"},
|
||||
{name:"tan", unit: ""}, {name:"sin", unit: ""}, {name:"cos", unit: ""},
|
||||
{name:"atan", unit: "rad"}, {name:"asin", unit: "rad"}, {name:"acos", unit: "rad"}],
|
||||
|
||||
Reference in New Issue
Block a user