Module: Megatron::TimeHelper

Defined in:
app/helpers/megatron/time_helper.rb

Instance Method Summary collapse

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, options={})
  options[:timeago] = true
  options[:class] = 'timeago has-tooltip'
  options[:data] ||= {}
  options[:data]['timeago-style'] = options.delete(:timeago_style) || 'long'
  options['aria-label'] = date.sub('T',' ').sub('+00:00', ' UTC')
  
  time_tag(date, options)
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, options={})
  iso_date = DateTime.parse(date.to_s).new_offset(0).iso8601

  options[:datetime] = iso_date

  icon = use_svg(options.delete(:icon)) if options[:icon]
  
  unless options.delete(:toggle) || options.delete(:timeago)
    options[:class] = 'has-tooltip'
    options['aria-label'] = time_ago_in_words(iso_date) + ' ago'
  end

  (:time, options) {
    concat (: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, options={})
  date = DateTime.parse(date.to_s).iso8601

  options[:class] = 'timeago'

  options[:data] ||= {}
  options[:data]['timeago-style'] = options.delete(:timeago_style)

  (:time, options) { 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, options={})
  options[:toggle] = true
  options[:class] = 'time-toggle'
  options[:data] ||= {}
  options[:data]['timeago'] = options.delete(:timeago_style) || 'long'
  options[:icon] = 'sync-circle'

  (:span, class: 'time-wrapper') {
    time_tag(date, options)
  }
end