[Pkg-javascript-commits] [less.js] 207/285: put the appendage of the .less extension through the file manager so that behaviour can be over-ridden. Fixes #2235

Jonas Smedegaard dr at jones.dk
Mon Oct 26 23:23:55 UTC 2015


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag v2.0.0
in repository less.js.

commit 148a0f59082d531c3297169a143d89bb13642d7d
Author: Luke Page <luke.a.page at gmail.com>
Date:   Tue Oct 21 13:16:40 2014 +0100

    put the appendage of the .less extension through the file manager so that behaviour can be over-ridden. Fixes #2235
---
 lib/less/environment/abstract-file-manager.js |  4 ++++
 lib/less/environment/file-manager-api.js      |  8 ++++++++
 lib/less/import-manager.js                    | 14 +++++++++++++-
 lib/less/tree/import.js                       |  3 +--
 lib/less/visitors/import-visitor.js           |  4 +++-
 5 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/lib/less/environment/abstract-file-manager.js b/lib/less/environment/abstract-file-manager.js
index e5e218d..b9db647 100644
--- a/lib/less/environment/abstract-file-manager.js
+++ b/lib/less/environment/abstract-file-manager.js
@@ -12,6 +12,10 @@ abstractFileManager.prototype.getPath = function (filename) {
     return filename.slice(0, j + 1);
 };
 
+abstractFileManager.prototype.tryAppendLessExtension = function(path) {
+    return /(\.[a-z]*$)|([\?;].*)$/.test(path) ? path : path + '.less';
+};
+
 abstractFileManager.prototype.supportsSync = function() {
     return false;
 };
diff --git a/lib/less/environment/file-manager-api.js b/lib/less/environment/file-manager-api.js
index 4138b7c..d1a67b1 100644
--- a/lib/less/environment/file-manager-api.js
+++ b/lib/less/environment/file-manager-api.js
@@ -8,6 +8,14 @@ module.exports = {
     getPath: function(filename) {
     },
     /**
+     * Append a .less extension if appropriate. Only called if less thinks one could be added.
+     * Provided by AbstractFileManager
+     * @param filename
+     * @returns {string}
+     */
+    tryAppendLessExtension: function(filename) {
+    },
+    /**
      * Whether the rootpath should be converted to be absolute.
      * The browser ovverides this to return true because urls must be absolute.
      * Provided by AbstractFileManager (returns false)
diff --git a/lib/less/import-manager.js b/lib/less/import-manager.js
index ac550a9..9da2b86 100644
--- a/lib/less/import-manager.js
+++ b/lib/less/import-manager.js
@@ -24,7 +24,15 @@ module.exports = function(environment) {
         this.queue = [];        // Files which haven't been imported yet
         this.files = [];        // Holds the imported parse trees.
     };
-    ImportManager.prototype.push = function (path, currentFileInfo, importOptions, callback) {
+    /**
+     * Add an import to be imported
+     * @param path - the raw path
+     * @param tryAppendLessExtension - whether to try appending the less extension (if the path has no extension)
+     * @param currentFileInfo - the current file info (used for instance to work out relative paths)
+     * @param importOptions - import options
+     * @param callback - callback for when it is imported
+     */
+    ImportManager.prototype.push = function (path, tryAppendLessExtension, currentFileInfo, importOptions, callback) {
         var importManager = this;
         this.queue.push(path);
 
@@ -54,6 +62,10 @@ module.exports = function(environment) {
             return;
         }
 
+        if (tryAppendLessExtension) {
+            path = fileManager.tryAppendLessExtension(path);
+        }
+
         fileManager.loadFile(path, currentFileInfo.currentDirectory, this.context, environment)
             .then(function loadFileCallback(loadedFile) {
                 var resolvedFilename = loadedFile.filename,
diff --git a/lib/less/tree/import.js b/lib/less/tree/import.js
index 5183d76..d8ce4f3 100644
--- a/lib/less/tree/import.js
+++ b/lib/less/tree/import.js
@@ -67,8 +67,7 @@ Import.prototype.genCSS = function (context, output) {
 };
 Import.prototype.getPath = function () {
     if (this.path instanceof Quoted) {
-        var path = this.path.value;
-        return (this.css !== undefined || /(\.[a-z]*$)|([\?;].*)$/.test(path)) ? path : path + '.less';
+        return this.path.value;
     } else if (this.path instanceof URL) {
         return this.path.value.value;
     }
diff --git a/lib/less/visitors/import-visitor.js b/lib/less/visitors/import-visitor.js
index 38b78fc..e995c7c 100644
--- a/lib/less/visitors/import-visitor.js
+++ b/lib/less/visitors/import-visitor.js
@@ -62,7 +62,9 @@ ImportVisitor.prototype = {
                     context.importMultiple = true;
                 }
 
-                this._importer.push(importNode.getPath(), importNode.currentFileInfo, importNode.options, function (e, root, importedAtRoot, fullPath) {
+                // try appending if we haven't determined if it is css or not
+                var tryAppendLessExtension = importNode.css === undefined;
+                this._importer.push(importNode.getPath(), tryAppendLessExtension, importNode.currentFileInfo, importNode.options, function (e, root, importedAtRoot, fullPath) {
                     if (e && !e.filename) {
                         e.index = importNode.index; e.filename = importNode.currentFileInfo.filename;
                     }

-- 
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