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

Introduction of thinreports-rails

06febd004d7cc9c9f6a4e0272b686bc7?s=47 Takeshi Shinoda
September 15, 2012

Introduction of thinreports-rails

06febd004d7cc9c9f6a4e0272b686bc7?s=128

Takeshi Shinoda

September 15, 2012
Tweet

Transcript

  1. UIJOSFQPSUTSBJMTͷ͝঺հ *OUSPEVDUJPOPGUIJOSFQPSUTSBJMT 12೥9݄16೔೔༵೔

  2. ࣗݾ঺հ wࣰా݈ ͠ͷ͚ͩͨ͠ w5BLFTIJ4)*/0%" w!UBLFTIJOPEB w4*FSʹͯاۀ৘ใγεςϜΛ࡞͍ͬͯ·͢ w஍Ҭ3VCZJTUूஂ"TBLVTBSC༓ྶஂһ w೔ຊ044ਪਐϑΥʔϥϜ3VCZ5' IUUQEIBUFOBOFKQUBLFTIJOPEB IUUQTHJUIVCDPNUBLFTIJOPEB

    12೥9݄16೔೔༵೔
  3. ࣗݾ঺հ wࣰా݈ ͠ͷ͚ͩͨ͠ w5BLFTIJ4)*/0%" w!UBLFTIJOPEB w4*FSʹͯاۀ৘ใγεςϜΛ࡞͍ͬͯ·͢ w஍Ҭ3VCZJTUूஂ"TBLVTBSC༓ྶஂһ w೔ຊ044ਪਐϑΥʔϥϜ3VCZ5' IUUQEIBUFOBOFKQUBLFTIJOPEB IUUQTHJUIVCDPNUBLFTIJOPEB

    12೥9݄16೔೔༵೔
  4. ΑΖ͘͠ ͓Ͷ͕͍͍ͨ͠·͢ 12೥9݄16೔೔༵೔

  5. ۀ຿ΞϓϦέʔγϣϯ 12೥9݄16೔೔༵೔

  6. Ϊϣʔϛʔͳ3VCZJTUͷΑ͋͘Δ೰Έ wாථग़͍ͨ͠ͳʔ w΍ͬͺॻྨจԽΛ੍ͯ͠φϯϘͰ͢Θʔ wϛϦ୯Ґͷमਖ਼ͯ͠ாථ৬ਓ͍ͨ͠ͳʔ wࠃ࢈ͷţŠƄŘιϑτͳ͍͔ͳʔ 12೥9݄16೔೔༵೔

  7. 5IJO3FQPSUT͝ଘ͡Ͱ͢ʁ .BU[ߐࢢ͕ތΔاۀʮϚπέΠʯ͞Μͷ ೔ߴࠀ໵͞Μ !IJEBLBUTVZB Β͕࡞ͬͨ 3VCZʹΑΔ3VCZͷͨΊͷ ாථιϦϡʔγϣϯ ೥ϑΫΦΧ3VCZେ৆ 12೥9݄16೔೔༵೔

  8. 5IJO3FQPSUT &EJUPS UMG SC 5IJO3FQPSUT (FOFSBUPS QEG PVUQVU PVUQVU JOQVU

    SFRVJSF 12೥9݄16೔೔༵೔
  9. 5IJO3FQPSUT&EJUPS ˠbPSEFSUMG` 12೥9݄16೔೔༵೔

  10. 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೔೔༵೔
  11. 12೥9݄16೔೔༵೔

  12. Pŋ㱼ŋ ੋඇզ͕ࣾͷ 3BJMTϓϩμΫπʹಋೖΛ 12೥9݄16೔೔༵೔

  13. ͔͠͠ʜ 12೥9݄16೔೔༵೔

  14. 7JFXʹॻ͖͍ͨ 12೥9݄16೔೔༵೔

  15. UIJOSFQPSUTSBJMT IUUQTHJUIVCDPNUBLFTIJOPEBUIJOSFQPSUTSBJMT IUUQTSVCZHFNTPSHHFNTUIJOSFQPSUTSBJMT 12೥9݄16೔೔༵೔

  16. $ gem install thinreports-rails Gemfile gem ‘thinreports-rails’ $ bundle install

    12೥9݄16೔೔༵೔
  17. class OrdersController < ApplicationController def index @orders = Order.query(hogehoge) end

    end 12೥9݄16೔೔༵೔
  18. 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೔೔༵೔
  19. IUUQMPDBMIPTUPSEFSTQEG 12೥9݄16೔೔༵೔

  20. UIJOSFQPSUTSBJMT ͕͋Δͱ͜Μͳ೔ৗ΋ ؆୯ʹ߈ུͰ͖·͢ 12೥9݄16೔೔༵೔

  21. 偉い人 「呟き台帳が欲しい」 12೥9݄16೔೔༵೔

  22. 12೥9݄16೔೔༵೔

  23. def twitter @user = Twitter.user(params[:id]) @tl = Twitter.user_timeline(params[:id]) end 12೥9݄16೔೔༵೔

  24. 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೔೔༵೔
  25. 12೥9݄16೔೔༵೔

  26. 5JQT 12೥9݄16೔೔༵೔

  27. 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೔೔༵೔
  28. QBSUJBM # ... report.start_new_page report.partial! 'header' # ... BQQWJFXTPSEFST@IFBEFSQEGUIJOSFQPSUT 12೥9݄16೔೔༵೔

  29. ৄ͘͠͸8FCͰ 12೥9݄16೔೔༵೔

  30. 12೥9݄16೔೔༵೔

  31. ࣗ෼ͷCMPHʹ࠘Έ͕·͘͠ IUUQEIBUFOBOFKQUBLFTIJOPEB ໊લ͸thinreports-railsʹ͔͚ͨͬͨ͠Ͳɺຊ ՈϓϩδΣΫτνʔϜͷํ͕࢖͏༧ఆΈ͍ͨ Ͱۭͷಉ໊ϦϙδτϦ͕͢Ͱʹ͋ͬͨɻͳͷ Ͱɺthinreports-handler ͱͨ͠ɻͪΐͬͱΘ ͔Γʹ͍͔͘ͳɻςϯϓϨʔτϋϯυϥͬͯ ҙຯͰ͢ɻ 12೥9݄16೔೔༵೔

  32. 12೥9݄16೔೔༵೔

  33. UIJOSFQPSUTIBOEMFS UIJOSFQPSUTSBJMT 改�名 12೥9݄16೔೔༵೔

  34. wۀ຿ͳΤϯδχΞͰ΋ιʔγϟϧίʔσΟϯάʹ ͞͞΍͔ͳ͕ΒࢀՃͰ͖Δͷ͔ͳ w͜Μͳ΍ΓͱΓָ͍͠Ͷ w5IJO3FQPSUT UIJOSFQPSUTSBJMTڞʑΑΖ͘͠ wUMGϑΝΠϧΛ$ rails generateίϚϯυͰ ੜ੒ग़དྷΔΑ͏ʹ͍ͨ͠ 12೥9݄16೔೔༵೔

  35. ͋Γ͕ͱ͏ ͍͟͝·ͨ͠ 5IBOLZPV 12೥9݄16೔೔༵೔