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 all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/utils/ExtensionUtils.js
Original file line number Diff line number Diff line change
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
32 changes: 30 additions & 2 deletions test/spec/ExtensionUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -137,6 +136,35 @@ define(function (require, exports, module) {
expect(testWindow.$.contains(testWindow.document, result)).toBeTruthy();
});
});

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