aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/CHANGELOG.md2
-rw-r--r--actionpack/lib/action_view/helpers/text_helper.rb9
-rw-r--r--actionpack/test/template/text_helper_test.rb81
3 files changed, 56 insertions, 36 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md
index 0e778eb01d..5bb5176083 100644
--- a/actionpack/CHANGELOG.md
+++ b/actionpack/CHANGELOG.md
@@ -1,5 +1,7 @@
## Rails 3.2.4 (unreleased) ##
+* Deprecate old APIs for highlight, excerpt and word_wrap *Jeremy Walker*
+
* Deprecate `:disable_with` in favor of `'data-disable-with'` option for `button_to`, `button_tag` and `submit_tag` helpers.
*Carlos Galdino + Rafael Mendonça França*
diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb
index 209360ee82..1834b88532 100644
--- a/actionpack/lib/action_view/helpers/text_helper.rb
+++ b/actionpack/lib/action_view/helpers/text_helper.rb
@@ -111,6 +111,9 @@ module ActionView
def highlight(text, phrases, *args)
options = args.extract_options!
unless args.empty?
+ ActiveSupport::Deprecation.warn "Calling highlight with a highlighter as an argument is deprecated. " \
+ "Please call with :highlighter => '#{args[0]}' instead.", caller
+
options[:highlighter] = args[0] || '<strong class="highlight">\1</strong>'
end
options.reverse_merge!(:highlighter => '<strong class="highlight">\1</strong>')
@@ -156,6 +159,9 @@ module ActionView
options = args.extract_options!
unless args.empty?
+ ActiveSupport::Deprecation.warn "Calling excerpt with radius and omission as arguments is deprecated. " \
+ "Please call with :radius => #{args[0]}#{", :omission => '#{args[1]}'" if args[1]} instead.", caller
+
options[:radius] = args[0] || 100
options[:omission] = args[1] || "..."
end
@@ -217,6 +223,9 @@ module ActionView
def word_wrap(text, *args)
options = args.extract_options!
unless args.blank?
+ ActiveSupport::Deprecation.warn "Calling word_wrap with line_width as an argument is deprecated. " \
+ "Please call with :line_width => #{args[0]} instead.", caller
+
options[:line_width] = args[0] || 80
end
options.reverse_merge!(:line_width => 80)
diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb
index a0afb77f05..182cf786d5 100644
--- a/actionpack/test/template/text_helper_test.rb
+++ b/actionpack/test/template/text_helper_test.rb
@@ -120,7 +120,7 @@ class TextHelperTest < ActionView::TestCase
assert_equal(
"This is a <b>beautiful</b> morning, but also a <b>beautiful</b> day",
- highlight("This is a beautiful morning, but also a beautiful day", "beautiful", '<b>\1</b>')
+ highlight("This is a beautiful morning, but also a beautiful day", "beautiful", :highlighter => '<b>\1</b>')
)
assert_equal(
@@ -130,6 +130,12 @@ class TextHelperTest < ActionView::TestCase
assert_equal ' ', highlight(' ', 'blank text is returned verbatim')
end
+
+ def test_highlight_old_api_is_depcrecated
+ assert_deprecated("Calling highlight with a highlighter as an argument is deprecated. Please call with :highlighter => '<mark>\\1</mark>' instead.") do
+ highlight("This is a beautiful morning", "beautiful", '<mark>\1</mark>')
+ end
+ end
def test_highlight_should_sanitize_input
assert_equal(
@@ -163,14 +169,7 @@ class TextHelperTest < ActionView::TestCase
end
def test_highlight_with_multiple_phrases_in_one_pass
- assert_equal %(<em>wow</em> <em>em</em>), highlight('wow em', %w(wow em), '<em>\1</em>')
- end
-
- def test_highlight_with_options_hash
- assert_equal(
- "This is a <b>beautiful</b> morning, but also a <b>beautiful</b> day",
- highlight("This is a beautiful morning, but also a beautiful day", "beautiful", :highlighter => '<b>\1</b>')
- )
+ assert_equal %(<em>wow</em> <em>em</em>), highlight('wow em', %w(wow em), :highlighter => '<em>\1</em>')
end
def test_highlight_with_html
@@ -201,40 +200,48 @@ class TextHelperTest < ActionView::TestCase
end
def test_excerpt
- assert_equal("...is a beautiful morn...", excerpt("This is a beautiful morning", "beautiful", 5))
- assert_equal("This is a...", excerpt("This is a beautiful morning", "this", 5))
- assert_equal("...iful morning", excerpt("This is a beautiful morning", "morning", 5))
+ 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))
+ assert_equal("...iful morning", excerpt("This is a beautiful morning", "morning", :radius => 5))
assert_nil excerpt("This is a beautiful morning", "day")
end
+
+ def test_excerpt_old_api_is_depcrecated
+ assert_deprecated("Calling excerpt with radius and omission as arguments is deprecated. Please call with :radius => 5 instead.") do
+ excerpt("This is a beautiful morning", "morning", 5)
+ end
+ assert_deprecated("Calling excerpt with radius and omission as arguments is deprecated. Please call with :radius => 5, :omission => 'mor' instead.") do
+ excerpt("This is a beautiful morning", "morning", 5, "mor")
+ end
+ end
def test_excerpt_should_not_be_html_safe
- assert !excerpt('This is a beautiful! morning', 'beautiful', 5).html_safe?
+ assert !excerpt('This is a beautiful! morning', 'beautiful', :radius => 5).html_safe?
end
def test_excerpt_in_borderline_cases
- assert_equal("", excerpt("", "", 0))
- assert_equal("a", excerpt("a", "a", 0))
- assert_equal("...b...", excerpt("abc", "b", 0))
- assert_equal("abc", excerpt("abc", "b", 1))
- assert_equal("abc...", excerpt("abcd", "b", 1))
- assert_equal("...abc", excerpt("zabc", "b", 1))
- assert_equal("...abc...", excerpt("zabcd", "b", 1))
- assert_equal("zabcd", excerpt("zabcd", "b", 2))
+ assert_equal("", excerpt("", "", :radius => 0))
+ assert_equal("a", excerpt("a", "a", :radius => 0))
+ assert_equal("...b...", excerpt("abc", "b", :radius => 0))
+ assert_equal("abc", excerpt("abc", "b", :radius => 1))
+ assert_equal("abc...", excerpt("abcd", "b", :radius => 1))
+ assert_equal("...abc", excerpt("zabc", "b", :radius => 1))
+ assert_equal("...abc...", excerpt("zabcd", "b", :radius => 1))
+ assert_equal("zabcd", excerpt("zabcd", "b", :radius => 2))
# excerpt strips the resulting string before ap-/prepending excerpt_string.
# whether this behavior is meaningful when excerpt_string is not to be
# appended is questionable.
- assert_equal("zabcd", excerpt(" zabcd ", "b", 4))
- assert_equal("...abc...", excerpt("z abc d", "b", 1))
+ assert_equal("zabcd", excerpt(" zabcd ", "b", :radius => 4))
+ assert_equal("...abc...", excerpt("z abc d", "b", :radius => 1))
end
def test_excerpt_with_regex
- assert_equal('...is a beautiful! mor...', excerpt('This is a beautiful! morning', 'beautiful', 5))
- assert_equal('...is a beautiful? mor...', excerpt('This is a beautiful? morning', 'beautiful', 5))
+ assert_equal('...is a beautiful! mor...', excerpt('This is a beautiful! morning', 'beautiful', :radius => 5))
+ assert_equal('...is a beautiful? mor...', excerpt('This is a beautiful? morning', 'beautiful', :radius => 5))
end
- def test_excerpt_with_options_hash
- assert_equal("...is a beautiful morn...", excerpt("This is a beautiful morning", "beautiful", :radius => 5))
+ def test_excerpt_with_omission
assert_equal("[...]is a beautiful morn[...]", excerpt("This is a beautiful morning", "beautiful", :omission => "[...]",:radius => 5))
assert_equal(
"This is the ultimate supercalifragilisticexpialidoceous very looooooooooooooooooong looooooooooooong beautiful morning with amazing sunshine and awesome tempera[...]",
@@ -246,30 +253,32 @@ class TextHelperTest < ActionView::TestCase
if RUBY_VERSION < '1.9'
def test_excerpt_with_utf8
with_kcode('u') do
- assert_equal("...\357\254\203ciency could not be...", excerpt("That's why e\357\254\203ciency could not be helped", 'could', 8))
+ assert_equal("...\357\254\203ciency could not be...", excerpt("That's why e\357\254\203ciency could not be helped", 'could', :line_width => 8))
end
with_kcode('none') do
- assert_equal("...\203ciency could not be...", excerpt("That's why e\357\254\203ciency could not be helped", 'could', 8))
+ assert_equal("...\203ciency could not be...", excerpt("That's why e\357\254\203ciency could not be helped", 'could', :line_width => 8))
end
end
else
def test_excerpt_with_utf8
- assert_equal("...\357\254\203ciency could not be...".force_encoding('UTF-8'), excerpt("That's why e\357\254\203ciency could not be helped".force_encoding('UTF-8'), 'could', 8))
+ assert_equal("...\357\254\203ciency could not be...".force_encoding('UTF-8'), excerpt("That's why e\357\254\203ciency could not be helped".force_encoding('UTF-8'), 'could', :radius => 8))
# .mb_chars always returns UTF-8, even in 1.9. This is not great, but it's how it works. Let's work this out.
# assert_equal("...\203ciency could not be...", excerpt("That's why e\357\254\203ciency could not be helped".force_encoding("BINARY"), 'could', 8))
end
end
def test_word_wrap
- assert_equal("my very very\nvery long\nstring", word_wrap("my very very very long string", 15))
+ assert_equal("my very very\nvery long\nstring", word_wrap("my very very very long string", :line_width => 15))
end
-
- def test_word_wrap_with_extra_newlines
- assert_equal("my very very\nvery long\nstring\n\nwith another\nline", word_wrap("my very very very long string\n\nwith another line", 15))
+
+ def test_word_wrap_old_api_is_depcrecated
+ assert_deprecated("Calling word_wrap with line_width as an argument is deprecated. Please call with :line_width => 15 instead.") do
+ word_wrap("my very very very long string", 15)
+ end
end
- def test_word_wrap_with_options_hash
- assert_equal("my very very\nvery long\nstring", word_wrap("my very very very long string", :line_width => 15))
+ def test_word_wrap_with_extra_newlines
+ assert_equal("my very very\nvery long\nstring\n\nwith another\nline", word_wrap("my very very very long string\n\nwith another line", :line_width => 15))
end
def test_pluralization