reportbuilder 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +4 -1
- data/Rakefile +4 -3
- data/data/reportbuilder.css +10 -0
- data/data/sheep.jpg +0 -0
- data/lib/reportbuilder/generator/html.rb +58 -28
- data/lib/reportbuilder/generator/text.rb +5 -2
- data/lib/reportbuilder/generator.rb +44 -9
- data/lib/reportbuilder/image.rb +78 -0
- data/lib/reportbuilder/section.rb +11 -17
- data/lib/reportbuilder/table/htmlgenerator.rb +2 -2
- data/lib/reportbuilder/table/textgenerator.rb +1 -1
- data/lib/reportbuilder/table.rb +6 -4
- data/lib/reportbuilder.rb +16 -17
- data/test/test_html.rb +2 -2
- data/test/test_image.rb +42 -0
- data/test/test_section.rb +13 -5
- metadata +8 -4
data/Manifest.txt
CHANGED
@@ -5,15 +5,18 @@ Rakefile
|
|
5
5
|
bin/reportbuilder
|
6
6
|
data/reportbuilder.css
|
7
7
|
data/reportbuilder.js
|
8
|
+
data/sheep.jpg
|
9
|
+
lib/reportbuilder.rb
|
8
10
|
lib/reportbuilder/generator.rb
|
9
11
|
lib/reportbuilder/generator/html.rb
|
10
12
|
lib/reportbuilder/generator/text.rb
|
11
|
-
lib/reportbuilder.rb
|
13
|
+
lib/reportbuilder/image.rb
|
12
14
|
lib/reportbuilder/section.rb
|
13
15
|
lib/reportbuilder/table.rb
|
14
16
|
lib/reportbuilder/table/htmlgenerator.rb
|
15
17
|
lib/reportbuilder/table/textgenerator.rb
|
16
18
|
test/test_html.rb
|
19
|
+
test/test_image.rb
|
17
20
|
test/test_reportbuilder.rb
|
18
21
|
test/test_section.rb
|
19
22
|
test/test_table.rb
|
data/Rakefile
CHANGED
@@ -5,11 +5,12 @@ require 'rubygems'
|
|
5
5
|
require 'hoe'
|
6
6
|
require 'reportbuilder'
|
7
7
|
|
8
|
+
|
8
9
|
Hoe.spec 'reportbuilder' do
|
9
10
|
self.version=ReportBuilder::VERSION
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
self.rubyforge_name = 'ruby-statsample'
|
12
|
+
self.developer('Claudio Bustos', 'clbustos_at_gmail.com')
|
13
|
+
self.url = "http://rubyforge.org/projects/ruby-statsample/"
|
13
14
|
|
14
15
|
end
|
15
16
|
|
data/data/reportbuilder.css
CHANGED
data/data/sheep.jpg
ADDED
Binary file
|
@@ -5,31 +5,49 @@ class ReportBuilder
|
|
5
5
|
class Html < Generator
|
6
6
|
PREFIX="html"
|
7
7
|
attr_reader :toc
|
8
|
-
def initialize(builder)
|
8
|
+
def initialize(builder, options)
|
9
9
|
super
|
10
10
|
@body=""
|
11
|
-
@toc=[]
|
12
|
-
@table_n=1
|
13
|
-
@entry_n=1
|
14
|
-
@list_tables=[]
|
15
11
|
@headers=[]
|
16
12
|
@footers=[]
|
17
13
|
end
|
18
14
|
def parse
|
15
|
+
# add_css(File.dirname(__FILE__)+"/../../../data/reportbuilder.css")
|
16
|
+
# add_js(File.dirname(__FILE__)+"/../../../data/reportbuilder.js")
|
19
17
|
parse_cycle(@builder)
|
20
18
|
end
|
19
|
+
def basic_css
|
20
|
+
<<-HERE
|
21
|
+
<style>
|
22
|
+
body {
|
23
|
+
margin:0;
|
24
|
+
padding:1em;
|
25
|
+
}
|
26
|
+
table {
|
27
|
+
border-collapse: collapse;
|
28
|
+
|
29
|
+
}
|
30
|
+
table td {
|
31
|
+
border: 1px solid black;
|
32
|
+
}
|
33
|
+
.section {
|
34
|
+
margin:0.5em;
|
35
|
+
}
|
36
|
+
</style>
|
37
|
+
HERE
|
38
|
+
end
|
21
39
|
def out
|
22
|
-
out=
|
40
|
+
out= <<-HERE
|
41
|
+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
42
|
+
<html>
|
43
|
+
<head>
|
44
|
+
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
|
45
|
+
<title>#{@builder.name}</title>
|
46
|
+
#{basic_css}
|
47
|
+
HERE
|
23
48
|
out << @headers.join("\n")
|
24
49
|
out << "</head><body>\n"
|
25
50
|
out << "<h1>#{@builder.name}</h1>"
|
26
|
-
if (@list_tables.size>0)
|
27
|
-
out << "<div class='tot'><div class='title'>List of tables</div><ul>"
|
28
|
-
@list_tables.each {|anchor,name|
|
29
|
-
out << "<li><a href='#"+anchor+"'>#{name}</a></li>"
|
30
|
-
}
|
31
|
-
out << "</ul></div>\n"
|
32
|
-
end
|
33
51
|
if(@toc.size>0)
|
34
52
|
out << "<div class='toc'><div class='title'>List of contents</div></div>"
|
35
53
|
actual_level=0
|
@@ -47,10 +65,30 @@ class ReportBuilder
|
|
47
65
|
actual_level.times { out << "</ul>\n"}
|
48
66
|
out << "</div>\n"
|
49
67
|
end
|
68
|
+
if (@list_tables.size>0)
|
69
|
+
out << "<div class='tot'><div class='title'>List of tables</div><ul>"
|
70
|
+
@list_tables.each {|anchor,name|
|
71
|
+
out << "<li><a href='#"+anchor+"'>#{name}</a></li>"
|
72
|
+
}
|
73
|
+
out << "</ul></div>\n"
|
74
|
+
end
|
75
|
+
|
50
76
|
out << @body
|
51
77
|
out << @footers.join("\n")
|
52
78
|
out << "</body></html>"
|
53
79
|
end
|
80
|
+
|
81
|
+
|
82
|
+
def add_image(filename)
|
83
|
+
if(File.exists? filename)
|
84
|
+
if(!File.exists? @builder.dir+"/images/"+File.basename(filename))
|
85
|
+
FileUtils.mkdir @builder.dir+"/images"
|
86
|
+
FileUtils.cp filename, @builder.dir+"/images/"+File.basename(filename)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
"images/"+File.basename(filename)
|
90
|
+
end
|
91
|
+
|
54
92
|
def add_js(js)
|
55
93
|
if(File.exists? js)
|
56
94
|
if(!File.exists? @builder.dir+"/js/"+File.basename(js))
|
@@ -74,26 +112,18 @@ class ReportBuilder
|
|
74
112
|
|
75
113
|
def add_text(t)
|
76
114
|
ws=(" "*parse_level*2)
|
77
|
-
@body << ws << "<
|
115
|
+
@body << ws << "<p>#{t}</p>\n"
|
78
116
|
end
|
79
|
-
def
|
117
|
+
def add_html(t)
|
80
118
|
ws=(" "*parse_level*2)
|
81
119
|
@body << ws << t << "\n"
|
82
120
|
end
|
83
|
-
def
|
84
|
-
|
85
|
-
@
|
86
|
-
|
87
|
-
anchor
|
88
|
-
end
|
89
|
-
# Add an entry for a table
|
90
|
-
# Returns the name of the anchor
|
91
|
-
def add_table_entry(name)
|
92
|
-
anchor="table_#{@table_n}"
|
93
|
-
@table_n+=1
|
94
|
-
@list_tables.push([anchor,name])
|
95
|
-
anchor
|
121
|
+
def add_preformatted(t)
|
122
|
+
ws=(" "*parse_level*2)
|
123
|
+
@body << ws << "<pre>#{t}</pre>\n"
|
124
|
+
|
96
125
|
end
|
126
|
+
|
97
127
|
end
|
98
128
|
end
|
99
129
|
end
|
@@ -4,7 +4,7 @@ class ReportBuilder
|
|
4
4
|
PREFIX="text"
|
5
5
|
attr_reader :toc
|
6
6
|
attr_reader :out
|
7
|
-
def initialize(builder)
|
7
|
+
def initialize(builder, options)
|
8
8
|
super
|
9
9
|
@out=""
|
10
10
|
end
|
@@ -17,9 +17,12 @@ class ReportBuilder
|
|
17
17
|
ws=" "*parse_level*2
|
18
18
|
@out << ws << t << "\n"
|
19
19
|
end
|
20
|
-
def
|
20
|
+
def add_preformatted(t)
|
21
21
|
@out << t
|
22
22
|
end
|
23
|
+
def add_html(t)
|
24
|
+
# Nothing printed
|
25
|
+
end
|
23
26
|
end
|
24
27
|
end
|
25
28
|
end
|
@@ -1,32 +1,67 @@
|
|
1
1
|
class ReportBuilder
|
2
2
|
# Abstract class for generators.
|
3
|
-
#
|
3
|
+
# A generator is a class which control the output for a builder.
|
4
4
|
# On parse_cycle()....
|
5
5
|
#
|
6
6
|
class Generator
|
7
|
-
#PREFIX="none"
|
8
7
|
attr_reader :parse_level
|
9
8
|
# builder is a ReportBuilder object
|
10
|
-
def initialize(builder)
|
9
|
+
def initialize(builder, options)
|
11
10
|
@builder=builder
|
12
11
|
@parse_level=0
|
12
|
+
@options=default_options.merge(options)
|
13
|
+
@toc=[]
|
14
|
+
@table_n=1
|
15
|
+
@entry_n=1
|
16
|
+
@list_tables=[]
|
17
|
+
|
18
|
+
end
|
19
|
+
def default_options
|
20
|
+
{}
|
13
21
|
end
|
14
22
|
# parse each element of the parameters
|
15
23
|
def parse_cycle(container)
|
16
24
|
@parse_level+=1
|
17
25
|
container.elements.each do |element|
|
18
|
-
|
19
|
-
if element.respond_to? method
|
20
|
-
element.send(method, self)
|
21
|
-
else
|
22
|
-
add_text(element.to_s)
|
23
|
-
end
|
26
|
+
parse_element(element)
|
24
27
|
end
|
25
28
|
@parse_level-=1
|
26
29
|
end
|
30
|
+
|
31
|
+
def parse_element(element)
|
32
|
+
method=("to_reportbuilder_"+self.class::PREFIX).intern
|
33
|
+
if element.respond_to? method
|
34
|
+
element.send(method, self)
|
35
|
+
elsif element.respond_to? :to_reportbuilder
|
36
|
+
element.send(:to_reportbuilder, self)
|
37
|
+
else
|
38
|
+
add_text(element.to_s)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
27
42
|
def add_text(t)
|
28
43
|
raise "Implement this"
|
29
44
|
end
|
45
|
+
def add_html(t)
|
46
|
+
raise "Implement this"
|
47
|
+
end
|
48
|
+
def add_preformatted(t)
|
49
|
+
raise "Implement this"
|
50
|
+
end
|
51
|
+
def add_toc_entry(name)
|
52
|
+
anchor="toc_#{@entry_n}"
|
53
|
+
@entry_n+=1
|
54
|
+
@toc.push([anchor, name, parse_level])
|
55
|
+
anchor
|
56
|
+
end
|
57
|
+
# Add an entry for a table
|
58
|
+
# Returns the name of the anchor
|
59
|
+
def add_table_entry(name)
|
60
|
+
anchor="table_#{@table_n}"
|
61
|
+
@table_n+=1
|
62
|
+
@list_tables.push([anchor,name])
|
63
|
+
anchor
|
64
|
+
end
|
30
65
|
end
|
31
66
|
class ElementGenerator
|
32
67
|
def initialize(generator,element)
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# Creates a Section
|
2
|
+
class ReportBuilder::Image
|
3
|
+
@@n=1
|
4
|
+
attr_reader :name
|
5
|
+
def initialize(filename, options={})
|
6
|
+
if !options.has_key? :name
|
7
|
+
@name="Image #{@@n}"
|
8
|
+
@@n+=1
|
9
|
+
else
|
10
|
+
@name=options[:name]
|
11
|
+
end
|
12
|
+
default_options={
|
13
|
+
:alt=>@name,
|
14
|
+
:chars => [ 'W', 'M', '$', '@', '#', '%', '^', 'x', '*', 'o', '=', '+',
|
15
|
+
':', '~', '.', ' ' ],
|
16
|
+
:font_rows => 8,
|
17
|
+
:font_cols => 4
|
18
|
+
}
|
19
|
+
@options=default_options.merge(options)
|
20
|
+
@filename=filename
|
21
|
+
end
|
22
|
+
# Based on http://rubyquiz.com/quiz50.html
|
23
|
+
def to_reportbuilder_text(generator)
|
24
|
+
require 'RMagick'
|
25
|
+
|
26
|
+
|
27
|
+
img = Magick::Image.read(@filename).first
|
28
|
+
|
29
|
+
# Resize too-large images. The resulting image is going to be
|
30
|
+
# about twice the size of the input, so if the original image is too
|
31
|
+
# large we need to make it smaller so the ASCII version won't be too
|
32
|
+
# big. The `change_geometry' method computes new dimensions for an
|
33
|
+
# image based on the geometry argument. The '320x320>' argument says
|
34
|
+
# "If the image is too big to fit in a 320x320 square, compute the
|
35
|
+
# dimensions of an image that will fit, but retain the original aspect
|
36
|
+
# ratio. If the image is already smaller than 320x320, keep the same
|
37
|
+
# dimensions."
|
38
|
+
img.change_geometry('320x320>') do |cols, rows|
|
39
|
+
img.resize!(cols, rows) if cols != img.columns || rows != img.rows
|
40
|
+
end
|
41
|
+
|
42
|
+
# Compute the image size in ASCII "pixels" and resize the image to have
|
43
|
+
# those dimensions. The resulting image does not have the same aspect
|
44
|
+
# ratio as the original, but since our "pixels" are twice as tall as
|
45
|
+
# they are wide we'll get our proportions back (roughly) when we render.
|
46
|
+
pr = img.rows / @options[:font_rows]
|
47
|
+
pc = img.columns / @options[:font_cols]
|
48
|
+
img.resize!(pc, pr)
|
49
|
+
|
50
|
+
img = img.quantize(@options[:chars].size, Magick::GRAYColorspace)
|
51
|
+
img = img.normalize
|
52
|
+
|
53
|
+
out=""
|
54
|
+
# Draw the image surrounded by a border. The `view' method is slow but
|
55
|
+
# it makes it easy to address individual pixels. In grayscale images,
|
56
|
+
# all three RGB channels have the same value so the red channel is as
|
57
|
+
# good as any for choosing which character to represent the intensity of
|
58
|
+
# this particular pixel.
|
59
|
+
border = '+' + ('-' * pc) + '+'
|
60
|
+
out += border+"\n"
|
61
|
+
img.view(0, 0, pc, pr) do |view|
|
62
|
+
pr.times do |i|
|
63
|
+
out+= '|'
|
64
|
+
pc.times do |j|
|
65
|
+
out+= @options[:chars][view[i][j].red / (2**16/@options[:chars].size)]
|
66
|
+
end
|
67
|
+
out+= '|'+"\n"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
out+= border
|
71
|
+
generator.add_raw(out)
|
72
|
+
end
|
73
|
+
|
74
|
+
def to_reportbuilder_html(generator)
|
75
|
+
src=generator.add_image(@filename)
|
76
|
+
generator.add_raw("<img src='#{src}' alt='#{@options[:alt]}' />")
|
77
|
+
end
|
78
|
+
end
|
@@ -2,12 +2,12 @@
|
|
2
2
|
class ReportBuilder::Section
|
3
3
|
@@n=1
|
4
4
|
attr_reader :parent, :elements, :name
|
5
|
-
def initialize(
|
6
|
-
if
|
5
|
+
def initialize(options={})
|
6
|
+
if !options.has_key? :name
|
7
7
|
@name="Section #{@nn}"
|
8
8
|
@nn+=1
|
9
9
|
else
|
10
|
-
@name=name
|
10
|
+
@name=options[:name]
|
11
11
|
end
|
12
12
|
@parent = nil
|
13
13
|
@elements = []
|
@@ -20,29 +20,23 @@ class ReportBuilder::Section
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
23
|
+
def to_reportbuilder_text(generator)
|
24
24
|
generator.add_text(("="*generator.parse_level)+" "+name)
|
25
25
|
generator.parse_cycle(self)
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
28
|
+
def to_reportbuilder_html(generator)
|
29
29
|
htag="h#{generator.parse_level+1}"
|
30
30
|
anchor=generator.add_toc_entry(name)
|
31
|
-
generator.
|
31
|
+
generator.add_html "<div class='section'><#{htag}>#{name}</#{htag}><a name='#{anchor}'></a>"
|
32
32
|
generator.parse_cycle(self)
|
33
|
-
generator.
|
33
|
+
generator.add_html "</div>"
|
34
34
|
end
|
35
35
|
|
36
|
-
def add(
|
37
|
-
|
38
|
-
|
39
|
-
element.parent=self
|
40
|
-
end
|
41
|
-
if element.respond_to?(:to_reportbuilder)
|
42
|
-
@elements.push(element.to_reportbuilder)
|
43
|
-
else
|
44
|
-
@elements.push(element)
|
45
|
-
end
|
36
|
+
def add(element)
|
37
|
+
if element.is_a? ReportBuilder::Section
|
38
|
+
element.parent=self
|
46
39
|
end
|
40
|
+
@elements.push(element)
|
47
41
|
end
|
48
42
|
end
|
@@ -4,7 +4,7 @@ class ReportBuilder
|
|
4
4
|
def generate()
|
5
5
|
t=@element
|
6
6
|
anchor=@generator.add_table_entry(t.name)
|
7
|
-
out="<a name='#{anchor}'></a><table>"
|
7
|
+
out="<a name='#{anchor}'></a><table><caption>#{t.name}</caption>"
|
8
8
|
@rowspans=[]
|
9
9
|
if t.header.size>0
|
10
10
|
out+="<thead>"+parse_row(t,t.header,"th")+"</thead>\n"
|
@@ -21,7 +21,7 @@ class ReportBuilder
|
|
21
21
|
end
|
22
22
|
}
|
23
23
|
out+="</tbody>\n</table>\n"
|
24
|
-
@generator.
|
24
|
+
@generator.add_html(out)
|
25
25
|
end
|
26
26
|
def parse_row(t,row,tag="td")
|
27
27
|
row_ary=[]
|
data/lib/reportbuilder/table.rb
CHANGED
@@ -19,8 +19,8 @@ class ReportBuilder
|
|
19
19
|
# | 4 | London |George | ab-4 |
|
20
20
|
# -----------------------------------------
|
21
21
|
class Table
|
22
|
-
@@n=1
|
23
|
-
|
22
|
+
@@n=1 # :nodoc:
|
23
|
+
|
24
24
|
DEFAULT_OPTIONS={
|
25
25
|
:header => [],
|
26
26
|
:name => nil
|
@@ -36,6 +36,7 @@ class ReportBuilder
|
|
36
36
|
# Use:
|
37
37
|
# table=ReportBuilder::Table.new(:header =>["var1","var2"])
|
38
38
|
def initialize(opts=Hash.new)
|
39
|
+
raise ArgumentError,"opts should be a Hash" if !opts.is_a? Hash
|
39
40
|
opts=DEFAULT_OPTIONS.merge opts
|
40
41
|
if opts[:name].nil?
|
41
42
|
@name= "Table #{@@n}"
|
@@ -57,6 +58,7 @@ class ReportBuilder
|
|
57
58
|
def add_hr
|
58
59
|
@rows.push(:hr)
|
59
60
|
end
|
61
|
+
alias_method :add_horizontal_line, :add_hr
|
60
62
|
# Adds a rowspan on a cell
|
61
63
|
# table.add_row(["a",table.rowspan("b",2)])
|
62
64
|
def rowspan(data,n)
|
@@ -93,12 +95,12 @@ class ReportBuilder
|
|
93
95
|
}
|
94
96
|
}
|
95
97
|
end
|
96
|
-
def
|
98
|
+
def to_reportbuilder_text(generator)
|
97
99
|
require 'reportbuilder/table/textgenerator'
|
98
100
|
table_generator=ReportBuilder::Table::TextGenerator.new( generator, self)
|
99
101
|
table_generator.generate
|
100
102
|
end
|
101
|
-
def
|
103
|
+
def to_reportbuilder_html(generator)
|
102
104
|
require 'reportbuilder/table/htmlgenerator'
|
103
105
|
table_generator=ReportBuilder::Table::HtmlGenerator.new(generator, self)
|
104
106
|
table_generator.generate
|
data/lib/reportbuilder.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
require 'reportbuilder/table'
|
2
2
|
require 'reportbuilder/section'
|
3
3
|
require 'reportbuilder/generator'
|
4
|
+
require 'reportbuilder/image'
|
4
5
|
|
5
6
|
class ReportBuilder
|
6
7
|
attr_reader :elements
|
7
8
|
attr_reader :name
|
8
9
|
attr_reader :dir
|
9
|
-
VERSION = '0.
|
10
|
+
VERSION = '0.2.0'
|
10
11
|
# Create a new Report
|
11
12
|
def initialize(name=nil,dir=nil)
|
12
13
|
name||="Report "+Time.new.to_s
|
@@ -19,40 +20,38 @@ class ReportBuilder
|
|
19
20
|
# If parameters is an object which respond to :to_reportbuilder,
|
20
21
|
# this method will called.
|
21
22
|
# Otherwise, the element itself will be added
|
22
|
-
def add(
|
23
|
-
|
24
|
-
if element.respond_to?(:to_reportbuilder)
|
25
|
-
@elements.push(element.to_reportbuilder)
|
26
|
-
else
|
27
|
-
@elements.push(element)
|
28
|
-
end
|
29
|
-
end
|
23
|
+
def add(element)
|
24
|
+
@elements.push(element)
|
30
25
|
end
|
31
26
|
# Returns a Section
|
32
|
-
def section(
|
33
|
-
|
27
|
+
def section(options={})
|
28
|
+
Section.new(options)
|
29
|
+
end
|
30
|
+
def image(filename)
|
31
|
+
Image.new(filename)
|
34
32
|
end
|
35
33
|
# Returns a Table
|
36
34
|
def table(h=[])
|
37
35
|
Table.new(h)
|
38
36
|
end
|
39
37
|
# Returns an Html output
|
40
|
-
def to_html
|
41
|
-
gen=Generator::Html.new(self)
|
38
|
+
def to_html(options={})
|
39
|
+
gen = Generator::Html.new(self,options)
|
42
40
|
gen.parse
|
43
41
|
gen.out
|
44
42
|
end
|
45
|
-
def save_html(file)
|
46
|
-
gen=Generator::Html.new(self)
|
43
|
+
def save_html(file, options={})
|
44
|
+
gen=Generator::Html.new(self,options)
|
47
45
|
gen.parse
|
48
46
|
File.open(@dir+"/"+file,"wb") {|fp|
|
49
47
|
fp.write(gen.out)
|
50
48
|
}
|
51
49
|
end
|
52
50
|
# Returns a Text output
|
53
|
-
def
|
54
|
-
gen=Generator::Text.new(self)
|
51
|
+
def to_text(options={})
|
52
|
+
gen=Generator::Text.new(self, options)
|
55
53
|
gen.parse
|
56
54
|
gen.out
|
57
55
|
end
|
56
|
+
alias_method :to_s, :to_text
|
58
57
|
end
|
data/test/test_html.rb
CHANGED
@@ -15,7 +15,7 @@ class TestReportbuilderHtml < Test::Unit::TestCase
|
|
15
15
|
def test_include_js
|
16
16
|
mock_element = ""
|
17
17
|
eval(" class << mock_element
|
18
|
-
def
|
18
|
+
def to_reportbuilder_html(generator)
|
19
19
|
generator.add_js('"+@datadir+"/reportbuilder.js')
|
20
20
|
end
|
21
21
|
end ")
|
@@ -35,7 +35,7 @@ class TestReportbuilderHtml < Test::Unit::TestCase
|
|
35
35
|
def test_include_css
|
36
36
|
mock_element = ""
|
37
37
|
eval(" class << mock_element
|
38
|
-
def
|
38
|
+
def to_reportbuilder_html(generator)
|
39
39
|
generator.add_css('"+@datadir+"/reportbuilder.css')
|
40
40
|
end
|
41
41
|
end ")
|
data/test/test_image.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
$:.unshift(File.dirname(__FILE__)+"/../lib")
|
3
|
+
require "reportbuilder"
|
4
|
+
|
5
|
+
class TestReportbuilderImage < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
@tmpdir=Dir::mktmpdir
|
8
|
+
@rp=ReportBuilder.new("Test", @tmpdir)
|
9
|
+
@datadir=File.dirname(__FILE__)+"/../data"
|
10
|
+
@rp.add(@rp.image(@datadir+"/sheep.jpg"))
|
11
|
+
end
|
12
|
+
def teardown
|
13
|
+
FileUtils.remove_entry_secure @tmpdir
|
14
|
+
end
|
15
|
+
def test_image_text
|
16
|
+
expected= <<-HERE
|
17
|
+
Report: Test
|
18
|
+
+--------------------------------+
|
19
|
+
| *********#** |
|
20
|
+
| ****#********# * |
|
21
|
+
| * * *********#******* * |
|
22
|
+
| * *** *** * *|
|
23
|
+
| * * WWW WW* *** |
|
24
|
+
| **** *WW* WWW * **#* |
|
25
|
+
| **** * * **** |
|
26
|
+
| ***** # ** *#*** |
|
27
|
+
| ****** ** * *#**** |
|
28
|
+
| ****** ******** |
|
29
|
+
| ******* ** ****** |
|
30
|
+
| **#*** * ******* |
|
31
|
+
| ****#** *#***** |
|
32
|
+
| **#***** |
|
33
|
+
+--------------------------------+
|
34
|
+
HERE
|
35
|
+
puts @rp.to_s
|
36
|
+
assert_equal(expected, @rp.to_s)
|
37
|
+
end
|
38
|
+
def test_image_html
|
39
|
+
assert_match(/img src='images\/sheep.jpg'/, @rp.to_html)
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
data/test/test_section.rb
CHANGED
@@ -5,14 +5,16 @@ require "reportbuilder"
|
|
5
5
|
class TestReportbuilderSection < Test::Unit::TestCase
|
6
6
|
def setup
|
7
7
|
@rp=ReportBuilder.new("Test Report")
|
8
|
-
s1=@rp.section("Section 1")
|
8
|
+
s1=@rp.section(:name=>"Section 1")
|
9
9
|
@rp.add s1
|
10
10
|
s1.add("Texto 1")
|
11
11
|
s1.add(2)
|
12
|
-
s11=@rp.section("Section 1.1")
|
12
|
+
s11=@rp.section(:name=>"Section 1.1")
|
13
13
|
s1.add s11
|
14
|
+
s111=@rp.section(:name=>"Section 1.1.1")
|
15
|
+
s11.add s111
|
14
16
|
s1.add("Texto 1.1")
|
15
|
-
s2=@rp.section("Section 2")
|
17
|
+
s2=@rp.section(:name=>"Section 2")
|
16
18
|
@rp.add s2
|
17
19
|
end
|
18
20
|
def test_section_text
|
@@ -22,6 +24,7 @@ Report: Test Report
|
|
22
24
|
Texto 1
|
23
25
|
2
|
24
26
|
== Section 1.1
|
27
|
+
=== Section 1.1.1
|
25
28
|
Texto 1.1
|
26
29
|
= Section 2
|
27
30
|
|
@@ -35,18 +38,23 @@ HERE
|
|
35
38
|
<li><a href='#toc_1'>Section 1</a></li>
|
36
39
|
<ul>
|
37
40
|
<li><a href='#toc_2'>Section 1.1</a></li>
|
41
|
+
<ul>
|
42
|
+
<li><a href='#toc_3'>Section 1.1.1</a></li>
|
43
|
+
</ul>
|
38
44
|
</ul>
|
39
|
-
<li><a href='#
|
45
|
+
<li><a href='#toc_4'>Section 2</a></li>
|
40
46
|
</ul>
|
41
47
|
</div>
|
42
48
|
<div class='section'><h2>Section 1</h2><a name='toc_1'></a>
|
43
49
|
<pre>Texto 1</pre>
|
44
50
|
<pre>2</pre>
|
45
51
|
<div class='section'><h3>Section 1.1</h3><a name='toc_2'></a>
|
52
|
+
<div class='section'><h4>Section 1.1.1</h4><a name='toc_3'></a>
|
53
|
+
</div>
|
46
54
|
</div>
|
47
55
|
<pre>Texto 1.1</pre>
|
48
56
|
</div>
|
49
|
-
<div class='section'><h2>Section 2</h2><a name='
|
57
|
+
<div class='section'><h2>Section 2</h2><a name='toc_4'></a>
|
50
58
|
</div>
|
51
59
|
</body></html>
|
52
60
|
HERE
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reportbuilder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Claudio Bustos
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-02-06 00:00:00 -03:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 2.
|
23
|
+
version: 2.4.0
|
24
24
|
version:
|
25
25
|
description: Report Abstract Interface. Creates text, html and pdf output, based on a common framework
|
26
26
|
email:
|
@@ -41,15 +41,18 @@ files:
|
|
41
41
|
- bin/reportbuilder
|
42
42
|
- data/reportbuilder.css
|
43
43
|
- data/reportbuilder.js
|
44
|
+
- data/sheep.jpg
|
45
|
+
- lib/reportbuilder.rb
|
44
46
|
- lib/reportbuilder/generator.rb
|
45
47
|
- lib/reportbuilder/generator/html.rb
|
46
48
|
- lib/reportbuilder/generator/text.rb
|
47
|
-
- lib/reportbuilder.rb
|
49
|
+
- lib/reportbuilder/image.rb
|
48
50
|
- lib/reportbuilder/section.rb
|
49
51
|
- lib/reportbuilder/table.rb
|
50
52
|
- lib/reportbuilder/table/htmlgenerator.rb
|
51
53
|
- lib/reportbuilder/table/textgenerator.rb
|
52
54
|
- test/test_html.rb
|
55
|
+
- test/test_image.rb
|
53
56
|
- test/test_reportbuilder.rb
|
54
57
|
- test/test_section.rb
|
55
58
|
- test/test_table.rb
|
@@ -85,5 +88,6 @@ summary: Report Abstract Interface
|
|
85
88
|
test_files:
|
86
89
|
- test/test_section.rb
|
87
90
|
- test/test_table.rb
|
91
|
+
- test/test_image.rb
|
88
92
|
- test/test_html.rb
|
89
93
|
- test/test_reportbuilder.rb
|