reportbuilder 1.4.0 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
@@ -1,3 +1,10 @@
1
+ === 1.4.1 / 2011-02-03
2
+ * Add generic ReportBuilder#save method, to save according to extension
3
+ * Better titles layout on PDF.
4
+ * Pages could be numbered on PDF
5
+ * Small fixed on docs
6
+ * Test works on Ruby 1.9.3
7
+
1
8
  === 1.4.0 / 2010-11-26
2
9
  * Basic support for pdf creation, using Prawn. SVG insertion could be realized using Prawn-svg (as vectors) or Rmagick (as bitmap)
3
10
  * Added SimpleCov support
data/README.txt CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  == DESCRIPTION:
6
6
 
7
- Report Abstract Interface. Creates text, html and rtf output, based on a common framework.
7
+ Report Abstract Interface. Creates text, html, pdf and rtf output, based on a common framework.
8
8
 
9
9
  == FEATURES
10
10
 
@@ -62,8 +62,13 @@ http://github.com/clbustos/reportbuilder
62
62
  * RMagick, only to generate text output of images (see examples/image.rb)
63
63
 
64
64
  == INSTALL:
65
+ With RVM
65
66
 
66
- sudo gem install reportbuilder
67
+ $ gem install reportbuilder
68
+
69
+ without RVM
70
+
71
+ $ sudo gem install reportbuilder
67
72
 
68
73
  == LICENSE:
69
74
 
data/Rakefile CHANGED
@@ -16,6 +16,4 @@ Hoe.spec 'reportbuilder' do
16
16
  self.extra_dev_deps << ["nokogiri", "~>1.4"]
17
17
  end
18
18
 
19
-
20
-
21
19
  # vim: syntax=ruby
@@ -5,7 +5,7 @@ require 'reportbuilder/image'
5
5
  require 'reportbuilder/graph'
6
6
 
7
7
  # = Report Abstract Interface.
8
- # Creates text, html and rtf output, based on a common framework.
8
+ # Creates text, html,pdf and rtf output, based on a common framework.
9
9
  #
10
10
  # == Use
11
11
  #
@@ -52,7 +52,7 @@ class ReportBuilder
52
52
  # Doesn't print a title if set to true
53
53
  attr_accessor :no_title
54
54
  # ReportBuilder version
55
- VERSION = '1.4.0'
55
+ VERSION = '1.4.1'
56
56
  DATA_DIR=File.dirname(__FILE__)+"/../data"
57
57
  FormatNotFound=Class.new(Exception)
58
58
  # Available formats
@@ -76,11 +76,9 @@ class ReportBuilder
76
76
  # * &block: block executed inside builder
77
77
  def self.generate(options=Hash.new, &block)
78
78
  options[:filename]||=nil
79
+ options[:format]||=self.get_format_from_filename(options[:filename]) if options[:filename]
79
80
  options[:format]||="text"
80
81
 
81
- if options[:filename] and options[:filename]=~/\.(\w+?)$/
82
- options[:format]=$1
83
- end
84
82
  file=options.delete(:filename)
85
83
  format=options.delete(:format)
86
84
  rb=ReportBuilder.new(options)
@@ -88,7 +86,7 @@ class ReportBuilder
88
86
  begin
89
87
  builder=builder_for(format).new(rb, options)
90
88
  rescue NameError => e
91
- raise FormatNotFound.new(e)
89
+ raise ReportBuilder::FormatNotFound.new(e)
92
90
  end
93
91
  builder.parse
94
92
  out=builder.out
@@ -100,11 +98,17 @@ class ReportBuilder
100
98
  out
101
99
  end
102
100
  end
101
+ def self.get_format_from_filename(filename)
102
+ filename=~/\.(\w+?)$/
103
+ $1
104
+ end
103
105
  # Create a new Report
104
106
  def initialize(options=Hash.new, &block)
105
107
  options[:name]||="Report "+Time.new.to_s
108
+
106
109
  @no_title=options.delete :no_title
107
110
  @name=options.delete :name
111
+ @name=@name.to_s
108
112
  @options=options
109
113
  @elements=Array.new
110
114
  add(block) if block
@@ -134,6 +138,10 @@ class ReportBuilder
134
138
  gen.parse
135
139
  gen.out
136
140
  end
141
+ def save(filename)
142
+ format=(self.class).get_format_from_filename(filename)
143
+ send("save_#{format}", filename)
144
+ end
137
145
  # Save a rtf file
138
146
  def save_rtf(filename)
139
147
  gen = Builder::Rtf.new(self,@options)
@@ -59,15 +59,16 @@ class ReportBuilder
59
59
  end
60
60
 
61
61
  # Parse one object, using this workflow
62
- # * If is a block, evaluate it
63
- # * Use #report_building_CODE, where CODE is one of the codes defined by #code
62
+ # * If is a block, evaluate it in the context of the builder
63
+ # * Use method #report_building_CODE, where CODE is one of the codes defined by
64
+ # ReportBuilder::Builder.code
64
65
  # * Use #report_building
65
66
  # * Use #to_s
66
67
  def parse_element(element)
67
68
  methods=self.class.code.map {|m| ("report_building_"+m).intern}
68
69
 
69
70
  if element.is_a? Proc
70
- element.arity<1 ? instance_eval(&element) : element.call(self)
71
+ element.arity < 1 ? instance_eval(&element) : element.call(self)
71
72
  elsif method=methods.find {|m| element.respond_to? m}
72
73
  element.send(method, self)
73
74
  elsif element.respond_to? :report_building
@@ -127,7 +128,6 @@ class ReportBuilder
127
128
  @toc.push([anchor, name, parse_level])
128
129
  anchor
129
130
  end
130
-
131
131
  # Add an entry for table index.
132
132
  # Returns the name of the anchor
133
133
  def table_entry(name)
@@ -17,6 +17,7 @@ class ReportBuilder
17
17
  super
18
18
  @pdf=Prawn::Document.new(options)
19
19
  @pdf.font_size=@options[:font_size]
20
+
20
21
  end
21
22
 
22
23
  def self.code
@@ -36,13 +37,14 @@ class ReportBuilder
36
37
  end
37
38
  # Add a paragraph of text.
38
39
  def text(t)
39
-
40
40
  @pdf.text(t)
41
41
  end
42
42
  # Add a header of level <tt>level</tt> with text <tt>t</tt>
43
43
  # Level works similar to h
44
44
  def header(level, t)
45
- @pdf.text t, :size=>15-level
45
+ @pdf.pad 5 do
46
+ @pdf.text t, {:size=>15-level*1.5,:align=>:center}
47
+ end
46
48
  end
47
49
  # Add preformatted text.
48
50
  def preformatted(t)
@@ -50,12 +52,18 @@ class ReportBuilder
50
52
  @pdf.text t
51
53
  end
52
54
  end
55
+ def at_end
56
+ @pdf.number_pages(@options[:number_pages], [@pdf.bounds.right - 50, 0] ) if @options[:numerate_pages]
57
+
58
+ end
53
59
  # Returns pdf code for report
54
60
  def out
61
+ at_end
55
62
  @pdf.render
56
63
  end
57
64
  # Save pdf file
58
65
  def save(filename)
66
+ at_end
59
67
  @pdf.render_file(filename)
60
68
  end
61
69
  # Do nothing on this builder
@@ -27,7 +27,7 @@ class ReportBuilder::Section
27
27
  end
28
28
 
29
29
  def report_building_text(builder)
30
- builder.text(("="*builder.parse_level)+" "+name)
30
+ builder.text(("="*builder.parse_level)+" #{name}")
31
31
  builder.parse_cycle(self)
32
32
  end
33
33
 
@@ -11,16 +11,22 @@ class ReportBuilder
11
11
  t=@element
12
12
  @pdf=@builder.pdf
13
13
  @rowspans=[]
14
- @pdf.text t.name, :size=>14
14
+ if !t.nil? and t.name!=""
15
+ @pdf.pad_top 10 do
16
+ @pdf.text t.name, {:size=>12, :align=>:center}
17
+ end
18
+ end
15
19
  return if t.header.size+t.rows.size==0
16
20
  has_header=t.header.size>0
17
- if has_header
18
- t_options=t.options.merge({:headers=>t.header})
19
- @pdf.table(t.rows.map{|row| parse_row(row)}, t_options) do
20
- row(0).style(:style => :bold, :background_color => 'cccccc')
21
+ @pdf.pad(10) do
22
+ if has_header
23
+ t_options=t.options.merge({:headers=>t.header, :align_headers=>:center})
24
+ @pdf.table(t.rows.map{|row| parse_row(row)}, t_options) do
25
+ row(0).style(:font_style => :bold, :background_color => 'cccccc')
26
+ end
27
+ else
28
+ @pdf.table(t.rows.map{|row| parse_row(row)}, t.options)
21
29
  end
22
- else
23
- @pdf.table(t.rows.map{|row| parse_row(row)}, t.options)
24
30
  end
25
31
  end
26
32
  # Parse a row
@@ -19,4 +19,4 @@ require 'tempfile'
19
19
 
20
20
 
21
21
 
22
- MiniTest::Unit.autorun
22
+ MiniTest::Unit.autorun
@@ -1,4 +1,4 @@
1
- require(File.dirname(__FILE__)+"/helper_test.rb")
1
+ require(File.expand_path(File.dirname(__FILE__)+"/helper_test.rb"))
2
2
 
3
3
  class TestReportbuilderGraph < MiniTest::Unit::TestCase
4
4
  def test_init_without_block
@@ -1,4 +1,4 @@
1
- require(File.dirname(__FILE__)+"/helper_test.rb")
1
+ require(File.expand_path(File.dirname(__FILE__)+"/helper_test.rb"))
2
2
  require 'json'
3
3
  class TestReportbuilderGraphHtmlFlot < MiniTest::Unit::TestCase
4
4
  def setup
@@ -1,4 +1,4 @@
1
- require(File.dirname(__FILE__)+"/helper_test.rb")
1
+ require(File.expand_path(File.dirname(__FILE__)+"/helper_test.rb"))
2
2
  require 'json'
3
3
  class TestReportbuilderGraphHtmlJqplot < MiniTest::Unit::TestCase
4
4
  def setup
@@ -1,5 +1,4 @@
1
- require(File.dirname(__FILE__)+"/helper_test.rb")
2
-
1
+ require(File.expand_path(File.dirname(__FILE__)+"/helper_test.rb"))
3
2
  class TestReportbuilderHtml < MiniTest::Unit::TestCase
4
3
  def setup
5
4
  @tmpdir=Dir::mktmpdir
@@ -1,4 +1,4 @@
1
- require(File.dirname(__FILE__)+"/helper_test.rb")
1
+ require(File.expand_path(File.dirname(__FILE__)+"/helper_test.rb"))
2
2
 
3
3
  class TestReportbuilderImage < MiniTest::Unit::TestCase
4
4
  def setup
@@ -1,4 +1,4 @@
1
- require(File.dirname(__FILE__)+"/helper_test.rb")
1
+ require(File.expand_path(File.dirname(__FILE__)+"/helper_test.rb"))
2
2
  class TestReportbuilder < MiniTest::Unit::TestCase
3
3
  def setup
4
4
  @datadir=File.dirname(__FILE__)+"/../data"
@@ -89,24 +89,27 @@ class TestReportbuilder < MiniTest::Unit::TestCase
89
89
 
90
90
  def test_generate
91
91
  txt_file=Tempfile.new("test.txt")
92
+
92
93
  ReportBuilder.generate(:name=>"Test", :filename=>txt_file.path) do
93
94
  text("hola")
94
95
  end
95
96
 
96
- text=ReportBuilder.generate(:format=>:text,:name=>"Test") do
97
+ text=ReportBuilder.generate(:format=>:text, :name=>"Test") do
97
98
  text("hola")
98
99
  end
100
+
99
101
  assert_match(/^Test\nhola$/,text)
100
102
  assert_equal(text, File.read(txt_file.path))
103
+
101
104
  html_file=Tempfile.new("test.html")
102
105
  html=ReportBuilder.generate(:name=>"Test", :format=>:html) do
103
106
  text("hola")
104
107
  end
108
+
105
109
  ReportBuilder.generate(:name=>"Test", :filename=>html_file.path,:format=>:html) do
106
110
  text("hola")
107
111
  end
108
112
 
109
113
  assert_equal(html,File.read(html_file.path))
110
-
111
114
  end
112
115
  end
@@ -1,4 +1,4 @@
1
- require(File.dirname(__FILE__)+"/helper_test.rb")
1
+ require(File.expand_path(File.dirname(__FILE__)+"/helper_test.rb"))
2
2
 
3
3
  class TestReportbuilderSection < MiniTest::Unit::TestCase
4
4
  def setup
@@ -1,5 +1,4 @@
1
- require(File.dirname(__FILE__)+"/helper_test.rb")
2
-
1
+ require(File.expand_path(File.dirname(__FILE__)+"/helper_test.rb"))
3
2
  class TestReportbuilderTable < MiniTest::Unit::TestCase
4
3
  def setup
5
4
  super
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reportbuilder
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
5
4
  prerelease: false
6
5
  segments:
7
6
  - 1
8
7
  - 4
9
- - 0
10
- version: 1.4.0
8
+ - 1
9
+ version: 1.4.1
11
10
  platform: ruby
12
11
  authors:
13
12
  - Claudio Bustos
@@ -36,7 +35,7 @@ cert_chain:
36
35
  rpP0jjs0
37
36
  -----END CERTIFICATE-----
38
37
 
39
- date: 2010-11-26 00:00:00 -03:00
38
+ date: 2011-02-03 00:00:00 -03:00
40
39
  default_executable:
41
40
  dependencies:
42
41
  - !ruby/object:Gem::Dependency
@@ -47,7 +46,6 @@ dependencies:
47
46
  requirements:
48
47
  - - ~>
49
48
  - !ruby/object:Gem::Version
50
- hash: 15
51
49
  segments:
52
50
  - 0
53
51
  - 4
@@ -63,7 +61,6 @@ dependencies:
63
61
  requirements:
64
62
  - - ~>
65
63
  - !ruby/object:Gem::Version
66
- hash: 11
67
64
  segments:
68
65
  - 1
69
66
  - 2
@@ -78,7 +75,6 @@ dependencies:
78
75
  requirements:
79
76
  - - ~>
80
77
  - !ruby/object:Gem::Version
81
- hash: 55
82
78
  segments:
83
79
  - 0
84
80
  - 8
@@ -94,7 +90,6 @@ dependencies:
94
90
  requirements:
95
91
  - - ~>
96
92
  - !ruby/object:Gem::Version
97
- hash: 57
98
93
  segments:
99
94
  - 0
100
95
  - 9
@@ -102,54 +97,36 @@ dependencies:
102
97
  version: 0.9.1
103
98
  type: :runtime
104
99
  version_requirements: *id004
105
- - !ruby/object:Gem::Dependency
106
- name: rubyforge
107
- prerelease: false
108
- requirement: &id005 !ruby/object:Gem::Requirement
109
- none: false
110
- requirements:
111
- - - ">="
112
- - !ruby/object:Gem::Version
113
- hash: 7
114
- segments:
115
- - 2
116
- - 0
117
- - 4
118
- version: 2.0.4
119
- type: :development
120
- version_requirements: *id005
121
100
  - !ruby/object:Gem::Dependency
122
101
  name: nokogiri
123
102
  prerelease: false
124
- requirement: &id006 !ruby/object:Gem::Requirement
103
+ requirement: &id005 !ruby/object:Gem::Requirement
125
104
  none: false
126
105
  requirements:
127
106
  - - ~>
128
107
  - !ruby/object:Gem::Version
129
- hash: 7
130
108
  segments:
131
109
  - 1
132
110
  - 4
133
111
  version: "1.4"
134
112
  type: :development
135
- version_requirements: *id006
113
+ version_requirements: *id005
136
114
  - !ruby/object:Gem::Dependency
137
115
  name: hoe
138
116
  prerelease: false
139
- requirement: &id007 !ruby/object:Gem::Requirement
117
+ requirement: &id006 !ruby/object:Gem::Requirement
140
118
  none: false
141
119
  requirements:
142
120
  - - ">="
143
121
  - !ruby/object:Gem::Version
144
- hash: 19
145
122
  segments:
146
123
  - 2
147
- - 7
124
+ - 8
148
125
  - 0
149
- version: 2.7.0
126
+ version: 2.8.0
150
127
  type: :development
151
- version_requirements: *id007
152
- description: Report Abstract Interface. Creates text, html and rtf output, based on a common framework.
128
+ version_requirements: *id006
129
+ description: Report Abstract Interface. Creates text, html, pdf and rtf output, based on a common framework.
153
130
  email:
154
131
  - clbustos_at_gmail.com
155
132
  executables:
@@ -585,7 +562,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
585
562
  requirements:
586
563
  - - ">="
587
564
  - !ruby/object:Gem::Version
588
- hash: 3
589
565
  segments:
590
566
  - 0
591
567
  version: "0"
@@ -594,7 +570,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
594
570
  requirements:
595
571
  - - ">="
596
572
  - !ruby/object:Gem::Version
597
- hash: 3
598
573
  segments:
599
574
  - 0
600
575
  version: "0"
metadata.gz.sig CHANGED
Binary file