Module: Tungsten::ContentHelper

Defined in:
app/helpers/tungsten/content_helper.rb

Instance Method Summary collapse

Instance Method Details

#app_nav(&block) ⇒ Object

Set custom top navigation for app links



20
21
22
# File 'app/helpers/tungsten/content_helper.rb', line 20

def app_nav(&block)
  content_for :app_nav, &block
end

#description(description = nil) ⇒ Object

Set custom page meta description



35
36
37
# File 'app/helpers/tungsten/content_helper.rb', line 35

def description(description = nil)
  description ? content_for(:description) { description } : content_for(:description).presence
end

#drawer(id, options = {}, &block) ⇒ Object



117
118
119
120
121
122
123
124
125
126
# File 'app/helpers/tungsten/content_helper.rb', line 117

def drawer(id, options = {}, &block)
  options[:id] = id
  options[:hidden] = true if options[:hidden].nil?
  options[:data] ||= {}
  options[:data][:animate] ||= options.delete(:animate)
  options[:class] = "#{options[:class]} #{"hidden" if options.delete(:hidden)}".strip
  options.delete(:hidden)

  (options.delete(:tag) || :div, options, &block )
end

#favicon(&block) ⇒ Object

Set custom favicon



5
6
7
# File 'app/helpers/tungsten/content_helper.rb', line 5

def favicon(&block)
  content_for :favicon, &block
end

Blank slate layout



25
26
27
# File 'app/helpers/tungsten/content_helper.rb', line 25

def footer(&block)
  content_for :footer, &block
end

#human_title(input) ⇒ Object



48
49
50
# File 'app/helpers/tungsten/content_helper.rb', line 48

def human_title(input)
  input.to_s.humanize.titlecase
end

#iso_date_string(date) ⇒ Object



101
102
103
# File 'app/helpers/tungsten/content_helper.rb', line 101

def iso_date_string(date)
  parse_date(date).sub('T', ' ').sub('+00:00', ' UTC')
end

#keywords(keywords = nil) ⇒ Object

Set custom page meta keywords



40
41
42
# File 'app/helpers/tungsten/content_helper.rb', line 40

def keywords(keywords = nil)
  keywords ? content_for(:keywords) { keywords } : content_for(:keywords).presence
end

#logo(&block) ⇒ Object

Set custom logo



10
11
12
# File 'app/helpers/tungsten/content_helper.rb', line 10

def (&block)
  content_for :logo, &block
end

#parse_date(date) ⇒ Object



75
76
77
# File 'app/helpers/tungsten/content_helper.rb', line 75

def parse_date(date)
  DateTime.parse(date.to_s).new_offset(0).iso8601
end

#pin_tab_icon(path, color = 'black') ⇒ Object



44
45
46
# File 'app/helpers/tungsten/content_helper.rb', line 44

def pin_tab_icon(path, color='black')
  %Q{<link rel="mask-icon" mask href="#{path}" color="#{color}">}.html_safe
end

#set_aria!(options, aria) ⇒ Object



128
129
130
131
132
133
134
135
# File 'app/helpers/tungsten/content_helper.rb', line 128

def set_aria!( options, aria )
  opts = {}
  aria.each do |key, val|
    opts["aria-#{key}"] = val
  end

  options.merge!(opts)
end

#time_ago_tag(date, options = {}) ⇒ Object



65
66
67
68
69
70
71
72
73
# File 'app/helpers/tungsten/content_helper.rb', line 65

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



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'app/helpers/tungsten/content_helper.rb', line 79

def time_tag(date, options={})
  iso_date = parse_date(date)

  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



105
106
107
108
109
110
111
112
113
114
# File 'app/helpers/tungsten/content_helper.rb', line 105

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

#title(title = nil) ⇒ Object

Set custom page title



30
31
32
# File 'app/helpers/tungsten/content_helper.rb', line 30

def title(title = nil)
  title ? content_for(:title) { title + " | " + Site.name } : content_for(:title).presence
end

#toggle_time_tag(date, options = {}) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/helpers/tungsten/content_helper.rb', line 52

def toggle_time_tag(date, options={})
  options[:toggle] = true
  options[:class] = 'time-toggle'
  options[:data] ||= {}
  options[:data]['timeago'] = options.delete(:timeago_style) || 'long'
  options[:data][:mode] = options.delete(:start)
  options[:icon] = 'sync-circle'

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

#top_nav(&block) ⇒ Object

Set custom top navigation



15
16
17
# File 'app/helpers/tungsten/content_helper.rb', line 15

def top_nav(&block)
  content_for :top_nav, &block
end