Module: Tungsten::ContentHelper
- Defined in:
- app/helpers/tungsten/content_helper.rb
Instance Method Summary collapse
-
#app_nav(&block) ⇒ Object
Set custom top navigation for app links.
-
#description(description = nil) ⇒ Object
Set custom page meta description.
- #drawer(id, options = {}, &block) ⇒ Object
-
#favicon(&block) ⇒ Object
Set custom favicon.
-
#footer(&block) ⇒ Object
Blank slate layout.
- #human_title(input) ⇒ Object
- #iso_date_string(date) ⇒ Object
-
#keywords(keywords = nil) ⇒ Object
Set custom page meta keywords.
-
#logo(&block) ⇒ Object
Set custom logo.
- #parse_date(date) ⇒ Object
- #pin_tab_icon(path, color = 'black') ⇒ Object
- #set_aria!(options, aria) ⇒ Object
- #time_ago_tag(date, options = {}) ⇒ Object
- #time_tag(date, options = {}) ⇒ Object
- #timeago_tag(date, options = {}) ⇒ Object
-
#title(title = nil) ⇒ Object
Set custom page title.
- #toggle_time_tag(date, options = {}) ⇒ Object
-
#top_nav(&block) ⇒ Object
Set custom top navigation.
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, = {}, &block) [:id] = id [:hidden] = true if [:hidden].nil? [:data] ||= {} [:data][:animate] ||= .delete(:animate) [:class] = "#{[:class]} #{"hidden" if .delete(:hidden)}".strip .delete(:hidden) content_tag(.delete(:tag) || :div, , &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 |
#footer(&block) ⇒ Object
Blank slate layout
25 26 27 |
# File 'app/helpers/tungsten/content_helper.rb', line 25 def (&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 logo(&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!( , aria ) opts = {} aria.each do |key, val| opts["aria-#{key}"] = val end .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, ={}) [: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
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, ={}) iso_date = parse_date(date) [: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
105 106 107 108 109 110 111 112 113 114 |
# File 'app/helpers/tungsten/content_helper.rb', line 105 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 |
#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, ={}) [:toggle] = true [:class] = 'time-toggle' [:data] ||= {} [:data]['timeago'] = .delete(:timeago_style) || 'long' [:data][:mode] = .delete(:start) [:icon] = 'sync-circle' content_tag(:span, class: 'time-wrapper') { time_tag(date, ) } 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 |