-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathhotcocoa.txt
52 lines (36 loc) · 3.71 KB
/
hotcocoa.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
---
title: HotCocoa
created_at: 2009-03-12 21:06:50.998294 -04:00
filter:
- erb
- textile
---
h1(title). <%= h(@page.title) %>
HotCocoa is a thin, idiomatic Ruby layer that sits above Cocoa and other frameworks. HotCocoa is currently included in the MacRuby distributions.
Cocoa classes have extremely large method and constant names. A substantial amount of code is written to just instantiate and configure instances of these classes. Interface Builder is used by most developers because it hides the complexity of manually configuring controls, but at the expense have having to use a GUI builder and the obscuring those configuration options inside the IB user interface. One of HotCocoa's chief goals is to allow Interface Builder simplicity, but in Ruby code.
Buttons, Sliders, Windows, WebViews...the whole works...HotCocoa simplifies this process by creating a mapping layer over the top of Objective C classes. HotCocoa adds Ruby-friendly methods, constants and delegate techniques that look refreshingly simple, but do not prevent full use of the Cocoa APIs. If you've done any amount of programming on OS X, you know that the API can be quite verbose.
Even with MacRuby's wonderful keyword arguments, it can be daunting to enter this...
<% coderay :lang => 'ruby' do -%>
win = NSWindow.alloc.initWithContentRect [10,20,300,300],
:styleMask => (NSTitledWindowMask |
NSClosableWindowMask |
NSMiniaturizableWindowMask |
NSResizableWindowMask)
<% end %>
...every time you want to create and configure a new NSWindow instance!
This is the reason most developers use Interface Builder to configure interface components. The purpose of HotCocoa is to allow you to use the flexible syntax of Ruby and its dynamic nature to simplify programmatically constructing user interfaces on OS X without an Interface Builder.
With HotCocoa, creating the NSWindow instance above is as simple as:
<% coderay :lang => 'ruby' do -%>
win = window( :frame => [10,20,300,300] )
<% end %>
HotCocoa achieves this feat by creating Mappings over the most common Classes and Constants used on OS X. Those mappings create constructor methods on the HotCocoa module (like the "window" method above). Each constructor method accepts an optional block which yields the created instance (more on that in the HotCocoaTutorial). Mappings also decorate the standard Objective-C API with nice Ruby APIs for common operations. The important thing to realize is the constructor methods return real instances of these common classes, not high-level abstractions. So, you can call any Objective-C method available on those objects.
h3. In HotCocoa, Mappings provide the following:
* <strong>Defaults:</strong> Smart default constructor parameters (like the styles in window) to minimize the parameters you have to pass in.
* <strong>Constants:</strong> Mapping of constants to Ruby symbols to minimize the text and readability of HotCocoa applications.
* <strong>Constructors:</strong> Building the instances of the mapped classes using the correct class-specific APIs.
* <strong>Custom Methods:</strong> Ruby-friendly API for commonly used methods (like << for addSubview on NSView subclasses).
* <strong>Delegate Methods:</strong> Simplified Ruby-friendly methods for delegating instances that use Ruby blocks
<div style="margin-top:8px;"></div>
h3. Want to learn more about HotCocoa?
Now that you understand the basics of what HotCocoa is and why we are building it, please look at the "tutorials":/documentation.html for examples of how to build OS X applications with it.
HotCocoa is a project developed on "GitHub":http://github.com/richkilmer/hotcocoa. Make sure to connect there to get the latest bits.