tags:

views:

199

answers:

3

I'm trying to run less.js in a C# application. I tried running the default distro using JavaScript.net but I'm getting window is undefined error. I think that is caused due to this not being run in a browser but on a JS engine. Is there any workaround / any pointers to resources that can help?

A: 

This is more a guess than a real answer but I will try to help so please don't downvote if it is wrong. But according to the documentation (I have never worked with Javascript.net) the following is valid:

// Initialize the context
JavascriptContext context = new JavascriptContext();

// Setting the externals parameters of the context
context.SetParameter("console", new SystemConsole());
context.SetParameter("message", "Hello World !");
context.SetParameter("number", 1);

// Running the script
context.Run("var i; for (i = 0; i < 5; i++) console.Print(message + ' (' + i + ')'); number += i;");

// Getting a parameter
Console.WriteLine("number: " + context.GetParameter("number"));

Maybe you should set the window as a parameter to the context ala this:

context.SetParameter("window", new YourWindow());

And insure the window your providing have the same attributes/methods/etc. as the standard browser window.

Addition You could try and implement a simple window which just writes to the console whenever some function is called on it. Unless of cause, Javascript.Net gives you a window wrapper (does not seem like it though)

lasseespeholt
A: 

Less.js indicates that it's intended to be run under Node.js. Because it sounds like you're writing a .NET app, why not see if Node.net will help you?

Voyagerfan5761
+6  A: 

You should probably run .Less instead. If I understand correctly, you are trying to run less.js on the server through a Javascript interpreter. Why not just skip the interpreter and run LESS conversion using all .NET code? Way less pain and overhead.

Igor Zevaka