mirror of
https://github.com/less/less.js.git
synced 2026-05-01 03:00:22 -04:00
some renames, tidy ups and bugfixes whilst adding npm plugin
This commit is contained in:
@@ -24,21 +24,21 @@ function getXMLHttpRequest() {
|
||||
}
|
||||
}
|
||||
|
||||
var BrowserImport = function() {
|
||||
var FileManager = function() {
|
||||
};
|
||||
|
||||
BrowserImport.prototype = new AbstractFileManager();
|
||||
FileManager.prototype = new AbstractFileManager();
|
||||
|
||||
BrowserImport.prototype.alwaysMakePathsAbsolute = function alwaysMakePathsAbsolute() {
|
||||
FileManager.prototype.alwaysMakePathsAbsolute = function alwaysMakePathsAbsolute() {
|
||||
return true;
|
||||
};
|
||||
BrowserImport.prototype.join = function join(basePath, laterPath) {
|
||||
FileManager.prototype.join = function join(basePath, laterPath) {
|
||||
if (!basePath) {
|
||||
return laterPath;
|
||||
}
|
||||
return this.extractUrlParts(laterPath, basePath).path;
|
||||
};
|
||||
BrowserImport.prototype.doXHR = function doXHR(url, type, callback, errback) {
|
||||
FileManager.prototype.doXHR = function doXHR(url, type, callback, errback) {
|
||||
|
||||
var xhr = getXMLHttpRequest();
|
||||
var async = isFileProtocol ? options.fileAsync : options.async;
|
||||
@@ -76,11 +76,11 @@ BrowserImport.prototype.doXHR = function doXHR(url, type, callback, errback) {
|
||||
handleResponse(xhr, callback, errback);
|
||||
}
|
||||
};
|
||||
BrowserImport.prototype.supports = function(filename, currentDirectory, options, environment) {
|
||||
FileManager.prototype.supports = function(filename, currentDirectory, options, environment) {
|
||||
return true;
|
||||
};
|
||||
|
||||
BrowserImport.prototype.loadFile = function loadFile(filename, currentDirectory, options, environment) {
|
||||
FileManager.prototype.loadFile = function loadFile(filename, currentDirectory, options, environment) {
|
||||
return new PromiseConstructor(function(fullfill, reject) {
|
||||
if (currentDirectory && !this.isPathAbsolute(filename)) {
|
||||
filename = currentDirectory + filename;
|
||||
@@ -115,5 +115,5 @@ BrowserImport.prototype.loadFile = function loadFile(filename, currentDirectory,
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
return new BrowserImport();
|
||||
return FileManager;
|
||||
};
|
||||
@@ -16,8 +16,10 @@ var isFileProtocol = /^(file|chrome(-extension)?|resource|qrc|app):/.test(window
|
||||
|
||||
window.less = less = require('../less')();
|
||||
var environment = less.environment,
|
||||
browserImport = require("./browser-import")(options, isFileProtocol, less.logger);
|
||||
environment.addFileManager(browserImport);
|
||||
FileManager = require("./file-manager")(options, isFileProtocol, less.logger),
|
||||
fileManager = new FileManager();
|
||||
environment.addFileManager(fileManager);
|
||||
less.FileManager = FileManager;
|
||||
|
||||
require("./log-listener")(less, options);
|
||||
//var utils = require("./utils");
|
||||
@@ -129,7 +131,7 @@ function loadStyleSheet(sheet, callback, reload, remaining, modifyVars) {
|
||||
instanceOptions.useFileCache = true;
|
||||
}
|
||||
|
||||
browserImport.loadFile(sheet.href, null, instanceOptions, environment)
|
||||
fileManager.loadFile(sheet.href, null, instanceOptions, environment)
|
||||
.then(function loadInitialFileCallback(loadedFile) {
|
||||
|
||||
var data = loadedFile.contents,
|
||||
@@ -137,7 +139,7 @@ function loadStyleSheet(sheet, callback, reload, remaining, modifyVars) {
|
||||
webInfo = loadedFile.webInfo;
|
||||
|
||||
var newFileInfo = {
|
||||
currentDirectory: browserImport.getPath(path),
|
||||
currentDirectory: fileManager.getPath(path),
|
||||
filename: path,
|
||||
rootFilename: path,
|
||||
relativeUrls: instanceOptions.relativeUrls};
|
||||
|
||||
@@ -3,19 +3,19 @@ var path = require('path'),
|
||||
PromiseConstructor = typeof Promise === 'undefined' ? require('promise') : Promise,
|
||||
AbstractFileManager = require("../less/environment/abstract-file-manager.js");
|
||||
|
||||
var FileImport = function() {
|
||||
var FileManager = function() {
|
||||
};
|
||||
|
||||
FileImport.prototype = new AbstractFileManager();
|
||||
FileManager.prototype = new AbstractFileManager();
|
||||
|
||||
FileImport.prototype.supports = function(filename, currentDirectory, options, environment) {
|
||||
FileManager.prototype.supports = function(filename, currentDirectory, options, environment) {
|
||||
return true;
|
||||
};
|
||||
FileImport.prototype.supportsSync = function(filename, currentDirectory, options, environment) {
|
||||
FileManager.prototype.supportsSync = function(filename, currentDirectory, options, environment) {
|
||||
return true;
|
||||
};
|
||||
|
||||
FileImport.prototype.loadFile = function(filename, currentDirectory, options, environment) {
|
||||
FileManager.prototype.loadFile = function(filename, currentDirectory, options, environment) {
|
||||
return new PromiseConstructor(function(fullfill, reject) {
|
||||
var fullFilename,
|
||||
data;
|
||||
@@ -71,9 +71,9 @@ FileImport.prototype.loadFile = function(filename, currentDirectory, options, en
|
||||
});
|
||||
};
|
||||
|
||||
FileImport.prototype.loadFileSync = function(filename, currentDirectory, options, environment) {
|
||||
FileManager.prototype.loadFileSync = function(filename, currentDirectory, options, environment) {
|
||||
filename = path.join(currentDirectory, filename);
|
||||
return { contents: fs.readFileSync(filename), filename: filename };
|
||||
};
|
||||
|
||||
module.exports = new FileImport();
|
||||
module.exports = FileManager;
|
||||
@@ -1,8 +1,8 @@
|
||||
var environment = require("./environment"),
|
||||
fileImport = require("./file-import.js"),
|
||||
urlImport = require("./url-import.js"),
|
||||
FileManager = require("./file-manager"),
|
||||
UrlFileManager = require("./url-file-manager"),
|
||||
createFromEnvironment = require("../less"),
|
||||
less = createFromEnvironment(environment, [fileImport, urlImport]),
|
||||
less = createFromEnvironment(environment, [new FileManager(), new UrlFileManager()]),
|
||||
lesscHelper = require('./lessc-helper');
|
||||
|
||||
// allow people to create less with their own environment
|
||||
@@ -10,8 +10,8 @@ less.createFromEnvironment = createFromEnvironment;
|
||||
less.lesscHelper = lesscHelper;
|
||||
less.PluginLoader = require("./plugin-loader");
|
||||
less.fs = require("./fs");
|
||||
less.fileImport = require("./file-import.js");
|
||||
less.urlImport = require("./url-import.js");
|
||||
less.FileManager = FileManager;
|
||||
less.UrlFileManager = UrlFileManager;
|
||||
less.formatError = function(ctx, options) {
|
||||
options = options || {};
|
||||
|
||||
|
||||
@@ -5,16 +5,16 @@ var isUrlRe = /^(?:https?:)?\/\//i,
|
||||
AbstractFileManager = require("../less/environment/abstract-file-manager.js"),
|
||||
logger = require("../less/logger");
|
||||
|
||||
var UrlImport = function() {
|
||||
var UrlFileManager = function() {
|
||||
};
|
||||
|
||||
UrlImport.prototype = new AbstractFileManager();
|
||||
UrlFileManager.prototype = new AbstractFileManager();
|
||||
|
||||
UrlImport.prototype.supports = function(filename, currentDirectory, options, environment) {
|
||||
UrlFileManager.prototype.supports = function(filename, currentDirectory, options, environment) {
|
||||
return isUrlRe.test( filename ) || isUrlRe.test(currentDirectory);
|
||||
};
|
||||
|
||||
UrlImport.prototype.loadFile = function(filename, currentDirectory, options, environment) {
|
||||
UrlFileManager.prototype.loadFile = function(filename, currentDirectory, options, environment) {
|
||||
return new PromiseConstructor(function(fullfill, reject) {
|
||||
if (request === undefined) {
|
||||
try { request = require('request'); }
|
||||
@@ -50,4 +50,4 @@ UrlImport.prototype.loadFile = function(filename, currentDirectory, options, env
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = new UrlImport();
|
||||
module.exports = UrlFileManager;
|
||||
@@ -70,7 +70,7 @@ abstractFileManager.prototype.extractUrlParts = function extractUrlParts(url, ba
|
||||
}
|
||||
|
||||
// Stylesheets in IE don't always return the full path
|
||||
if (!urlParts[1] || urlParts[2]) {
|
||||
if (baseUrl && (!urlParts[1] || urlParts[2])) {
|
||||
baseUrlParts = baseUrl.match(urlPartsRegex);
|
||||
if (!baseUrlParts) {
|
||||
throw new Error("Could not parse page url - '"+baseUrl+"'");
|
||||
@@ -102,7 +102,7 @@ abstractFileManager.prototype.extractUrlParts = function extractUrlParts(url, ba
|
||||
|
||||
returner.hostPart = urlParts[1];
|
||||
returner.directories = directories;
|
||||
returner.path = urlParts[1] + directories.join("/");
|
||||
returner.path = (urlParts[1] || "") + directories.join("/");
|
||||
returner.fileUrl = returner.path + (urlParts[4] || "");
|
||||
returner.url = returner.fileUrl + (urlParts[5] || "");
|
||||
return returner;
|
||||
|
||||
Reference in New Issue
Block a user