CodeStock :: Introduction To MacRuby and HotCocoa

2,439 views

Published on

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.

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

  • Be the first to like this

No Downloads
Views
Total views
2,439
On SlideShare
0
From Embeds
0
Number of Embeds
262
Actions
Shares
0
Downloads
15
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • \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

    1. 1. Michael
“Doc”
NortonMacRuby
and
HotCocoa
    2. 2. 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.
    3. 3. 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!
    4. 4. Introduction toMacRuby &HotCocoaMichael “Doc” Norton@DocOnDevhttp://www.docondev.com/doc@leandog.com
    5. 5. RubyCocoa• 2001 Written by Fujimoto Hisakuni• A bridge between objective C and Ruby• Bundled with Mac OSX 10.5• Ugly (for Ruby)
    6. 6. 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
    7. 7. MacRuby• 2008 to replace RubyCocoa• Not a bridge • Run MUCH Faster• Still looks ugly
    8. 8. 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
    9. 9. What is HotCocoa?• Ruby API • Looks and Feels like Ruby - YAY!• Simplifies use of Objective C/ Cocoa
    10. 10. 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
    11. 11. 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
    12. 12. 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
    13. 13. 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
    14. 14. 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
    15. 15. Getting Started• hotcocoa stock_schedule• cd stock_schedule• macrake
    16. 16. What did we make? ./Rakefile ./Stock Schedule.app/ ./config/build.yml ./lib/application.rb ./lib/menu.rb ./resources/HotCocoa.icns
    17. 17. Menu.rb
    18. 18. Menu.rb (Redacted)
    19. 19. Application.rb
    20. 20. Application.rb (Updated)
    21. 21. Application.rb (Updated)
    22. 22. Windows & Frames
    23. 23. Window with no layout
    24. 24. Window with no layout
    25. 25. 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
    26. 26. Assign layout to window view
    27. 27. Assign layout to window view
    28. 28. Filter Bar
    29. 29. Inject scrolling view with table
    30. 30. Inject scrolling view with table
    31. 31. Simple Grid
    32. 32. Are we there yet?
    33. 33. Create two columns
    34. 34. Create two columns
    35. 35. Populate both columns
    36. 36. Populate both columns
    37. 37. Simple Grid
    38. 38. Get Data from the API
    39. 39. Get Data from the API
    40. 40. Big Hideous String
    41. 41. Big Hideous String
    42. 42. Uses API (poorly)
    43. 43. Add Title Column
    44. 44. Add Title Column
    45. 45. Filter API Results
    46. 46. Filter API Results
    47. 47. Filters API Results
    48. 48. Are we there yet?
    49. 49. Thank You!Michael “Doc” Norton@DocOnDevhttp://www.docondev.com/doc@leandog.com

    ×