mirror of
https://github.com/less/less.js.git
synced 2026-05-01 03:00:22 -04:00
continue moving node functionality into the environment interface. function names need making consistent etc.
This commit is contained in:
@@ -397,16 +397,14 @@ var functions = {
|
||||
|
||||
"data-uri": function(mimetypeNode, filePathNode) {
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
if (!less.environment.supportsDataURI(this.env)) {
|
||||
return new tree.URL(filePathNode || mimetypeNode, this.currentFileInfo).eval(this.env);
|
||||
}
|
||||
|
||||
var mimetype = mimetypeNode.value;
|
||||
var filePath = (filePathNode && filePathNode.value);
|
||||
|
||||
var fs = require('fs'),
|
||||
path = require('path'),
|
||||
useBase64 = false;
|
||||
var useBase64 = false;
|
||||
|
||||
if (arguments.length < 2) {
|
||||
filePath = mimetype;
|
||||
@@ -414,25 +412,19 @@ var functions = {
|
||||
|
||||
if (this.env.isPathRelative(filePath)) {
|
||||
if (this.currentFileInfo.relativeUrls) {
|
||||
filePath = path.join(this.currentFileInfo.currentDirectory, filePath);
|
||||
filePath = less.environment.join(this.currentFileInfo.currentDirectory, filePath);
|
||||
} else {
|
||||
filePath = path.join(this.currentFileInfo.entryPath, filePath);
|
||||
filePath = less.environment.join(this.currentFileInfo.entryPath, filePath);
|
||||
}
|
||||
}
|
||||
|
||||
// detect the mimetype if not given
|
||||
if (arguments.length < 2) {
|
||||
var mime;
|
||||
try {
|
||||
mime = require('mime');
|
||||
} catch (ex) {
|
||||
mime = tree._mime;
|
||||
}
|
||||
|
||||
mimetype = mime.lookup(filePath);
|
||||
mimetype = less.environment.mimeLookup(this.env, filePath);
|
||||
|
||||
// use base 64 unless it's an ASCII or UTF-8 format
|
||||
var charset = mime.charsets.lookup(mimetype);
|
||||
var charset = less.environment.charsetLookup(this.env, mimetype);
|
||||
useBase64 = ['US-ASCII', 'UTF-8'].indexOf(charset) < 0;
|
||||
if (useBase64) { mimetype += ';base64'; }
|
||||
}
|
||||
@@ -440,7 +432,7 @@ var functions = {
|
||||
useBase64 = /;base64$/.test(mimetype);
|
||||
}
|
||||
|
||||
var buf = fs.readFileSync(filePath);
|
||||
var buf = less.environment.readFileSync(filePath);
|
||||
|
||||
// IE8 cannot handle a data-uri larger than 32KB. If this is exceeded
|
||||
// and the --ieCompat flag is enabled, return a normal url() instead.
|
||||
@@ -541,34 +533,6 @@ var 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' : '';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Math
|
||||
|
||||
var mathFunctions = {
|
||||
|
||||
Reference in New Issue
Block a user