ruport 1.6.3 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/AUTHORS +11 -0
- data/CHANGELOG.md +38 -0
- data/HACKING +1 -17
- data/README.md +97 -0
- data/Rakefile +9 -50
- data/examples/add_row_table.rb +46 -0
- data/examples/data/wine.csv +255 -0
- data/examples/pdf_grouping.rb +39 -0
- data/examples/pdf_table.rb +28 -0
- data/examples/pdf_table_from_csv.rb +26 -0
- data/examples/pdf_table_prawn.rb +30 -0
- data/examples/pdf_table_simple.rb +13 -0
- data/examples/row_renderer.rb +1 -1
- data/examples/simple_pdf_lines.rb +1 -1
- data/examples/trac_ticket_status.rb +1 -1
- data/lib/ruport/controller.rb +17 -21
- data/lib/ruport/data/feeder.rb +2 -2
- data/lib/ruport/data/grouping.rb +8 -8
- data/lib/ruport/data/record.rb +4 -4
- data/lib/ruport/data/table.rb +318 -206
- data/lib/ruport/formatter/csv.rb +6 -7
- data/lib/ruport/formatter/html.rb +13 -11
- data/lib/ruport/formatter/markdown.rb +105 -0
- data/lib/ruport/formatter/prawn_pdf.rb +159 -0
- data/lib/ruport/formatter/template.rb +1 -1
- data/lib/ruport/formatter/text.rb +1 -1
- data/lib/ruport/formatter.rb +54 -54
- data/lib/ruport/version.rb +1 -1
- data/lib/ruport.rb +7 -23
- data/test/controller_test.rb +201 -225
- data/test/csv_formatter_test.rb +36 -36
- data/test/data_feeder_test.rb +64 -64
- data/test/expected_outputs/prawn_pdf_formatter/pdf_basic.pdf.test +265 -0
- data/test/grouping_test.rb +103 -102
- data/test/helpers.rb +29 -10
- data/test/html_formatter_test.rb +46 -46
- data/test/markdown_formatter_test.rb +142 -0
- data/test/prawn_pdf_formatter_test.rb +108 -0
- data/test/record_test.rb +91 -91
- data/test/samples/sales.csv +21 -0
- data/test/table_pivot_test.rb +77 -26
- data/test/table_test.rb +376 -354
- data/test/template_test.rb +13 -13
- data/test/text_formatter_test.rb +52 -52
- data/util/bench/data/table/bench_column_manip.rb +0 -1
- data/util/bench/data/table/bench_dup.rb +0 -1
- data/util/bench/data/table/bench_init.rb +1 -2
- data/util/bench/data/table/bench_manip.rb +0 -1
- data/util/bench/formatter/bench_csv.rb +0 -1
- data/util/bench/formatter/bench_html.rb +0 -1
- data/util/bench/formatter/bench_pdf.rb +0 -1
- data/util/bench/formatter/bench_text.rb +0 -1
- metadata +131 -82
- data/README +0 -114
- data/lib/ruport/formatter/pdf.rb +0 -591
- data/test/pdf_formatter_test.rb +0 -354
data/test/html_formatter_test.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
#!/usr/bin/env ruby -w
|
1
|
+
#!/usr/bin/env ruby -w
|
2
2
|
require File.join(File.expand_path(File.dirname(__FILE__)), "helpers")
|
3
3
|
|
4
|
-
class TestRenderHTMLTable < Test
|
5
|
-
|
4
|
+
class TestRenderHTMLTable < Minitest::Test
|
5
|
+
|
6
6
|
def setup
|
7
7
|
Ruport::Formatter::Template.create(:simple) do |format|
|
8
8
|
format.table = {
|
@@ -14,7 +14,7 @@ class TestRenderHTMLTable < Test::Unit::TestCase
|
|
14
14
|
}
|
15
15
|
end
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def test_html_table
|
19
19
|
a = Ruport::Formatter::HTML.new
|
20
20
|
|
@@ -23,34 +23,34 @@ class TestRenderHTMLTable < Test::Unit::TestCase
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def test_render_html_basic
|
26
|
-
|
26
|
+
|
27
27
|
actual = Ruport::Controller::Table.render_html { |r|
|
28
|
-
r.data = Table([], :data => [[1,2,3],[4,5,6]])
|
29
|
-
}
|
30
|
-
|
28
|
+
r.data = Ruport.Table([], :data => [[1,2,3],[4,5,6]])
|
29
|
+
}
|
30
|
+
|
31
31
|
assert_equal("\t<table>\n\t\t<tr>\n\t\t\t<td>1</td>\n\t\t\t<td>2"+
|
32
32
|
"</td>\n\t\t\t<td>3</td>\n\t\t</tr>\n\t\t<tr>\n\t\t"+
|
33
33
|
"\t<td>4</td>\n\t\t\t<td>5</td>\n\t\t\t<td>6</td>\n\t"+
|
34
34
|
"\t</tr>\n\t</table>\n",actual)
|
35
35
|
|
36
|
-
actual = Ruport::Controller::Table.render_html { |r|
|
37
|
-
r.data = Table(%w[a b c], :data => [ [1,2,3],[4,5,6]])
|
36
|
+
actual = Ruport::Controller::Table.render_html { |r|
|
37
|
+
r.data = Ruport.Table(%w[a b c], :data => [ [1,2,3],[4,5,6]])
|
38
38
|
}
|
39
|
-
|
40
|
-
assert_equal("\t<table>\n\t\t<tr>\n\t\t\t<th>a</th>\n\t\t\t<th>b</th>"+
|
41
|
-
"\n\t\t\t<th>c</th>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>1</td>"+
|
39
|
+
|
40
|
+
assert_equal("\t<table>\n\t\t<thead>\n\t\t<tr>\n\t\t\t<th>a</th>\n\t\t\t<th>b</th>"+
|
41
|
+
"\n\t\t\t<th>c</th>\n\t\t</tr>\n\t\t</thead>\n\t\t<tr>\n\t\t\t<td>1</td>"+
|
42
42
|
"\n\t\t\t<td>2</td>\n\t\t\t<td>3</td>\n\t\t</tr>\n\t\t<tr>"+
|
43
43
|
"\n\t\t\t<td>4</td>\n\t\t\t<td>5</td>\n\t\t\t<td>6</td>\n\t"+
|
44
|
-
"\t</tr>\n\t</table>\n",actual)
|
45
|
-
|
44
|
+
"\t</tr>\n\t</table>\n",actual)
|
45
|
+
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
def test_render_with_template
|
49
49
|
formatter = Ruport::Formatter::HTML.new
|
50
50
|
formatter.options = Ruport::Controller::Options.new
|
51
51
|
formatter.options.template = :simple
|
52
52
|
formatter.apply_template
|
53
|
-
|
53
|
+
|
54
54
|
assert_equal false, formatter.options.show_table_headers
|
55
55
|
|
56
56
|
assert_equal :justified, formatter.options.style
|
@@ -59,7 +59,7 @@ class TestRenderHTMLTable < Test::Unit::TestCase
|
|
59
59
|
|
60
60
|
def test_options_hashes_override_template
|
61
61
|
opts = nil
|
62
|
-
table = Table(%w[a b c])
|
62
|
+
table = Ruport.Table(%w[a b c])
|
63
63
|
table.to_html(
|
64
64
|
:template => :simple,
|
65
65
|
:table_format => {
|
@@ -72,7 +72,7 @@ class TestRenderHTMLTable < Test::Unit::TestCase
|
|
72
72
|
) do |r|
|
73
73
|
opts = r.options
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
assert_equal true, opts.show_table_headers
|
77
77
|
|
78
78
|
assert_equal :inline, opts.style
|
@@ -81,7 +81,7 @@ class TestRenderHTMLTable < Test::Unit::TestCase
|
|
81
81
|
|
82
82
|
def test_individual_options_override_template
|
83
83
|
opts = nil
|
84
|
-
table = Table(%w[a b c])
|
84
|
+
table = Ruport.Table(%w[a b c])
|
85
85
|
table.to_html(
|
86
86
|
:template => :simple,
|
87
87
|
:show_table_headers => true,
|
@@ -90,35 +90,35 @@ class TestRenderHTMLTable < Test::Unit::TestCase
|
|
90
90
|
) do |r|
|
91
91
|
opts = r.options
|
92
92
|
end
|
93
|
-
|
93
|
+
|
94
94
|
assert_equal true, opts.show_table_headers
|
95
95
|
|
96
96
|
assert_equal :inline, opts.style
|
97
97
|
assert_equal true, opts.show_group_headers
|
98
98
|
end
|
99
99
|
end
|
100
|
-
|
101
100
|
|
102
|
-
|
103
|
-
|
101
|
+
|
102
|
+
class TestRenderHTMLRow < Minitest::Test
|
103
|
+
|
104
104
|
def test_render_html_row
|
105
105
|
actual = Ruport::Controller::Row.render_html { |r| r.data = [1,2,3] }
|
106
106
|
assert_equal("\t\t<tr>\n\t\t\t<td>1</td>\n\t\t\t<td>2"+
|
107
107
|
"</td>\n\t\t\t<td>3</td>\n\t\t</tr>\n",actual)
|
108
108
|
end
|
109
109
|
end
|
110
|
-
|
111
110
|
|
112
|
-
|
113
|
-
|
111
|
+
|
112
|
+
class TestRenderHTMLGroup < Minitest::Test
|
113
|
+
|
114
114
|
def test_render_html_group
|
115
115
|
group = Ruport::Data::Group.new(:name => 'test',
|
116
116
|
:data => [[1,2,3],[4,5,6]],
|
117
117
|
:column_names => %w[a b c])
|
118
118
|
actual = Ruport::Controller::Group.render(:html, :data => group)
|
119
119
|
assert_equal "\t<p>test</p>\n"+
|
120
|
-
"\t<table>\n\t\t<tr>\n\t\t\t<th>a</th>\n\t\t\t<th>b</th>"+
|
121
|
-
"\n\t\t\t<th>c</th>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>1</td>"+
|
120
|
+
"\t<table>\n\t\t<thead>\n\t\t<tr>\n\t\t\t<th>a</th>\n\t\t\t<th>b</th>"+
|
121
|
+
"\n\t\t\t<th>c</th>\n\t\t</tr>\n\t\t</thead>\n\t\t<tr>\n\t\t\t<td>1</td>"+
|
122
122
|
"\n\t\t\t<td>2</td>\n\t\t\t<td>3</td>\n\t\t</tr>\n\t\t<tr>"+
|
123
123
|
"\n\t\t\t<td>4</td>\n\t\t\t<td>5</td>\n\t\t\t<td>6</td>\n\t"+
|
124
124
|
"\t</tr>\n\t</table>\n", actual
|
@@ -134,14 +134,14 @@ class TestRenderHTMLGroup < Test::Unit::TestCase
|
|
134
134
|
"\n\t\t\t<td>2</td>\n\t\t\t<td>3</td>\n\t\t</tr>\n\t\t<tr>"+
|
135
135
|
"\n\t\t\t<td>4</td>\n\t\t\t<td>5</td>\n\t\t\t<td>6</td>\n\t"+
|
136
136
|
"\t</tr>\n\t</table>\n", actual
|
137
|
-
end
|
137
|
+
end
|
138
138
|
end
|
139
139
|
|
140
140
|
|
141
|
-
class TestRenderHTMLGrouping < Test
|
141
|
+
class TestRenderHTMLGrouping < Minitest::Test
|
142
142
|
|
143
143
|
def test_render_html_grouping
|
144
|
-
table = Table(%w[a b c]) << [1,2,3] << [1,1,3] << [2,7,9]
|
144
|
+
table = Ruport.Table(%w[a b c]) << [1,2,3] << [1,1,3] << [2,7,9]
|
145
145
|
g = Grouping(table,:by => "a")
|
146
146
|
actual = Ruport::Controller::Grouping.render(:html, :data => g,
|
147
147
|
:show_table_headers => false)
|
@@ -153,27 +153,27 @@ class TestRenderHTMLGrouping < Test::Unit::TestCase
|
|
153
153
|
end
|
154
154
|
|
155
155
|
def test_render_html_grouping_with_table_headers
|
156
|
-
table = Table(%w[a b c]) << [1,2,3] << [1,1,3] << [2,7,9]
|
156
|
+
table = Ruport.Table(%w[a b c]) << [1,2,3] << [1,1,3] << [2,7,9]
|
157
157
|
g = Grouping(table,:by => "a")
|
158
158
|
actual = Ruport::Controller::Grouping.render(:html, :data => g)
|
159
159
|
|
160
|
-
assert_equal "\t<p>1</p>\n\t<table>\n\t\t<tr>\n\t\t\t<th>b</th>\n"+
|
161
|
-
"\t\t\t<th>c</th>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>"+
|
160
|
+
assert_equal "\t<p>1</p>\n\t<table>\n\t\t<thead>\n\t\t<tr>\n\t\t\t<th>b</th>\n"+
|
161
|
+
"\t\t\t<th>c</th>\n\t\t</tr>\n\t\t</thead>\n\t\t<tr>\n\t\t\t<td>"+
|
162
162
|
"2</td>\n\t\t\t<td>3</td>\n\t\t</tr>\n\t\t<tr>\n\t\t"+
|
163
163
|
"\t<td>1</td>\n\t\t\t<td>3</td>\n\t\t</tr>\n\t</table>\n\n"+
|
164
|
-
"\t<p>2</p>\n\t<table>\n\t\t<tr>\n\t\t\t<th>b</th>\n\t\t"+
|
165
|
-
"\t<th>c</th>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>7</td>\n"+
|
164
|
+
"\t<p>2</p>\n\t<table>\n\t\t<thead>\n\t\t<tr>\n\t\t\t<th>b</th>\n\t\t"+
|
165
|
+
"\t<th>c</th>\n\t\t</tr>\n\t\t</thead>\n\t\t<tr>\n\t\t\t<td>7</td>\n"+
|
166
166
|
"\t\t\t<td>9</td>\n\t\t</tr>\n\t</table>\n\n", actual
|
167
167
|
end
|
168
168
|
|
169
169
|
def test_render_justified_html_grouping
|
170
|
-
table = Table(%w[a b c]) << [1,2,3] << [1,1,3] << [2,7,9]
|
170
|
+
table = Ruport.Table(%w[a b c]) << [1,2,3] << [1,1,3] << [2,7,9]
|
171
171
|
g = Grouping(table,:by => "a")
|
172
172
|
actual = Ruport::Controller::Grouping.render(:html, :data => g,
|
173
173
|
:style => :justified)
|
174
174
|
|
175
|
-
assert_equal "\t<table>\n\t\t<tr>\n\t\t\t<th>a</th>\n\t\t\t<th>b</th>\n"+
|
176
|
-
"\t\t\t<th>c</th>\n\t\t</tr>\n\t\t<tr>\n\t\t\t"+
|
175
|
+
assert_equal "\t<table>\n\t\t<thead>\n\t\t<tr>\n\t\t\t<th>a</th>\n\t\t\t<th>b</th>\n"+
|
176
|
+
"\t\t\t<th>c</th>\n\t\t</tr>\n\t\t</thead>\n\t\t<tr>\n\t\t\t"+
|
177
177
|
"<td class=\"groupName\">1</td>\n\t\t\t<td>"+
|
178
178
|
"2</td>\n\t\t\t<td>3</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t"+
|
179
179
|
"<td> </td>\n\t\t\t<td>1</td>\n\t\t\t<td>3</td>"+
|
@@ -181,21 +181,21 @@ class TestRenderHTMLGrouping < Test::Unit::TestCase
|
|
181
181
|
"<td class=\"groupName\">2</td>\n\t\t\t<td>7</td>\n"+
|
182
182
|
"\t\t\t<td>9</td>\n\t\t</tr>\n\t</table>\n", actual
|
183
183
|
end
|
184
|
-
end
|
185
|
-
|
184
|
+
end
|
186
185
|
|
187
|
-
|
186
|
+
|
187
|
+
class TestHTMLFormatterHelpers < Minitest::Test
|
188
188
|
begin
|
189
189
|
require "rubygems"
|
190
190
|
rescue LoadError
|
191
191
|
nil
|
192
192
|
end
|
193
|
-
|
194
|
-
def test_textile
|
193
|
+
|
194
|
+
def test_textile
|
195
195
|
require "redcloth"
|
196
196
|
a = Ruport::Formatter::HTML.new
|
197
197
|
assert_equal "<p><strong>foo</strong></p>", a.textile("*foo*")
|
198
198
|
rescue LoadError
|
199
|
-
STDERR.puts "Skipping textile test... needs
|
199
|
+
STDERR.puts "Skipping textile test... needs RedCloth gem"
|
200
200
|
end
|
201
201
|
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "helpers")
|
4
|
+
|
5
|
+
class TestRenderMarkdownTable < Minitest::Test
|
6
|
+
def test_render_markdown_table_basic
|
7
|
+
actual = Ruport::Controller::Table.render_markdown do |r|
|
8
|
+
r.data = Ruport::Table([:foo, :bar, :baz], data: [[1, 2, 3], [], [4, 5], [6]])
|
9
|
+
end
|
10
|
+
|
11
|
+
assert_equal([
|
12
|
+
"|foo|bar|baz|\n",
|
13
|
+
"|:--|:--|:--|\n",
|
14
|
+
"|1|2|3|\n",
|
15
|
+
"||||\n",
|
16
|
+
"|4|5||\n",
|
17
|
+
"|6|||\n"
|
18
|
+
].join, actual)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_render_markdown_table_without_column_names
|
22
|
+
actual = Ruport::Controller::Table.render_markdown do |r|
|
23
|
+
r.data = Ruport::Table(data: [[:foo, :bar], [1, 2], [3, 4]])
|
24
|
+
end
|
25
|
+
|
26
|
+
assert_equal([
|
27
|
+
"|foo|bar|\n",
|
28
|
+
"|:--|:--|\n",
|
29
|
+
"|1|2|\n",
|
30
|
+
"|3|4|\n",
|
31
|
+
].join, actual)
|
32
|
+
|
33
|
+
actual = Ruport::Controller::Table.render_markdown do |r|
|
34
|
+
r.data = Ruport::Table([], data: [[:foo, :bar], [1, 2], [3, 4]])
|
35
|
+
end
|
36
|
+
|
37
|
+
assert_equal([
|
38
|
+
"|foo|bar|\n",
|
39
|
+
"|:--|:--|\n",
|
40
|
+
"|1|2|\n",
|
41
|
+
"|3|4|\n",
|
42
|
+
].join, actual)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_escape_virtical_bar
|
46
|
+
actual = Ruport::Controller::Table.render_markdown do |r|
|
47
|
+
r.data = Ruport::Table([:foo], data: [['foo0|foo1']])
|
48
|
+
end
|
49
|
+
|
50
|
+
assert_equal([
|
51
|
+
"|foo|\n",
|
52
|
+
"|:--|\n",
|
53
|
+
"|foo0|foo1|\n"
|
54
|
+
].join, actual)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_escape_newline_code
|
58
|
+
actual = Ruport::Controller::Table.render_markdown do |r|
|
59
|
+
r.data = Ruport::Table([:foo], data: [["foo0\nfoo1"]])
|
60
|
+
end
|
61
|
+
|
62
|
+
assert_equal([
|
63
|
+
"|foo|\n",
|
64
|
+
"|:--|\n",
|
65
|
+
"|foo0<br>foo1|\n"
|
66
|
+
].join, actual)
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_alignment_option
|
70
|
+
actual = Ruport::Controller::Table.render_markdown(alignment: :left) do |r|
|
71
|
+
r.data = Ruport::Table([:foo, :bar], data: [[1, 2], [3, 4]])
|
72
|
+
end
|
73
|
+
|
74
|
+
assert_equal([
|
75
|
+
"|foo|bar|\n",
|
76
|
+
"|:--|:--|\n",
|
77
|
+
"|1|2|\n",
|
78
|
+
"|3|4|\n"
|
79
|
+
].join, actual)
|
80
|
+
|
81
|
+
actual = Ruport::Controller::Table.render_markdown(alignment: :center) do |r|
|
82
|
+
r.data = Ruport::Table([:foo, :bar], data: [[1, 2], [3, 4]])
|
83
|
+
end
|
84
|
+
|
85
|
+
assert_equal([
|
86
|
+
"|foo|bar|\n",
|
87
|
+
"|:-:|:-:|\n",
|
88
|
+
"|1|2|\n",
|
89
|
+
"|3|4|\n"
|
90
|
+
].join, actual)
|
91
|
+
|
92
|
+
actual = Ruport::Controller::Table.render_markdown(alignment: :right) do |r|
|
93
|
+
r.data = Ruport::Table([:foo, :bar], data: [[1, 2], [3, 4]])
|
94
|
+
end
|
95
|
+
|
96
|
+
assert_equal([
|
97
|
+
"|foo|bar|\n",
|
98
|
+
"|--:|--:|\n",
|
99
|
+
"|1|2|\n",
|
100
|
+
"|3|4|\n"
|
101
|
+
].join, actual)
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_column_alignments_option
|
105
|
+
actual = Ruport::Controller::Table.render_markdown(
|
106
|
+
column_alignments: { foo: :left, bar: :right, baz: :center }
|
107
|
+
) do |r|
|
108
|
+
r.data = Ruport::Table([:foo, :bar, :baz, :qux], data: [[1, 2, 3, 4], [5, 6, 7, 8]])
|
109
|
+
end
|
110
|
+
|
111
|
+
assert_equal([
|
112
|
+
"|foo|bar|baz|qux|\n",
|
113
|
+
"|:--|--:|:-:|:--|\n",
|
114
|
+
"|1|2|3|4|\n",
|
115
|
+
"|5|6|7|8|\n"
|
116
|
+
].join, actual)
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_options_hash_override_template
|
120
|
+
Ruport::Formatter::Template.create(:a_template) do |format|
|
121
|
+
format.table = {
|
122
|
+
alignment: :center,
|
123
|
+
column_alignments: { foo: :right }
|
124
|
+
}
|
125
|
+
end
|
126
|
+
|
127
|
+
actual = Ruport::Controller::Table.render_markdown(
|
128
|
+
template: :a_template,
|
129
|
+
alignment: :right,
|
130
|
+
column_alignments: { foo: :left, bar: :center }
|
131
|
+
) do |r|
|
132
|
+
r.data = Ruport::Table([:foo, :bar, :baz], data: [[1, 2, 3], [4, 5, 6]])
|
133
|
+
end
|
134
|
+
|
135
|
+
assert_equal([
|
136
|
+
"|foo|bar|baz|\n",
|
137
|
+
"|:--|:-:|--:|\n",
|
138
|
+
"|1|2|3|\n",
|
139
|
+
"|4|5|6|\n"
|
140
|
+
].join, actual)
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
#!/usr/bin/env ruby -w
|
2
|
+
|
3
|
+
require_relative 'helpers'
|
4
|
+
|
5
|
+
class TestRenderPDFTable < Minitest::Test
|
6
|
+
|
7
|
+
def setup
|
8
|
+
Ruport::Formatter::Template.create(:simple) do |format|
|
9
|
+
format.page = {
|
10
|
+
size: "LETTER",
|
11
|
+
layout: :landscape
|
12
|
+
}
|
13
|
+
format.text = {
|
14
|
+
font_size: 16
|
15
|
+
}
|
16
|
+
format.table = {
|
17
|
+
show_headings: false
|
18
|
+
}
|
19
|
+
format.column = {
|
20
|
+
alignment: :center,
|
21
|
+
width: 50
|
22
|
+
}
|
23
|
+
format.heading = {
|
24
|
+
alignment: :right,
|
25
|
+
bold: false,
|
26
|
+
title: "Test"
|
27
|
+
}
|
28
|
+
format.grouping = {
|
29
|
+
style: :separated
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_render_pdf_errors
|
35
|
+
# can't render without column names
|
36
|
+
data = Ruport.Table([], data: [[1,2],[3,4]])
|
37
|
+
assert_raises(Ruport::FormatterError) do
|
38
|
+
data.to_prawn_pdf
|
39
|
+
end
|
40
|
+
|
41
|
+
data.column_names = %w[a b]
|
42
|
+
|
43
|
+
data.to_prawn_pdf
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_render_pdf_basic
|
47
|
+
expected_output = IO.binread(File.join(__dir__, 'expected_outputs/prawn_pdf_formatter/pdf_basic.pdf.test')).bytes
|
48
|
+
|
49
|
+
data = Ruport.Table(%w[a b c], data: [[1,2,3]])
|
50
|
+
# debugging:
|
51
|
+
# data.to_prawn_pdf(:file => File.join(__dir__, 'expected_outputs/prawn_pdf_formatter/pdf_actual.pdf.test'))
|
52
|
+
actual_output = data.to_prawn_pdf.bytes
|
53
|
+
|
54
|
+
assert_equal expected_output, actual_output
|
55
|
+
end
|
56
|
+
|
57
|
+
# this is mostly to check that the transaction hack gets called
|
58
|
+
def test_relatively_large_pdf
|
59
|
+
table = Ruport.Table(File.join(File.expand_path(File.dirname(__FILE__)), "../test/",
|
60
|
+
%w[samples dates.csv]))
|
61
|
+
table.reduce(0..99)
|
62
|
+
table.to_prawn_pdf
|
63
|
+
end
|
64
|
+
|
65
|
+
#--------BUG TRAPS--------#
|
66
|
+
|
67
|
+
# PDF::SimpleTable does not handle symbols as column names
|
68
|
+
# Ruport should smartly fix this surprising behaviour (#283)
|
69
|
+
def test_tables_should_render_with_symbol_column_name
|
70
|
+
data = Ruport.Table([:a,:b,:c], data: [[1,2,3],[4,5,6]])
|
71
|
+
data.to_prawn_pdf
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
class TestRenderPDFGrouping < Minitest::Test
|
77
|
+
|
78
|
+
#--------BUG TRAPS----------#
|
79
|
+
|
80
|
+
def test_grouping_should_have_consistent_font_size
|
81
|
+
a = Ruport.Table(%w[a b c]) << %w[eye like chicken] << %w[eye like liver] <<
|
82
|
+
%w[meow mix meow ] << %w[mix please deliver ]
|
83
|
+
b = Grouping(a, by: "a")
|
84
|
+
splat = b.to_prawn_pdf.split("\n")
|
85
|
+
splat.grep(/meow/).each do |m|
|
86
|
+
assert_equal '10.0', m.split[5]
|
87
|
+
end
|
88
|
+
splat.grep(/mix/).each do |m|
|
89
|
+
assert_equal '10.0', m.split[5]
|
90
|
+
end
|
91
|
+
splat.grep(/eye/).each do |m|
|
92
|
+
assert_equal '10.0', m.split[5]
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
class TestPDFFormatterHelpers < Minitest::Test
|
99
|
+
|
100
|
+
def test_move_up
|
101
|
+
a = Ruport::Formatter::PrawnPDF.new
|
102
|
+
a.move_cursor_to(500)
|
103
|
+
a.move_up(50)
|
104
|
+
assert_equal(550,a.cursor)
|
105
|
+
a.move_down(100)
|
106
|
+
assert_equal(450,a.cursor)
|
107
|
+
end
|
108
|
+
end
|