Class: Diff2Xml::Diff2Html
- Inherits:
-
Object
- Object
- Diff2Xml::Diff2Html
show all
- Includes:
- Handler, XmlTool
- Defined in:
- lib/diff2xml/diff2html.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from XmlTool
#convert_illegal_characters, #convert_space, #sanitize
Methods included from Handler
#end_block
Constructor Details
#initialize(os = STDOUT, inline_css = false, css = 'diff2html.css') ⇒ Diff2Html
68
69
70
71
72
73
74
75
|
# File 'lib/diff2xml/diff2html.rb', line 68
def initialize(os = STDOUT, inline_css = false, css = 'diff2html.css')
@file_count = 0
@diff_count = 0
@next_block = false
@ostream = os
@inline_css = inline_css
@css_name = css
end
|
Instance Attribute Details
#css_name ⇒ Object
Returns the value of attribute css_name.
38
39
40
|
# File 'lib/diff2xml/diff2html.rb', line 38
def css_name
@css_name
end
|
#ostream=(value) ⇒ Object
Sets the attribute ostream
37
38
39
|
# File 'lib/diff2xml/diff2html.rb', line 37
def ostream=(value)
@ostream = value
end
|
Class Method Details
.print_default_css(os) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/diff2xml/diff2html.rb', line 44
def self.print_default_css(os)
os << <<STYLE
a:link { color:#000; cursor:point; text-decoration:none }
a:hover { cursor:point; text-decoration:none }
a:visited { color:#000; cursor:point; text-decoration:none }
body { margin:0px; font-family:\"Verdana\",Serif; background-color:#fff }
h4.title { margin:20px 0px 10px 10px }
table { padding:0px; margin:0px; border-collapse:collapse; }
th.title { border-width:8px 0px 8px 0px; border-color:Green; border-style:solid; font-family:\"Verdana\"; font-size:1.25em; text-align:left; padding:10px 10px 10px 20px; background-color:#fff }
th, td { font-family:\"Courier New\",Monospace; font-size:.9em; padding-left:20px }
td.del { background-color:#888 }
td.add { font-weight:bold; font-size:.9em; background-color:#ff0 }
td.blank { background-color:DarkGray }
td.same,td.omit { color:#444; background-color:#ccc }
td.omit { font-weight:bold; padding:20px }
span.c, span.g, span.m { color:#f00 }
span.a, span.u, span.p { color:#00f }
span.d { color:#880 }
p.timestamp { font-size:.8em; margin-right:20px }
p.result { text-align:center; font-weight:bold; font-size:.8em; margin-right:20px }
p.diff2html-header { padding:10px; margin:0px }
STYLE
end
|
Instance Method Details
#common_line(line) ⇒ Object
152
153
154
155
156
|
# File 'lib/diff2xml/diff2html.rb', line 152
def common_line(line)
line = sanitize(line)
@ostream.puts "<tr><td class=\"same\">#{line}</td></tr>"
@next_block = true
end
|
#end_document ⇒ Object
122
123
|
# File 'lib/diff2xml/diff2html.rb', line 122
def end_document
end
|
#end_parse ⇒ Object
105
106
107
|
# File 'lib/diff2xml/diff2html.rb', line 105
def end_parse
@ostream.puts "</table>\n</body>\n</html>"
end
|
#source_line(line) ⇒ Object
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/diff2xml/diff2html.rb', line 130
def source_line(line)
line = sanitize(line)
if @next_block then
@diff_count = @diff_count + 1
@next_block = false
@ostream.puts "<tr><td class=\"del\"><a name=\"diff_#{@diff_count}\"/><a href=\"#diff_#{@diff_count+1}\">#{line}</a></td></tr>"
else
@ostream.puts "<tr><td class=\"del\"><a href=\"#diff_#{@diff_count+1}\">#{line}</a></td></tr>"
end
end
|
#start_block(source_base, source_length, target_base, target_length) ⇒ Object
125
126
127
128
|
# File 'lib/diff2xml/diff2html.rb', line 125
def start_block(source_base, source_length, target_base, target_length)
@ostream.puts "<tr><td class=\"omit\">(From line #{source_base} to #{source_base.to_i+source_length.to_i})</td></tr>"
@next_block = true
end
|
#start_document(source, target) ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/diff2xml/diff2html.rb', line 109
def start_document(source, target)
source = sanitize(source)
target = sanitize(target)
title = ""
if source == target then
title = source
else
title = "Source: #{source}<br/>Target: #{target}"
end
@ostream.puts "<tr><th class=\"title\"><a name=\"file_#{@file_count}\"/><a name=\"#{source}\"/><a href=\"#file_#{@file_count+1}\">#{title}</a></th></tr>"
@file_count = @file_count + 1
end
|
#start_parse ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/diff2xml/diff2html.rb', line 81
def start_parse
@ostream << <<HEAD
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>diff2html result</title>
HEAD
if @inline_css
@ostream.puts '<style>'
Diff2Html.print_default_css(@ostream)
@ostream.puts '</style>'
else
@ostream.puts "<link rel=\"stylesheet\" type=\"text/css\" href=\"#{@css_name}\" />"
end
@ostream << <<HEAD
</head>
<body>
<p class="diff2html-header">Created on #{Time.now}</p>
<table cellspacing=\"0\" cellpadding=\"0\">
HEAD
end
|
#target_line(line) ⇒ Object
141
142
143
144
145
146
147
148
149
150
|
# File 'lib/diff2xml/diff2html.rb', line 141
def target_line(line)
line = sanitize(line)
if @next_block then
@diff_count = @diff_count + 1
@next_block = false
@ostream.puts "<tr><td class=\"add\"><a name=\"diff_#{@diff_count}\"/><a href=\"#diff_#{@diff_count+1}\">#{line}</a></td></tr>"
else
@ostream.puts "<tr><td class=\"add\"><a href=\"#diff_#{@diff_count+1}\">#{line}</a></td></tr>"
end
end
|