Module: ReleaseHelper

Included in:
ReleasesController
Defined in:
app/helpers/release_helper.rb

Instance Method Summary collapse

Instance Method Details

#_format_time_ago(time) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/helpers/release_helper.rb', line 31

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



50
51
52
# File 'app/helpers/release_helper.rb', line 50

def format_change(change)
  mdown change.description
end

#format_change_tag(tag) ⇒ Object



54
55
56
# File 'app/helpers/release_helper.rb', line 54

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



22
23
24
# File 'app/helpers/release_helper.rb', line 22

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_release_description(release) ⇒ Object



11
12
13
14
15
16
# File 'app/helpers/release_helper.rb', line 11

def format_release_description(release)
  ordered_by_tag(release.release_changes)
    .map { |change| "#{change.tag.name.upcase}&nbsp;&nbsp;&nbsp;#{change.description}" }
    .join("\r\n")
    .html_safe
end

#format_release_subject(release) ⇒ Object



7
8
9
# File 'app/helpers/release_helper.rb', line 7

def format_release_subject(release)
  release.date.strftime("%b %e, %Y • ") + release.released_at.strftime("%-I:%M%p").downcase
end

#format_time_ago(time) ⇒ Object



26
27
28
29
# File 'app/helpers/release_helper.rb', line 26

def format_time_ago(time)
  return "&mdash;".html_safe unless time
  "<span class=\"friendly-duration\">#{_format_time_ago(time)}</span>".html_safe
end

#ordered_by_tag(changes) ⇒ Object



18
19
20
# File 'app/helpers/release_helper.rb', line 18

def ordered_by_tag(changes)
  changes.sort_by { |change| change.tag ? change.tag.position : 99 }
end

#replace_quotes(string) ⇒ Object



46
47
48
# File 'app/helpers/release_helper.rb', line 46

def replace_quotes(string)
  h(string).gsub(/&quot;(.+?)&quot;/, '<code>\1</code>').html_safe
end