Module: Megatron::TimeHelper
- Defined in:
- app/helpers/megatron/time_helper.rb
Instance Method Summary collapse
- #time_ago_tag(date, options = {}) ⇒ Object
- #time_tag(date, options = {}) ⇒ Object
- #timeago_tag(date, options = {}) ⇒ Object
- #toggle_time_tag(date, options = {}) ⇒ Object
Instance Method Details
#time_ago_tag(date, options = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'app/helpers/megatron/time_helper.rb', line 16 def time_ago_tag(date, ={}) [:timeago] = true [:class] = 'timeago has-tooltip' [:data] ||= {} [:data]['timeago-style'] = .delete(:timeago_style) || 'long' ['aria-label'] = date.sub('T',' ').sub('+00:00', ' UTC') time_tag(date, ) end |
#time_tag(date, options = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/helpers/megatron/time_helper.rb', line 26 def time_tag(date, ={}) iso_date = DateTime.parse(date.to_s).new_offset(0).iso8601 [:datetime] = iso_date icon = use_svg(.delete(:icon)) if [:icon] unless .delete(:toggle) || .delete(:timeago) [:class] = 'has-tooltip' ['aria-label'] = time_ago_in_words(iso_date) + ' ago' end content_tag(:time, ) { concat content_tag(:span, class: 'date-text') { ('<span class="date">' + iso_date.sub('T','</span> <span class="time">').sub('+00:00','</span> <span class="timezone">UTC</span>')).html_safe } concat ' ' concat icon } end |
#timeago_tag(date, options = {}) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'app/helpers/megatron/time_helper.rb', line 48 def timeago_tag(date, ={}) date = DateTime.parse(date.to_s).iso8601 [:class] = 'timeago' [:data] ||= {} [:data]['timeago-style'] = .delete(:timeago_style) content_tag(:time, ) { date } end |
#toggle_time_tag(date, options = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'app/helpers/megatron/time_helper.rb', line 4 def toggle_time_tag(date, ={}) [:toggle] = true [:class] = 'time-toggle' [:data] ||= {} [:data]['timeago'] = .delete(:timeago_style) || 'long' [:icon] = 'sync-circle' content_tag(:span, class: 'time-wrapper') { time_tag(date, ) } end |