mirror of
https://github.com/less/less.js.git
synced 2026-01-22 21:58:14 -05:00
Relative url's option for node lessc
This commit is contained in:
32
bin/lessc
32
bin/lessc
@@ -15,7 +15,8 @@ var options = {
|
||||
paths: [],
|
||||
color: true,
|
||||
strictImports: false,
|
||||
rootpath: ''
|
||||
rootpath: '',
|
||||
relativeUrls: false
|
||||
};
|
||||
var continueProcessing = true,
|
||||
currentErrorcode;
|
||||
@@ -65,12 +66,17 @@ args = args.filter(function (arg) {
|
||||
options.color = false;
|
||||
break;
|
||||
case 'include-path':
|
||||
options.paths = match[2].split(os.type().match(/Windows/) ? ';' : ':')
|
||||
.map(function(p) {
|
||||
if (p) {
|
||||
return path.resolve(process.cwd(), p);
|
||||
}
|
||||
});
|
||||
if (!match[2]) {
|
||||
sys.puts("include-path option requires a parameter");
|
||||
continueProcessing = false;
|
||||
} else {
|
||||
options.paths = match[2].split(os.type().match(/Windows/) ? ';' : ':')
|
||||
.map(function(p) {
|
||||
if (p) {
|
||||
return path.resolve(process.cwd(), p);
|
||||
}
|
||||
});
|
||||
}
|
||||
break;
|
||||
case 'O0': options.optimization = 0; break;
|
||||
case 'O1': options.optimization = 1; break;
|
||||
@@ -80,7 +86,16 @@ args = args.filter(function (arg) {
|
||||
break;
|
||||
case 'rp':
|
||||
case 'rootpath':
|
||||
options.rootpath = path.normalize(match[2] + '/');
|
||||
if (!match[2]) {
|
||||
sys.puts("rootpath option requires a parameter");
|
||||
continueProcessing = false;
|
||||
} else {
|
||||
options.rootpath = path.normalize(match[2] + '/').replace('\\', '/');
|
||||
}
|
||||
break;
|
||||
case "ru":
|
||||
case "relative-urls":
|
||||
options.relativeUrls = true;
|
||||
break;
|
||||
}
|
||||
});
|
||||
@@ -126,6 +141,7 @@ var parseLessFile = function (e, data) {
|
||||
optimization: options.optimization,
|
||||
filename: input,
|
||||
rootpath: options.rootpath,
|
||||
relativeUrls: options.relativeUrls,
|
||||
strictImports: options.strictImports,
|
||||
dumpLineNumbers: options.dumpLineNumbers
|
||||
}).parse(data, function (err, tree) {
|
||||
|
||||
@@ -211,11 +211,17 @@ function loadStyleSheet(sheet, callback, reload, remaining) {
|
||||
var css = cache && cache.getItem(href);
|
||||
var timestamp = cache && cache.getItem(href + ':timestamp');
|
||||
var styles = { css: css, timestamp: timestamp };
|
||||
var rootpath = hrefParts.path;
|
||||
//TODO - sheet.rootpath might be a unique path that needs using
|
||||
// or it might be the url of the last sheet
|
||||
// hrefParts.path is the full url path in the current sheet
|
||||
// we need to take sheet.rootpath and if that is set, combine it
|
||||
// somehow with the relative part of the href?
|
||||
// also need to take into account sheet.relativeUrls
|
||||
var rootpath = hrefParts.path;
|
||||
|
||||
xhr(href, sheet.type, function (data, lastModified) {
|
||||
// Store data this session
|
||||
session_cache += data.replace(/@import .+?;/ig, '');
|
||||
// Store data this session
|
||||
session_cache += data.replace(/@import .+?;/ig, '');
|
||||
|
||||
if (!reload && styles && lastModified &&
|
||||
(new(Date)(lastModified).valueOf() ===
|
||||
@@ -233,6 +239,7 @@ function loadStyleSheet(sheet, callback, reload, remaining) {
|
||||
mime: sheet.type,
|
||||
filename: href,
|
||||
rootpath: rootpath,
|
||||
relativeUrls: sheet.relativeUrls,
|
||||
contents: contents, // Passing top importing parser content cache ref down.
|
||||
files: files,
|
||||
dumpLineNumbers: less.dumpLineNumbers
|
||||
|
||||
@@ -116,7 +116,7 @@ less.Parser.importer = function (file, paths, callback, env) {
|
||||
// then rootpath should become 'less/module/nav/'
|
||||
// - If path of imported file is '../mixins.less' and rootpath is 'less/',
|
||||
// then rootpath should become 'less/../'
|
||||
if(!/^(?:[a-z-]+:|\/)/.test(file) && j != -1) {
|
||||
if(env.relativeUrls && !/^(?:[a-z-]+:|\/)/.test(file) && j != -1) {
|
||||
rootpath = rootpath + file.slice(0, j+1); // append (sub|sup) directory path of imported file
|
||||
}
|
||||
|
||||
@@ -127,6 +127,7 @@ less.Parser.importer = function (file, paths, callback, env) {
|
||||
contents: env.contents,
|
||||
files: env.files,
|
||||
syncImport: env.syncImport,
|
||||
relativeUrls: env.relativeUrls,
|
||||
rootpath: rootpath,
|
||||
dumpLineNumbers: env.dumpLineNumbers
|
||||
}).parse(data, function (e, root) {
|
||||
|
||||
@@ -23,7 +23,7 @@ var lessc_helper = {
|
||||
|
||||
//Print command line options
|
||||
printUsage: function() {
|
||||
sys.puts("usage: lessc [options] <source> [destination]");
|
||||
sys.puts("usage: lessc [option option=parameter ...] <source> [destination]");
|
||||
sys.puts("");
|
||||
sys.puts("If source is set to `-' (dash or hyphen-minus), input is read from stdin.");
|
||||
sys.puts("");
|
||||
@@ -48,6 +48,8 @@ var lessc_helper = {
|
||||
sys.puts(" media query which is compatible with the SASS");
|
||||
sys.puts(" format, and 'all' which will do both.");
|
||||
sys.puts(" -rp, --rootpath Set rootpath for url rewriting in relative imports and urls.");
|
||||
sys.puts(" Works with or withour the relative-urls option.");
|
||||
sys.puts(" -ru, --relative-urls re-write relative urls to the base less file.");
|
||||
sys.puts("");
|
||||
sys.puts("Report bugs to: http://github.com/cloudhead/less.js/issues");
|
||||
sys.puts("Home page: <http://lesscss.org/>");
|
||||
|
||||
@@ -1500,8 +1500,15 @@ if (less.mode === 'browser' || less.mode === 'rhino') {
|
||||
// We pass `true` as 3rd argument, to force the reload of the import.
|
||||
// This is so we can get the syntax tree as opposed to just the CSS output,
|
||||
// as we need this to evaluate the current stylesheet.
|
||||
// __ Now using the hack of passing a ref to top parser's content cache in the 1st arg. __
|
||||
loadStyleSheet({ href: path, title: path, type: env.mime, contents: env.contents, files: env.files, rootpath: env.rootpath }, function (e, root, data, sheet, _, path) {
|
||||
loadStyleSheet({
|
||||
href: path,
|
||||
title: path,
|
||||
type: env.mime,
|
||||
contents: env.contents,
|
||||
files: env.files,
|
||||
rootpath: env.rootpath,
|
||||
relativeUrls: env.relativeUrls },
|
||||
function (e, root, data, sheet, _, path) {
|
||||
if (e && typeof(env.errback) === "function") {
|
||||
env.errback.call(null, path, paths, callback, env);
|
||||
} else {
|
||||
|
||||
@@ -23,7 +23,7 @@ less.tree.functions._color = function (str) {
|
||||
|
||||
sys.puts("\n" + stylize("LESS", 'underline') + "\n");
|
||||
|
||||
runTestSet();
|
||||
runTestSet({relativeUrls: true});
|
||||
|
||||
runTestSet(null, "errors/", function(name, err, compiledLess, doReplacements) {
|
||||
fs.readFile(path.join('test/less/', name) + '.txt', 'utf8', function (e, expectedErr) {
|
||||
|
||||
Reference in New Issue
Block a user