Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

time_tag support for blocks

  • Loading branch information...
commit 05406442b81be49154737d763fc65c7fb0f03608 1 parent 2b5cb1c
@atd atd authored
View
9 actionpack/lib/action_view/helpers/date_helper.rb
@@ -625,13 +625,18 @@ def select_year(date, options = {}, html_options = {})
# 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
View
4 actionpack/test/template/date_helper_test.rb
@@ -2865,6 +2865,10 @@ def test_time_tag_with_given_text
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>"
Please sign in to comment.
Something went wrong with that request. Please try again.