Ruby on Rails的BBCode

所以我正在组建一个简单的论坛。 我想允许我的用户使用有限的格式化选项,而BBCode对我的用户来说将是充足的。 知道我肯定不是第一个想要使用BR与RoR的人我用Google搜索但是找不到关于如何创建接受BBCode的编辑器的直接教程,也没有找到解析和显示BBCode格式输入的方法。

任何帮助或指南将不胜感激!

你应该尝试一下bb-ruby 。 它在网页上的文档似乎非常清晰明了。

这是你可能觉得有用的另一个gem

http://github.com/jarrett/rbbcode

的Gemfile

gem 'bb-ruby' # run `bundle` 

在这个地方(haml):

 %h1= put_header_string.bbcode_to_html.html_safe %p= "[b]bold text[/b]".bbcode_to_html.html_safe 

除了内置内容,您还可以根据需要扩展自己的bbcode。 例如:

 module BBRuby @@tags = @@tags.merge({ 'Email' => [ /\[email(:.*)?\](.*?)\[\/file\1?\]/mi, lambda{ |e| ""}, 'protect email from spam', '[email]electronic@test.ru[/email]', :email ], }) end 

到位

 [b]Contact me:[/b][email]email@test.ru[/email] 

联系我: email (at) test.ru


github上的bb-ruby | rubygems上的bb-ruby | bb-ruby home | 标签处理列表