From 9f27e1076ac6aacb33b0f4ee0e940c2a90f1c630 Mon Sep 17 00:00:00 2001 From: Lucas Mazza Date: Thu, 19 Jun 2014 14:58:36 -0300 Subject: 'TextHelper#highlight' now accepts a block to highlight the matched words. The helper will yield each matched word, and you can use this instead of the ':highlighter' option for more complex replacing logic: highlight('My email is me@work.com', EMAIL_REGEXP) { |m| mail_to(m) } # => 'My email is me@work.com' --- actionview/test/template/text_helper_test.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'actionview/test/template') diff --git a/actionview/test/template/text_helper_test.rb b/actionview/test/template/text_helper_test.rb index 2467c9527a..858232a2b9 100644 --- a/actionview/test/template/text_helper_test.rb +++ b/actionview/test/template/text_helper_test.rb @@ -265,6 +265,13 @@ class TextHelperTest < ActionView::TestCase assert_equal options, passed_options end + def test_highlight_with_block + assert_equal( + "one two three", + highlight("one two three", ["one", "two", "three"]) { |word| "#{word}" } + ) + end + def test_excerpt assert_equal("...is a beautiful morn...", excerpt("This is a beautiful morning", "beautiful", :radius => 5)) assert_equal("This is a...", excerpt("This is a beautiful morning", "this", :radius => 5)) -- cgit v1.2.3