class RequestLogAnalyzer::Output::HTML
HTML
Output
class. Generated a HTML-formatted report, including CSS.
Public Instance Methods
colorize(text, *style)
click to toggle source
def initialize(io, options = {})
super(io, options)
end
# File lib/request_log_analyzer/output/html.rb 8 def colorize(text, *style) 9 if style.include?(:bold) 10 tag(:strong, text) 11 else 12 text 13 end 14 end
header()
click to toggle source
Genrate HTML
header and associated stylesheet
# File lib/request_log_analyzer/output/html.rb 76 def header 77 @io.content_type = content_type if @io.respond_to?(:content_type) 78 79 @io << '<html>' 80 @io << tag(:head) do |headers| 81 headers << tag(:title, 'Request-log-analyzer report') 82 headers << tag(:style, ' 83 body { 84 font: normal 11px auto "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; 85 color: #4f6b72; 86 background: #E6EAE9; 87 padding-left:20px; 88 padding-top:20px; 89 padding-bottom:20px; 90 } 91 92 a { 93 color: #c75f3e; 94 } 95 96 .color_bar { 97 border: 1px solid; 98 height:10px; 99 background: #CAE8EA; 100 } 101 102 .rla-report-table { 103 width: 700px; 104 padding: 0; 105 margin: 0; 106 padding-bottom:10px; 107 } 108 109 caption { 110 padding: 0 0 5px 0; 111 width: 700px; 112 font: italic 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; 113 text-align: right; 114 } 115 116 th { 117 font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; 118 color: #4f6b72; 119 border-right: 1px solid #C1DAD7; 120 border-bottom: 1px solid #C1DAD7; 121 border-top: 1px solid #C1DAD7; 122 letter-spacing: 2px; 123 text-transform: uppercase; 124 text-align: left; 125 padding: 6px 6px 6px 12px; 126 background: #CAE8EA url(images/bg_header.jpg) no-repeat; 127 } 128 129 td { 130 font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; 131 border-right: 1px solid #C1DAD7; 132 border-bottom: 1px solid #C1DAD7; 133 background: #fff; 134 padding: 6px 6px 6px 12px; 135 color: #4f6b72; 136 } 137 138 td.alt { 139 background: #F5FAFA; 140 color: #797268; 141 } 142 ', type: 'text/css') 143 end 144 @io << '<body>' 145 @io << tag(:h1, 'Request-log-analyzer summary report') 146 @io << tag(:p, "Version #{RequestLogAnalyzer::VERSION} - written by Willem van Bergen and Bart ten Brinke") 147 end
line(*_font)
click to toggle source
Render a single line *font
The font.
# File lib/request_log_analyzer/output/html.rb 35 def line(*_font) 36 @io.puts(tag(:hr)) 37 end
link(text, url = nil)
click to toggle source
Write a link text
The text in the link url
The url to link to.
# File lib/request_log_analyzer/output/html.rb 42 def link(text, url = nil) 43 url = text if url.nil? 44 tag(:a, text, href: url) 45 end
print(str)
click to toggle source
Print a string to the io object.
# File lib/request_log_analyzer/output/html.rb 17 def print(str) 18 @io << str 19 end
Also aliased as: <<
puts(str = '')
click to toggle source
Put a string with newline
# File lib/request_log_analyzer/output/html.rb 24 def puts(str = '') 25 @io << str << "<br/>\n" 26 end
table(*columns) { |rows| ... }
click to toggle source
Generate a report table in HTML
and push it into the output object. *colums<tt> Columns hash <tt>&block
: A block yeilding the rows.
# File lib/request_log_analyzer/output/html.rb 50 def table(*columns, &_block) 51 rows = [] 52 yield(rows) 53 54 @io << tag(:table, class: 'rla-report-table', cellspacing: 0) do |content| 55 if table_has_header?(columns) 56 content << tag(:tr) do 57 columns.map { |col| tag(:th, col[:title]) }.join("\n") 58 end 59 end 60 61 odd = false 62 rows.each do |row| 63 odd = !odd 64 content << tag(:tr) do 65 if odd 66 row.map { |cell| tag(:td, cell, class: 'alt') }.join("\n") 67 else 68 row.map { |cell| tag(:td, cell) }.join("\n") 69 end 70 end 71 end 72 end 73 end
title(title)
click to toggle source
Place a title
# File lib/request_log_analyzer/output/html.rb 29 def title(title) 30 @io.puts(tag(:h2, title)) 31 end
Protected Instance Methods
tag(tag, content = nil, attributes = nil) { |content_string| ... }
click to toggle source
HTML
tag writer helper tag
The tag to generate content
The content inside the tag attributes
Attributes to write in the tag
# File lib/request_log_analyzer/output/html.rb 163 def tag(tag, content = nil, attributes = nil) 164 if block_given? 165 attributes = content.nil? ? '' : ' ' + content.map { |(key, value)| "#{key}=\"#{value}\"" }.join(' ') 166 content_string = '' 167 content = yield(content_string) 168 content = content_string unless content_string.empty? 169 "<#{tag}#{attributes}>#{content}</#{tag}>" 170 else 171 attributes = attributes.nil? ? '' : ' ' + attributes.map { |(key, value)| "#{key}=\"#{value}\"" }.join(' ') 172 if content.nil? 173 "<#{tag}#{attributes} />" 174 else 175 if content.class == Float 176 "<#{tag}#{attributes}><div class='color_bar' style=\"width:#{(content * 200).floor}px;\"/></#{tag}>" 177 else 178 "<#{tag}#{attributes}>#{content}</#{tag}>" 179 end 180 end 181 end 182 end