From e4915e1796db6e990a149e2ad760d393342449a8 Mon Sep 17 00:00:00 2001 From: Brian Cardarella Date: Sun, 5 Feb 2012 12:08:21 -0500 Subject: [PATCH] Highlight defaults to HTML5 `mark` element --- actionpack/CHANGELOG.md | 3 +++ .../lib/action_view/helpers/text_helper.rb | 8 +++---- actionpack/test/template/text_helper_test.rb | 24 +++++++++---------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 8922a4ac32..3487c96414 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -73,6 +73,9 @@ * `favicon_link_tag` helper will now use the favicon in app/assets by default. *Lucas Caton* +* `ActionView::Helpers::TextHelper#highlight` now defaults to the + HTML5 `mark` element. *Brian Cardarella* + ## Rails 3.2.0 (January 20, 2012) ## * Add `config.action_dispatch.default_charset` to configure default charset for ActionDispatch::Response. *Carlos Antonio da Silva* diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index ce79a3da48..3dc651501e 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -90,11 +90,11 @@ module ActionView # Highlights one or more +phrases+ everywhere in +text+ by inserting it into # a :highlighter string. The highlighter can be specialized by passing :highlighter # as a single-quoted string with \1 where the phrase is to be inserted (defaults to - # '\1') + # '\1') # # ==== Examples # highlight('You searched for: rails', 'rails') - # # => You searched for: rails + # # => You searched for: rails # # highlight('You searched for: ruby, rails, dhh', 'actionpack') # # => You searched for: ruby, rails, dhh @@ -111,9 +111,9 @@ module ActionView def highlight(text, phrases, *args) options = args.extract_options! unless args.empty? - options[:highlighter] = args[0] || '\1' + options[:highlighter] = args[0] || '\1' end - options.reverse_merge!(:highlighter => '\1') + options.reverse_merge!(:highlighter => '\1') text = sanitize(text) unless options[:sanitize] == false if text.blank? || phrases.blank? diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb index aa185d9cb0..5865b7f23c 100644 --- a/actionpack/test/template/text_helper_test.rb +++ b/actionpack/test/template/text_helper_test.rb @@ -91,12 +91,12 @@ class TextHelperTest < ActionView::TestCase def test_highlight assert_equal( - "This is a beautiful morning", + "This is a beautiful morning", highlight("This is a beautiful morning", "beautiful") ) assert_equal( - "This is a beautiful morning, but also a beautiful day", + "This is a beautiful morning, but also a beautiful day", highlight("This is a beautiful morning, but also a beautiful day", "beautiful") ) @@ -115,31 +115,31 @@ class TextHelperTest < ActionView::TestCase def test_highlight_should_sanitize_input assert_equal( - "This is a beautiful morning", + "This is a beautiful morning", highlight("This is a beautiful morning", "beautiful") ) end def test_highlight_should_not_sanitize_if_sanitize_option_if_false assert_equal( - "This is a beautiful morning", + "This is a beautiful morning", highlight("This is a beautiful morning", "beautiful", :sanitize => false) ) end def test_highlight_with_regexp assert_equal( - "This is a beautiful! morning", + "This is a beautiful! morning", highlight("This is a beautiful! morning", "beautiful!") ) assert_equal( - "This is a beautiful! morning", + "This is a beautiful! morning", highlight("This is a beautiful! morning", "beautiful! morning") ) assert_equal( - "This is a beautiful? morning", + "This is a beautiful? morning", highlight("This is a beautiful? morning", "beautiful? morning") ) end @@ -157,23 +157,23 @@ class TextHelperTest < ActionView::TestCase def test_highlight_with_html assert_equal( - "

This is a beautiful morning, but also a beautiful day

", + "

This is a beautiful morning, but also a beautiful day

", highlight("

This is a beautiful morning, but also a beautiful day

", "beautiful") ) assert_equal( - "

This is a beautiful morning, but also a beautiful day

", + "

This is a beautiful morning, but also a beautiful day

", highlight("

This is a beautiful morning, but also a beautiful day

", "beautiful") ) assert_equal( - "

This is a beautiful morning, but also a beautiful day

", + "

This is a beautiful morning, but also a beautiful day

", highlight("

This is a beautiful morning, but also a beautiful day

", "beautiful") ) assert_equal( - "

This is a beautiful morning, but also a beautiful day

", + "

This is a beautiful morning, but also a beautiful day

", highlight("

This is a beautiful morning, but also a beautiful day

", "beautiful") ) assert_equal( - "

This is a beautiful morning, but also a beautiful day

", + "

This is a beautiful morning, but also a beautiful day

", highlight("

This is a beautiful morning, but also a beautiful day

", "beautiful") ) assert_equal(