ruport 0.6.1 → 0.7.0

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.
Files changed (83) hide show
  1. data/AUTHORS +6 -0
  2. data/Rakefile +4 -4
  3. data/TODO +3 -2
  4. data/bin/rope +2 -103
  5. data/examples/pdf_complex_report.rb +53 -0
  6. data/lib/ruport/config.rb +7 -7
  7. data/lib/ruport/data/collection.rb +8 -7
  8. data/lib/ruport/data/groupable.rb +3 -2
  9. data/lib/ruport/data/record.rb +13 -16
  10. data/lib/ruport/data/table.rb +89 -18
  11. data/lib/ruport/format/csv.rb +29 -0
  12. data/lib/ruport/format/html.rb +40 -0
  13. data/lib/ruport/format/latex.rb +50 -0
  14. data/lib/ruport/format/pdf.rb +78 -0
  15. data/lib/ruport/format/plugin.rb +20 -65
  16. data/lib/ruport/format/svg.rb +39 -0
  17. data/lib/ruport/format/text.rb +77 -0
  18. data/lib/ruport/format/xml.rb +32 -0
  19. data/lib/ruport/format.rb +1 -159
  20. data/lib/ruport/generator.rb +158 -0
  21. data/lib/ruport/layout/component.rb +7 -0
  22. data/lib/ruport/layout.rb +1 -0
  23. data/lib/ruport/query.rb +3 -3
  24. data/lib/ruport/renderer/graph.rb +48 -0
  25. data/lib/ruport/renderer/table.rb +132 -0
  26. data/lib/ruport/renderer.rb +193 -0
  27. data/lib/ruport/report/graph.rb +2 -2
  28. data/lib/ruport/report.rb +94 -96
  29. data/lib/ruport/system_extensions.rb +3 -6
  30. data/lib/ruport.rb +6 -4
  31. data/test/samples/dates.csv +1409 -0
  32. data/test/samples/foo.rtxt +3 -0
  33. data/test/test_collection.rb +0 -14
  34. data/test/test_config.rb +6 -6
  35. data/test/test_graph_renderer.rb +97 -0
  36. data/test/test_groupable.rb +1 -0
  37. data/test/test_query.rb +325 -324
  38. data/test/test_record.rb +3 -2
  39. data/test/test_renderer.rb +74 -0
  40. data/test/test_report.rb +29 -26
  41. data/test/test_table.rb +54 -29
  42. data/test/test_table_renderer.rb +93 -0
  43. data/test/test_text_table.rb +61 -0
  44. data/test/unit.log +24 -0
  45. metadata +41 -63
  46. data/CHANGELOG +0 -587
  47. data/examples/basic_grouping.rb +0 -19
  48. data/examples/fieldless_table.rb +0 -13
  49. data/examples/latex_table.rb +0 -17
  50. data/examples/line_graph.rb +0 -22
  51. data/examples/line_graph_report.rb +0 -23
  52. data/examples/line_plotter.rb +0 -46
  53. data/examples/long.txt +0 -24
  54. data/examples/new_plugin.rb +0 -24
  55. data/examples/report.rb +0 -35
  56. data/examples/sample_invoice_report.rb +0 -32
  57. data/examples/simple_mail.rb +0 -15
  58. data/examples/simple_table_interface.rb +0 -20
  59. data/examples/sql_erb.rb +0 -20
  60. data/examples/template.rb +0 -15
  61. data/examples/text_processors.rb +0 -13
  62. data/lib/ruport/format/engine/document.rb +0 -28
  63. data/lib/ruport/format/engine/graph.rb +0 -18
  64. data/lib/ruport/format/engine/invoice.rb +0 -23
  65. data/lib/ruport/format/engine/table.rb +0 -54
  66. data/lib/ruport/format/engine.rb +0 -108
  67. data/lib/ruport/format/plugin/csv_plugin.rb +0 -26
  68. data/lib/ruport/format/plugin/html_plugin.rb +0 -32
  69. data/lib/ruport/format/plugin/latex_plugin.rb +0 -50
  70. data/lib/ruport/format/plugin/pdf_plugin.rb +0 -126
  71. data/lib/ruport/format/plugin/svg_plugin.rb +0 -61
  72. data/lib/ruport/format/plugin/text_plugin.rb +0 -77
  73. data/lib/ruport/meta_tools.rb +0 -66
  74. data/lib/ruport/report/invoice.rb +0 -29
  75. data/test/_test_groupable.rb +0 -0
  76. data/test/test_format.rb +0 -39
  77. data/test/test_format_engine.rb +0 -264
  78. data/test/test_graph.rb +0 -93
  79. data/test/test_invoice.rb +0 -32
  80. data/test/test_latex.rb +0 -20
  81. data/test/test_meta_tools.rb +0 -14
  82. data/test/test_plugin.rb +0 -277
  83. data/test/ts_all.rb +0 -21
@@ -1,126 +0,0 @@
1
- module Ruport
2
- class Format::Plugin
3
- class PDFPlugin < Format::Plugin
4
- attribute :pdf
5
- attribute :paper
6
-
7
- helper(:init_plugin) {
8
- require "pdf/writer"
9
- require "pdf/simpletable"
10
- self.pdf = PDF::Writer.new( :paper => paper || "LETTER" )
11
- }
12
-
13
- renderer :table do
14
- pre[pdf] if pre
15
- PDF::SimpleTable.new do |table|
16
- table.maximum_width = 500
17
- table.orientation = :center
18
- table.data = data
19
- m = "Sorry, cant build PDFs from array like things (yet)"
20
- raise m if self.rendered_field_names.empty?
21
- table.column_order = self.rendered_field_names
22
- table.render_on(pdf)
23
- end
24
- post[pdf] if post
25
- pdf.render
26
- end
27
-
28
- format_field_names { data.column_names }
29
-
30
- renderer(:invoice) { pdf.render }
31
-
32
- # Company Information in top lefthand corner
33
- helper(:build_company_header, :engine => :invoice_engine) { |eng|
34
- @tod = pdf.y
35
- text_box(eng.company_info)
36
- }
37
-
38
- helper(:build_headers, :engine => :invoice_engine) { |eng|
39
- build_company_header_helper(eng)
40
- build_customer_header_helper(eng)
41
- build_title_helper(eng)
42
- build_order_header_helper(eng)
43
- }
44
-
45
- helper(:build_order_header, :engine => :invoice_engine) { |eng|
46
- if eng.order_info
47
- text_box(eng.order_info, :position => 350)
48
- end
49
- }
50
-
51
- helper(:build_title, :engine => :invoice_engine) { |eng|
52
- pdf.y = @tod
53
- if eng.title
54
- pdf.text eng.title, :left => 350, :font_size => 14
55
- pdf.y -= 10
56
- end
57
- }
58
-
59
- helper(:build_footer, :engine => :invoice_engine) { |eng|
60
- # footer
61
- pdf.open_object do |footer|
62
- pdf.save_state
63
- pdf.stroke_color! Color::RGB::Black
64
- pdf.stroke_style! PDF::Writer::StrokeStyle::DEFAULT
65
- if eng.comments
66
- pdf.y -= 20
67
- text_box eng.comments, :position => 110, :width => 400,
68
- :font_size => 14
69
- end
70
- pdf.add_text_wrap( 50, 20, 200, "Printed at " +
71
- Time.now.strftime("%H:%M %d/%m/%Y"), 8)
72
-
73
- pdf.restore_state
74
- pdf.close_object
75
- pdf.add_object(footer, :all_pages)
76
- end
77
- pdf.stop_page_numbering(true, :current)
78
- }
79
-
80
- helper(:build_body, :engine => :invoice_engine) do
81
- pdf.start_page_numbering(500, 20, 8, :right)
82
-
83
- # order contents
84
- pdf.y = 620
85
-
86
- PDF::SimpleTable.new do |table|
87
- table.width = 450
88
- table.orientation = :center
89
- table.data = data
90
- table.show_lines = :outer
91
- table.column_order = data.column_names
92
- table.render_on(pdf)
93
- table.font_size = 12
94
- end
95
- end
96
-
97
- # Order details
98
- helper(:build_customer_header, :engine => :invoice_engine) { |eng|
99
- pdf.y -= 10
100
- text_box(eng.customer_info)
101
- }
102
-
103
- def self.text_box(content,options={})
104
- PDF::SimpleTable.new do |table|
105
- table.data = content.to_a.inject([]) do |s,line|
106
- s << { "value" => line }
107
- end
108
- table.column_order = "value"
109
- table.show_headings = false
110
- table.show_lines = :outer
111
- table.shade_rows = :none
112
- table.width = options[:width] || 200
113
- table.orientation = options[:orientation] || :right
114
- table.position = options[:position] || :left
115
- table.font_size = options[:font_size] || 10
116
- table.render_on(pdf)
117
- end
118
- end
119
-
120
- plugin_name :pdf
121
- register_on :table_engine
122
- register_on :invoice_engine
123
- end
124
- end
125
- end
126
-
@@ -1,61 +0,0 @@
1
- module Ruport
2
- class Format::Plugin
3
- class SVGPlugin < Format::Plugin
4
- helper(:init_plugin) { |eng|
5
- # check the supplied data can be used for graphing
6
- data.each { |r|
7
- if data.column_names.size != r.data.size
8
- raise InvalidGraphDataError,
9
- "Column names and data do not match"
10
- end
11
- r.data.each { |c|
12
- begin
13
- c = BigDecimal.new(c) unless c.kind_of?(Float) ||
14
- c.kind_of?(Fixnum) || c.kind_of?(BigDecimal)
15
- rescue
16
- raise InvalidGraphDataError,
17
- "Unable to convert #{c.to_s} into a number"
18
- end
19
- }
20
- }
21
-
22
- raise InvalidGraphOptionError,
23
- 'You must provide a width before rendering a graph' if eng.width.nil?
24
- raise InvalidGraphOptionError,
25
- 'You must provide a height before rendering a graph' if eng.height.nil?
26
- raise InvalidGraphOptionError,
27
- 'You must provide a style before rendering a graph' if eng.style.nil?
28
- if eng.style != :area && eng.style != :bar &&
29
- eng.style != :line &&
30
- eng.style != :smiles &&
31
- eng.style != :stacked
32
- raise InvalidGraphOptionError, 'Invalid graph style'
33
- end
34
-
35
- require 'scruffy'
36
- @graph = Scruffy::Graph.new
37
- @graph.title = eng.title unless eng.title.nil?
38
- @graph.theme = Scruffy::Themes::Mephisto.new
39
- @graph.point_markers = @data.column_names
40
- @graph_style = eng.style
41
- @graph_width = eng.width
42
- @graph_height = eng.height
43
- }
44
-
45
- renderer :graph do
46
-
47
- data.each_with_index { |r,i|
48
- @graph.add(@graph_style,
49
- r.tags[0] || 'series ' + (i+1).to_s,
50
- r.data)
51
- }
52
-
53
- # return the rendered graph
54
- @graph.render(:size => [@graph_width, @graph_height])
55
- end
56
-
57
- plugin_name :svg
58
- register_on :graph_engine
59
- end
60
- end
61
- end
@@ -1,77 +0,0 @@
1
- module Ruport
2
- class Format::Plugin
3
- class TextPlugin < Format::Plugin
4
- rendering_options :erb_enabled => true, :red_cloth_enabled => false
5
-
6
- renderer :document
7
-
8
- renderer :table do
9
- require "ruport/system_extensions"
10
-
11
- return "" if data.length == 0;
12
-
13
- calculate_max_col_widths
14
-
15
- width = self.right_margin || SystemExtensions.terminal_width
16
-
17
- s = "#{rendered_field_names}#{hr}"
18
-
19
- data.each { |r|
20
- line = Array.new
21
- r.each_with_index { |f,i|
22
- line << f.to_s.center(max_col_width[i])
23
- }
24
- s += "| #{line.join(' | ')} |\n"
25
- }
26
- s += hr
27
-
28
- s.split("\n").each { |r|
29
- r.gsub!(/\A.{#{width+1},}/) { |m| m[0,width-2] + ">>" }
30
- }.join("\n") + "\n"
31
-
32
- end
33
-
34
- format_field_names do
35
- return "" if data.length == 0
36
- calculate_max_col_widths
37
- c=data.column_names.dup
38
- c.each_with_index { |f,i|
39
- c[i] = f.to_s.center(max_col_width[i])
40
- }
41
- "#{hr}| #{c.to_a.join(' | ')} |\n"
42
- end
43
-
44
- action :max_col_width do
45
- @max_col_width
46
- end
47
-
48
- action :calculate_max_col_widths do
49
- @max_col_width=Array.new
50
- if defined?(data.column_names)
51
- data.column_names.each_index do |i|
52
- @max_col_width[i] = data.column_names[i].to_s.length
53
- end
54
- end
55
-
56
- data.each {|r|
57
- r.each_with_index { |f,i|
58
- if !max_col_width[i] || f.to_s.length > max_col_width[i]
59
- max_col_width[i] = f.to_s.length
60
- end
61
- }
62
- }
63
- end
64
-
65
- action :hr do
66
- len = max_col_width.inject(data[0].to_a.length * 3) {|s,e| s+e} + 1
67
- "+" + "-"*(len-2) + "+\n"
68
- end
69
-
70
- attribute :right_margin
71
- plugin_name :text
72
- register_on :table_engine
73
- register_on :document_engine
74
- end
75
- end
76
- end
77
-
@@ -1,66 +0,0 @@
1
- # Gets raised if you try to add the same action to an object more than once.
2
- class ActionAlreadyDefinedError < RuntimeError; end
3
-
4
- module Ruport
5
-
6
- #
7
- # === Overview
8
- #
9
- # This module provides a few tools for doing some manipulations of the
10
- # singleton class of an object. These are used in the implementation of
11
- # Ruport's formatting system, and might be useful for other things.
12
- #
13
- module MetaTools
14
- #
15
- # Allows you to define an attribute accessor on the singleton class.
16
- #
17
- # Example:
18
- #
19
- # class A
20
- # extend Ruport::MetaTools
21
- # attribute :foo
22
- # end
23
- #
24
- # A.foo #=> nil
25
- # A.foo = 7 #=> 7
26
- #
27
- def attribute(sym,value = nil)
28
- singleton_class.send(:attr_accessor, sym )
29
- self.send("#{sym}=",value)
30
- end
31
-
32
- #
33
- # Same as <tt>attribute</tt>, but takes an Array of attributes.
34
- #
35
- # Example:
36
- #
37
- # attributes [:foo,:bar,:baz]
38
- #
39
- def attributes(syms)
40
- syms.each { |s| attribute s }
41
- end
42
-
43
- #
44
- # Allows you to define a method on the singleton class.
45
- #
46
- # Example:
47
- #
48
- # class A
49
- # extend Ruport::MetaTools
50
- # action(:bar) { |x| x + 1 }
51
- # end
52
- #
53
- # A.bar(3) #=> 4
54
- #
55
- def action(name,&block)
56
- raise ActionAlreadyDefinedError if respond_to? name
57
- singleton_class.send(:define_method, name, &block)
58
- end
59
-
60
- end
61
- end
62
-
63
- class Module
64
- # Provides the singleton_class object.
65
- def singleton_class; (class << self; self; end); end
66
- end
@@ -1,29 +0,0 @@
1
- module Ruport
2
- class Report
3
- module Invoice #:nodoc:
4
-
5
- # Returns a Format::Engine::Invoice object
6
- #
7
- # If a block is given, it is possible to customize this object before it
8
- # is returned
9
- #
10
- # Example:
11
- #
12
- # inv = build_invoice do |i|
13
- # i.company_info = "Foo Inc.\n42 Front Street\nNew Haven CT"
14
- # i.customer_info = "Joe User\njoe@test.com"
15
- # i.data = [["Aspirin","$2.00"]].to_table(%w[item cost])
16
- # end
17
- def build_invoice
18
- a = Ruport::Format.invoice_object(:plugin => :pdf)
19
- yield(a); return a
20
- end
21
-
22
- # Takes a block and calls build_invoice then calls render on the resulting
23
- # Format::Engine::Invoice object
24
- def render_invoice(&block)
25
- build_invoice(&block).render
26
- end
27
- end
28
- end
29
- end
File without changes
data/test/test_format.rb DELETED
@@ -1,39 +0,0 @@
1
- require "ruport"
2
- require "test/unit"
3
-
4
- begin; require "rubygems"; rescue LoadError; nil; end
5
- class TestFormat < Test::Unit::TestCase
6
-
7
- def setup
8
- @format = Ruport::Format.new(binding)
9
- end
10
-
11
- def test_filter_erb
12
- @format.content = "<%= 4 + 2 %>"
13
- assert_equal "6", @format.filter_erb
14
- @name = "awesome"
15
- @format.content = " <%= @name %> "
16
- assert_equal " awesome ", @format.filter_erb
17
- end
18
-
19
- def test_filter_red_cloth
20
- if defined? RedCloth
21
- @format.content = "* foo\n* bar"
22
- assert_equal "<ul>\n\t<li>foo</li>\n\t\t<li>bar</li>\n\t</ul>",
23
- @format.filter_red_cloth
24
- end
25
- end
26
-
27
- def filter_ruby
28
- @format.content = "Hash.new"
29
- assert_equal({},@format.filter_ruby)
30
- end
31
-
32
- def test_register_filter
33
- Ruport::Format.register_filter(:lower) { |content| content.downcase }
34
- @format.content = "FoO"
35
- assert_equal("foo", @format.filter_lower)
36
- end
37
-
38
- end
39
-
@@ -1,264 +0,0 @@
1
- require 'ruport'
2
- begin; require 'rubygems'; rescue LoadError; nil; end
3
- require 'test/unit'
4
-
5
- class Naked < Ruport::Format::Engine
6
- alias_engine Naked, :naked_engine
7
- Ruport::Format.build_interface_for Naked, :naked
8
- end
9
-
10
-
11
- class MockPlugin < Ruport::Format::Plugin
12
-
13
- renderer(:table) { "#{rendered_field_names}#{data}" }
14
-
15
- format_field_names { "#{data.column_names}" }
16
-
17
- renderer(:document) { data }
18
-
19
- rendering_options :red_cloth_enabled => true,
20
- :erb_enabled => true
21
-
22
- action(:reverse_data) { data.reverse }
23
- action(:mock_action) { "mock" }
24
-
25
- helper(:test) { |eng| eng }
26
-
27
- attribute :apple
28
-
29
- helper(:complex_test) { |eng|
30
- eng.rewrite_column(0) { "a" } if apple
31
- }
32
-
33
- helper(:init_plugin) { |eng|
34
- eng.options ||= {}
35
- eng.options = options.merge!(:init_ran => true)
36
- }
37
-
38
- plugin_name :mock
39
- register_on :table_engine
40
- register_on :document_engine
41
- register_on :naked_engine
42
-
43
- end
44
-
45
- class MockForTestingTableEngine < Ruport::Format::Plugin
46
-
47
- renderer(:table) {}
48
-
49
- format_field_names { raise }
50
- plugin_name :table_mock
51
- register_on :table_engine
52
-
53
- end
54
-
55
- class TestFormatEngine < Test::Unit::TestCase
56
-
57
- def test_no_data_required
58
- assert_nothing_raised {
59
- Ruport::Format.naked_object(:plugin => :mock).render
60
- }
61
- end
62
-
63
- def test_init_plugin_helper
64
- a = Ruport::Format.naked_object(:plugin => :mock)
65
- a.render
66
- assert a.options[:init_ran]
67
- end
68
-
69
- def test_options_hash
70
- a = Ruport::Format.naked_object(:plugin => :mock, :data => [1,2,3])
71
- assert(a.respond_to?(:options))
72
- assert(a.active_plugin.respond_to?(:options))
73
- a.render
74
- assert_equal a.options, a.active_plugin.options
75
- end
76
-
77
- end
78
-
79
- class TestTabularFormatEngine < Test::Unit::TestCase
80
-
81
- include Ruport
82
-
83
- def setup
84
- @engine = Format::Engine::Table.dup
85
- end
86
-
87
- def test_plugin_attributes
88
- assert_equal nil, @engine.active_plugin.apple
89
- @engine.active_plugin.apple = :banana
90
- assert_equal :banana, @engine.active_plugin.apple
91
- end
92
-
93
- def test_ensure_column_names_only_rendered_if_non_empty
94
- @engine.plugin = :mock
95
- @engine.data = [[1,2,3]].to_table
96
- assert_nothing_raised { @engine.render }
97
- end
98
-
99
- def test_basic_render
100
- @engine.plugin = :mock
101
- @engine.data = [[1,2,3],[4,5,6],[7,8,9]]
102
- assert_equal( "#{@engine.data}", @engine.render )
103
- end
104
-
105
- def test_plugin_actions
106
- @engine.plugin = :mock
107
- @engine.data = [1,2,3,4]
108
- assert_equal( [4,3,2,1], @engine.active_plugin.reverse_data )
109
- assert_equal( "mock", @engine.active_plugin.mock_action )
110
- end
111
-
112
- def test_helper
113
- @engine.plugin = :mock
114
- assert_equal @engine, @engine.test
115
- @engine.data = [[1,2,3],[4,5,6]]
116
- @engine.complex_test
117
- assert_equal([[1,2,3],[4,5,6]],@engine.data)
118
- @engine.active_plugin.apple = true
119
- @engine.complex_test
120
- assert_equal([['a',2,3],['a',5,6]],@engine.data)
121
- end
122
-
123
- def test_render_without_field_names
124
- @engine.plugin = :mock
125
- @engine.show_field_names = false
126
-
127
- @engine.data = [[1,2,3],[4,5,6],[7,8,9]]
128
- assert_equal "#{@engine.data}", @engine.render
129
- end
130
-
131
- # test that attempting to render using an invalid plugin returns an exception
132
- # with a useful message
133
- def test_render_with_invalid_plugin
134
- assert_raises(InvalidPluginError) {
135
- Format.table(:plugin => :monkeys,
136
- :data => [[1,2,3],[4,5,6],[7,8,9]].to_table(%w[a b c]))
137
- }
138
- end
139
-
140
- def test_simple_interface
141
- expected = "#{[[1,2],[3,4]]}"
142
- actual = Format.table(:plugin => :mock, :data => [[1,2],[3,4]])
143
- assert_equal(expected,actual)
144
- end
145
-
146
- def test_rewrite_column
147
- a = @engine.dup
148
- a.plugin = :mock
149
-
150
- a.data = [[1,2],[3,4]].to_table(:column_names =>%w[a b])
151
- a.rewrite_column("a") { |r| r["a"] + 1 }
152
- assert_equal([[2,2],[4,4]].to_table(:column_names => %w[a b]),a.data)
153
- assert_nothing_raised { a.render }
154
-
155
- a.data = [[5,6],[7,8]]
156
- a.rewrite_column(1) { "apple" }
157
- assert_equal [[5,"apple"],[7,"apple"]], a.data
158
- assert_nothing_raised { a.render }
159
- end
160
-
161
- def test_num_columns
162
- @engine.data = [[1,2,3,4],[5,6,7,8]]
163
- assert_equal(4,@engine.num_cols)
164
-
165
- @engine.data = [[1,2,3],[4,5,6]].to_table(:column_names => %w[a b c])
166
- assert_equal(3,@engine.num_cols)
167
- end
168
-
169
- def test_plugin_access
170
- @engine.plugin = :mock
171
- @engine.data = [[1,5],[3,8]]
172
-
173
- #normal access
174
- assert_equal :mock, @engine.active_plugin.plugin_name
175
- assert_equal [[1,5],[3,8]], @engine.active_plugin.data
176
-
177
- #block access
178
- @engine.active_plugin do |p|
179
- assert_equal :mock, p.plugin_name
180
- assert_equal [[1,5],[3,8]], p.data
181
- end
182
- end
183
-
184
- def test_prune
185
- @engine.plugin = :mock
186
- @engine.data = [[1,2,3],[1,4,3],[2,4,1]]
187
- @engine.prune
188
- assert_equal([[1,2,3],[nil,4,3],[2,4,1]],@engine.data)
189
- @engine.data = [[1,2,3],[2,4,1],[2,7,9],[1,2,3],[1,7,9]]
190
- @engine.prune
191
- assert_equal([[1,2,3],[2,4,1],[nil,7,9],[1,2,3],[nil,7,9]],
192
- @engine.data)
193
- @engine.data = [[1,2,3],[1,2,4],[1,3,7],[2,1,9],[2,2,3],[2,2,9]]
194
- @engine.prune
195
- assert_equal( [[1,2,3],[nil,nil,4],[nil,3,7],
196
- [2,1,9],[nil,2,3],[nil,nil,9]], @engine.data)
197
-
198
- @engine.data = [[1,2,3],[1,2,4],[1,3,7],[2,1,9],[2,2,3],[2,2,9]]
199
- @engine.prune(1)
200
- assert_equal( [[1,2,3],[nil,2,4],[nil,3,7],
201
- [2,1,9],[nil,2,3],[nil,2,9]], @engine.data)
202
-
203
- data = Ruport::Data::Table.new :column_names => %w[name date service amount]
204
- data << [ "Greg Gibson", "1/1/2000", "Prophy", "100.00" ] <<
205
- [ "Greg Gibson", "1/1/2000", "Filling", "100.00" ] <<
206
- [ "Greg Gibson", "1/12/2000", "Prophy", "100.00" ] <<
207
- [ "Greg Gibson", "1/12/2000", "Filling", "100.00" ] <<
208
- [ "Greg Brown", "1/12/2000", "Prophy", "100.00" ]
209
-
210
- @engine.data = data
211
- @engine.prune(1)
212
- data2 = data.dup
213
- data2[1][0] = data2[2][0] = data2[3][0] = nil
214
- assert_equal(data2, @engine.data)
215
-
216
- @engine.data=data
217
-
218
- data3 = data2.dup
219
- data3[1][1] = data3[3][1] = nil
220
- @engine.prune(2)
221
-
222
- assert_equal(data3, @engine.data)
223
- end
224
-
225
- end
226
-
227
- class TestDocumentFormatEngine < Test::Unit::TestCase
228
-
229
- include Ruport
230
-
231
- def setup
232
- @engine = Format::Engine::Document.dup
233
- end
234
-
235
- def test_basic_render
236
- @engine.plugin = :mock
237
- @engine.red_cloth_enabled = true
238
- @engine.erb_enabled = true
239
- @engine.data = "* <%= 3 + 2 %>\n* <%= 'apple'.reverse %>\n* <%= [1,2][0] %>"
240
- h = "<ul>\n\t<li>5</li>\n\t\t<li>elppa</li>\n\t\t<li>1</li>\n\t</ul>"
241
- assert_equal h, @engine.render
242
- end
243
-
244
- def test_simple_interface
245
-
246
- d = "*<%= 'apple'.reverse %>*"
247
- opts = { :data => d, :plugin => :mock }
248
-
249
- a = Format.document opts
250
- assert_equal "<p><strong>elppa</strong></p>", a
251
-
252
- a = Format.document opts.merge!({:red_cloth_enabled => false})
253
- assert_equal "*elppa*", a
254
-
255
- a = Format.document opts.merge!({:erb_enabled => false})
256
- assert_equal d, a
257
-
258
- a = Format.document :data => d, :plugin => :mock
259
- assert_equal "<p><strong>elppa</strong></p>", a
260
-
261
- end
262
- end
263
-
264
-