aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorMichael Koziarski <michael@koziarski.com>2006-10-14 00:31:30 +0000
committerMichael Koziarski <michael@koziarski.com>2006-10-14 00:31:30 +0000
commit81ddeadd4962f110d51a073a270c844407222593 (patch)
tree7c2ff92d6132fd9d9d8234c51e1c0970e3aa373c /actionpack
parentd73f32ce0004ddb1a8470ed50c9f8323ebc5613f (diff)
downloadrails-81ddeadd4962f110d51a073a270c844407222593.tar.gz
rails-81ddeadd4962f110d51a073a270c844407222593.tar.bz2
rails-81ddeadd4962f110d51a073a270c844407222593.zip
Replace KCODE checks with String#chars for truncate. Closes #6385 [Manfred Stienstra]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5300 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_view/helpers/text_helper.rb9
-rw-r--r--actionpack/test/template/text_helper_test.rb4
3 files changed, 6 insertions, 9 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index f099513766..f24bd1e214 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Replace KCODE checks with String#chars for truncate. Closes #6385 [Manfred Stienstra]
+
* Make page caching respect the format of the resource that is being requested even if the current route is the default route so that, e.g. posts.rss is not transformed by url_for to '/' and subsequently cached as '/index.html' when it should be cached as '/posts.rss'. [Marcel Molina Jr.]
* Use String#chars in TextHelper::excerpt. Closes #6386 [Manfred Stienstra]
diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb
index 0e142cbaff..33d86441ef 100644
--- a/actionpack/lib/action_view/helpers/text_helper.rb
+++ b/actionpack/lib/action_view/helpers/text_helper.rb
@@ -20,13 +20,8 @@ module ActionView
# if the +text+ is longer than +length+.
def truncate(text, length = 30, truncate_string = "...")
if text.nil? then return end
- l = length - truncate_string.length
- if $KCODE == "NONE"
- text.length > length ? text[0...l] + truncate_string : text
- else
- chars = text.split(//)
- chars.length > length ? chars[0...l].join + truncate_string : text
- end
+ l = length - truncate_string.chars.length
+ text.chars.length > length ? text.chars[0...l] + truncate_string : text
end
# Highlights the +phrase+ where it is found in the +text+ by surrounding it like
diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb
index dd127cde66..8649798bc3 100644
--- a/actionpack/test/template/text_helper_test.rb
+++ b/actionpack/test/template/text_helper_test.rb
@@ -29,8 +29,8 @@ class TextHelperTest < Test::Unit::TestCase
assert_equal "\354\225\210\353\205\225\355...", truncate("\354\225\210\353\205\225\355\225\230\354\204\270\354\232\224", 10)
end
with_kcode 'u' do
- assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254\353\236 ...",
- truncate("\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254\353\236 \354\225\204\353\235\274\353\246\254\354\230\244", 10)
+ assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...",
+ truncate("\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244", 10)
end
end