diff options
author | Antonio Tapiador del Dujo <atapiador@dit.upm.es> | 2012-03-18 11:58:08 +0100 |
---|---|---|
committer | Antonio Tapiador del Dujo <atapiador@dit.upm.es> | 2012-03-18 12:07:51 +0100 |
commit | 05406442b81be49154737d763fc65c7fb0f03608 (patch) | |
tree | 19e1b66bb872556c7267a6101cfe1de7f3d70722 | |
parent | 2b5cb1cd41ea765ae665321236c83c9d0128636b (diff) | |
download | rails-05406442b81be49154737d763fc65c7fb0f03608.tar.gz rails-05406442b81be49154737d763fc65c7fb0f03608.tar.bz2 rails-05406442b81be49154737d763fc65c7fb0f03608.zip |
time_tag support for blocks
-rw-r--r-- | actionpack/lib/action_view/helpers/date_helper.rb | 9 | ||||
-rw-r--r-- | actionpack/test/template/date_helper_test.rb | 4 |
2 files changed, 11 insertions, 2 deletions
diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb index 2d37923825..ee9f0da9b8 100644 --- a/actionpack/lib/action_view/helpers/date_helper.rb +++ b/actionpack/lib/action_view/helpers/date_helper.rb @@ -625,13 +625,18 @@ module ActionView # time_tag Date.today, :pubdate => true # => # <time datetime="2010-11-04" pubdate="pubdate">November 04, 2010</time> # - def time_tag(date_or_time, *args) + # <%= time_tag Time.now do %> + # <span>Right now</span> + # <% end %> + # # => <time datetime="2010-11-04T17:55:45+01:00"><span>Right now</span></time> + # + def time_tag(date_or_time, *args, &block) options = args.extract_options! format = options.delete(:format) || :long content = args.first || I18n.l(date_or_time, :format => format) datetime = date_or_time.acts_like?(:time) ? date_or_time.xmlschema : date_or_time.rfc3339 - content_tag(:time, content, options.reverse_merge(:datetime => datetime)) + content_tag(:time, content, options.reverse_merge(:datetime => datetime), &block) end end diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb index 9e2f4ec347..1d934b153f 100644 --- a/actionpack/test/template/date_helper_test.rb +++ b/actionpack/test/template/date_helper_test.rb @@ -2865,6 +2865,10 @@ class DateHelperTest < ActionView::TestCase assert_match(/<time.*>Right now<\/time>/, time_tag(Time.now, 'Right now')) end + def test_time_tag_with_given_block + assert_match(/<time.*><span>Right now<\/span><\/time>/, time_tag(Time.now){ '<span>Right now</span>'.html_safe }) + end + def test_time_tag_with_different_format time = Time.now expected = "<time datetime=\"#{time.xmlschema}\">#{I18n.l(time, :format => :short)}</time>" |