lib/request_log_analyzer/output/html.rb in request-log-analyzer-1.3.7 vs lib/request_log_analyzer/output/html.rb in request-log-analyzer-1.4.0
- old
+ new
@@ -1,14 +1,14 @@
module RequestLogAnalyzer::Output
-
+
# HTML Output class. Generated a HTML-formatted report, including CSS.
class HTML < Base
-
+
# def initialize(io, options = {})
# super(io, options)
# end
-
+
# Print a string to the io object.
def print(str)
@io << str
end
@@ -24,14 +24,14 @@
@io.puts(tag(:h2, title))
end
# Render a single line
# <tt>*font</tt> The font.
- def line(*font)
+ def line(*font)
@io.puts(tag(:hr))
end
-
+
# Write a link
# <tt>text</tt> The text in the link
# <tt>url</tt> The url to link to.
def link(text, url = nil)
url = text if url.nil?
@@ -42,33 +42,33 @@
# <tt>*colums<tt> Columns hash
# <tt>&block</tt>: A block yeilding the rows.
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")
+ row.map { |cell| tag(:td, cell, :class => 'alt') }.join("\n")
else
- row.map { |cell| tag(:td, cell) }.join("\n")
+ row.map { |cell| tag(:td, cell) }.join("\n")
end
end
end
end
-
+
end
-
+
# Genrate HTML header and associated stylesheet
def header
@io << "<html>"
@io << tag(:head) do |headers|
headers << tag(:title, 'Request-log-analyzer report')
@@ -83,27 +83,27 @@
}
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;
+ width: 700px;
font: italic 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
text-align: right;
}
th {
@@ -136,31 +136,31 @@
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
-
+
# Generate a footer for a report
def footer
@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('contact@railsdoctors.com', 'mailto:contact@railsdoctors.com') + ' or visit us at ' + link('http://railsdoctors.com', 'http://railsdoctors.com') + '.')
@io << "</body></html>\n"
end
-
- protected
-
+
+ protected
+
# HTML tag writer helper
# <tt>tag</tt> The tag to generate
# <tt>content</tt> The content inside the tag
# <tt>attributes</tt> Attributes to write in the tag
def tag(tag, content = nil, attributes = nil)
if block_given?
attributes = content.nil? ? '' : ' ' + content.map { |(key, value)| "#{key}=\"#{value}\"" }.join(' ')
content_string = ''
content = yield(content_string)
- content = content_string unless content_string.empty?
+ content = content_string unless content_string.empty?
"<#{tag}#{attributes}>#{content}</#{tag}>"
else
attributes = attributes.nil? ? '' : ' ' + attributes.map { |(key, value)| "#{key}=\"#{value}\"" }.join(' ')
if content.nil?
"<#{tag}#{attributes} />"
@@ -170,8 +170,8 @@
else
"<#{tag}#{attributes}>#{content}</#{tag}>"
end
end
end
- end
+ end
end
end
\ No newline at end of file