Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Fix a case when extension less file is importing other less files #7230

Merged
merged 4 commits into from Mar 19, 2014
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/utils/ExtensionUtils.js
Expand Up @@ -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.
Expand Down Expand Up @@ -90,6 +90,16 @@ define(function (require, exports, module) {
paths: [dir],
rootpath: dir
};

if (PathUtils.isAbsoluteUrl(url)) {
options.currentFileInfo = {
currentDirectory: dir,
entryPath: dir,
filename: url,
rootFilename: url,
rootpath: dir
};
}
}

var parser = new less.Parser(options);
Expand Down Expand Up @@ -151,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;
Expand Down
30 changes: 30 additions & 0 deletions test/spec/ExtensionUtils-test.js
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment doesn't seems to make sense. Remove both copies.

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();
});
});
});
});
});