Module: ApplicationHelper
- Defined in:
- app/helpers/application_helper.rb
Constant Summary collapse
Instance Method Summary collapse
- #_format_time_ago(time) ⇒ Object
- #custom_link_unless_current(link_text, url) ⇒ Object
- #follows?(project) ⇒ Boolean
- #format_boolean(boolean) ⇒ Object
- #format_date_with_year(date) ⇒ Object
- #format_duration(seconds) ⇒ Object
- #format_duration_with_units(quantity, unit) ⇒ Object
- #format_time(time, options = {}) ⇒ Object
- #format_time_ago(time) ⇒ Object
- #google_analytics_script_tag ⇒ Object
- #header {|PageHeaderBuilder.new(self)| ... } ⇒ Object
- #html_safe(html) ⇒ Object
- #in_columns(collection, options = {}, &block) ⇒ Object
- #in_groups_of(collection, column_count, css_class = "column") ⇒ Object (also: #in_columns_of)
- #revision ⇒ Object
- #title ⇒ Object
Instance Method Details
#_format_time_ago(time) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'app/helpers/application_helper.rb', line 120 def _format_time_ago(time) duration = (Time.now - time).to_i return "#{duration} seconds ago" if duration < 90.seconds return "#{duration / 60} minutes ago" if duration < 90.minutes return "%.1f hours ago" % (duration / 3600.0) if duration < 20.hours days = (duration / 86400.0).round return "1 day ago" if days == 1 return "#{days} days ago" if days < 21 return "#{days / 7} weeks ago" if days < 63 return "#{days / 30} months ago" if days < 456 return ">1 year ago" if days < 730 return ">#{days / 365} years ago" end |
#custom_link_unless_current(link_text, url) ⇒ Object
20 21 22 |
# File 'app/helpers/application_helper.rb', line 20 def custom_link_unless_current(link_text, url) "<li>#{link_to(link_text, url)}</li>".html_safe unless current_page?(url) end |
#follows?(project) ⇒ Boolean
144 145 146 |
# File 'app/helpers/application_helper.rb', line 144 def follows?(project) followed_projects.member?(project) end |
#format_boolean(boolean) ⇒ Object
81 82 83 84 85 86 87 |
# File 'app/helpers/application_helper.rb', line 81 def format_boolean(boolean) if boolean '<i class="fa fa-check success"></i>'.html_safe else '<i class="fa fa-times failure"></i>'.html_safe end end |
#format_date_with_year(date) ⇒ Object
137 138 139 140 |
# File 'app/helpers/application_helper.rb', line 137 def format_date_with_year(date) return "" if date.nil? "#{date.strftime("%b %d")}<span class=\"year\">#{date.strftime("%Y")}</span>".html_safe end |
#format_duration(seconds) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'app/helpers/application_helper.rb', line 93 def format_duration(seconds) if seconds.nil? return "—".html_safe elsif seconds < 1 "#{(seconds * 1000).floor}ms" elsif seconds < MINUTE "%.2f seconds" % seconds elsif seconds < HOUR format_duration_with_units(seconds / MINUTE, 'minute') elsif seconds < DAY format_duration_with_units(seconds / HOUR, 'hour') else format_duration_with_units(seconds / DAY, 'day') end end |
#format_duration_with_units(quantity, unit) ⇒ Object
109 110 111 112 113 |
# File 'app/helpers/application_helper.rb', line 109 def format_duration_with_units(quantity, unit) quantity = quantity.floor unit << 's' unless quantity == 1 "#{quantity} #{unit}" end |
#format_time(time, options = {}) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/helpers/application_helper.rb', line 64 def format_time(time, ={}) if time.nil? date, time = ["", "Never"] elsif time.to_date == Date.today date, time = [[:today] ? "Today" : "", time.strftime("%l:%M %p")] elsif time.to_date == Date.today - 1 date, time = ["Yesterday", time.strftime("%l:%M %p")] else date, time = [time.strftime("%b %e"), time.strftime("%l:%M %p")] end <<-HTML.strip.html_safe <span class="time-date">#{date}</span> <span class="time-time">#{time.gsub(" AM", "a").gsub(" PM", "p")}</span> HTML end |
#format_time_ago(time) ⇒ Object
115 116 117 118 |
# File 'app/helpers/application_helper.rb', line 115 def format_time_ago(time) return "—".html_safe unless time "<span class=\"friendly-duration\">#{_format_time_ago(time)}</span>".html_safe end |
#google_analytics_script_tag ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/helpers/application_helper.rb', line 24 def google_analytics_script_tag id = Houston.config.google_analytics[:tracking_id] return nil if id.blank? return "<!-- Google Analytics for #{id.inspect} in Production -->".html_safe unless Rails.env.production? <<-HTML.html_safe <script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); ga('create', #{id.inspect}, 'auto'); ga('send', 'pageview'); </script> HTML end |
#header {|PageHeaderBuilder.new(self)| ... } ⇒ Object
15 16 17 18 |
# File 'app/helpers/application_helper.rb', line 15 def header yield PageHeaderBuilder.new(self) "<hr class=\"clear\" />".html_safe end |
#html_safe(html) ⇒ Object
11 12 13 |
# File 'app/helpers/application_helper.rb', line 11 def html_safe(html) html.html_safe end |
#in_columns(collection, options = {}, &block) ⇒ Object
42 43 44 45 46 47 |
# File 'app/helpers/application_helper.rb', line 42 def in_columns(collection, ={}, &block) max_size = .fetch(:max_size, 10) column_count = (collection.length.to_f / max_size).ceil column_count = 1 if column_count < 1 in_columns_of(collection, column_count, &block) end |
#in_groups_of(collection, column_count, css_class = "column") ⇒ Object Also known as: in_columns_of
49 50 51 52 53 54 55 56 57 58 |
# File 'app/helpers/application_helper.rb', line 49 def in_groups_of(collection, column_count, css_class="column") html = collection.in_groups_of(column_count).each_with_object("") do |items_in_column, html| html << "<div class=\"#{css_class}\">" items_in_column.compact.each do |item| html << capture { yield (item) } end html << "</div>" end html.html_safe end |
#revision ⇒ Object
7 8 9 |
# File 'app/helpers/application_helper.rb', line 7 def revision controller.revision end |