JRuby on Rails, Flying Saucer

2,227 views

Published on

A brief introduction to JRuby and JRuby on Rails, and an example of using a Java library from a JRuby on Rails application; the flying saucer library used to convert XHTML to PDF.

Slides for presentation given at ArrrrCamp on October 16th 2009.

Published in: Technology, Education
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,227
On SlideShare
0
From Embeds
0
Number of Embeds
68
Actions
Shares
0
Downloads
8
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

JRuby on Rails, Flying Saucer

  1. 1. Who's this then? Alexander Malfait Enjoying Rails since 2007 Tallest employee at CAT Solutions
  2. 2. Wait, didn't we hate Java? JVM is fast JVM is everywhere, corporate approved Tons of useful & widely used libraries Runs great on Windows
  3. 3. Running Rails jruby -S gem install glassfish jruby -S glassfish -e production config.threadsafe! Works on other app servers (.war file)
  4. 4. Hiding behind Apache <VirtualHost *:80> ServerName my.awesome.app.be RewriteEngine On ProxyPass / http://localhost:3000/ retry=0 ProxyPassReverse / http://localhost:3000/ ErrorDocument 503 "<b>Come back in 10 seconds</b>" </VirtualHost> http://blog.headius.com/2009/04/apache-jruby-rails-glassfish-easy.html
  5. 5. Talking to Java Just create java objects like Ruby objects Extend Java classes in Ruby Require jars from Ruby without mucking about with the JVM ClassPath
  6. 6. Ruby Style Java java.lang.System.current_time_millis x.setSomething(var) => x.something = var button = javax.swing.JButton.new "Press me!" button.add_action_listener do |event| event.source.text = "You did it!" end
  7. 7. Flying Saucer Renders XHTML/CSS3 to PDF (very well!) Written in Java Handles any reporting problem you can throw at it
  8. 8. acts_as_flying_saucer Rails apps produce HTML You know HTML Report to PDF using HTML
  9. 9. Cocktail Reporting class DrinksController < ApplicationController acts_as_flying_saucer def mojito @ingredients = [ "4.0 cl White Rum", "3.0 cl Fresh lime juice", "3 sprigs of Mint", "2 teaspoons Sugar", "Soda Water" ] render_pdf :send_file => { :filename => "tasty.pdf" } end end
  10. 10. Cocktail Reporting <h1 style="color: green;">Mojito!</h1> <ul> <% @ingredients.each do |ingredient| %> <li><%=h ingredient %></li> <% end %> </ul> render_pdf
  11. 11. I want my mojito NOW! Rendering drinks/mojito Completed in 16ms ~62 mojitos/second
  12. 12. Larger documents Rendering the holy bible 4.5MB of HTML Resulting PDF: 1134 pages Completed in 22500ms
  13. 13. Real Example
  14. 14. Typical Reporting Problems Repeating headers / footers Paginating/nesting tables Lots of data Maintaining uniform reporting style All covered by the flying saucer!
  15. 15. Script anything! JFreeChart: powerful charting Apache POI: read & write Excel files JODConvertor: convert (almost) anything to anything using OpenOffice.org Swing Hundreds more...
  16. 16. References http://github.com/alexandermalfait/acts_as_flying_saucer http://bosmeeuw.wordpress.com/ http://www.catsolutions.be/

×