2010-08-30 60 views
5

BlueCloth与Rails 3兼容吗?我不能让它工作,也许有人使用它?BlueCloth无法与Rails 3兼容

在要求'bluecloth'后,应该有一个名为'markdown'的助手可用,但这似乎不可用。

+1

有这个问题,太 – postfuturist 2010-09-26 20:13:11

回答

2

我创建了一个新的Rails应用程序3,并在Gemfile中我加:

gem 'bluecloth', '>= 2.0.0' 

然后打开控制台:

ruby-1.8.7-p302 > BlueCloth.new('**hello**').to_html 
=> "<p><strong>hello</strong></p>" 

所以它似乎是工作,至少对我来说。

你也可以尝试Rdiscount,我不是很舒服,但我认为是基于相同的C库,或者至少有类似的基准。

你应该更具体地说明它是如何工作的:它是否会引发错误?它不呈现HTML吗?等等......

+0

是的,BlueCloth库的工作原理,但它有没有“降价”帮手。 – postfuturist 2010-09-27 16:52:47

+0

我一直在ApplicationHelper中定义我的帮助器,我想BlueGem不是专用于Rails的,BlueGem是否包含Rails帮助器? – Macario 2010-09-27 19:55:00

0

你能做什么,不能说是漂亮,是建立在你的Rails项目的初始化,并把它下面:

require 'bluecloth' 

class String 
def markdown 
    BlueCloth.new(self).to_html 
end 
end 

这应该在每个字符串启用降价方法目的。

10

我正在将应用升级到rails3,它对我来说工作得很好。我在模板中使用了一个名为“format”的助手函数,尽管下面的代码也提供了一个markdown函数(在rails3中,您必须使用raw())来使用它。这里是我的[项目]的像以前的海报说的内容/app/helpers/application_helper.rb

module ApplicationHelper 
    # Format text for display.                  
    def format(text) 
    sanitize(markdown(text)) 
    end 

    # Process text with Markdown.                 
    def markdown(text) 
    BlueCloth::new(text).to_html 
    end 
end 

,您还需要

gem 'bluecloth' 

在[项目]/Gemfile中。我的模板的样子:

<p><%= format @post.body %></p> 

随着降价的功能那就是:

<p><%= raw(markdown(@post.body)) %></p> 

所以我使用的格式功能。不管你想要什么,重命名这些功能。

+0

我会将.html_safe添加到助手返回的字符串中。然后它只是“<%= markdown @ post.body%>”,不需要“原始”。 – 2012-10-16 14:01:48

相关问题