Module: NdrUi::TimeagoHelper
- Includes:
- CssHelper
- Defined in:
- app/helpers/ndr_ui/timeago_helper.rb
Overview
Provides helper methods for the jQuery Timeago plugin
Instance Method Summary collapse
-
#timeago_tag(date_or_time, options = {}) ⇒ Object
Returns an timeago tag for the given date or time.
Methods included from CssHelper
Instance Method Details
#timeago_tag(date_or_time, options = {}) ⇒ Object
Returns an timeago tag for the given date or time. By default it returns an HTML 5 time element, but to return a legacy microformat abbr element set the :html5
key to false in the options
.
timeago_tag Date.today # =>
<time datetime="2016-08-16" class="timeago">August 16, 2016</time>
timeago_tag Time.now # =>
<time datetime="2016-08-16T15:21:16+01:00" class="timeago">August 16, 2016 15:21</time>
timeago_tag Date.today, pubdate: true # =>
<time datetime="2016-08-16" pubdate="pubdate" class="timeago">August 16, 2016</time>
timeago_tag Date.today, class: 'apples' # =>
<time datetime="2016-08-16" class="timeago apples">August 16, 2016</time>
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/helpers/ndr_ui/timeago_helper.rb', line 20 def timeago_tag(date_or_time, = {}) return if date_or_time.nil? = (, %w(timeago)) html5 = true unless .delete(:html5) == false content = I18n.l(date_or_time, format: :long) = date_or_time.iso8601 if html5 content_tag('time', content, .reverse_merge(datetime: )) else content_tag('abbr', content, .reverse_merge(title: )) end end |