Skip to content
Browse files

Support passing Redcloth options via textilize helper [#2973 state:re…

…solved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information...
1 parent 8056c57 commit d1202cfeb2cc7961c93a33ef3f5622d5393186f1 @rizwanreza rizwanreza committed with lifo Aug 9, 2009
Showing with 28 additions and 3 deletions.
  1. +11 −3 actionpack/lib/action_view/helpers/text_helper.rb
  2. +17 −0 actionpack/test/template/text_helper_test.rb
View
14 actionpack/lib/action_view/helpers/text_helper.rb
@@ -235,12 +235,20 @@ def word_wrap(text, *args)
#
# textilize("Visit the Rails website "here":http://www.rubyonrails.org/.)
# # => "<p>Visit the Rails website <a href="http://www.rubyonrails.org/">here</a>.</p>"
- def textilize(text)
+ #
+ # textilize("This is worded <strong>strongly</strong>")
+ # # => "<p>This is worded <strong>strongly</strong></p>"
+ #
+ # textilize("This is worded <strong>strongly</strong>", :filter_html)
+ # # => "<p>This is worded &lt;strong&gt;strongly&lt;/strong&gt;</p>"
+ #
+ def textilize(text, *options)
+ options ||= [:hard_breaks]
+
if text.blank?
""
else
- textilized = RedCloth.new(text, [ :hard_breaks ])
- textilized.hard_breaks = true if textilized.respond_to?(:hard_breaks=)
+ textilized = RedCloth.new(text, options)
textilized.to_html
end
end
View
17 actionpack/test/template/text_helper_test.rb
@@ -1,5 +1,6 @@
require 'abstract_unit'
require 'testing_sandbox'
+require 'redcloth'
class TextHelperTest < ActionView::TestCase
tests ActionView::Helpers::TextHelper
@@ -517,4 +518,20 @@ def test_cycle_no_instance_variable_clashes
assert_equal("red", cycle("red", "blue"))
assert_equal(%w{Specialized Fuji Giant}, @cycles)
end
+
+ def test_textilize
+ assert_equal("<p><strong>This is Textile!</strong> Rejoice!</p>", textilize("*This is Textile!* Rejoice!"))
+ end
+
+ def test_textilize_with_blank
+ assert_equal("", textilize(""))
+ end
+
+ def test_textilize_with_options
+ assert_equal("<p>This is worded &lt;strong&gt;strongly&lt;/strong&gt;</p>", textilize("This is worded <strong>strongly</strong>", :filter_html))
+ end
+
+ def test_textilize_with_hard_breaks
+ assert_equal("<p>This is one scary world.<br />\n True.</p>", textilize("This is one scary world.\n True."))
+ end
end

0 comments on commit d1202cf

Please sign in to comment.
Something went wrong with that request. Please try again.