tuskar-ui/bin/lib/less/rhino.js
John Postlethwait 0074328fbb Updating Horizon to use LESS.
This changes all of the Bootstrap CSS and Horizon
CSS to use LESS. Horizon's specific CSS will be
organized into separate files in another commit,
as it is outside the scope of this BP.

We are also now packing LESS 1.3.0 directly within
Horizon.

Implementation of Blueprint transition-to-lesscss

Change-Id: Ie4be8b28ab3ce04ea21d7d5cd49c2ccb66bd8ade
2012-06-07 14:32:43 -07:00

63 lines
1.6 KiB
JavaScript

var name;
function loadStyleSheet(sheet, callback, reload, remaining) {
var sheetName = name.slice(0, name.lastIndexOf('/') + 1) + sheet.href;
var input = readFile(sheetName);
var parser = new less.Parser({
paths: [sheet.href.replace(/[\w\.-]+$/, '')]
});
parser.parse(input, function (e, root) {
if (e) {
print("Error: " + e);
quit(1);
}
callback(root, sheet, { local: false, lastModified: 0, remaining: remaining });
});
// callback({}, sheet, { local: true, remaining: remaining });
}
function writeFile(filename, content) {
var fstream = new java.io.FileWriter(filename);
var out = new java.io.BufferedWriter(fstream);
out.write(content);
out.close();
}
// Command line integration via Rhino
(function (args) {
name = args[0];
var output = args[1];
if (!name) {
print('No files present in the fileset; Check your pattern match in build.xml');
quit(1);
}
path = name.split("/");path.pop();path=path.join("/")
var input = readFile(name);
if (!input) {
print('lesscss: couldn\'t open file ' + name);
quit(1);
}
var result;
var parser = new less.Parser();
parser.parse(input, function (e, root) {
if (e) {
quit(1);
} else {
result = root.toCSS();
if (output) {
writeFile(output, result);
print("Written to " + output);
} else {
print(result);
}
quit(0);
}
});
print("done");
}(arguments));