Class: Gemstar::Outputs::HTML

Inherits:
Basic
  • Object
show all
Defined in:
lib/gemstar/outputs/html.rb

Instance Method Summary collapse

Instance Method Details

#render_diff(diff_command) ⇒ Object



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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/gemstar/outputs/html.rb', line 16

def render_diff(diff_command)
  body = diff_command.updates.sort.map do |gem_name, info|
    icon = icon_for(info)
    tooltip = info[:description] ? "title=\"#{info[:description].gsub('"', """)}\"" : ""
    link = "<a href=\"#{info[:homepage_url]}\" #{tooltip} target=\"_blank\">#{gem_name}</a>"
    html = if info[:sections]
      info[:sections].map do |_version, lines|
        html_chunk = begin
          opts = { hard_wrap: false }
          opts[:input] = "GFM" if defined?(Kramdown::Parser::GFM)
          Kramdown::Document.new(lines.join, opts).to_html
        rescue Kramdown::Error
          Kramdown::Document.new(lines.join, { hard_wrap: false }).to_html
        end
        <<~HTML
          #{html_chunk}
        HTML
      end.join("\n")
    elsif info[:release_urls]
      "" # the changelog wasn't found, but we have release links — skip the message
    else
      "<p><strong>#{gem_name}:</strong> No changelog entries found</p>"
    end

    <<~HTML
      <section>
        <h2>#{icon} #{link}: #{version_label(info)}</h2>
        #{"<p><a href='#{info[:release_page]}' target='_blank'>View all GitHub release notes</a></p>" if info[:release_page]}
        #{html}
      </section>
    HTML
  end.join("\n")

  project_name = diff_command.project_name

  <<~HTML
    <!DOCTYPE html>
    <html>
    <head>
      <meta charset="UTF-8">
      <title>#{project_name}: Gem Updates with Changelogs</title>
      <style>
        body { font-family: sans-serif; padding: 2em; background: #fdfdfd; }
        section { margin-bottom: 3em; border-bottom: 1px solid #ccc; padding-bottom: 1em; }
        h2 { color: #333; }
        h3 { margin-top: 1em; color: #444; }
        pre { background: #eee; padding: 1em; overflow-x: auto; }
        a { color: #0645ad; text-decoration: none; }
      </style>
    </head>
    <body>
      <h1>#{project_name}: Package Updates</h1>
      <p><i>Showing changes from #{diff_command.from} to #{diff_command.to || "now"}, generated on #{Time.now.strftime("%Y-%m-%d %H:%M:%S %z")}.</i></p>
      #{range_details(diff_command)}
      #{body}
      #{considered_commits(diff_command)}
    </body>
    </html>
  HTML
end