Sha256: 97c508d9cebde4c3b4899ca7d1a198607c97bd42cab1f67efcb94d587ecf77e4

Contents?: true

Size: 1.22 KB

Versions: 9

Compression:

Stored size: 1.22 KB

Contents

# encoding: utf-8

$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
require "prawn"                                                 

ruby_18 do
  require "rubygems"
  require "ruport"

  module Ruport
    class Formatter 
      class PrawnPDF < Ruport::Formatter
        renders :pdf, :for => Ruport::Controller::Table

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

        def table_body
          data.map { |e| e.to_a }
        end

        build :table_header do
          @headers = options.headers || data.column_names
        end

        build :table_body do
          document.table table_body, 
            :headers            => @headers, 
            :row_colors         => :pdf_writer,
            :position           => :center,
            :font_size          => 10,
            :vertical_padding   => 2,
            :horizontal_padding => 5
        end

        def finalize
          output << document.render
        end

      end
    end
  end

  if __FILE__ == $PROGRAM_NAME
    t = Table("#{Prawn::BASEDIR}/examples/addressbook.csv")
    headers = t.column_names.map { |c| c.capitalize }
    t.save_as "addressbook_ruport.pdf", :headers => headers
  end  
end

Version data entries

9 entries across 9 versions & 4 rubygems

Version Path
fullcirclegroup-fullcirclegroup-prawn-0.2.99.2 examples/ruport_formatter.rb
fullcirclegroup-prawn-0.2.99.3 examples/ruport_formatter.rb
satoko-prawn-0.2.99.6 examples/ruport_formatter.rb
prawn-0.1.1 examples/ruport_formatter.rb
prawn-0.1.2 examples/ruport_formatter.rb
prawn-0.2.2 examples/ruport_formatter.rb
prawn-0.2.1 examples/ruport_formatter.rb
prawn-0.2.0 examples/ruport_formatter.rb
prawn-0.2.3 examples/ruport_formatter.rb