Skip to content

Instantly share code, notes, and snippets.

@rarous
Created May 11, 2011 07:22
Show Gist options
  • Select an option

  • Save rarous/966039 to your computer and use it in GitHub Desktop.

Select an option

Save rarous/966039 to your computer and use it in GitHub Desktop.
Helper for less compiler via jshost.exe
LoadModule('jsstd');
LoadModule('jsio');
var thisDir = arguments[0].replace(/[^\\/]+$/, '');
var srcFile = arguments[1];
var dstFile = arguments[2];
var window = {
location: {
port: 80,
href: "file:///" + srcFile.replace("\\", "/")
},
XMLHttpRequest: function() { }
};
var document = {
getElementsByTagName: function() { return [] },
createElemet: function() { }
};
var location = window.location;
var XMLHttpRequest = window.XMLHttpRequest;
XMLHttpRequest.prototype.open = function(verb, url) {
this.status = url.indexOf("file:///") == 0 ? 0 : 200;
this.responseText = new File(url).content;
};
XMLHttpRequest.prototype.getResponseHeader = function() {};
XMLHttpRequest.prototype.setRequestHeader = function() {};
XMLHttpRequest.prototype.send = function() {};
Exec(thisDir + 'less.js');
var less = window.less || {};
new less.Parser({ opimization: 2 }).parse(
new File(srcFile).content,
function (err, tree) {
if (err) File.stdout.Write(err.message);
(dstFile ?
new File(dstFile).Open(File.WRONLY | File.CREATE_FILE | File.TRUNCATE) :
File.stdout
).Write(tree.toCSS({ compress: true }));
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment