Sha256: d426566333f3ee869186e5c5e456e20bd2c7172b33a321a3a81f376a70a68cfb

Contents?: true

Size: 983 Bytes

Versions: 41

Compression:

Stored size: 983 Bytes

Contents

# encoding : utf-8
class PdfReport < Prawn::Document
  def to_pdf(model, mode_scope)
    
    columns = model.attribute_names
    
    data = [columns]

    mode_scope.each{ |modelobj| 
      data << (columns.map{ |c| modelobj[c].to_s }).to_a
    }
    
    table data, :header => true, :cell_style => { :padding => 5 } do
        i = 0
        for col in columns
          align = case model.columns_hash[col].type
            when "integer" then
              'right'
            when "string", "text" then
              'left'
            else   
              'center'
          end
          style(columns(i)){ |c| c.align = align.to_sym }
          i += 1
        end
    end
    
    # Paginate
    font_size 10
    number_pages Time.now.strftime('%d/%m/%Y - %H:%M') + ' - <page>/<total>', :at => [0, -5], :align => :center
    repeat(:all) do
      bounding_box([0,0], :width => 540, :height => 2) do
        stroke_horizontal_rule
      end
    end
    
    render
  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
beautiful_scaffold-0.3.0.pre lib/generators/templates/app/models/pdf_report.rb
beautiful_scaffold-0.2.7 lib/generators/templates/app/models/pdf_report.rb
beautiful_scaffold-0.2.6 lib/generators/templates/app/models/pdf_report.rb
beautiful_scaffold-0.2.5 lib/generators/templates/app/models/pdf_report.rb
beautiful_scaffold-0.2.4 lib/generators/templates/app/models/pdf_report.rb
beautiful_scaffold-0.2.3 lib/generators/templates/app/models/pdf_report.rb
beautiful_scaffold-0.2.2 lib/generators/templates/app/models/pdf_report.rb
beautiful_scaffold-0.2.1 lib/generators/templates/app/models/pdf_report.rb
beautiful_scaffold-0.2.0 lib/generators/templates/app/models/pdf_report.rb
beautiful_scaffold-0.1.9 lib/generators/templates/app/models/pdf_report.rb
beautiful_scaffold-0.1.8 lib/generators/templates/app/models/pdf_report.rb
beautiful_scaffold-0.1.7 lib/generators/templates/app/models/pdf_report.rb
beautiful_scaffold-0.1.5 lib/generators/templates/app/models/pdf_report.rb
beautiful_scaffold-0.1.4 lib/generators/templates/app/models/pdf_report.rb
beautiful_scaffold-0.1.3 lib/generators/templates/app/models/pdf_report.rb
beautiful_scaffold-0.1.2 lib/generators/templates/app/models/pdf_report.rb
beautiful_scaffold-0.1.1 lib/generators/templates/app/models/pdf_report.rb
beautiful_scaffold-0.1.0 lib/generators/templates/app/models/pdf_report.rb
beautiful_scaffold-0.0.8 lib/generators/templates/app/models/pdf_report.rb
beautiful_scaffold-0.0.7 lib/generators/templates/app/models/pdf_report.rb