aboutsummaryrefslogtreecommitdiff
blob: 619582ce5abe8ccd64c81de9e78b5e8129997cf2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
module ApplicationHelper
  def cp_to_atom(category, package)
    '%s/%s' % [category, package]
  end

  def atom_add_version(atom, version)
    '%s-%s' % [atom, version]
  end

  # Generates a somewhat sensible atom ID
  def atom_id(*args)
    ['tag:packages.gentoo.org,2015-10-03', args].flatten.compact.join ':'
  end

  def alternate_feed_link(url, description, mime = 'application/atom+xml')
    tag :link,
        rel: 'alternate',
        href: url,
        title: description,
        type: mime
  end

  # Renders a label displaying the first letters of the components of a string
  def abbreviated_label(items, css_class, message_id)
    return '' if items.nil? || items.empty?

    letters = strip_conditionals(items).map { |r| r[0].upcase }.uniq

    content_tag :span,
                letters.join(', '),
                class: 'label %s' % css_class,
                title: t(message_id, list: items.join(' '))
  end

  def last_import_start
    Rails.cache.fetch(::KK_CACHE_LAST_IMPORT)
  end

  def i18n_date(date, format = '%a, %e %b %Y %H:%M')
    content_tag :span,
                l(date, format: format),
                class: 'kk-i18n-date',
                :'data-utcts' => date.strftime('%s'),
                :'data-format' => format.to_s,
                title: date.to_formatted_s(:rfc822)
  end

  def kk_changelog
    File.read('CHANGES.md')
  end
end