The World’s Leading Microsoft .NET Magazine
   
 
The .NET Addict's Blog

My Top Tags

                                                           

My RSS Feeds








I heart FeedBurner

Latest Diggs - Programming

Computers Blogs - Blog Top Sites

Site Hits

Total: 4,863,575
since: 19 Jan 2005

Silverlight and Ruby on the Mac, Part 1: Hello Ruby

posted Sun 26 Oct 08

Ingredients you're going to need before following along with this blog post:

  • Mono (latest stable release) for Mac OS X
  • Silverlight 2.0 Plugin for Firefox (you can download this from http://www.silverlight.net
  • Silverlight Dynamic Languages SDK (You can download this from CodePlex )

Don't worry if the dynamic languages SDK seems like it's a windows-only download. Things are going to get really interesting during this post, and there will be some really, really blurry cross-platform lines... especially when we start busting out the Mono.

Hello Ruby

I have been listening to a lot of people tell me that I should be using Ruby for my Silverlight development because the dynamic language dramatically simplifies common development tasks and that my Silverlight applications will be quicker to market, cooler, more elegant, and indeed will sprout their own halos and emit solid gold from their debuggers. Not being one to believe anything anybody tells me, this series of blog posts is all about me trying to determine for myself if any of this prattle about Ruby and Silverlight being the holy grail is true. The first step in any evaluation of a new technology for me is the Hello World app. So this is how to build a Hello Ruby application using Silverlight and nothing but a Mac running Leopard... NO Windows machines.

Environment Setup

After installing Mono and the SDL SDK, its time to get rockin'. The SDL SDK comes with a shell script that will generate an empty Silverlight Ruby application in the directory of your choice. To do this, I dropped into Terminal in the SDK directory and issued the following command:

script/sl ruby hello

This created a new directory called hello that contained an index.html to host my Silverlight control, some stylesheets for reporting errors in specific divs, and of course a directory called ruby that contains all the good stuff.

Once I've got this directory set up, I change into the hello/ruby directory and I edit the App.xaml file and the App.rb file. The following image is a screenshot of me editing the App.xaml file:

And this is a screenshot of me editing the App.rb file:

Keep in mind that I'm not using a Windows machine to do any of this, nor have I invoked anything mono-related yet. Also worth noting is the classic Ruby syntax where I'm defining an event handler for the Click event on my button. One main difference between building C# Silverlight apps and Dynamic Silverlight apps is that the Xaml parser does not know ahead of time about dynamic classes and so cannot rig events directly in Xaml. My guess is that this also means I'm not going to be able to use ObjectDataSources with Ruby objects, but that's a topic for another post.

The next thing we need is a XAP file. A Xap file is basically a ZIP file that contains your Xaml, your Ruby, and all of your dependent DLLs and resources. When you hit a website that is hosting a Silverlight control, the plugin fetches the Xap file, cracks it open, and then starts running code in the client-side sandbox using what it found in the XAP.

This is where mono comes in. The SDL SDK comes with a tool called Chiron (that's pronounced KAI-RON in case you're curious). This tool can either run a web server that dynamically generates a XAP from the contents of a directory, or it can produce a static XAP that you can then use to deploy your control. For debugging and testing purposes, running the web server is a great option because you can see changes you make just by refreshing the browser.

To run Chiron, I simply changed to the hello directory and ran ../script/server /w (Chiron in web server mode defaulting to the current directory). Worth noting here is that Chiron.exe is a Windows-compiled application, but because it makes use of System.Net it can be invoked flawlessly using mono. In fact, when you run the server script, it is actually invoking Mono to run Chiron.exe. Here's a screenshot of me hitting the Chiron-hosted website using Firefox (again, this is all on the Mac):

So what's really going on here??

Basically what's happening is that when my client (Firefox on Leopard in this case) hits a web page that is hosting a Silverlight 2.0 control, the plug-in downloads the appropriate XAP file and then begins executing. It uses traditional Silverlight CLR code to create an instance of the DLR host that is appropriate for the language it discovered I'm using. In this case, it's going to use the Silverlight CLR to create an instance of the Ruby DLR host. From that point afterward, the Ruby DLR host is in charge and I'm now running Ruby code in the DLR, which is inside the Silverlight-CLR, which is inside the browser plug-in sandbox provided by Firefox.

Verdict

So far so good. I can use my favorite text editor to create Ruby files that are powering my Silverlight app and still have my Xaml so that I can still make use of Expression Blend (yes, I'd have to use Windows for this) to do up my GUIs. My next test will be to see if I can data bind a Silverlight Xaml GUI to Ruby objects. I'll cover my attempt to get that working in my next blog post.

tags:                  

links: digg this    del.icio.us    technorati    reddit

AddThis Social Bookmark Button




1. Craig left...
Sun 26 Oct 08 9:10 pm :: http://www.typemismatch.com/

Cool stuff, been looking around for mac only development that was more like .net - so I assume you "could" use C# like this via Mono if you don't like Ruby and still keep all Dev inside the mac or maybe C# for the SL app and Ruby/Rails for data via web services or something close.


2. Kevin Hoffman left...
Mon 27 Oct 08 7:05 am

If you want C# Silverlight development on the Mac, you should be able to use a forthcoming (might already be out, I haven't checked) Eclipse plug-in that should, in theory, provide the entire life cycle for a Silverlight app without requiring the use of Windows or Visual Studio.


3. Craig left...
Wed 31 Dec 08 5:12 pm :: http://www.typemismatch.com/

Hey, I can't see a way to msg you anymore so here it is! :) I got a macbook for the wife, very quickly followed by a mbp for myself and the 8XEON Pro :):) - a complete switch so I'm dying for more articles on Ruby/Mac. thanks! also any good Ruby books.


4. NO LIGHT IN SIGHT left...
Tue 03 Feb 09 12:13 pm

I cannot get the app to work. When I click on index.html after launching chiron, by entering localhost:2060, i get the error get Microsoft Silverlight. What gives. I have all silverlight componnets installed, and I copied /Program Files/Microsoft Silverlight/2*/* into my chiron/bin directory for good measure, to make sure the dlls were being found.

I am running this with IE and Windows Vista


Tag Related Posts

Would you like to touch my mono?

Mon 23 Nov 09 2:59 P GMT-05

Microsoft Codename "Oslo" Distilled

Mon 27 Apr 09 12:46 P GMT-05

Geneva Distilled

Thu 09 Apr 09 1:27 P GMT-05

T4, Visual Studio 2008's Best Kept Secret

Thu 02 Apr 09 10:42 A GMT-05
tags:        

WPF Control Development Unleashed

Wed 25 Mar 09 2:26 P GMT-05

What's New in Silverlight 3

Fri 20 Mar 09 2:38 P GMT-05

MIX 2009 - Day 1 Recap

Thu 19 Mar 09 2:17 P GMT-05

At MIX 2009, pre-keynote

Wed 18 Mar 09 2:50 P GMT-05

Live Framework April 2009 CTP is out!

Fri 13 Mar 09 12:11 P GMT-05

Velocity CTP3 coming up next week

Thu 12 Mar 09 4:44 P GMT-05
tags:            

My first day using Windows 7 Beta 1

Wed 25 Feb 09 1:58 P GMT-05

Upgrading your Leopard install to Java SE 6 64-Bit

Mon 12 Jan 09 1:38 P GMT-05
tags:            

Live Mesh Tutorial 1 - Hello Live Mesh

Thu 06 Nov 08 2:33 P GMT-05

Microsoft Windows Azure Distilled

Tue 28 Oct 08 1:42 P GMT-05

Microsoft's Lofty Direction

Sun 05 Oct 08 2:30 P GMT-05

Apple drops the iPhone NDA for Released Software

Wed 01 Oct 08 3:54 P GMT-05
tags:          

Cappuccino, Objective-J, and You

Wed 10 Sep 08 6:14 P GMT-05

So I'm in the LA Times ;)

Wed 27 Aug 08 2:51 P GMT-05
tags:                  

MobileMe vs. Live Mesh Throwdown - Round 1

Wed 16 Jul 08 10:33 A GMT-05

Building Model Classes in C# and Cocoa

Sun 15 Jun 08 3:13 P GMT-05
tags:            

MobileMe vs. Live Mesh - Round 1

Wed 11 Jun 08 12:20 A GMT-05

My Macbook Air is masculine, dammit!

Mon 17 Mar 08 6:59 P GMT-05
tags:          

iPhone Underrated as a Gaming Device?

Fri 14 Mar 08 1:50 P GMT-05
tags:        

My take on the iPhone SDK

Sat 08 Mar 08 1:39 P GMT-05

Jobs says "not likely" to Flash on the iPhone

Thu 06 Mar 08 1:39 A GMT-05
tags:          

My Macbook Air Review

Sun 02 Mar 08 4:20 P GMT-05

iPhone Roadmap March 6th

Fri 29 Feb 08 10:41 P GMT-05
tags:        

One Framework to Rule them All

Mon 25 Feb 08 6:49 P GMT-05

Video of the Macbook Air in Action

Wed 20 Feb 08 3:04 P GMT-05

Macbook Airはきれいですよ!

Sun 17 Feb 08 2:38 A GMT-05

Why is O'Reilly Condoning iPhone Hacking?

Mon 11 Feb 08 3:55 P GMT-05

Evaluating my next laptop purchase

Wed 06 Feb 08 8:40 P GMT-05