Class: RequestLogAnalyzer::Output::HTML
- Defined in:
- lib/request_log_analyzer/output/html.rb
Overview
HTML Output class. Generated a HTML-formatted report, including CSS.
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#content_type ⇒ Object
Generate HTML content type.
-
#footer ⇒ Object
Generate a footer for a report.
-
#header ⇒ Object
Genrate HTML header and associated stylesheet.
-
#line(*font) ⇒ Object
Render a single line
*font
The font. -
#link(text, url = nil) ⇒ Object
Write a link
text
The text in the linkurl
The url to link to. -
#print(str) ⇒ Object
(also: #<<)
Print a string to the io object.
-
#puts(str = '') ⇒ Object
Put a string with newline.
-
#table(*columns) {|rows| ... } ⇒ Object
Generate a report table in HTML and push it into the output object.
-
#title(title) ⇒ Object
Place a title.
Methods inherited from Base
#initialize, #slice_results, #with_style
Constructor Details
This class inherits a constructor from RequestLogAnalyzer::Output::Base
Instance Method Details
#content_type ⇒ Object
Generate HTML content type
71 72 73 |
# File 'lib/request_log_analyzer/output/html.rb', line 71 def content_type 'text/html; charset="ISO-8859-1";' end |
#footer ⇒ Object
Generate a footer for a report
150 151 152 153 154 155 |
# File 'lib/request_log_analyzer/output/html.rb', line 150 def @io << tag(:hr) << tag(:h2, 'Thanks for using request-log-analyzer') @io << tag(:p, 'For more information please visit the ' + link('Request-log-analyzer website', 'http://github.com/wvanbergen/request-log-analyzer')) @io << tag(:p, 'If you need an expert who can analyze your application, mail to ' + link('[email protected]', 'mailto:[email protected]') + ' or visit us at ' + link('http://railsdoctors.com', 'http://railsdoctors.com') + '.') @io << "</body></html>\n" end |
#header ⇒ Object
Genrate HTML header and associated stylesheet
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/request_log_analyzer/output/html.rb', line 76 def header @io.content_type = content_type if @io.respond_to?(:content_type) @io << "<html>" @io << tag(:head) do |headers| headers << tag(:title, 'Request-log-analyzer report') headers << tag(:style, ' body { font: normal 11px auto "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; color: #4f6b72; background: #E6EAE9; padding-left:20px; padding-top:20px; padding-bottom:20px; } a { color: #c75f3e; } .color_bar { border: 1px solid; height:10px; background: #CAE8EA; } #mytable { width: 700px; padding: 0; margin: 0; padding-bottom:10px; } caption { padding: 0 0 5px 0; width: 700px; font: italic 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; text-align: right; } th { font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; color: #4f6b72; border-right: 1px solid #C1DAD7; border-bottom: 1px solid #C1DAD7; border-top: 1px solid #C1DAD7; letter-spacing: 2px; text-transform: uppercase; text-align: left; padding: 6px 6px 6px 12px; background: #CAE8EA url(images/bg_header.jpg) no-repeat; } td { font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; border-right: 1px solid #C1DAD7; border-bottom: 1px solid #C1DAD7; background: #fff; padding: 6px 6px 6px 12px; color: #4f6b72; } td.alt { background: #F5FAFA; color: #797268; } ', :type => "text/css") end @io << '<body>' @io << tag(:h1, 'Request-log-analyzer summary report') @io << tag(:p, "Version #{RequestLogAnalyzer::VERSION} - written by Willem van Bergen and Bart ten Brinke") end |
#line(*font) ⇒ Object
Render a single line *font
The font.
29 30 31 |
# File 'lib/request_log_analyzer/output/html.rb', line 29 def line(*font) @io.puts(tag(:hr)) end |
#link(text, url = nil) ⇒ Object
Write a link text
The text in the link url
The url to link to.
36 37 38 39 |
# File 'lib/request_log_analyzer/output/html.rb', line 36 def link(text, url = nil) url = text if url.nil? tag(:a, text, :href => url) end |
#print(str) ⇒ Object Also known as: <<
Print a string to the io object.
11 12 13 |
# File 'lib/request_log_analyzer/output/html.rb', line 11 def print(str) @io << str end |
#puts(str = '') ⇒ Object
Put a string with newline
18 19 20 |
# File 'lib/request_log_analyzer/output/html.rb', line 18 def puts(str = '') @io << str << "<br/>\n" end |
#table(*columns) {|rows| ... } ⇒ Object
Generate a report table in HTML and push it into the output object. *colums<tt> Columns hash <tt>&block
: A block yeilding the rows.
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 |
# File 'lib/request_log_analyzer/output/html.rb', line 44 def table(*columns, &block) rows = Array.new yield(rows) @io << tag(:table, {:id => 'mytable', :cellspacing => 0}) do |content| if table_has_header?(columns) content << tag(:tr) do columns.map { |col| tag(:th, col[:title]) }.join("\n") end end odd = false rows.each do |row| odd = !odd content << tag(:tr) do if odd row.map { |cell| tag(:td, cell, :class => 'alt') }.join("\n") else row.map { |cell| tag(:td, cell) }.join("\n") end end end end end |
#title(title) ⇒ Object
Place a title
23 24 25 |
# File 'lib/request_log_analyzer/output/html.rb', line 23 def title(title) @io.puts(tag(:h2, title)) end |