[Pkg-javascript-commits] [less.js] 22/58: Support include-path inside data-uri. Related to #1634 and #2275
Jonas Smedegaard
dr at jones.dk
Mon Oct 26 23:28:26 UTC 2015
This is an automated email from the git hooks/post-receive script.
js pushed a commit to annotated tag v2.3.0
in repository less.js.
commit 84b1863ddf916b43e4f1cc7d999f437372493c2d
Author: jurcovicovam <meri at meri.org>
Date: Tue Jan 13 15:09:41 2015 +0100
Support include-path inside data-uri. Related to #1634 and #2275
---
.gitattributes | 1 +
lib/less-node/file-manager.js | 67 ++++++++++++++++++--------------
lib/less/contexts.js | 1 +
lib/less/tree/expression.js | 2 +-
test/css/include-path/include-path.css | 6 +++
test/index.js | 1 +
test/less-test.js | 19 +++++++--
test/less/include-path/include-path.less | 6 +++
8 files changed, 70 insertions(+), 33 deletions(-)
diff --git a/.gitattributes b/.gitattributes
index d2a478b..f184602 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1,4 +1,5 @@
*.js text eol=lf
+*.svg text eol=lf
lessc text eol=lf
*.less text eol=lf
*.css text eol=lf
diff --git a/lib/less-node/file-manager.js b/lib/less-node/file-manager.js
index 3d1a185..4680250 100644
--- a/lib/less-node/file-manager.js
+++ b/lib/less-node/file-manager.js
@@ -23,36 +23,16 @@ FileManager.prototype.loadFile = function(filename, currentDirectory, options, e
options = options || {};
- var paths = isAbsoluteFilename ? [""] : [currentDirectory];
- if (options.paths) paths.push.apply(paths, options.paths);
- if (!isAbsoluteFilename && paths.indexOf('.') === -1) { paths.push('.'); }
-
if (options.syncImport) {
- var err, result;
- for (var i = 0; i < paths.length; i++) {
- try {
- fullFilename = filename;
- if (paths[i]) {
- fullFilename = path.join(paths[i], fullFilename);
- }
- filenamesTried.push(fullFilename);
- fs.statSync(fullFilename);
- break;
- } catch (e) {
- fullFilename = null;
- }
- }
-
- if (!fullFilename) {
- err = { type: 'File', message: "'" + filename + "' wasn't found. Tried - " + filenamesTried.join(",") };
- } else {
- data = fs.readFileSync(fullFilename, 'utf-8');
- result = { contents: data, filename: fullFilename};
- }
- callback(err, result);
+ data = this.loadFileSync(filename, currentDirectory, options, environment, 'utf-8');
+ callback(data.error, data);
return;
}
+ var paths = isAbsoluteFilename ? [""] : [currentDirectory];
+ if (options.paths) paths.push.apply(paths, options.paths);
+ if (!isAbsoluteFilename && paths.indexOf('.') === -1) { paths.push('.'); }
+
// promise is guarenteed to be asyncronous
// which helps as it allows the file handle
// to be closed before it continues with the next file
@@ -82,9 +62,38 @@ FileManager.prototype.loadFile = function(filename, currentDirectory, options, e
});
};
-FileManager.prototype.loadFileSync = function(filename, currentDirectory, options, environment) {
- filename = path.join(currentDirectory, filename);
- return { contents: fs.readFileSync(filename), filename: filename };
+FileManager.prototype.loadFileSync = function(filename, currentDirectory, options, environment, encoding) {
+ var fullFilename, paths, filenamesTried=[], isAbsoluteFilename = this.isPathAbsolute(filename),data;
+ options = options || {};
+
+ paths = isAbsoluteFilename ? [""] : [currentDirectory];
+ if (options.paths) paths.push.apply(paths, options.paths);
+ if (!isAbsoluteFilename && paths.indexOf('.') === -1) { paths.push('.'); }
+
+ var err, result;
+ for (var i = 0; i < paths.length; i++) {
+ try {
+ fullFilename = filename;
+ if (paths[i]) {
+ fullFilename = path.join(paths[i], fullFilename);
+ }
+ filenamesTried.push(fullFilename);
+ fs.statSync(fullFilename);
+ break;
+ } catch (e) {
+ fullFilename = null;
+ }
+ }
+
+ if (!fullFilename) {
+ err = { type: 'File', message: "'" + filename + "' wasn't found. Tried - " + filenamesTried.join(",") };
+ result = { error: err };
+ } else {
+ data = fs.readFileSync(fullFilename, encoding);
+ result = { contents: data, filename: fullFilename};
+ }
+
+ return result;
};
module.exports = FileManager;
diff --git a/lib/less/contexts.js b/lib/less/contexts.js
index 5c0ef6d..52b902e 100644
--- a/lib/less/contexts.js
+++ b/lib/less/contexts.js
@@ -41,6 +41,7 @@ contexts.Parse = function(options) {
};
var evalCopyProperties = [
+ 'paths', // additional include paths
'compress', // whether to compress
'ieCompat', // whether to enforce IE compatibility (IE8 data-uri)
'strictMath', // whether math has to be within parenthesis
diff --git a/lib/less/tree/expression.js b/lib/less/tree/expression.js
index 00024ce..c852d42 100644
--- a/lib/less/tree/expression.js
+++ b/lib/less/tree/expression.js
@@ -5,7 +5,7 @@ var Node = require("./node"),
var Expression = function (value) {
this.value = value;
if (!value) {
- throw new Error("Expression requires a array parameter");
+ throw new Error("Expression requires an array parameter");
}
};
Expression.prototype = new Node();
diff --git a/test/css/include-path/include-path.css b/test/css/include-path/include-path.css
new file mode 100644
index 0000000..586cb61
--- /dev/null
+++ b/test/css/include-path/include-path.css
@@ -0,0 +1,6 @@
+body {
+ width: 100%;
+}
+data-uri {
+ property: url("data:image/svg+xml,%3Csvg%20height%3D%22100%22%20width%3D%22100%22%3E%0A%20%20%3Ccircle%20cx%3D%2250%22%20cy%3D%2250%22%20r%3D%2240%22%20stroke%3D%22black%22%20stroke-width%3D%221%22%20fill%3D%22blue%22%20%2F%3E%0A%3C%2Fsvg%3E");
+}
diff --git a/test/index.js b/test/index.js
index a82bc9a..1146ff5 100644
--- a/test/index.js
+++ b/test/index.js
@@ -45,6 +45,7 @@ lessTester.runTestSet({globalVars: true, banner: "/**\n * Test\n */\n"}, "glob
lessTester.runTestSet({modifyVars: true}, "modifyVars/",
null, null, null, function(name) { return path.join('test/less/', name) + '.json'; });
lessTester.runTestSet({urlArgs: '424242'}, "url-args/");
+lessTester.runTestSet({paths: ['test/data/','test/less/import/']}, "include-path/");
lessTester.testSyncronous({syncImport: true}, "import");
lessTester.testSyncronous({syncImport: true}, "css");
lessTester.testNoOptions();
diff --git a/test/less-test.js b/test/less-test.js
index 93caf9b..8a9dc4b 100644
--- a/test/less-test.js
+++ b/test/less-test.js
@@ -280,11 +280,24 @@ module.exports = function() {
}
}
- function toCSS(options, path, callback) {
+ function contains(fullArray, obj) {
+ for (var i = 0; i < fullArray.length; i++) {
+ if (fullArray[i] === obj) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+ function toCSS(options, path, callback) {
options = options || {};
- var str = fs.readFileSync(path, 'utf8');
+ var str = fs.readFileSync(path, 'utf8'), addPath = require('path').dirname(path);
- options.paths = [require('path').dirname(path)];
+ options.paths = options.paths || [];
+ if (!contains(options.paths, addPath)) {
+ options.paths.push(addPath);
+ }
options.filename = require('path').resolve(process.cwd(), path);
options.optimization = options.optimization || 0;
diff --git a/test/less/include-path/include-path.less b/test/less/include-path/include-path.less
new file mode 100644
index 0000000..bd1f1d1
--- /dev/null
+++ b/test/less/include-path/include-path.less
@@ -0,0 +1,6 @@
+ at import "import-test-e";
+
+data-uri {
+ property: data-uri('image.svg');
+}
+
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/less.js.git
More information about the Pkg-javascript-commits
mailing list