Question

I am interested in using a ruby script (https://github.com/zmoazeni/csscss) withing an ASPNET MVC site. I have no previous experience with ruby so my question could be naive.

Is it possible to import the ironruby nuget package and execute the ruby scripts?

My goal would be to put a .net wrapper around the ruby script(s) and put the output out as HTML.


So far I have tried Googling getting started with ironruby but have not found much that I understand and could get working, (yes that sound vague, but I don't know ruby or ironruby and couldn't find any good simple guides on getting started).

Was it helpful?

Solution

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.

OTHER TIPS

I'm the author of csscss and I built the JSON output for this reason.

csscss -j file.css

It's not a perfect solution, but instead of outputting human readable text, it will output JSON that you can parse from whatever language/runtime.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top