1

我对Ruby一无所知:)

问题是,我需要一种将 HTML 电子邮件中的所有 CSS 转换为内联样式的方法。没有比使用Alex Dunae 的 Premailer更好的方法了。

但我想在 Windows 上运行它。我的目标是能够从 C# 运行脚本,并获取由 C# 中的 ruby​​ 脚本创建的文件,并将 HTML 用于电子邮件。

无论如何,运行 ruby​​ 脚本对我来说是困难的部分。我已经下载并安装了Ruby Installer,并且还下载了 Premailer 1.6.2 包。

我尝试这样做:

C:\Ruby192\bin>ruby.exe C:\Workspace\Premailer\bin\premailer C:\Workspace\index.htm > C:\Workspace\index2.htm

它告诉我的是:

C:\Ruby192\bin>ruby.exe C:\Workspace\Premailer\bin\premailer C:\Workspace\index.htm > C:\Workspace\index2.htm
<internal:lib/rubygems/custom_require>:29:in `require': no such file to load -- hpricot (LoadError)
        from <internal:lib/rubygems/custom_require>:29:in `require'
        from C:/Workspace/Premailer/lib/premailer.rb:4:in `<top (required)>'
        from <internal:lib/rubygems/custom_require>:29:in `require'
        from <internal:lib/rubygems/custom_require>:29:in `require'
        from C:/Workspace/Premailer/bin/premailer:5:in `<main>'

我可能需要一些依赖项,还是什么?

4

2 回答 2

3

您缺少 Hpricot 库,它是一个 HTML 解析器。

但是,我不确定它为什么会丢失。它在 Premailer 的包规范中被正确列为依赖项,并且它应该在您安装 Premailer 时自动安装(除非您使用--ignore-dependencies标志明确禁用它)。

此外,Premailer 二进制文件应该已安装在 中C:\Ruby192\bin,而不是C:\Workspace\Premailer\bin.

尝试卸载 Premailer:

gem uninstall --force premailer

然后再次尝试安装它:

gem install premailer

注意:Hpricot 实际上是用 C 语言编写的,而不是用 Ruby 编写的,因此要安装它,您需要安装 RubyInstaller DevKit。(这可以解释为什么它没有自动安装。)

一般提示:如果您想在 CLI 和 Ruby 之间进行互操作,使用 IronRuby Ruby 实现比使用 YARV 更容易,因为 IronRuby 实际上在 CLI(更准确地说是 DLR)上运行,并且具有用于从 Ruby 调用 CLI 代码的标准化 API,反之亦然(并且该 API 与 C# 4 完全兼容dynamic)。除非在这种特殊情况下不起作用,因为正如我所提到的,Hpricot 是用 C 编写的,作为 YARV 的扩展,因此它根本无法与 IronRuby 一起使用。

于 2010-11-23T20:28:54.660 回答
1

是的,“hpricot”不见了。最简单的方法可能是使用 ruby​​gems 安装:

gem install -r hpricot
于 2010-11-23T20:08:03.510 回答