0

I would like to allow my user to change some less variables so they can customize the styles.

When done I would like to generate the css file.

I m working in .net and have an azure worker role that can probably handle the task. if it's not possible in .net may be with node.js?

Can someone suggest me a way to do it?

Thank you

fred_
  • 1,486
  • 1
  • 19
  • 31
  • Changing LESS variables dynamically has already been solved in another SO thread. Can you check this thread http://stackoverflow.com/questions/10274260/programmatically-editing-less-css-code-with-jquery-like-selector-syntax and confirm if that is what you want. – ramiramilu Jan 06 '14 at 13:02
  • thx very interesting link. for load time, and performance reason I would like to serve only css files. so when it's done I need to run some sort of less compiler to get the css out. – fred_ Jan 06 '14 at 13:15

1 Answers1

0

I'm currently building my LESS files using lessc.wsf which you can download here: https://github.com/duncansmart/less.js-windows/tree/windows-script-host

Then in your Worker Role you can do something like this:

        // File path.
        var lessCompilerPath = "...\\lessc.wsf";
        var lessPath = "site.less");
        var cssPath = "site.css");

        // Compile.
        var process = new Process
        {
            StartInfo = new ProcessStartInfo("cscript")
            {
                WindowStyle = ProcessWindowStyle.Hidden,
                CreateNoWindow = true,
                Arguments = "//nologo \"" + lessCompilerPath + "\" \"" + lessPath + "\" \"" + cssPath + "\" -filenames",
                UseShellExecute = false,
                RedirectStandardError = true,
                RedirectStandardOutput = true
            }
        };
        process.Start();
        process.WaitForExit();

        // Error.
        if (process.ExitCode != 0)
        {
            throw new InvalidOperationException(process.StandardError.ReadToEnd());
        }

You'll need to match the path to your files depending on where they are located in your solution.

Sandrino Di Mattia
  • 24,739
  • 2
  • 60
  • 65
  • thx you, I think I m going to do a processStart also. Any reason you didn't use directly $ lessc styles.less > styles.css from http://lesscss.org/#usage – fred_ Jan 06 '14 at 22:39