Permalink
Browse files

Bug fix on RTF Builder for Table

  • Loading branch information...
1 parent fb74002 commit d46e3c7367d57247993bd5249a315e95969fdad3 @clbustos committed Apr 30, 2010
Showing with 26 additions and 21 deletions.
  1. +1 −8 Rakefile
  2. +1 −1 lib/reportbuilder.rb
  3. +4 −1 lib/reportbuilder/table.rb
  4. +20 −11 lib/reportbuilder/table/rtfbuilder.rb
View
@@ -5,7 +5,7 @@ $:.unshift(File.dirname(__FILE__)+"/lib")
require 'rubygems'
require 'hoe'
require 'reportbuilder'
-
+Hoe.plugin :git
Hoe.spec 'reportbuilder' do
self.testlib=:minitest
self.version=ReportBuilder::VERSION
@@ -16,11 +16,4 @@ Hoe.spec 'reportbuilder' do
self.extra_dev_deps << ["nokogiri", "~>1.4"]
end
-task :release do
- version="v#{ReportBuilder::VERSION}"
- sh %(git commit -a -m "Release #{version}")
- sh %(git tag "#{version}")
- sh %(git push origin --tags)
-end
-
# vim: syntax=ruby
View
@@ -87,7 +87,7 @@ def self.generate(options=Hash.new, &block)
end
end
# Create a new Report
- def initialize(options=Hash.new,&block)
+ def initialize(options=Hash.new, &block)
options[:name]||="Report "+Time.new.to_s
@no_title=options.delete :no_title
@name=options.delete :name
@@ -75,6 +75,9 @@ def rowspan(data,n)
def n_rows_no_hr
@rows.inject(0) {|ac,v| ac+(v==:hr ? 0 : 1)}
end
+ def n_rows
+ @rows.size
+ end
# Adds a colspan on a cell
# table.add_row(["a",table.colspan("b",2)])
def colspan(data,n)
@@ -128,7 +131,7 @@ def total_width # :nodoc:
0
end
end
-
+
######################
@@ -5,57 +5,66 @@ class RtfBuilder < ElementBuilder
def generate()
@t=@element
@rtf=@builder.rtf
-
+
# Title
-
+
@builder.header(6,@t.name)
-
+
max_cols=@t.calculate_widths
n_rows=@t.n_rows_no_hr+(@t.header.size>0 ? 1: 0)
args=[n_rows, @t.n_columns]+max_cols.map{|m| m*@builder.options[:font_size]*10}
@table=@rtf.table(*args)
@table.border_width=@builder.options[:table_border_width]
@rowspans=[]
+ row_i=0
if @t.header.size>0
+ row_i=1
@t.header.each_with_index do |th,i|
@table[0][i] << th
end
+ add_hr_on_bottom(0)
end
next_with_hr=false
- @t.rows.each_with_index{|row, row_i|
+
+ @t.rows.each_with_index{|row|
if row==:hr
next_with_hr=true
# Nothing
else
parse_row(row,row_i)
if next_with_hr
- create_hr(row_i)
+ add_hr_on_top(row_i)
next_with_hr=false
end
- #row_i+=1
+ row_i+=1
end
}
-
+
end
- def create_hr(row_i)
+ def add_hr_on_top(row_i)
(0...@t.n_columns).each {|i|
@table[row_i][i].top_border_width=@builder.options[:table_hr_width]
}
end
-
+ def add_hr_on_bottom(row_i)
+ (0...@t.n_columns).each {|i|
+ @table[row_i][i].bottom_border_width=@builder.options[:table_hr_width]
+ }
+ end
+
def parse_row(row,row_i)
t=@element
row_ary=[]
real_i=0
colspan_i=0
row.each_index do |i|
- extra=1
+ extra=1
while !@rowspans[real_i].nil? and @rowspans[real_i]>0
@rowspans[real_i]-=1
real_i+=1
end
if row[i].is_a? Table::Colspan
- @table[row_i][real_i] << row[i].data
+ @table[row_i][real_i] << row[i].data
colspan_i=row[i].cols-1
extra=row[i].cols
elsif row[i].nil?

0 comments on commit d46e3c7

Please sign in to comment.