/thinreports-rails

Rails Template handler for ThinReports DSL.

Primary LanguageRubyMIT LicenseMIT

ThinreportsRails

ThinReporsRails is constructed by Rails Template Handler ThinReports the PDF.

Oldname: thinreports-handler

Supported versions

  • Ruby 1.8.7, 1.9.3, 2.0.0
  • Rails 3.0.X, 3.1.X, 3.2.X, 4.0.X
  • ThinReports 0.7.6 later

Installation

Add this line to your application's Gemfile:

gem 'thinreports-rails'

And then execute:

$ bundle

Or install it yourself as:

$ gem install thinreports-rails

Usage

Example to, Display in the browser.

Controllers

class OrdersController < ApplicationController
  def index
    @orders = Order.all
  end
end

Views

app/views/orders/index.pdf.thinreports

report.start_new_page
report.page.values printed_at: Time.now
@orders.each do |order|
  report.page.list(:list).add_row do |row|
    row.item(:col1).value order.name
    row.item(:col2).value order.num
  end
end

Example to, Download PDF.

class OrdersController < ApplicationController
  def index
    @orders = Order.all
    respond_to do |format|
      format.pdf { 
        send_data render_to_string, filename: 'foo.pdf', type: 'application/pdf', disposition: 'attachment'
      }
    end
  end
end

Configuration

Layout file(.tlf) and options.

Example of using the app/views/reports/index.tlf. Write code like this to index.pdf.thinreports.

:layout_options is an option ThinReports::Report::Base#use_layout method.

report.set_layout tlf: 'reports/index', layout_options: { default: true }

generate options.

report.generate_options(security: { 
  user_password: 'foo',
  owner_password: 'bar',
  permissions: { 
    print_document: false,
    modify_contents: false,
    copy_contents: false 
  }
})

Partial

For exsample to use, app/views/orders/_header.pdf.thinreports. title is local variable in _header.pdf.thinreports.

report.partial! 'header', title: title

Author

Contributing

m(__)m, send me pull request.

Copyright

Copyright (c) 2012 Takeshi Shinoda.