Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction of thinreports-rails

Takeshi Shinoda
September 15, 2012

Introduction of thinreports-rails

Takeshi Shinoda

September 15, 2012
Tweet

More Decks by Takeshi Shinoda

Other Decks in Programming

Transcript

  1. require 'thinreports' # ... ThinReports::Report.create layout: 'order.tlf' do |report| report.start_new_page

    do |page| page.item(:company_name).value(@customer.name) page.item(:ordered_at).value(Time.now) page.list(:list) do |list| list.config.events.on :footer_insert do |e| e.section.item(:total).value(@orders.total) end @orders.each do |order| list.add_row do |row| row.values(name: order.name, num: order.num, price: order.price, order_total: order.total) end end end end end.generate_file('order.pdf') HFNbUIJOSFQPSUT` 5IJO3FQPSUTHFOFSBUPS 12೥9݄16೔೔༵೔
  2. report.start_new_page do |page| page.item(:company_name).value(@orders.first.company.name) page.item(:ordered_at).value(Time.now) page.list(:list) do |list| list.config.events.on :footer_insert

    do |e| e.section.item(:total).value(@orders.total) end @orders.each do |order| list.add_row do |row| row.values(name: order.name, num: order.num, price: order.price, order_total: order.total) end end end end JOEFYUMG BQQWJFXTPSEFSTJOEFYQEGUIJOSFQPSUT 12೥9݄16೔೔༵೔
  3. require 'open-uri' report.start_new_page do |page| page.item(:icon).src(open(@user.profile_image_url)) page.values(twitter_id: params[:id], bio: @user.description)

    page.list(:timeline) do |list| @tl.take(4).each do |tweet| list.add_row do |row| row.values(created_at: tweet.created_at, tweet: tweet.text) end end end end UXJUUFSUMG BQQWJFXTUXJUUFSUXJUUFSQEGUIJOSFQPSUT 12೥9݄16೔೔༵೔
  4. class OrdersController < ApplicationController def index @orders = Order.all send_data

    render_to_string, filename: 'orders.pdf', type: 'application/pdf', disposition: 'attachment' end end %PXOMPBE 12೥9݄16೔೔༵೔