Module: ReleaseHelper
- Defined in:
- app/helpers/release_helper.rb
Instance Method Summary collapse
- #_format_time_ago(time) ⇒ Object
- #format_change(change) ⇒ Object
- #format_change_tag(tag) ⇒ Object
- #format_release_age(release) ⇒ Object
- #format_release_date(date) ⇒ Object
- #format_time_ago(time) ⇒ Object
- #ordered_by_tag(changes) ⇒ Object
- #replace_quotes(string) ⇒ Object
Instance Method Details
#_format_time_ago(time) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/helpers/release_helper.rb', line 20 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 |
#format_change(change) ⇒ Object
39 40 41 |
# File 'app/helpers/release_helper.rb', line 39 def format_change(change) mdown change.description end |
#format_change_tag(tag) ⇒ Object
43 44 45 |
# File 'app/helpers/release_helper.rb', line 43 def format_change_tag(tag) "<div class=\"change-tag\" style=\"background-color: ##{tag.color};\">#{tag.name}</div>".html_safe end |
#format_release_age(release) ⇒ Object
11 12 13 |
# File 'app/helpers/release_helper.rb', line 11 def format_release_age(release) format_time_ago release && release.created_at end |
#format_release_date(date) ⇒ Object
3 4 5 |
# File 'app/helpers/release_helper.rb', line 3 def format_release_date(date) "<span class=\"weekday\">#{date.strftime("%A")}</span> #{date.strftime("%b %e, %Y")}".html_safe end |
#format_time_ago(time) ⇒ Object
15 16 17 18 |
# File 'app/helpers/release_helper.rb', line 15 def format_time_ago(time) return "—".html_safe unless time "<span class=\"friendly-duration\">#{_format_time_ago(time)}</span>".html_safe end |
#ordered_by_tag(changes) ⇒ Object
7 8 9 |
# File 'app/helpers/release_helper.rb', line 7 def ordered_by_tag(changes) changes.sort_by { |change| change.tag ? change.tag.position : 99 } end |
#replace_quotes(string) ⇒ Object
35 36 37 |
# File 'app/helpers/release_helper.rb', line 35 def replace_quotes(string) h(string).gsub(/"(.+?)"/, '<code>\1</code>').html_safe end |