• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
CodeStock :: Introduction To MacRuby and HotCocoa
 

CodeStock :: Introduction To MacRuby and HotCocoa

on

  • 2,511 views

MacRuby is an implementation of Ruby 1.9 directly on top of Mac OS X core technologies. HotCocoa is a thin, idiomatic Ruby layer that sits above Cocoa and other frameworks. Together, they make ...

MacRuby is an implementation of Ruby 1.9 directly on top of Mac OS X core technologies. HotCocoa is a thin, idiomatic Ruby layer that sits above Cocoa and other frameworks. Together, they make building Mac applications pain free (for Rubyists). Doc shows us how to get started and then walks us through the creation of a simple app.

Statistics

Views

Total Views
2,511
Views on SlideShare
2,260
Embed Views
251

Actions

Likes
0
Downloads
13
Comments
0

5 Embeds 251

http://leandog.com 132
http://www.leandog.com 91
http://localhost 24
http://www.hanrss.com 3
https://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

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
  • \n
  • \n
  • \n
  • \n
  • \n
  • Bridge\nTwo different Run-Times\nMessaging between Objective C and Ruby was slow\n
  • Every Class, Object, and Method is an Objective-C Class, Object, Method\n
  • \n
  • \n
  • \n
  • Window is easy to define\n
  • Button much easier to define\n
  • Button much easier to define\n
  • \n
  • Be sure to use macrake, macirb, macgem, and macruby\n
  • Notice StockSchedule.app is a directory\n
  • Menu Names (Apple, File, Window, Help)\nHotKeys - “,” indicates command+, :: modifiers is explicit\n:apple is special and appears in menu under app name\n
  • \n
  • I don’t want it absolutely placed, I want it centered.\n
  • Change frame to size and tell it to center the window\n
  • Change frame to size and tell it to center the window\n
  • This is what we are after.\nOur window will be an invisible container with inserted (nested) views.\n
  • \n
  • \n
  • Building block of presentations\n
  • and inject filter layout\n
  • and inject filter layout\n
  • \n
  • \n
  • \n
  • \n
  • Let’s see if we can split the column in the table\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • No, but much closer.\nWasn’t sure about date format and ran out of time. (sorry)\nActually didn’t do the drop-downs due to multiple API calls for demo.\n
  • \n

CodeStock :: Introduction To MacRuby and HotCocoa CodeStock :: Introduction To MacRuby and HotCocoa Presentation Transcript

  • Michael
“Doc”
NortonMacRuby
and
HotCocoa
  • CodeStock
is
proudly
partnered
with: RecruitWise
and
Staff
with
Excellence
‐
www.recruitwise.jobs Send
instant
feedback
on
this
session
via
Twi?er: 



Send
a
direct
message
with
the
room
number
to
@CodeStock 



d codestock 503 This session is great! For
more
informa<on
on
sending
feedback
using
Twi>er
while
at
 CodeStock,
please
see
the
“CodeStock
README”
in
your
CodeStock
guide.
  • Telerik Deliver More Than Expected @ Code Stock 2011.Check
out
our
NEW
Just
Decompile
Product
–
Powerful,
Free
Decompiler.
Forever. hDp://www.telerik.com/products/decompiling.aspx
 @telerik Contact
your
user
group
leader
for
a
$100
discount
off
your
next
Telerik
purchase!
  • Introduction toMacRuby &HotCocoaMichael “Doc” Norton@DocOnDevhttp://www.docondev.com/doc@leandog.com
  • RubyCocoa• 2001 Written by Fujimoto Hisakuni• A bridge between objective C and Ruby• Bundled with Mac OSX 10.5• Ugly (for Ruby)
  • RubyCocoa Hello Worldrequire osx/cocoa; include OSXapp = NSApplication.sharedApplicationwin = NSWindow.alloc.initWithContentRect_styleMask_backing_defer( [0, 0, 200, 60], NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask, NSBackingStoreBuffered, false)win.title = Hello Worldbutton = NSButton.alloc.initWithFrame(NSZeroRect)win.contentView.addSubview(button)button.bezelStyle = NSRoundedBezelStylebutton.title = Hello!button.sizeToFitbutton.frameOrigin = NSMakePoint((win.contentView.frameSize.width / 2.0) - (button.frameSize.width / 2.0), (win.contentView.frameSize.height / 2.0) - (button.frameSize.height / 2.0))button_controller = Object.newdef button_controller.sayHello(sender) puts "Hello World!"endbutton.target = button_controllerbutton.action = sayHello:win.displaywin.orderFrontRegardlessapp.run
  • MacRuby• 2008 to replace RubyCocoa• Not a bridge • Run MUCH Faster• Still looks ugly
  • MacRuby Hello Worldframework ‘Cocoa’app = NSApplication.sharedApplicationwin = NSWindow.alloc.initWithContentRect([0, 0, 200, 60], styleMask:NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask, backing:NSBackingStoreBuffered, defer:false)win.title = Hello Worldbutton = NSButton.alloc.initWithFrame(NSZeroRect)win.contentView.addSubview(button)button.bezelStyle = NSRoundedBezelStylebutton.title = Hello!button.sizeToFitbutton.frameOrigin = NSMakePoint((win.contentView.frameSize.width / 2.0) - (button.frameSize.width / 2.0), (win.contentView.frameSize.height / 2.0) - (button.frameSize.height / 2.0))button_controller = Object.newdef button_controller.sayHello(sender) puts "Hello World!"endbutton.target = button_controllerbutton.action = sayHello:win.displaywin.orderFrontRegardlessapp.run
  • What is HotCocoa?• Ruby API • Looks and Feels like Ruby - YAY!• Simplifies use of Objective C/ Cocoa
  • HotCocoa Hello Worldrequire ‘hotcocoa’; include HotCocoaapp = NSApplication.sharedApplicationwin = NSWindow.alloc.initWithContentRect([0, 0, 200, 60], styleMask:NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask, backing:NSBackingStoreBuffered, defer:false)win.title = Hello Worldbutton = NSButton.alloc.initWithFrame(NSZeroRect)win.contentView.addSubview(button)button.bezelStyle = NSRoundedBezelStylebutton.title = Hello!button.sizeToFitbutton.frameOrigin = NSMakePoint((win.contentView.frameSize.width / 2.0) - (button.frameSize.width / 2.0), (win.contentView.frameSize.height / 2.0) - (button.frameSize.height / 2.0))button_controller = Object.newdef button_controller.sayHello(sender) puts "Hello World!"endbutton.target = button_controllerbutton.action = sayHello:win.displaywin.orderFrontRegardlessapp.run
  • HotCocoa Hello Worldrequire ‘hotcocoa’; include HotCocoaapp = NSApplication.sharedApplicationwin = window :title => ‘hello world’, :frame => [0, 0, 200, 60]button = NSButton.alloc.initWithFrame(NSZeroRect)win.contentView.addSubview(button)button.bezelStyle = NSRoundedBezelStylebutton.title = Hello!button.sizeToFitbutton.frameOrigin = NSMakePoint((win.contentView.frameSize.width / 2.0) - (button.frameSize.width / 2.0), (win.contentView.frameSize.height / 2.0) - (button.frameSize.height / 2.0))button_controller = Object.newdef button_controller.sayHello(sender) puts "Hello World!"endbutton.target = button_controllerbutton.action = sayHello:win.displaywin.orderFrontRegardlessapp.run
  • HotCocoa Hello Worldrequire ‘hotcocoa’; include HotCocoaapp = NSApplication.sharedApplicationwin = window :title => ‘hello world’, :frame => [0, 0, 200, 60]b = button :title => ‘Hello!’, :layout => {:align => :center}win << bbutton_controller = Object.newdef button_controller.sayHello(sender) puts "Hello World!"endbutton.target = button_controllerbutton.action = sayHello:win.displaywin.orderFrontRegardlessapp.run
  • HotCocoa Hello Worldrequire ‘hotcocoa’; include HotCocoaapp = NSApplication.sharedApplicationwin = window :title => ‘hello world’, :frame => [0, 0, 200, 60]b = button :title => ‘Hello!’, :layout => {:align => :center}win << bb.on_action { puts “Hello World!” }win.displaywin.orderFrontRegardlessapp.run
  • HotCocoa Hello Worldrequire ‘hotcocoa’; include HotCocoaapplication do win = window :title => ‘hello world’, :frame => [0, 0, 200, 60] b = button :title => ‘Hello!’, :layout => {:align => :center} win << b b.on_action { puts “Hello World!” }end
  • Getting Started• hotcocoa stock_schedule• cd stock_schedule• macrake
  • What did we make? ./Rakefile ./Stock Schedule.app/ ./config/build.yml ./lib/application.rb ./lib/menu.rb ./resources/HotCocoa.icns
  • Menu.rb
  • Menu.rb (Redacted)
  • Application.rb
  • Application.rb (Updated)
  • Application.rb (Updated)
  • Windows & Frames
  • Window with no layout
  • Window with no layout
  • layout_view• :mode -> :horizontal, :vertical • options• :spacing • :expand -> :height, :width, [:height, :width]• :frame -> [:top, :right, :width, :height] • :padding• :size -> [:width, :height] • :left_ | :right_ | :top_ | :bottom_• :padding • :align -> :left | :center | :right | :top • :left_ | :right_ | :top_ | :bottom_ | :bottom• :margin • :left_ | :right_ | :top_ | :bottom_ https://github.com/richkilmer/hotcocoa/blob/master/lib/hotcocoa/layout_view.rb
  • Assign layout to window view
  • Assign layout to window view
  • Filter Bar
  • Inject scrolling view with table
  • Inject scrolling view with table
  • Simple Grid
  • Are we there yet?
  • Create two columns
  • Create two columns
  • Populate both columns
  • Populate both columns
  • Simple Grid
  • Get Data from the API
  • Get Data from the API
  • Big Hideous String
  • Big Hideous String
  • Uses API (poorly)
  • Add Title Column
  • Add Title Column
  • Filter API Results
  • Filter API Results
  • Filters API Results
  • Are we there yet?
  • Thank You!Michael “Doc” Norton@DocOnDevhttp://www.docondev.com/doc@leandog.com