提交 0c18fafc 编写于 作者: J José Valim

Merge pull request #5496 from atd/master

time_tag support for blocks
......@@ -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
......
......@@ -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>"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册