Class: ReportBuilder::Builder::Html
Instance Attribute Summary collapse
#options, #parse_level, #toc
Class Method Summary
collapse
Instance Method Summary
collapse
#graph, #graph_entry, #image, #image_blob, #image_filename, inherited, inherited_classes, #parse, #parse_cycle, #parse_element, #save, #section, #table, #table_entry, #toc_entry
Constructor Details
permalink
#initialize(builder, options) ⇒ Html
Returns a new instance of Html.
[View source]
6
7
8
9
10
11
12
|
# File 'lib/reportbuilder/builder/html.rb', line 6
def initialize(builder, options)
super
@directory = @options.delete :directory
@body=""
@headers=[]
@footers=[]
end
|
Instance Attribute Details
permalink
#directory ⇒ Object
Returns the value of attribute directory.
5
6
7
|
# File 'lib/reportbuilder/builder/html.rb', line 5
def directory
@directory
end
|
Class Method Details
[View source]
14
15
16
|
# File 'lib/reportbuilder/builder/html.rb', line 14
def self.code
%w{html htm}
end
|
Instance Method Details
permalink
#basic_css ⇒ Object
[View source]
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/reportbuilder/builder/html.rb', line 21
def basic_css
<<-HERE
<style>
body {
margin:0;
padding:1em;
}
table {
border-collapse: collapse;
}
table td {
border: 1px solid black;
}
.section {
margin:0.5em;
}
</style>
HERE
end
|
permalink
#css(css) ⇒ Object
[View source]
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/reportbuilder/builder/html.rb', line 98
def css(css)
if(File.exists? css)
if(!File.exists? @directory+"/css")
FileUtils.mkdir @directory+"/css"
end
if(!File.exists? @directory+"/css/"+File.basename(css))
FileUtils.cp css, @directory+"/css/"+File.basename(css)
end
@headers.push("<link rel='stylesheet' type='text/css' href='css/#{File.basename(css)}' />")
end
end
|
permalink
#default_options ⇒ Object
[View source]
18
19
20
|
# File 'lib/reportbuilder/builder/html.rb', line 18
def default_options
{:directory => Dir.pwd}
end
|
[View source]
148
149
150
151
|
# File 'lib/reportbuilder/builder/html.rb', line 148
def html(t)
ws=(" "*parse_level*2)
@body << ws << t << "\n"
end
|
[View source]
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/reportbuilder/builder/html.rb', line 86
def js(js)
if(File.exists? js)
if(!File.exists? @directory+"/js")
FileUtils.mkdir @directory+"/js"
end
if(!File.exists? @directory+"/js/"+File.basename(js))
FileUtils.cp js, @directory+"/js/"+File.basename(js)
end
@headers.push("<script type='text/javascript' src='js/#{File.basename(js)}'></script>")
end
end
|
permalink
#new_page ⇒ Object
[View source]
141
142
143
|
# File 'lib/reportbuilder/builder/html.rb', line 141
def new_page
@body << "<hr />\n"
end
|
[View source]
41
42
43
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/reportbuilder/builder/html.rb', line 41
def out
out= <<-HERE
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
<title>#{@builder.name}</title>
#{basic_css}
HERE
out << @headers.join("\n")
out << "</head><body>\n"
out << "<h1>#{@builder.name}</h1>"
if(@toc.size>0)
out << "<div id='toc'><div class='title'>List of contents</div>\n"
actual_level=0
@toc.each do |anchor,name,level|
if actual_level!=level
if actual_level > level
(actual_level-level).times { out << "</ul>\n"}
else
(level-actual_level).times { out << "<ul>\n"}
end
end
out << "<li><a href='##{anchor}'>#{name}</a></li>\n"
actual_level=level
end
actual_level.times { out << "</ul>\n"}
out << "</div>\n"
end
if (@list_tables.size>0)
out << "<div class='tot'><div class='title'>List of tables</div><ul>"
@list_tables.each {|anchor,name|
out << "<li><a href='#"+anchor+"'>#{name}</a></li>"
}
out << "</ul></div>\n"
end
out << @body
out << @footers.join("\n")
out << "</body></html>"
out
end
|
permalink
#parse_js(d, level = 0) ⇒ Object
[View source]
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
|
# File 'lib/reportbuilder/builder/html.rb', line 110
def parse_js(d, level=0)
ei=5
indent=" "*(level*2)
case d
when String
"\"#{d}\""
when TrueClass
'true'
when FalseClass
'false'
when Numeric
d.to_s
when Array
if d.size>ei
sep,pre=",\n"+indent, "\n"+indent
else
sep, pre=", ", ""
end
pre+"["+d.map {|i| parse_js(i, level+1)}.join(sep)+pre+"]"
when Hash
if d.size>ei
sep, pre=",\n"+indent, "\n"+indent
else
sep, pre=", ", ""
end
pre+"{ "+d.map {|k,v| parse_js(k)+" : "+parse_js(v, level+1)}.join(sep)+pre+"}"
else
d.to_s
end
end
|
[View source]
152
153
154
155
156
|
# File 'lib/reportbuilder/builder/html.rb', line 152
def preformatted(t)
ws=(" "*parse_level*2)
@body << ws << "<pre>#{t}</pre>\n"
end
|
[View source]
144
145
146
147
|
# File 'lib/reportbuilder/builder/html.rb', line 144
def text(t)
ws=(" "*parse_level*2)
@body << ws << "<p>#{t}</p>\n"
end
|