简体   繁体   English

可以安装ironruby nuget软件包,然后在香草VS2012中使用

[英]can ironruby nuget package be installed then used in a vanilla VS2012

I am interested in using a ruby script ( https://github.com/zmoazeni/csscss ) withing an ASPNET MVC site. 我对在ASPNET MVC网站上使用ruby脚本( https://github.com/zmoazeni/csscss )感兴趣。 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? 是否可以导入ironruby nuget包并执行ruby脚本?

My goal would be to put a .net wrapper around the ruby script(s) and put the output out as HTML. 我的目标是在.ruby脚本周围放置一个.net包装器,并将输出作为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). 到目前为止,我已经尝试使用Googling来开始使用Ironruby,但是并没有发现我所了解的很多知识并且可以开始工作,(是的,这听起来有些含糊,但是我不了解ruby或Ironruby,也找不到关于入门的任何简单指南)。

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. 我已经在https://github.com/edymtt/csscss-from-ironruby上实现了一个简单的概念证明,它在控制台应用程序中显示了如何使用IronRuby运行csscss的源代码来分析从文件加载的CSS。 。 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. 为了达到这个结果,我从这个SO问题开始-您可以找到我在程序注释中使用的其他资源。 I haven't tried this code in a ASP.net MVC site -- anyway this sample should be a good starting point. 我没有在ASP.net MVC站点中尝试过此代码-无论如何,此示例应该是一个很好的起点。

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. 维护该解决方案有点麻烦,因为您必须手动将csscss及其依赖库的源放入解决方案中。 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. 另一种解决方案是在机器上安装Ruby,使用gem安装csscss (以便它自动下载依赖项),然后从.NET调用程序-我还将在示例中展示这种方法。 Note that this solution requires that you could install Ruby on the web server. 请注意,此解决方案要求您可以在Web服务器上安装Ruby。

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. UPDATE 2013-09-02 18:15 UTC根据Zach Moazeni的建议,我已经能够简化使用IronRuby运行csscss的方法,并据此更新了概念验证。 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; 在.NET程序之外,我使用捆绑程序将csscssjson (以及相关的gems)下载到项目的本地文件夹中;
  • 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 ); 在.NET程序中,我编写了一个函数,以发现由bundler创建的gem文件夹中库的所有路径(通过找到gems文件夹,然后为每个子文件夹包括lib文件夹,此算法均受此SO线程的启发);
  • I've passed this list of paths to the IronRuby interpreter before launching csscss . 在启动csscss之前,我已经将此路径列表传递给IronRuby解释器。

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 . 这种方法应该使仅使用.NET来运行程序的能力与gembundler提供的轻松更新相结合。

I'm the author of csscss and I built the JSON output for this reason. 我是csscss的作者,因此我构建了JSON输出。

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. 这不是一个完美的解决方案,但是它会输出可以从任何语言/运行时解析的JSON,而不是输出人类可读的文本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM