I've realized a simple proof of concept at https://github.com/edymtt/csscss-from-ironruby that shows in a console application how to use IronRuby to run the source code of csscss
to analyze a CSS loaded from a file. To achieve this result I've started from this SO question -- you can find the additional resources I've used in the comments of the program. I haven't tried this code in a ASP.net MVC site -- anyway this sample should be a good starting point.
This solution is a bit cumbersome to maintain, since you have to manually put the sources for the csscss
and its dependent libraries in the solution. An alternative solution is to install Ruby on the machine, install csscss
using gem
(so it download the dependencies automatically) and to invoke the program from .NET -- I'll also show this approach in the sample. Note that this solution requires that you could install Ruby on the web server.
UPDATE 2013-09-02 18:15 UTC Following the suggestion from Zach Moazeni I've been able to semplify the approach that used IronRuby to run csscss
and I've updated accordingly the proof of concept. In a nutshell:
- outside the .NET program I've used bundler to download
csscss
and json
(and dependent gems) to a local folder of the project;
- in the .NET program I've written a function to discover all the paths of the libraries in the gem folder created by
bundler
(by finding the gems
folder and then including for each subfolder the lib
folder, this algoritm was inspired by this SO thread);
- I've passed this list of paths to the IronRuby interpreter before launching
csscss
.
This approach should conjugate the ability to use only .NET to run the program with the ease of the update given by gem
and bundler
.