ruport 1.2.2 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -1
- data/examples/png_embed.rb +2 -3
- data/lib/ruport.rb +1 -1
- data/lib/ruport/formatter/csv.rb +8 -9
- data/lib/ruport/formatter/html.rb +7 -7
- data/lib/ruport/formatter/pdf.rb +12 -10
- data/lib/ruport/formatter/template.rb +4 -2
- data/lib/ruport/formatter/text.rb +12 -12
- data/lib/ruport/renderer.rb +2 -0
- data/test/csv_formatter_test.rb +56 -11
- data/test/html_formatter_test.rb +52 -10
- data/test/pdf_formatter_test.rb +120 -26
- data/test/query_test.rb +7 -4
- data/test/renderer_test.rb +19 -0
- data/test/text_formatter_test.rb +74 -16
- metadata +2 -2
data/Rakefile
CHANGED
data/examples/png_embed.rb
CHANGED
@@ -54,7 +54,6 @@ end
|
|
54
54
|
|
55
55
|
formats = [:html, :pdf]
|
56
56
|
formats.each do |format|
|
57
|
-
|
58
|
-
|
59
|
-
end
|
57
|
+
RoadmapRenderer.render(format, :image_file => "roadmap.png",
|
58
|
+
:file => "roadmap.#{format}")
|
60
59
|
end
|
data/lib/ruport.rb
CHANGED
data/lib/ruport/formatter/csv.rb
CHANGED
@@ -43,8 +43,7 @@ module Ruport
|
|
43
43
|
apply_table_format_template(template.table_format)
|
44
44
|
apply_grouping_format_template(template.grouping_format)
|
45
45
|
|
46
|
-
options.format_options
|
47
|
-
template.format_options
|
46
|
+
options.format_options ||= template.format_options
|
48
47
|
end
|
49
48
|
|
50
49
|
# Generates table header by turning column_names into a CSV row.
|
@@ -122,16 +121,16 @@ module Ruport
|
|
122
121
|
end
|
123
122
|
|
124
123
|
def apply_table_format_template(t)
|
125
|
-
t = t || {}
|
126
|
-
options.show_table_headers = t[:show_headings]
|
127
|
-
|
124
|
+
t = (t || {}).merge(options.table_format || {})
|
125
|
+
options.show_table_headers = t[:show_headings] if
|
126
|
+
options.show_table_headers.nil?
|
128
127
|
end
|
129
128
|
|
130
129
|
def apply_grouping_format_template(t)
|
131
|
-
t = t || {}
|
132
|
-
options.style
|
133
|
-
options.show_group_headers = t[:show_headings]
|
134
|
-
|
130
|
+
t = (t || {}).merge(options.grouping_format || {})
|
131
|
+
options.style ||= t[:style]
|
132
|
+
options.show_group_headers = t[:show_headings] if
|
133
|
+
options.show_group_headers.nil?
|
135
134
|
end
|
136
135
|
|
137
136
|
end
|
@@ -148,16 +148,16 @@ module Ruport
|
|
148
148
|
end
|
149
149
|
|
150
150
|
def apply_table_format_template(t)
|
151
|
-
t = t || {}
|
152
|
-
options.show_table_headers = t[:show_headings]
|
153
|
-
|
151
|
+
t = (t || {}).merge(options.table_format || {})
|
152
|
+
options.show_table_headers = t[:show_headings] if
|
153
|
+
options.show_table_headers.nil?
|
154
154
|
end
|
155
155
|
|
156
156
|
def apply_grouping_format_template(t)
|
157
|
-
t = t || {}
|
158
|
-
options.style
|
159
|
-
options.show_group_headers = t[:show_headings]
|
160
|
-
|
157
|
+
t = (t || {}).merge(options.grouping_format || {})
|
158
|
+
options.style ||= t[:style]
|
159
|
+
options.show_group_headers = t[:show_headings] if
|
160
|
+
options.show_group_headers.nil?
|
161
161
|
end
|
162
162
|
|
163
163
|
end
|
data/lib/ruport/formatter/pdf.rb
CHANGED
@@ -194,7 +194,7 @@ module Ruport
|
|
194
194
|
y = image_opts[:y]
|
195
195
|
width = image_opts[:width]
|
196
196
|
height = image_opts[:height]
|
197
|
-
info = ::PDF::Writer::Graphics::ImageInfo.new(File.
|
197
|
+
info = ::PDF::Writer::Graphics::ImageInfo.new(File.open(path, "rb"))
|
198
198
|
|
199
199
|
# reduce the size of the image until it fits into the requested box
|
200
200
|
img_width, img_height =
|
@@ -554,21 +554,23 @@ module Ruport
|
|
554
554
|
end
|
555
555
|
|
556
556
|
def apply_page_format_template(t)
|
557
|
-
t = t || {}
|
558
|
-
options.paper_size
|
559
|
-
options.paper_orientation
|
557
|
+
t = (t || {}).merge(options.page_format || {})
|
558
|
+
options.paper_size ||= t[:size]
|
559
|
+
options.paper_orientation ||= t[:layout]
|
560
560
|
end
|
561
561
|
|
562
562
|
def apply_text_format_template(t)
|
563
|
-
|
563
|
+
t = (t || {}).merge(options.text_format || {})
|
564
|
+
options.text_format = t unless t.empty?
|
564
565
|
end
|
565
566
|
|
566
567
|
def apply_table_format_template(t)
|
567
|
-
|
568
|
+
t = (t || {}).merge(options.table_format || {})
|
569
|
+
options.table_format = t unless t.empty?
|
568
570
|
end
|
569
571
|
|
570
572
|
def apply_column_format_template(t)
|
571
|
-
t = t || {}
|
573
|
+
t = (t || {}).merge(options.column_format || {})
|
572
574
|
column_opts = {}
|
573
575
|
column_opts.merge!(:justification => t[:alignment]) if t[:alignment]
|
574
576
|
column_opts.merge!(:width => t[:width]) if t[:width]
|
@@ -587,7 +589,7 @@ module Ruport
|
|
587
589
|
end
|
588
590
|
|
589
591
|
def apply_heading_format_template(t)
|
590
|
-
t = t || {}
|
592
|
+
t = (t || {}).merge(options.heading_format || {})
|
591
593
|
heading_opts = {}
|
592
594
|
heading_opts.merge!(:justification => t[:alignment]) if t[:alignment]
|
593
595
|
heading_opts.merge!(:bold => t[:bold]) unless t[:bold].nil?
|
@@ -619,8 +621,8 @@ module Ruport
|
|
619
621
|
end
|
620
622
|
|
621
623
|
def apply_grouping_format_template(t)
|
622
|
-
t = t || {}
|
623
|
-
options.style
|
624
|
+
t = (t || {}).merge(options.grouping_format || {})
|
625
|
+
options.style ||= t[:style]
|
624
626
|
end
|
625
627
|
end
|
626
628
|
end
|
@@ -7,6 +7,8 @@
|
|
7
7
|
# This is free software. Please see the LICENSE and COPYING files for details.
|
8
8
|
|
9
9
|
|
10
|
+
class Ruport::Formatter::TemplateNotDefined < StandardError; end
|
11
|
+
|
10
12
|
# This class provides templating functionality for Ruport.
|
11
13
|
# New templates are created using the Template.create method.
|
12
14
|
#
|
@@ -162,6 +164,6 @@ class Ruport::Formatter::Template < Ruport::Renderer::Options
|
|
162
164
|
|
163
165
|
# Returns an existing template with the provided name (label).
|
164
166
|
def self.[](label)
|
165
|
-
templates[label]
|
167
|
+
templates[label] or raise Ruport::Formatter::TemplateNotDefined
|
166
168
|
end
|
167
|
-
end
|
169
|
+
end
|
@@ -218,24 +218,24 @@ module Ruport
|
|
218
218
|
private
|
219
219
|
|
220
220
|
def apply_table_format_template(t)
|
221
|
-
t = t || {}
|
222
|
-
options.show_table_headers = t[:show_headings]
|
223
|
-
|
224
|
-
options.table_width
|
225
|
-
options.ignore_table_width = t[:ignore_width]
|
226
|
-
|
221
|
+
t = (t || {}).merge(options.table_format || {})
|
222
|
+
options.show_table_headers = t[:show_headings] if
|
223
|
+
options.show_table_headers.nil?
|
224
|
+
options.table_width ||= t[:width]
|
225
|
+
options.ignore_table_width = t[:ignore_width] if
|
226
|
+
options.ignore_table_width.nil?
|
227
227
|
end
|
228
228
|
|
229
229
|
def apply_column_format_template(t)
|
230
|
-
t = t || {}
|
231
|
-
options.max_col_width
|
232
|
-
options.alignment
|
230
|
+
t = (t || {}).merge(options.column_format || {})
|
231
|
+
options.max_col_width ||= t[:maximum_width]
|
232
|
+
options.alignment ||= t[:alignment]
|
233
233
|
end
|
234
234
|
|
235
235
|
def apply_grouping_format_template(t)
|
236
|
-
t = t || {}
|
237
|
-
options.show_group_headers = t[:show_headings]
|
238
|
-
|
236
|
+
t = (t || {}).merge(options.grouping_format || {})
|
237
|
+
options.show_group_headers = t[:show_headings] if
|
238
|
+
options.show_group_headers.nil?
|
239
239
|
end
|
240
240
|
|
241
241
|
end
|
data/lib/ruport/renderer.rb
CHANGED
data/test/csv_formatter_test.rb
CHANGED
@@ -9,6 +9,19 @@ class TestRenderCSVRow < Test::Unit::TestCase
|
|
9
9
|
end
|
10
10
|
|
11
11
|
class TestRenderCSVTable < Test::Unit::TestCase
|
12
|
+
|
13
|
+
def setup
|
14
|
+
Ruport::Formatter::Template.create(:simple) do |t|
|
15
|
+
t.table_format = {
|
16
|
+
:show_headings => false
|
17
|
+
}
|
18
|
+
t.grouping_format = {
|
19
|
+
:style => :justified,
|
20
|
+
:show_headings => false
|
21
|
+
}
|
22
|
+
t.format_options = { :col_sep => ":" }
|
23
|
+
end
|
24
|
+
end
|
12
25
|
|
13
26
|
def test_render_csv_table
|
14
27
|
actual = Ruport::Renderer::Table.render_csv do |r|
|
@@ -36,17 +49,6 @@ class TestRenderCSVTable < Test::Unit::TestCase
|
|
36
49
|
end
|
37
50
|
|
38
51
|
def test_render_with_template
|
39
|
-
Ruport::Formatter::Template.create(:simple) do |t|
|
40
|
-
t.table_format = {
|
41
|
-
:show_headings => false
|
42
|
-
}
|
43
|
-
t.grouping_format = {
|
44
|
-
:style => :justified,
|
45
|
-
:show_headings => false
|
46
|
-
}
|
47
|
-
t.format_options = { :col_sep => ":" }
|
48
|
-
end
|
49
|
-
|
50
52
|
formatter = Ruport::Formatter::CSV.new
|
51
53
|
formatter.options = Ruport::Renderer::Options.new
|
52
54
|
formatter.options.template = :simple
|
@@ -59,6 +61,49 @@ class TestRenderCSVTable < Test::Unit::TestCase
|
|
59
61
|
|
60
62
|
assert_equal ":", formatter.options.format_options[:col_sep]
|
61
63
|
end
|
64
|
+
|
65
|
+
def test_options_hashes_override_template
|
66
|
+
opts = nil
|
67
|
+
table = Table(%w[a b c])
|
68
|
+
table.to_csv(
|
69
|
+
:template => :simple,
|
70
|
+
:table_format => {
|
71
|
+
:show_headings => true
|
72
|
+
},
|
73
|
+
:grouping_format => {
|
74
|
+
:style => :raw,
|
75
|
+
:show_headings => true
|
76
|
+
}
|
77
|
+
) do |r|
|
78
|
+
opts = r.options
|
79
|
+
end
|
80
|
+
|
81
|
+
assert_equal true, opts.show_table_headers
|
82
|
+
|
83
|
+
assert_equal :raw, opts.style
|
84
|
+
assert_equal true, opts.show_group_headers
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_individual_options_override_template
|
88
|
+
opts = nil
|
89
|
+
table = Table(%w[a b c])
|
90
|
+
table.to_csv(
|
91
|
+
:template => :simple,
|
92
|
+
:show_table_headers => true,
|
93
|
+
:style => :raw,
|
94
|
+
:show_group_headers => true,
|
95
|
+
:format_options => { :col_sep => ";" }
|
96
|
+
) do |r|
|
97
|
+
opts = r.options
|
98
|
+
end
|
99
|
+
|
100
|
+
assert_equal true, opts.show_table_headers
|
101
|
+
|
102
|
+
assert_equal :raw, opts.style
|
103
|
+
assert_equal true, opts.show_group_headers
|
104
|
+
|
105
|
+
assert_equal ";", opts.format_options[:col_sep]
|
106
|
+
end
|
62
107
|
end
|
63
108
|
|
64
109
|
class TestRenderCSVGroup < Test::Unit::TestCase
|
data/test/html_formatter_test.rb
CHANGED
@@ -3,6 +3,18 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "helpers")
|
|
3
3
|
|
4
4
|
class TestRenderHTMLTable < Test::Unit::TestCase
|
5
5
|
|
6
|
+
def setup
|
7
|
+
Ruport::Formatter::Template.create(:simple) do |t|
|
8
|
+
t.table_format = {
|
9
|
+
:show_headings => false
|
10
|
+
}
|
11
|
+
t.grouping_format = {
|
12
|
+
:style => :justified,
|
13
|
+
:show_headings => false
|
14
|
+
}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
6
18
|
def test_html_table
|
7
19
|
a = Ruport::Formatter::HTML.new
|
8
20
|
|
@@ -34,16 +46,6 @@ class TestRenderHTMLTable < Test::Unit::TestCase
|
|
34
46
|
end
|
35
47
|
|
36
48
|
def test_render_with_template
|
37
|
-
Ruport::Formatter::Template.create(:simple) do |t|
|
38
|
-
t.table_format = {
|
39
|
-
:show_headings => false
|
40
|
-
}
|
41
|
-
t.grouping_format = {
|
42
|
-
:style => :justified,
|
43
|
-
:show_headings => false
|
44
|
-
}
|
45
|
-
end
|
46
|
-
|
47
49
|
formatter = Ruport::Formatter::HTML.new
|
48
50
|
formatter.options = Ruport::Renderer::Options.new
|
49
51
|
formatter.options.template = :simple
|
@@ -54,6 +56,46 @@ class TestRenderHTMLTable < Test::Unit::TestCase
|
|
54
56
|
assert_equal :justified, formatter.options.style
|
55
57
|
assert_equal false, formatter.options.show_group_headers
|
56
58
|
end
|
59
|
+
|
60
|
+
def test_options_hashes_override_template
|
61
|
+
opts = nil
|
62
|
+
table = Table(%w[a b c])
|
63
|
+
table.to_html(
|
64
|
+
:template => :simple,
|
65
|
+
:table_format => {
|
66
|
+
:show_headings => true
|
67
|
+
},
|
68
|
+
:grouping_format => {
|
69
|
+
:style => :inline,
|
70
|
+
:show_headings => true
|
71
|
+
}
|
72
|
+
) do |r|
|
73
|
+
opts = r.options
|
74
|
+
end
|
75
|
+
|
76
|
+
assert_equal true, opts.show_table_headers
|
77
|
+
|
78
|
+
assert_equal :inline, opts.style
|
79
|
+
assert_equal true, opts.show_group_headers
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_individual_options_override_template
|
83
|
+
opts = nil
|
84
|
+
table = Table(%w[a b c])
|
85
|
+
table.to_html(
|
86
|
+
:template => :simple,
|
87
|
+
:show_table_headers => true,
|
88
|
+
:style => :inline,
|
89
|
+
:show_group_headers => true
|
90
|
+
) do |r|
|
91
|
+
opts = r.options
|
92
|
+
end
|
93
|
+
|
94
|
+
assert_equal true, opts.show_table_headers
|
95
|
+
|
96
|
+
assert_equal :inline, opts.style
|
97
|
+
assert_equal true, opts.show_group_headers
|
98
|
+
end
|
57
99
|
end
|
58
100
|
|
59
101
|
|
data/test/pdf_formatter_test.rb
CHANGED
@@ -2,6 +2,33 @@
|
|
2
2
|
require File.join(File.expand_path(File.dirname(__FILE__)), "helpers")
|
3
3
|
|
4
4
|
class TestRenderPDFTable < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
Ruport::Formatter::Template.create(:simple) do |t|
|
8
|
+
t.page_format = {
|
9
|
+
:size => "LETTER",
|
10
|
+
:layout => :landscape
|
11
|
+
}
|
12
|
+
t.text_format = {
|
13
|
+
:font_size => 16
|
14
|
+
}
|
15
|
+
t.table_format = {
|
16
|
+
:show_headings => false
|
17
|
+
}
|
18
|
+
t.column_format = {
|
19
|
+
:alignment => :center,
|
20
|
+
:width => 50
|
21
|
+
}
|
22
|
+
t.heading_format = {
|
23
|
+
:alignment => :right,
|
24
|
+
:bold => false,
|
25
|
+
:title => "Test"
|
26
|
+
}
|
27
|
+
t.grouping_format = {
|
28
|
+
:style => :separated
|
29
|
+
}
|
30
|
+
end
|
31
|
+
end
|
5
32
|
|
6
33
|
def test_render_pdf_basic
|
7
34
|
# can't render without column names
|
@@ -35,31 +62,6 @@ class TestRenderPDFTable < Test::Unit::TestCase
|
|
35
62
|
end
|
36
63
|
|
37
64
|
def test_render_with_template
|
38
|
-
Ruport::Formatter::Template.create(:simple) do |t|
|
39
|
-
t.page_format = {
|
40
|
-
:size => "LETTER",
|
41
|
-
:layout => :landscape
|
42
|
-
}
|
43
|
-
t.text_format = {
|
44
|
-
:font_size => 16
|
45
|
-
}
|
46
|
-
t.table_format = {
|
47
|
-
:show_headings => false
|
48
|
-
}
|
49
|
-
t.column_format = {
|
50
|
-
:alignment => :center,
|
51
|
-
:width => 50
|
52
|
-
}
|
53
|
-
t.heading_format = {
|
54
|
-
:alignment => :right,
|
55
|
-
:bold => false,
|
56
|
-
:title => "Test"
|
57
|
-
}
|
58
|
-
t.grouping_format = {
|
59
|
-
:style => :separated
|
60
|
-
}
|
61
|
-
end
|
62
|
-
|
63
65
|
formatter = Ruport::Formatter::PDF.new
|
64
66
|
formatter.options = Ruport::Renderer::Options.new
|
65
67
|
formatter.options.template = :simple
|
@@ -87,6 +89,98 @@ class TestRenderPDFTable < Test::Unit::TestCase
|
|
87
89
|
assert_equal :separated, formatter.options.style
|
88
90
|
end
|
89
91
|
|
92
|
+
def test_options_hashes_override_template
|
93
|
+
opts = nil
|
94
|
+
table = Table(%w[a b c])
|
95
|
+
table.to_pdf(
|
96
|
+
:template => :simple,
|
97
|
+
:page_format => {
|
98
|
+
:size => "LEGAL",
|
99
|
+
:layout => :portrait
|
100
|
+
},
|
101
|
+
:text_format => {
|
102
|
+
:font_size => 20
|
103
|
+
},
|
104
|
+
:table_format => {
|
105
|
+
:show_headings => true
|
106
|
+
},
|
107
|
+
:column_format => {
|
108
|
+
:alignment => :left,
|
109
|
+
:width => 25
|
110
|
+
},
|
111
|
+
:heading_format => {
|
112
|
+
:alignment => :left,
|
113
|
+
:bold => true,
|
114
|
+
:title => "Replace"
|
115
|
+
},
|
116
|
+
:grouping_format => {
|
117
|
+
:style => :inline
|
118
|
+
}
|
119
|
+
) do |r|
|
120
|
+
opts = r.options
|
121
|
+
end
|
122
|
+
|
123
|
+
assert_equal "LEGAL", opts.paper_size
|
124
|
+
assert_equal :portrait, opts.paper_orientation
|
125
|
+
|
126
|
+
assert_equal 20, opts.text_format[:font_size]
|
127
|
+
|
128
|
+
assert_equal true, opts.table_format[:show_headings]
|
129
|
+
|
130
|
+
assert_equal :left, opts.table_format[:column_options][:justification]
|
131
|
+
assert_equal 25, opts.table_format[:column_options][:width]
|
132
|
+
|
133
|
+
assert_equal :left,
|
134
|
+
opts.table_format[:column_options][:heading][:justification]
|
135
|
+
assert_equal true, opts.table_format[:column_options][:heading][:bold]
|
136
|
+
assert_equal "Replace", opts.table_format[:column_options][:heading][:title]
|
137
|
+
|
138
|
+
assert_equal :inline, opts.style
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_individual_options_override_template
|
142
|
+
opts = nil
|
143
|
+
table = Table(%w[a b c])
|
144
|
+
table.to_pdf(
|
145
|
+
:template => :simple,
|
146
|
+
:paper_size => "LEGAL",
|
147
|
+
:paper_orientation => :portrait,
|
148
|
+
:text_format => { :font_size => 20 },
|
149
|
+
:table_format => {
|
150
|
+
:show_headings => true,
|
151
|
+
:column_options => {
|
152
|
+
:justification => :left,
|
153
|
+
:width => 25,
|
154
|
+
:heading => {
|
155
|
+
:justification => :left,
|
156
|
+
:bold => true,
|
157
|
+
:title => "Replace"
|
158
|
+
}
|
159
|
+
}
|
160
|
+
},
|
161
|
+
:style => :inline
|
162
|
+
) do |r|
|
163
|
+
opts = r.options
|
164
|
+
end
|
165
|
+
|
166
|
+
assert_equal "LEGAL", opts.paper_size
|
167
|
+
assert_equal :portrait, opts.paper_orientation
|
168
|
+
|
169
|
+
assert_equal 20, opts.text_format[:font_size]
|
170
|
+
|
171
|
+
assert_equal true, opts.table_format[:show_headings]
|
172
|
+
|
173
|
+
assert_equal :left, opts.table_format[:column_options][:justification]
|
174
|
+
assert_equal 25, opts.table_format[:column_options][:width]
|
175
|
+
|
176
|
+
assert_equal :left,
|
177
|
+
opts.table_format[:column_options][:heading][:justification]
|
178
|
+
assert_equal true, opts.table_format[:column_options][:heading][:bold]
|
179
|
+
assert_equal "Replace", opts.table_format[:column_options][:heading][:title]
|
180
|
+
|
181
|
+
assert_equal :inline, opts.style
|
182
|
+
end
|
183
|
+
|
90
184
|
#--------BUG TRAPS--------#
|
91
185
|
|
92
186
|
# PDF::SimpleTable does not handle symbols as column names
|
@@ -105,7 +199,7 @@ class TestRenderPDFTable < Test::Unit::TestCase
|
|
105
199
|
f.draw_table [[1,2,3],[4,5,6]].to_table(%w[a b c])
|
106
200
|
assert_equal({ :justification => :center },
|
107
201
|
f.options[:table_format][:column_options][:heading])
|
108
|
-
end
|
202
|
+
end
|
109
203
|
|
110
204
|
end
|
111
205
|
|
data/test/query_test.rb
CHANGED
@@ -215,7 +215,6 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "helpers")
|
|
215
215
|
def setup_mock_dbi(count, options={})
|
216
216
|
sql = options[:sql] || @sql[0]
|
217
217
|
source = options[:source] || :default
|
218
|
-
returns = options[:returns] || Proc.new { @datasets.shift }
|
219
218
|
resultless = options[:resultless]
|
220
219
|
params = options[:params] || []
|
221
220
|
|
@@ -233,9 +232,13 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "helpers")
|
|
233
232
|
@dbh.stubs(:sth__).returns(@sth)
|
234
233
|
@sth.expects(:finish).with().times(count)
|
235
234
|
unless resultless
|
236
|
-
@sth.stubs(:fetchable?).returns(true)
|
237
|
-
@sth.stubs(:column_names).returns(@columns)
|
238
|
-
|
235
|
+
@sth.stubs(:fetchable?).returns(true)
|
236
|
+
@sth.stubs(:column_names).returns(@columns)
|
237
|
+
if options[:returns]
|
238
|
+
@sth.expects(:data__).returns(options[:returns]).times(count)
|
239
|
+
else
|
240
|
+
@sth.expects(:data__).returns(*@datasets).times(count)
|
241
|
+
end
|
239
242
|
else
|
240
243
|
@sth.stubs(:fetchable?).returns(false)
|
241
244
|
@sth.stubs(:column_names).returns([])
|
data/test/renderer_test.rb
CHANGED
@@ -77,6 +77,12 @@ class TestRenderer < Test::Unit::TestCase
|
|
77
77
|
Table(%w[a b c]).to_csv(:template => :stub) do |r|
|
78
78
|
r.formatter.expects(:apply_template)
|
79
79
|
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def specify_undefined_template_should_throw_sensible_error
|
83
|
+
assert_raises(Ruport::Formatter::TemplateNotDefined) do
|
84
|
+
Table(%w[a b c]).to_csv(:template => :sub)
|
85
|
+
end
|
80
86
|
end
|
81
87
|
end
|
82
88
|
|
@@ -560,4 +566,17 @@ class TestRendererHooks < Test::Unit::TestCase
|
|
560
566
|
|
561
567
|
end
|
562
568
|
|
569
|
+
context "when attempting to render a format that doesn't exist" do
|
570
|
+
|
571
|
+
def specify_an_unknown_format_error_should_be_raised
|
572
|
+
|
573
|
+
assert_raises(Ruport::Renderer::UnknownFormatError) do
|
574
|
+
Ruport::Renderer.render_foo
|
575
|
+
end
|
576
|
+
|
577
|
+
end
|
578
|
+
end
|
579
|
+
|
580
|
+
|
581
|
+
|
563
582
|
end
|
data/test/text_formatter_test.rb
CHANGED
@@ -3,6 +3,23 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "helpers")
|
|
3
3
|
|
4
4
|
class TestRenderTextTable < Test::Unit::TestCase
|
5
5
|
|
6
|
+
def setup
|
7
|
+
Ruport::Formatter::Template.create(:simple) do |t|
|
8
|
+
t.table_format = {
|
9
|
+
:show_headings => false,
|
10
|
+
:width => 50,
|
11
|
+
:ignore_width => true
|
12
|
+
}
|
13
|
+
t.column_format = {
|
14
|
+
:maximum_width => [5,5,7],
|
15
|
+
:alignment => :center
|
16
|
+
}
|
17
|
+
t.grouping_format = {
|
18
|
+
:show_headings => false
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
6
23
|
def test_basic
|
7
24
|
|
8
25
|
tf = "+-------+\n"
|
@@ -63,21 +80,6 @@ class TestRenderTextTable < Test::Unit::TestCase
|
|
63
80
|
end
|
64
81
|
|
65
82
|
def test_render_with_template
|
66
|
-
Ruport::Formatter::Template.create(:simple) do |t|
|
67
|
-
t.table_format = {
|
68
|
-
:show_headings => false,
|
69
|
-
:width => 50,
|
70
|
-
:ignore_width => true
|
71
|
-
}
|
72
|
-
t.column_format = {
|
73
|
-
:maximum_width => 5,
|
74
|
-
:alignment => :center
|
75
|
-
}
|
76
|
-
t.grouping_format = {
|
77
|
-
:show_headings => false
|
78
|
-
}
|
79
|
-
end
|
80
|
-
|
81
83
|
formatter = Ruport::Formatter::Text.new
|
82
84
|
formatter.options = Ruport::Renderer::Options.new
|
83
85
|
formatter.options.template = :simple
|
@@ -87,11 +89,67 @@ class TestRenderTextTable < Test::Unit::TestCase
|
|
87
89
|
assert_equal 50, formatter.options.table_width
|
88
90
|
assert_equal true, formatter.options.ignore_table_width
|
89
91
|
|
90
|
-
assert_equal 5, formatter.options.max_col_width
|
92
|
+
assert_equal [5,5,7], formatter.options.max_col_width
|
91
93
|
assert_equal :center, formatter.options.alignment
|
92
94
|
|
93
95
|
assert_equal false, formatter.options.show_group_headers
|
94
96
|
end
|
97
|
+
|
98
|
+
def test_options_hashes_override_template
|
99
|
+
opts = nil
|
100
|
+
table = Table(%w[a b c])
|
101
|
+
table.to_text(
|
102
|
+
:template => :simple,
|
103
|
+
:table_format => {
|
104
|
+
:show_headings => true,
|
105
|
+
:width => 25,
|
106
|
+
:ignore_width => false
|
107
|
+
},
|
108
|
+
:column_format => {
|
109
|
+
:maximum_width => [10,10,10],
|
110
|
+
:alignment => :left
|
111
|
+
},
|
112
|
+
:grouping_format => {
|
113
|
+
:show_headings => true
|
114
|
+
}
|
115
|
+
) do |r|
|
116
|
+
opts = r.options
|
117
|
+
end
|
118
|
+
|
119
|
+
assert_equal true, opts.show_table_headers
|
120
|
+
assert_equal 25, opts.table_width
|
121
|
+
assert_equal false, opts.ignore_table_width
|
122
|
+
|
123
|
+
assert_equal [10,10,10], opts.max_col_width
|
124
|
+
assert_equal :left, opts.alignment
|
125
|
+
|
126
|
+
assert_equal true, opts.show_group_headers
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_individual_options_override_template
|
130
|
+
opts = nil
|
131
|
+
table = Table(%w[a b c])
|
132
|
+
table.to_text(
|
133
|
+
:template => :simple,
|
134
|
+
:show_table_headers => true,
|
135
|
+
:table_width => 75,
|
136
|
+
:ignore_table_width => false,
|
137
|
+
:max_col_width => [4,4,4],
|
138
|
+
:alignment => :left,
|
139
|
+
:show_group_headers => true
|
140
|
+
) do |r|
|
141
|
+
opts = r.options
|
142
|
+
end
|
143
|
+
|
144
|
+
assert_equal true, opts.show_table_headers
|
145
|
+
assert_equal 75, opts.table_width
|
146
|
+
assert_equal false, opts.ignore_table_width
|
147
|
+
|
148
|
+
assert_equal [4,4,4], opts.max_col_width
|
149
|
+
assert_equal :left, opts.alignment
|
150
|
+
|
151
|
+
assert_equal true, opts.show_group_headers
|
152
|
+
end
|
95
153
|
|
96
154
|
# -- BUG TRAPS ------------------------------
|
97
155
|
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: ruport
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.2.
|
7
|
-
date: 2007-
|
6
|
+
version: 1.2.3
|
7
|
+
date: 2007-11-24 00:00:00 -05:00
|
8
8
|
summary: A generalized Ruby report generation and templating engine.
|
9
9
|
require_paths:
|
10
10
|
- lib
|