[macruby-changes] [1686] MacRubyWebsite/trunk

source_changes at macosforge.org source_changes at macosforge.org
Sun May 31 20:26:13 PDT 2009


Revision: 1686
          http://trac.macosforge.org/projects/ruby/changeset/1686
Author:   mattaimonetti at gmail.com
Date:     2009-05-31 20:26:13 -0700 (Sun, 31 May 2009)
Log Message:
-----------
added creating an obj-c bundle recipe and added links between articles

Modified Paths:
--------------
    MacRubyWebsite/trunk/content/hotcocoa/application_layout.txt
    MacRubyWebsite/trunk/content/hotcocoa/getting_started.txt
    MacRubyWebsite/trunk/lib/team.rb

Added Paths:
-----------
    MacRubyWebsite/trunk/content/recipes/
    MacRubyWebsite/trunk/content/recipes/create-an-objective-c-bundle.txt

Modified: MacRubyWebsite/trunk/content/hotcocoa/application_layout.txt
===================================================================
--- MacRubyWebsite/trunk/content/hotcocoa/application_layout.txt	2009-05-31 23:34:49 UTC (rev 1685)
+++ MacRubyWebsite/trunk/content/hotcocoa/application_layout.txt	2009-06-01 03:26:13 UTC (rev 1686)
@@ -217,4 +217,6 @@
 
 The third part of this series will be, hopefully, pulling real data back from "PostRank":http://postrank.com and displaying it in a custom cell in our table.
 
+<a href="/hotcocoa/functionality.html">Read the next article: "Adding Functionality"</a>
+
 </div>
\ No newline at end of file

Modified: MacRubyWebsite/trunk/content/hotcocoa/getting_started.txt
===================================================================
--- MacRubyWebsite/trunk/content/hotcocoa/getting_started.txt	2009-05-31 23:34:49 UTC (rev 1685)
+++ MacRubyWebsite/trunk/content/hotcocoa/getting_started.txt	2009-06-01 03:26:13 UTC (rev 1686)
@@ -240,4 +240,5 @@
 
 That's it for part I. We've now setup with our basic application structure and have an idea of what we're working with. In the next installment, we'll work on getting our application views setup as we want.
 
+<a href="/hotcocoa/application_layout.html">Read the next article: "Application Layout"</a>
 </div>
\ No newline at end of file

Added: MacRubyWebsite/trunk/content/recipes/create-an-objective-c-bundle.txt
===================================================================
--- MacRubyWebsite/trunk/content/recipes/create-an-objective-c-bundle.txt	                        (rev 0)
+++ MacRubyWebsite/trunk/content/recipes/create-an-objective-c-bundle.txt	2009-06-01 03:26:13 UTC (rev 1686)
@@ -0,0 +1,91 @@
+--- 
+title:      Creating an Objective-C bundle to use with MacRuby
+created_at: 2009-05-31 18:51:36.516659 -07:00
+recipe:     true
+author:     Matt Aimonetti
+filter:
+  - erb
+  - textile
+--- 
+h1(title). <%= h(@page.title) %>
+
+<div class="author">
+  By <%= member_name(@page.author) %>
+</div>
+
+<div class='recipe'>
+
+Objective-C has a lot of very interesting libraries and Free Open Source code that 
+you might want to use in your MacRuby/HotCocoa projects.
+
+h3. Creating a MacRuby compatible bundle
+
+If you are using MacRuby with Xcode, adding Objective-C frameworks, 
+dynamic libraries and third party code is easy and you just need to add the code 
+you want to use and make it available in your build target.
+
+You might wonder how to do that when using HotCocoa or pure Ruby.
+
+If you want to use a Cocoa Framework, you just need to make sure it's in your path and then require it.
+
+The easiest way to add non framework code is to create a Dynamic Library compatible with MacRuby and simply require it.
+
+Let's see how to do that:
+
+h3. Xcode template
+
+Start Xcode and choose the Cocoa Bundle template.
+
+!http://img.skitch.com/20090601-q4gwtihhbcfcgy4ndjg8jgs3it.jpg!
+
+Choose a name for your project and add the Objective-C files you want to make bundle.
+
+h3. Build settings
+
+Edit your build settings as follows:
+
+Click on: Project > Edit Active Target "TheNameOfYourTarget"
+
+!http://img.skitch.com/20090601-g8qg3hipqutewktankus5q9796.jpg!
+
+Pick the appropriate architectures and choose GCC version 4.0 or more recent.
+
+!http://img.skitch.com/20090601-fhtbsq4t3rwuegussa6c1r26f4.jpg!
+
+Change the executable from 'dylib' to 'bundle'. An if you want to, change the 'product name'.
+(From the Ruby side, we will later on require the bundle using this product name)
+
+!http://img.skitch.com/20090601-jc6qmc3bnmex4cme7tfa5sfx5q.jpg!
+
+Finally, enable the Objective-C Garbage Collector.
+
+Your project should now be properly setup to build, but we need one more thing.
+
+h3. MacRuby compatibility
+
+Because we want our bundle/dynamic library to behave like a C extension and just require it, we need to add a constructor.
+Choose an implementation file (.m file) and add an empty function as follows:
+
+<% coderay :lang => 'Objective-C' do -%>
+// Added for MacRuby
+void Init_twitter_engine(void) { }
+<% end %>
+
+In this case 'twitter_engine' is the name of our bundle/dylib. (The name was set as `product name` in our build settings)
+Use Init_XXX where XXX is the name of your bundle. When requiring your bundle, Ruby will automatically call this method.
+If it doesn't exist, Ruby will throw an exception.
+
+h3. Requiring the bundle
+
+Your bundle now behaves just like a Ruby C extension, require it and start using it directly:
+
+<% coderay :lang => 'ruby' do -%>
+[mattetti at matt-aimonettis-macbook lib (master)]$ macirb
+>> require 'twitter_engine'
+=> true
+>> engine = MGTwitterEngine.alloc.initWithDelegate(self)
+=> #<MGTwitterEngine:0x8007a0e40>
+<% end %>
+
+Pretty easy, isn't it?
+</div>
\ No newline at end of file

Modified: MacRubyWebsite/trunk/lib/team.rb
===================================================================
--- MacRubyWebsite/trunk/lib/team.rb	2009-05-31 23:34:49 UTC (rev 1685)
+++ MacRubyWebsite/trunk/lib/team.rb	2009-06-01 03:26:13 UTC (rev 1686)
@@ -18,7 +18,7 @@
       Member.new("patrick", "Patrick Thomson", "Apple, Inc.", nil, "pthomson at apple.com", "All things OS X"),
       Member.new("eloy", "Eloy Duran", nil, nil, "eloy.de.enige at gmail.com", "Testing"),
       Member.new("vincent", "Vincent Isambart"),
-      Member.new("matt", "Matt Aimonetti", "m|a agile consulting", nil, "http://merbist.com", "HotCocoa")
+      Member.new("matt", "Matt Aimonetti", "m|a agile consulting", "http://merbist.com", "mattaimonetti at gmail.com" "HotCocoa")
     ]
   end
   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090531/2272ac28/attachment.html>


More information about the macruby-changes mailing list