Module: Katello::PackagesHelper

Defined in:
app/helpers/katello/packages_helper.rb

Instance Method Summary collapse

Instance Method Details

#changelog_changes(changes) ⇒ Object



48
49
50
51
52
53
54
# File 'app/helpers/katello/packages_helper.rb', line 48

def changelog_changes(changes)
  if (lines = changes.split(/\n/)).length > 10
    previewed_changelog(lines)
  else
    format_changelog_changes(changes)
  end
end

#format_changelog_changes(changes) ⇒ Object



3
4
5
# File 'app/helpers/katello/packages_helper.rb', line 3

def format_changelog_changes(changes)
  (h(changes).gsub(/\n/, "<br>")).html_safe
end

#format_changelog_date(date) ⇒ Object



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

def format_changelog_date(date)
  format_time(DateTime.strptime(date.to_s, "%s").to_date, format: :long)
end

#format_package_details(package) ⇒ Object

This method will format the package details provided using a format similar to what is used in an rpm spec. For example:

package-a
package-b = 1.2.0
package-c = 9:1.2.0
package-d >= 9:1.2.0-3

where, the operator, epoch (e.g. 9), version (e.g 1.2.0) and release (e.g. 3) are optional



20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/helpers/katello/packages_helper.rb', line 20

def format_package_details(package)
  package_details = package[:name]

  unless package[:flags].blank?
    package_details = [package_details, package_operator(package[:flags]), ''].join(' ')
    package_details += package[:epoch] + ':' unless package[:epoch].blank?
    package_details += package[:version] unless package[:version].blank?
    package_details += '-' + package[:release] unless package[:release].blank?
  end

  package_details
end

#package_operator(flag) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/helpers/katello/packages_helper.rb', line 33

def package_operator(flag)
  case flag
  when 'EQ'
    '='
  when 'LT'
    '<'
  when 'LE'
    '<='
  when 'GT'
    '>'
  when 'GE'
    '>='
  end
end

#previewed_changelog(lines) ⇒ Object



56
57
58
59
60
61
62
63
64
65
# File 'app/helpers/katello/packages_helper.rb', line 56

def previewed_changelog(lines)
  html = format_changelog_changes(lines[0, 10].join("\n"))
  html +=  "p" do
    more_lines = number_with_delimiter(lines.length - 10)
    link_to((_("Show %s more line(s)") % more_lines), "", class: "show-more-changelog")
  end
  html + ("div", :class => "more-changelog") do
    format_changelog_changes(lines[10..-1].join("\n"))
  end
end