After seeing the [staggering number](http://www.macrumors.com/2008/02/05/iphone-with-28-of-u-s-smartphone-marketshare-for-q4-2007/ “iPhone with 28% of U.S. Smartphone Marketshare for Q4 2007 - Mac Rumors”) of iPhones sold in the forth quarter, I decided it was time to port my [site](http://dcrails.com “DCRails.com || Making the Metrorail fun!”) to the iPhone. As of a few days ago there is an iPhone version of [DCRails](http://dcrails.com “DCRails.com || Making the Metrorail fun!”). It was a joy to build!
It was built on the back of the [brilliant work](http://code.google.com/p/iui/ “iui - Google Code”) by the amazing [Joe Hewitt](http://joehewitt.com “JoeHewitt.com”). But this brings me to my announcement, Joe also brought [firebug lite](http://www.getfirebug.com/lite.html “Firebug Lite”) to the iPhone. It is a very cool piece of code that proxies **console.log** output through a server-side proxy and displays it in a local browser. The flip (and equally cool) side is you can execute arbitrary javascript from a local browser and have it run on the iPhone. It is called [iBug](http://www.joehewitt.com/blog/firebug_for_iph.php “JoeHewitt.com”), I am not sure my description does it justice, so give that article a read.
Anyway, iBug relies on you starting a little python webserver locally. Unfortunately, this is was problematic, since it relies on iFrames having access to the **parent** window. This poses a security risk since mongrel and iBug were on different ports (XSS police are comin’ to get ya!). So, I ported his webserver over to mongrel. This was very challenging for me, it took me far out of my normal element. I had to learn the following technologies to get this to work, [mongrel handlers](http://mongrel.rubyforge.org/rdoc/index.html “Mongrel”), [comet](http://cyll.org/blog/tech/2006-08-09-themongrelcomet.html “Topher Cyll”), and a little threading in Ruby.
Anyway it isn’t completely done, it looks a little like someone ported some python to ruby, and it could use some polishing, but it does work and I would love some feedback or patches. To get started, install the plugin and read the README file (it’s shorter than this post).
script/plugin install http://svn.simpltry.com/plugins/iphone4r
There are 2 more things, you must use mongrel, and mongrel will have trouble stopping because of an intentional infinite loop (suggestions are welcome).
You might want to correct the URI. It’s actually available at
http://svn.simpltry.com/plugins/iphone4r/nothttp://rails.simpltry.com/plugins/iphone4r/Hi again. It appears that there’s an error in install.rb . The iui directory is not getting copied over from the plugin to /public when the plugin is installed. I added one line to install.rb and it is now working. So install.rb (in its entirety) should look like this:
require 'fileutils'
RAILS_ROOT = File.dirname(__FILE__) + "/../../../" unless defined? RAILS_ROOT
#Install hook code here
def copy_files(source_path, destination_path, directory)
source, destination = File.join(directory, source_path), File.join(RAILS_ROOT, destination_path)
FileUtils.mkdir(destination) unless File.exist?(destination)
FileUtils.cp(Dir.glob(source+'/*'), destination)
end
directory = File.join(File.dirname(__FILE__), "copy_on_install")
copy_files("/script", "/script", directory)
FileUtils.chmod 0755, File.join(RAILS_ROOT, "script", "ibug"), :verbose => true
copy_files("/public/ibug", "/public/ibug", directory)
copy_files("/public/iui", "/public/iui", directory)
P.S. Sorry about the <pre> tags. I didn’t realize those would be escaped and presented as text… oh my!: looks like Textile had a field day messing up the code… okay, I’ll post it on my blog instead…
You can copy it from:
http://brandonzylstra.com/2008/03/12/fixing-iphone4r/
Yeah, I should really start branching my side projects, I never intended to included iUi in this version, until I could offer something on top of iUi in the way of rails helpers.
Any way good catch on the svn repo, I have corrected it.