Permalink
Browse files

Better rendering of titles on pdf. Add number pages on pdf

  • Loading branch information...
1 parent ce0e624 commit 7144ec24174d3be5f6b11aaf9e28d6312cc75875 @clbustos committed Jan 7, 2011
Showing with 30 additions and 15 deletions.
  1. +1 −0 .gitignore
  2. +1 −1 README.txt
  3. +4 −4 lib/reportbuilder/builder.rb
  4. +10 −2 lib/reportbuilder/builder/pdf.rb
  5. +13 −7 lib/reportbuilder/table/pdfbuilder.rb
  6. +1 −1 test/helper_test.rb
View
@@ -1,3 +1,4 @@
+js/*
coverage*
pkg
doc
View
@@ -4,7 +4,7 @@
== DESCRIPTION:
-Report Abstract Interface. Creates text, html and rtf output, based on a common framework.
+Report Abstract Interface. Creates text, html,pdf and rtf output, based on a common framework.
== FEATURES
@@ -59,15 +59,16 @@ def parse_cycle(container)
end
# Parse one object, using this workflow
- # * If is a block, evaluate it
- # * Use #report_building_CODE, where CODE is one of the codes defined by #code
+ # * If is a block, evaluate it in the context of the builder
+ # * Use method #report_building_CODE, where CODE is one of the codes defined by
+ # ReportBuilder::Builder.code
# * Use #report_building
# * Use #to_s
def parse_element(element)
methods=self.class.code.map {|m| ("report_building_"+m).intern}
if element.is_a? Proc
- element.arity<1 ? instance_eval(&element) : element.call(self)
+ element.arity < 1 ? instance_eval(&element) : element.call(self)
elsif method=methods.find {|m| element.respond_to? m}
element.send(method, self)
elsif element.respond_to? :report_building
@@ -127,7 +128,6 @@ def toc_entry(name)
@toc.push([anchor, name, parse_level])
anchor
end
-
# Add an entry for table index.
# Returns the name of the anchor
def table_entry(name)
@@ -17,6 +17,7 @@ def initialize(builder, options)
super
@pdf=Prawn::Document.new(options)
@pdf.font_size=@options[:font_size]
+
end
def self.code
@@ -36,26 +37,33 @@ def default_options
end
# Add a paragraph of text.
def text(t)
-
@pdf.text(t)
end
# Add a header of level <tt>level</tt> with text <tt>t</tt>
# Level works similar to h
def header(level, t)
- @pdf.text t, :size=>15-level
+ @pdf.pad 5 do
+ @pdf.text t, {:size=>15-level*1.5,:align=>:center}
+ end
end
# Add preformatted text.
def preformatted(t)
@pdf.font("Courier") do
@pdf.text t
end
end
+ def at_end
+ @pdf.number_pages(@options[:number_pages], [@pdf.bounds.right - 50, 0] ) if @options[:numerate_pages]
+
+ end
# Returns pdf code for report
def out
+ at_end
@pdf.render
end
# Save pdf file
def save(filename)
+ at_end
@pdf.render_file(filename)
end
# Do nothing on this builder
@@ -11,16 +11,22 @@ def generate()
t=@element
@pdf=@builder.pdf
@rowspans=[]
- @pdf.text t.name, :size=>14
+ if !t.nil? and t.name!=""
+ @pdf.pad_top 10 do
+ @pdf.text t.name, {:size=>12, :align=>:center}
+ end
+ end
return if t.header.size+t.rows.size==0
has_header=t.header.size>0
- if has_header
- t_options=t.options.merge({:headers=>t.header})
- @pdf.table(t.rows.map{|row| parse_row(row)}, t_options) do
- row(0).style(:style => :bold, :background_color => 'cccccc')
+ @pdf.pad(10) do
+ if has_header
+ t_options=t.options.merge({:headers=>t.header, :align_headers=>:center})
+ @pdf.table(t.rows.map{|row| parse_row(row)}, t_options) do
+ row(0).style(:font_style => :bold, :background_color => 'cccccc')
+ end
+ else
+ @pdf.table(t.rows.map{|row| parse_row(row)}, t.options)
end
- else
- @pdf.table(t.rows.map{|row| parse_row(row)}, t.options)
end
end
# Parse a row
View
@@ -19,4 +19,4 @@
-MiniTest::Unit.autorun
+MiniTest::Unit.autorun

0 comments on commit 7144ec2

Please sign in to comment.