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-2.0.3 lib/generators/templates/app/models/pdf_report.rb
beautiful_scaffold-2.0.2 lib/generators/templates/app/models/pdf_report.rb
beautiful_scaffold-2.0.1 lib/generators/templates/app/models/pdf_report.rb
beautiful_scaffold-2.0.0 lib/generators/templates/app/models/pdf_report.rb
beautiful_scaffold-2.0.0.pre lib/generators/templates/app/models/pdf_report.rb
beautiful_scaffold-1.0.2 lib/generators/templates/app/models/pdf_report.rb
beautiful_scaffold-1.0.1 lib/generators/templates/app/models/pdf_report.rb
beautiful_scaffold-1.0.0.pre lib/generators/templates/app/models/pdf_report.rb
beautiful_scaffold-0.3.6 lib/generators/templates/app/models/pdf_report.rb
beautiful_scaffold-0.3.5 lib/generators/templates/app/models/pdf_report.rb
beautiful_scaffold-0.3.4 lib/generators/templates/app/models/pdf_report.rb
beautiful_scaffold-0.3.3 lib/generators/templates/app/models/pdf_report.rb
beautiful_scaffold-0.3.2 lib/generators/templates/app/models/pdf_report.rb
beautiful_scaffold-0.3.1 lib/generators/templates/app/models/pdf_report.rb
beautiful_scaffold-0.3.0.rc6 lib/generators/templates/app/models/pdf_report.rb
beautiful_scaffold-0.3.0.rc5 lib/generators/templates/app/models/pdf_report.rb
beautiful_scaffold-0.3.0.rc4 lib/generators/templates/app/models/pdf_report.rb
beautiful_scaffold-0.3.0.rc3 lib/generators/templates/app/models/pdf_report.rb
beautiful_scaffold-0.3.0.rc2 lib/generators/templates/app/models/pdf_report.rb
beautiful_scaffold-0.3.0.rc1 lib/generators/templates/app/models/pdf_report.rb