From cfb4bf49c24f410b797a7158f043201ca3867c67 Mon Sep 17 00:00:00 2001 From: Martin Zagora Date: Tue, 18 Mar 2014 23:16:40 +1100 Subject: [PATCH 1/4] Fix a case when extension less file is importing other less files --- src/utils/ExtensionUtils.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/utils/ExtensionUtils.js b/src/utils/ExtensionUtils.js index b6773907ab6..3a6be23cc9d 100644 --- a/src/utils/ExtensionUtils.js +++ b/src/utils/ExtensionUtils.js @@ -88,7 +88,14 @@ define(function (require, exports, module) { options = { filename: file, paths: [dir], - rootpath: dir + rootpath: dir, + currentFileInfo: { + currentDirectory: dir, + entryPath: dir, + filename: url, + rootFilename: url, + rootpath: dir + } }; } From 5433de58c0757ef2c8bcdd8bc83219d23dbef22c Mon Sep 17 00:00:00 2001 From: Martin Zagora Date: Wed, 19 Mar 2014 12:28:10 +1100 Subject: [PATCH 2/4] Unit test no longer fails --- src/utils/ExtensionUtils.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/utils/ExtensionUtils.js b/src/utils/ExtensionUtils.js index 3a6be23cc9d..834cbe91574 100644 --- a/src/utils/ExtensionUtils.js +++ b/src/utils/ExtensionUtils.js @@ -88,15 +88,18 @@ define(function (require, exports, module) { options = { filename: file, paths: [dir], - rootpath: dir, - currentFileInfo: { + rootpath: dir + }; + + if (url.indexOf("file://") === 0) { + options.currentFileInfo = { currentDirectory: dir, entryPath: dir, filename: url, rootFilename: url, rootpath: dir - } - }; + }; + } } var parser = new less.Parser(options); From 8568b20f8e79668b7a18c52cb82754d269c05820 Mon Sep 17 00:00:00 2001 From: Martin Zagora Date: Wed, 19 Mar 2014 13:00:36 +1100 Subject: [PATCH 3/4] Use isAbsoluteUrl and add passing test for absolute paths --- src/utils/ExtensionUtils.js | 6 +++--- test/spec/ExtensionUtils-test.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/utils/ExtensionUtils.js b/src/utils/ExtensionUtils.js index 834cbe91574..aff98c03e7a 100644 --- a/src/utils/ExtensionUtils.js +++ b/src/utils/ExtensionUtils.js @@ -23,7 +23,7 @@ /*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */ -/*global define, $, brackets, less */ +/*global define, $, brackets, less, PathUtils */ /** * ExtensionUtils defines utility methods for implementing extensions. @@ -91,7 +91,7 @@ define(function (require, exports, module) { rootpath: dir }; - if (url.indexOf("file://") === 0) { + if (PathUtils.isAbsoluteUrl(url)) { options.currentFileInfo = { currentDirectory: dir, entryPath: dir, @@ -161,7 +161,7 @@ define(function (require, exports, module) { * @return {!$.Promise} A promise object that is resolved with the contents of the requested file **/ function loadFile(module, path) { - var url = getModuleUrl(module, path), + var url = PathUtils.isAbsoluteUrl(path) ? path : getModuleUrl(module, path), promise = $.get(url); return promise; diff --git a/test/spec/ExtensionUtils-test.js b/test/spec/ExtensionUtils-test.js index c28a8823a4b..48a34f8ee7b 100644 --- a/test/spec/ExtensionUtils-test.js +++ b/test/spec/ExtensionUtils-test.js @@ -137,6 +137,36 @@ define(function (require, exports, module) { expect(testWindow.$.contains(testWindow.document, result)).toBeTruthy(); }); }); + + // putting everything LESS related in 1 test so it runs faster + it("should attach LESS style sheets using absolute url", function () { + var promise, result; + + runs(function () { + var indexLocation = testWindow.location.origin + testWindow.location.pathname, + bracketsLocation = indexLocation.substring(0, indexLocation.length - "src/index.html".length), + basicLessLocation = bracketsLocation + "test/spec/ExtensionUtils-test-files/basic.less"; + + promise = loadStyleSheet(testWindow.document, basicLessLocation); + promise.done(function (style) { + result = style; + }); + + waitsForDone(promise); + }); + + runs(function () { + // convert all line endings to platform default + var windowText = FileUtils.translateLineEndings(testWindow.$(result).text()), + lessText = FileUtils.translateLineEndings(LESS_RESULT); + + // confirm style sheet contents + expect(windowText).toBe(lessText); + + // confirm style is attached to document + expect(testWindow.$.contains(testWindow.document, result)).toBeTruthy(); + }); + }); }); }); }); From ec543161882eeefbd30c66613659863a05d435e5 Mon Sep 17 00:00:00 2001 From: Martin Zagora Date: Wed, 19 Mar 2014 14:21:31 +1100 Subject: [PATCH 4/4] Removed comments --- test/spec/ExtensionUtils-test.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/spec/ExtensionUtils-test.js b/test/spec/ExtensionUtils-test.js index 48a34f8ee7b..96a5026d7b8 100644 --- a/test/spec/ExtensionUtils-test.js +++ b/test/spec/ExtensionUtils-test.js @@ -111,8 +111,7 @@ define(function (require, exports, module) { waitsForFail(promise, "loadStyleSheet: " + path); }); }); - - // putting everything LESS related in 1 test so it runs faster + it("should attach LESS style sheets", function () { var promise, result; @@ -138,7 +137,6 @@ define(function (require, exports, module) { }); }); - // putting everything LESS related in 1 test so it runs faster it("should attach LESS style sheets using absolute url", function () { var promise, result;