Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Create a new formatter called prawn_pdf with basic functionality
  • Loading branch information
map7 committed Apr 29, 2010
1 parent 09d396f commit 0b3cb9b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions examples/pdf_table.rb
@@ -0,0 +1,5 @@
require "ruport"

class Document < Ruport::Controller

end
1 change: 1 addition & 0 deletions lib/ruport/formatter.rb
Expand Up @@ -252,3 +252,4 @@ def method_missing(id,*args)
require "ruport/formatter/html"
require "ruport/formatter/text"
require "ruport/formatter/pdf"
require "ruport/formatter/prawn_pdf"
30 changes: 30 additions & 0 deletions lib/ruport/formatter/prawn_pdf.rb
@@ -0,0 +1,30 @@
module Ruport
class Formatter::PrawnPDF < Formatter

renders :prawn_pdf, :for =>[Controller::Row, Controller::Table,
Controller::Group, Controller::Grouping]

attr_accessor :pdf

def initialize
require 'prawn'
require 'prawn/layout'
end

def pdf
@pdf ||= ::Prawn::Document.new()
end

def draw_table(table)
pdf.table(table_to_array(table))
end

def table_to_array(tbl)
tbl.map { |row| row.to_a}
end

def finalize
output << pdf.render
end
end
end

0 comments on commit 0b3cb9b

Please sign in to comment.