• Save
Monkeybars in the Manor
Upcoming SlideShare
Loading in...5
×
 

Monkeybars in the Manor

on

  • 4,942 views

How to build a Twitter desktop client using JRuby + MonkeyBars. As demo’d at RubyManor

How to build a Twitter desktop client using JRuby + MonkeyBars. As demo’d at RubyManor

Statistics

Views

Total Views
4,942
Views on SlideShare
4,937
Embed Views
5

Actions

Likes
0
Downloads
0
Comments
0

2 Embeds 5

http://www.slideshare.net 4
http://192.168.10.100 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Monkeybars in the Manor Monkeybars in the Manor Presentation Transcript

  • Monkeybars in the manor
  • What do you think? about Java?
  • DIE, DIE DIE, DIE DIE, DIE DIE, DIE DIE, DIE DIE, DIE DIE, DIE DIE, DIE DIE, DIE DIE, DIE DIE, DIE DIE, DIE DIE, DIE
  • What do you think? About JRuby?
  • What do you think? About JRuby? (it’s not so bad really)
  • Before... JRuby Installed Netbeans Downloaded Gems
  • Before... JRuby Installed Netbeans Downloaded Gems
  • Before... JRuby Installed Netbeans Downloaded Gems
  • Before... JRuby Installed Netbeans Downloaded Gems
  • Twitter Client The Spec •Login •Report errors •Display friend tweets •Post tweets
  • Creating... the app
  • Initial Setup + scaffolding $> monkeybars projectname $> cd projectname $> rawr install (choose option 2) $> jruby -S rake generate ALL='src/login'
  • Install Gems and freeze Gems $> jruby -S gem install twitter $> cd lib/ruby $> jruby -S gem unpack twitter $> jruby -S gem unpack hpricot
  • Skeleton App will look something like this
  • Net Beans New Project 1. Import Existing Java project with sources 2. Add JRuby complete library 3. Add Swing.. Net Beans
  • Net Beans New Project 1. Import Existing Java project with sources 2. Add JRuby complete library 3. Add Swing.. LIVE DEMO! Net Beans
  • Under the hood Like Rails but not as you know it M VC
  • Under the hood Like Rails but not as you know it M VC
  • username.text View password.text login_button username Controller Model password
  • Sample Code a quick look controllers, models, views event handling
  • Controller class LoginController < ApplicationController set_model 'LoginModel' set_view 'LoginView' set_close_action :exit def login_button_action_performed model, view_transfer = view_state if @user = model.login(model.username, model.password) TweetController.instance.setup(model) TweetController.instance.open close else transfer[:errors] = model.errors signal(:login_failed) end end end
  • Model class LoginModel attr_accessor :username, :password, :message, :errors, :user def login(username, password) begin @user = Twitter::Base.new(username, password) @user.timeline self rescue Twitter::CantConnect => e @errors ||= [] @errors << $!.to_s return false end end end
  • View class LoginView < ApplicationView set_java_class 'login.LoginFrame' map :view => quot;username.textquot;, :model => :username map :view => quot;password.textquot;, :model => :password define_signal :name => :login_failed, :handler => :login_failed def login_failed(model, transfer) message.text = transfer[:errors].to_s end nom end nom..
  • The App pre alpha 0.333333333333
  • Result
  • Package For cross platform distro rawr install Text 2: Keep the current Rakefile, and add the rawr content to the top. http://rawr.rubyforge.org/
  • Package Commands For cross platform distro Text Remember to edit your build_configuration.yaml 1st
  • Package Sample Config for RAWR to generate app # Name of the created jar file project_name: tweetobix # Directory to create and place produced project files in output_dir: package ----------<SNIP>---------------- # Individual files that should be loaded on the classpath classpath_files: - lib/java/jruby-complete.jar - lib/java/swing-layout-1.0.3.jar see build_configuration.yaml
  • Tricks and tips
  • Why didn’t you use the twitter4r gem ?
  • jruby --command gem install twitter4r Building native extensions. This could take a while... mypath/jruby-1.1.4/lib/ruby/1.8/mkmf.rb:7: JRuby does not support native extensions. Check wiki.jruby.org for alternatives. (NotImplementedError) from mypath/jruby-1.1.4/lib/ruby/1.8/mkmf.rb:1:in `require' from extconf.rb:1 ERROR: Error installing twitter4r: ERROR: Failed to build gem native extension. mypath/jruby-1.1.4/bin/jruby extconf.rb install twitter4r Gem files will remain installed in /mypath/jruby-1.1.4/lib/ruby/ gems/1.8/gems/json-1.1.3 for inspection. Results logged to mypath/jruby-1.1.4/lib/ruby/gems/1.8/gems/ json-1.1.3/ext/json/ext/parser/gem_make.out
  • Requiring Gems Frozen require 'manifest' # Add vendored gems to load path and require them automatically Dir[File.expand_path(File.dirname(__FILE__) + quot;/../lib/ruby/**quot;)].map do |dir| lib = quot;#{dir}/libquot; lib = dir if lib =~ /.w+$/ #File.directory? is broken in current JRuby for dirs inside jars $: << lib gem_name = File.basename(dir.gsub(/-d+.d+.d+$/, '')) gem_path = dir + quot;/lib/quot; + gem_name + quot;.rbquot; begin require gem_path if File.exists? gem_path rescue p quot;could not load gem #{gem_path}quot; end end
  • Gotchas a few java.lang.NullPointerException: null build paths gems
  • -1’s The not so good bits • Assumes knowledge of Java • Quirky MVC • Learning curve • Early days...
  • +1’s The good bits • GUI Builder (using Netbeans) • Interface with mature Java libs • It’s all Ruby! • Cross platform distribution • No platform dependancy on Ruby • Cutting edge
  • Blinked? Go here http://tweetobix.com Steps plus code to download
  • Fin. martinbtt http://www.beyondthetype.com