Class: HealthRack::Renderers::HTMLRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/health_rack/renderers/html_renderer.rb

Constant Summary collapse

CONTENT_TYPE =
"text/html; charset=UTF-8"

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ HTMLRenderer

Returns a new instance of HTMLRenderer.



6
7
8
# File 'lib/health_rack/renderers/html_renderer.rb', line 6

def initialize(app)
  @app = app
end

Instance Method Details

#content_typeObject



10
11
12
# File 'lib/health_rack/renderers/html_renderer.rb', line 10

def content_type
  CONTENT_TYPE
end

#render(buffer) ⇒ Object



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
# File 'lib/health_rack/renderers/html_renderer.rb', line 14

def render(buffer)
  buffer.write <<-HTML
  <doctype html>
  <html>
    <head>
      <meta charset="utf-8">
      <title>#{@app.title}</title>
    </head>
    <body>
      <table border="1">
        <caption>#{@app.title}</caption>
        <thead>
          <tr>
            <th>&nbsp;</th>
            <th>Status</th>
            <th>Time</th>
          </tr>
        </thead>
        <tbody>
  HTML

  results.each do |result|
    buffer.write <<-HTML
    <tr>
      <th>#{result.title}</th>
      <td>#{status(result)}</td>
      <td>#{result.duration.to_f * 1000}</td>
    </tr>
    HTML
  end

  buffer.write <<-HTML
        </tbody>
      </table>
    </body>
  </html>
  HTML
end