<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Scott Montgomerie&#039;s Blog</title>
	<atom:link href="http://blog.scottmontgomerie.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.scottmontgomerie.com</link>
	<description>Programming, Business, Stuff</description>
	<lastBuildDate>Wed, 18 May 2011 22:32:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Universal Apps in Appcelerator</title>
		<link>http://blog.scottmontgomerie.com/05/universal-apps-in-appcelerator/</link>
		<comments>http://blog.scottmontgomerie.com/05/universal-apps-in-appcelerator/#comments</comments>
		<pubDate>Wed, 18 May 2011 22:32:21 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[Appcelerator]]></category>
		<category><![CDATA[Appcelerator Titanium]]></category>
		<category><![CDATA[IPad]]></category>
		<category><![CDATA[IPhone]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://blog.scottmontgomerie.com/?p=21</guid>
		<description><![CDATA[Appcelerator is by far the best mobile rapid development platform out there, but they&#8217;re lacking a major feature &#8211; Universal app support.  Universal App support is the ability for an app to run in native resolutions on both the iPhone and iPad platforms.  Until now, you had to produce two versions of your app &#8211; [...]]]></description>
			<content:encoded><![CDATA[<p>Appcelerator is by far the best mobile rapid development platform out there, but they&#8217;re lacking a major feature &#8211; Universal app support.  Universal App support is the ability for an app to run in native resolutions on both the iPhone and iPad platforms.  Until now, you had to produce two versions of your app &#8211; an iPhone app and an &#8220;HD&#8221; app for your iPad.  This has its benefits &#8211; apps typically selling for $0.99 on an iPhone will often go for $2.99 or more for the &#8220;HD&#8221; version, but what if you want to write a Universal App?  With Appcelerator, you&#8217;re out of luck, until now.</p>
<p>With a simple hack, you can get your application to be a Universal App.  Coles notes: Change the &#8220;Targeted Device Family&#8221; to iPhone/iPad in your Xcode Active Target settings.</p>
<p><strong>Using XCode to work with Appcelerator</strong></p>
<p>This hack is predicated on my preferred way of using Appcelerator: (hint: it&#8217;s not using the Titanium IDE). The Titanium IDE and build process is a horrible way to work with Appcelerator. If that was my first introduction to Appcelerator, I would never continue with it. Creating a project is buggy, rebuilding it buggy. Sometimes it picks up your changes, sometimes it does a full build and makes you wait forever, sometimes you want it to do a full build and it doesn&#8217;t; the whole process is just a bad hack.  So when I use Appcelerator, I:</p>
<ul>
<li>Create the project with Titanium.</li>
<li>Open the .Xcodeproj file that it created with Xcode.</li>
<li>Never open Titanium again</li>
</ul>
<p>You can reload your app much quicker by simply using the Console view in Xcode.  Once you build and run it with XCode, you can simply hit the &#8220;Restart&#8221; button, and your code will be instantly reloaded, no recompilation, nothing. There are however, some caveats (see here).</p>
<p><strong>Universal Apps</strong></p>
<p>There are two possible reasons why you&#8217;d want to write a universal app with Appcelerator: to produce one, universal version of your app, or just to minimize the amount of code you have to write and maintain between your normal and HD versions of your app. As far as I can tell, Appcelerator encourages you to write <em>either</em> an iPhone or iPad app, even though it gives you two distinct targets in XCode (App and App-iPad).  But writing two distinct apps, as I have done in the past, is a waste &#8211; you end up reimplementing way too much of your business logic and duplicating it in two places.  It&#8217;s much better to follow the DRY (Don&#8217;t Repeat Yourself) principle.</p>
<p><strong><strong>Universal App architecture</strong></strong></p>
<div id="attachment_29" class="wp-caption alignleft" style="width: 261px"><a href="http://blog.scottmontgomerie.com/wp-content/uploads/2011/01/Screen-shot-2011-01-14-at-11.55.47-PM1.png"><img class="size-full wp-image-29" title="MVC Directory Structure" src="http://blog.scottmontgomerie.com/wp-content/uploads/2011/01/Screen-shot-2011-01-14-at-11.55.47-PM1.png" alt="MVC Directory Structure" width="251" height="243" /></a><p class="wp-caption-text">MVC Directory Structure</p></div>
<p>Regardless of if you actually plan on delivering two distinct apps (normal and HD) or not, you&#8217;ll want to architect your application in such a way that you can maximize the sharing of code.  This means using Object-oriented Javascript and a true MVC (Model-View-Controller) paradigm in your code organization.</p>
<p>First we&#8217;ll start off with app organization. This seems simple, but it isn&#8217;t.</p>
<p>The first thing an Appcelerator app does when loading your app is to run &#8220;app.js&#8221;.  So our app.js looks something like this:</p>
<p><code> </code></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>code<span style="color: #339933;">&gt;</span>var window <span style="color: #339933;">=</span> Ti.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createWindow</span><span style="color: #009900;">&#40;</span>
<span style="color: #009900;">&#123;</span>
url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;views/main.js&quot;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
window.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;&lt;/</span>code<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p><code> </code></p>
<p>What this does is open up a new window, with a new execution context in the views/main.js file.  This is great, because when we include further javascript files, they will all be loaded from the 2nd-level directory (i.e. views, controllers, include, etc.).  If we had stayed within the first execution context, we wouldn&#8217;t have been able to organize our files so nicely, since everything would have to be loaded from the base directory. You can read more on execution contexts <a href="http://developer.appcelerator.com/blog/2010/08/execution-contexts.html">here</a>.</p>
<p><strong>Object-oriented Architecture</strong></p>
<p>In modern programming app design, we want to write and maintain as little code as possible, which means re-using code wherever possible.  In order to do this with Appcelerator, we need to use good inheritance and OO design principles.</p>
<p>First, we should create a base controller class. This uses a custom inheritance scheme by <a href="http://ejohn.org/blog/simple-javascript-inheritance/ejohn.org/blog/simple-javascript-inheritance/">John Resig</a> (code attached at the end of the article).</p>
<p><em>controllers/app_controller.js</em></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">Ti.<span style="color: #660066;">include</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;../include/inheritance.js&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> AppController <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">Class</span>.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
<span style="color: #006600; font-style: italic;">// application logic that is common to your application</span>
  doLayout<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Then, extend these classes for iPad and iPhone specific logic:</p>
<p><em>controllers/iphone_controller.js</em></p>
<p><em> </em></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">Ti.<span style="color: #660066;">include</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;../controllers/app_controller.js&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> iPhoneController <span style="color: #339933;">=</span> AppController.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// application logic that is specific to iPhones</span>
  doLayout<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// Layout code specific to iPads</span>
    <span style="color: #000066; font-weight: bold;">this</span>._super.<span style="color: #660066;">doLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><em>controllers/ipad_controller.js</em></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">Ti.<span style="color: #660066;">include</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;../controllers/app_controller.js&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> iPadController <span style="color: #339933;">=</span> AppController.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
<span style="color: #006600; font-style: italic;">// application logic that is specific to iPads</span>
  doLayout<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// Layout code specific to iPads</span>
    <span style="color: #000066; font-weight: bold;">this</span>._super.<span style="color: #660066;">doLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Then, in your views/main.js file:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> ipad <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">Platform</span>.<span style="color: #660066;">osname</span> <span style="color: #339933;">===</span> <span style="color: #3366CC;">&quot;ipad&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>ipad<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  Ti.<span style="color: #660066;">include</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;../controllers/ipad_controller.js&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> controller <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> iPadController<span style="color: #009900;">&#40;</span>win<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
  Ti.<span style="color: #660066;">include</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;../controllers/iphone_controller.js&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  controller <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> iPhoneController<span style="color: #009900;">&#40;</span>win<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
controller.<span style="color: #660066;">doLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #006600; font-style: italic;">// Get your hardware-specific controller to lay out your UI</span>
controller.<span style="color: #660066;">doSomething</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Voila! Lots of code-sharing and a nicely organized Object-Oriented app!</p>
<p>You may have noticed we&#8217;re not separating the controller code from the view code&#8230;  I must admit that I haven&#8217;t much figured out how to separate the controller logic from the view logic, mostly since controller code will invariably affect the iPhone&#8217;s UI widgets and there isn&#8217;t a lot of separation in this paradigm (unlike Ruby on Rails or other MVC frameworks where there is a clear delineation between views and controllers).  I&#8217;m sure this will be the discussion of a future post when I wrap my head around better organization.</p>
<br/>(Contains <a href="http://blog.scottmontgomerie.com/05/universal-apps-in-appcelerator/#attachments">1 attachments</a>.)]]></content:encoded>
			<wfw:commentRss>http://blog.scottmontgomerie.com/05/universal-apps-in-appcelerator/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>What Startup Weekend means for a Developer</title>
		<link>http://blog.scottmontgomerie.com/02/what-startup-weekend-means-for-a-developer/</link>
		<comments>http://blog.scottmontgomerie.com/02/what-startup-weekend-means-for-a-developer/#comments</comments>
		<pubDate>Thu, 10 Feb 2011 17:47:53 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[Startup]]></category>

		<guid isPermaLink="false">http://blog.scottmontgomerie.com/?p=66</guid>
		<description><![CDATA[As developers, we&#8217;re an inventive bunch. All day long, we sit around and figure out innovative ways of solving the world&#8217;s problems, one line of code at a time. So, it&#8217;s only natural that we come up with new ideas that solve bigger problems than the latest bug we&#8217;re asked to fix. But who has [...]]]></description>
			<content:encoded><![CDATA[<div class="zemanta-img" style="margin: 1em; display: block;">
<div class="wp-caption alignright" style="width: 260px"><a href="http://www.crunchbase.com/company/startup-weekend"><img title="Image representing Startup Weekend as depicted..." src="http://www.crunchbase.com/assets/images/resized/0004/2867/42867v3-max-250x250.png" alt="Image representing Startup Weekend as depicted..." width="250" height="114" /></a><p class="wp-caption-text">Image via CrunchBase</p></div>
</div>
<p>As developers, we&#8217;re an inventive bunch.</p>
<p>All day long, we sit around and figure out innovative ways of solving the world&#8217;s problems, one line of code at a time. So, it&#8217;s only natural that we come up with new ideas that solve bigger problems than the latest bug we&#8217;re asked to fix.  But who has time to really follow through on that awesome idea, or to write that really great piece of software that does it better than anything else out there?  Most of us don&#8217;t.</p>
<p>Enter the solution: roughly twice a year, a fantastic event known as <a href="http://edmonton.startupweekend.org/">Startup Weekend</a> emerges to give us the opportunity to innovate!  This event is a great chance to get that nagging idea out and to do something with it.</p>
<p>Startup Weekend brings together innovative young entrepreneurs through events held all over the world for an action-packed weekend of brainstorming, hard-core coding and bug squashing &#8211; all for the thrill to build a new product in a mere 54 hours. As developers, we are the jet fuel that propels that nebulous idea to its greatness as a final wondrous creation, and it feels great to stand up at the end of three long sleepless days and nights and show to the world that we are the kings of code. But other than showing off your coding Kung-Fu to the world, why should developers come out to startup weekend?</p>
<p><strong>Reason #1: It&#8217;s fun</strong></p>
<p>As a guy who just loves to build stuff, take it from me: Startup Weekend is fun. What self-respecting coder wouldn&#8217;t love a weekend of free food and working with really smart people to get something out the door? And if that doesn&#8217;t do it for you, then the serious party afterward will be sure to float your boat! (Although be sure not to go too crazy on Saturday or the jet fuel in your coding machine might be molasses on Sunday, when it counts the most.  I speak from experience.)</p>
<p><strong>Reason #2: Job Opportunities</strong></p>
<p>Representatives from lots of local startups and established companies will be around, and they&#8217;re always in the market for their next rock star coder.  And even if you don&#8217;t meet a guy who&#8217;s looking to hire, it&#8217;s never a bad idea to show off your mad skills to everyone in the community, since you never know when you&#8217;ll be looking for a new gig. Besides, having a great reputation as a killer coder will certainly present opportunities in the future, even if you aren&#8217;t looking for something now.</p>
<p><strong>Reason #3 : Social Network Building</strong></p>
<div class="wp-caption alignright" style="width: 310px"><img class=" " title="A Scene from Last Startup Weekend*" src="http://www.bloggersblog.com/pics/the_social_network_computer_picture.jpg" alt="Not Really." width="300" /><p class="wp-caption-text">Last Startup Weekend*</p></div>
<p>As mentioned above, knowing people <em>In The Know</em> is never a bad thing. People from varying disciplines, from the arts, to education, business, and IT, come out to Startup Weekend, so it&#8217;s a great place to make some new friends.</p>
<p><strong>Reason #4: Learn a New Language</strong></p>
<p>Who doesn&#8217;t want to learn the intricacies of Erlang while trying to build the next Facebook in 54 hours? In all seriousness, Erlang looks horrible. I was at a presentation from the Edmonton Ruby User Group a few weeks ago where they presented Erlang &#8211; it really looks horrible.</p>
<p>OK, really seriously, as a developer, we are constantly pressured to keep up with the latest trends.  If you&#8217;re a C# guy, maybe you&#8217;re partnered with a guy who knows Ruby or Java &#8211; why not give it a go and see how you like it?  Being able to add another language to your resume, on top of the ten you already know, can only help you in the future, right?</p>
<p><strong>Reason #5: Learn a New Skill set</strong></p>
<p>This one is huge.  Maybe in your current role as a programmer at a large company, or as a student, you don&#8217;t get a lot of leadership or project management opportunities. Well, now&#8217;s your chance! The great thing about Startup Weekend is that it&#8217;s all about pitching in wherever you can &#8211; so if your team is seriously lacking in leadership or another role, step up and give it a chance! Who knows &#8211; Monday, you might realize that you really hate programming and would rather manage people instead!</p>
<p>All in all, Startup Weekend is one of my favorite events in the Startup Edmonton group of events. The opportunity to get a group of smart people in a room and build something useful as fast as possible is truly amazing. Even if you don&#8217;t produce something that works, it&#8217;s a lot of fun and the benefits are numerous.</p>
<p>See you there!</p>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;">* Not Really from Last Startup Weekend.</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.scottmontgomerie.com/02/what-startup-weekend-means-for-a-developer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MVC in Appcelerator</title>
		<link>http://blog.scottmontgomerie.com/01/mvc-in-appcelerator/</link>
		<comments>http://blog.scottmontgomerie.com/01/mvc-in-appcelerator/#comments</comments>
		<pubDate>Thu, 27 Jan 2011 19:40:06 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[Appcelerator]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.scottmontgomerie.com/?p=46</guid>
		<description><![CDATA[Regardless of if you actually plan on delivering two distinct apps (normal and HD) or not, you&#8217;ll want to architect your application in such a way that you can maximize the sharing of code.  This means using Object-oriented Javascript and a true MVC (Model-View-Controller) paradigm in your code organization. First we&#8217;ll start off with app [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-47" title="Screen shot 2011-01-27 at 11.51.56 AM" src="http://blog.scottmontgomerie.com/wp-content/uploads/2011/01/Screen-shot-2011-01-27-at-11.51.56-AM.png" alt="" width="191" height="208" /></p>
<div id="_mcePaste">Regardless of if you actually plan on delivering two distinct apps (normal and HD) or not, you&#8217;ll want to architect your application in such a way that you can maximize the sharing of code.  This means using <a class="zem_slink" title="Object-oriented programming" rel="wikipedia" href="http://en.wikipedia.org/wiki/Object-oriented_programming">Object-oriented</a> Javascript and a true MVC (<a class="zem_slink" title="Model–View–Controller" rel="wikipedia" href="http://en.wikipedia.org/wiki/Model%E2%80%93View%E2%80%93Controller">Model-View-Controller</a>) paradigm in your code organization.</div>
<div>
<p>First we&#8217;ll start off with app organization. This seems simple, but it isn&#8217;t.</p>
<p>The first thing an Appcelerator app does when loading your app is to run &#8220;app.js&#8221;.  So our app.js looks something like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> window <span style="color: #339933;">=</span> Ti.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createWindow</span><span style="color: #009900;">&#40;</span>
<span style="color: #009900;">&#123;</span>
  url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;views/main.js&quot;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
window.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>What this does is open up a new window, with a new execution context in the views/main.js file.  This is great, because when we include further javascript files, they will all be loaded from the 2nd-level directory (i.e. views, controllers, include, etc.).  If we had stayed within the first execution context, we wouldn&#8217;t have been able to organize our files so nicely, since everything would have to be loaded from the base directory. You can read more on execution contexts <a href="http://developer.appcelerator.com/blog/2010/08/execution-contexts.html">here</a>.</p>
<p><strong>Object-oriented Architecture</strong></p>
<p>In modern programming app design, we want to write and maintain as little code as possible, which means re-using code wherever possible.  In order to do this with Appcelerator, we need to use good inheritance and OO design principles.</p>
<p>First, we should create a base controller and view class. This uses a custom inheritance scheme by <a href="http://ejohn.org/blog/simple-javascript-inheritance/ejohn.org/blog/simple-javascript-inheritance/">John Resig</a> .</p>
<p><span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal; font-size: 13px;"><em>common/controller.js</em></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">Ti.<span style="color: #660066;">include</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;../include/inheritance.js&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> Controller <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">Class</span>.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    init<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>win<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">win</span> <span style="color: #339933;">=</span> win<span style="color: #339933;">;</span>
        win.<span style="color: #660066;">controllerClass</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal; font-size: 13px;"> </span><br />
<span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal; font-size: 13px;"><em>common/view.js</em></span></p>
</div>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">Ti.<span style="color: #660066;">include</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;../include/inheritance.js&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> View <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">Class</span>.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    init<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>win<span style="color: #339933;">,</span> controller<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">win</span> <span style="color: #339933;">=</span> win<span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">controller</span> <span style="color: #339933;">=</span> controller<span style="color: #339933;">;</span>
&nbsp;
        win.<span style="color: #660066;">viewClass</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Now, we can create our real controllers and views:</p>
<p><em>controllers/main.js</em></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">Ti.<span style="color: #660066;">include</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;../include/inheritance.js&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Ti.<span style="color: #660066;">include</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;../include/db.js&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Ti.<span style="color: #660066;">include</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;../common/controller.js&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Ti.<span style="color: #660066;">include</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;../views/main.js&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> MainController <span style="color: #339933;">=</span> Controller.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    init<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>win<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">this</span>._super<span style="color: #009900;">&#40;</span>win<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #006600; font-style: italic;">// Create the view for this controller</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">view</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> MainView<span style="color: #009900;">&#40;</span>win<span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> win <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">currentWindow</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// Create our controller for this window.</span>
    <span style="color: #003366; font-weight: bold;">new</span> MainController<span style="color: #009900;">&#40;</span>win<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>As you can see, now we&#8217;ve got a main controller, which also instantiates a view.   Now, the view can handle all layout code, and the controller can respond to those events, and affect the view appropriately.  This works especially well when designing Universal Apps, as we can Design two views, a iPhoneMainView, and iPadMainView, and instantiate the appropriate one.</p>
<p>Now for the view code:<br />
<em>controllers/main.js</em></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">Ti.<span style="color: #660066;">include</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;../include/inheritance.js&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Ti.<span style="color: #660066;">include</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;../include/db.js&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Ti.<span style="color: #660066;">include</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;../common/view.js&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> MainView <span style="color: #339933;">=</span> View.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    init<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>win<span style="color: #339933;">,</span> controller<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">this</span>._super<span style="color: #009900;">&#40;</span>win<span style="color: #339933;">,</span> controller<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">layout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
    layout<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
       <span style="color: #006600; font-style: italic;">// Your layout code.  Ti.UI.createLabel({}), etc.;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>I&#8217;ve created a Github project called <a href="https://github.com/smontgomerie/Appcelerator-on-Rails">Appcelerator-On-Rails</a> to show this code.  I use this template in all my Appcelerator projects and add to it when necessary.</p>
<p>Happy iPhone coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.scottmontgomerie.com/01/mvc-in-appcelerator/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Rails CMS plugins</title>
		<link>http://blog.scottmontgomerie.com/01/rails-cms-plugins/</link>
		<comments>http://blog.scottmontgomerie.com/01/rails-cms-plugins/#comments</comments>
		<pubDate>Wed, 12 Jan 2011 23:07:52 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Content management system]]></category>
		<category><![CDATA[Radiant (software)]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://blog.scottmontgomerie.com/?p=5</guid>
		<description><![CDATA[I&#8217;m currently working on a project that requires a built-in CMS solution to enable quick SEO and content modification by site administrators.  This is not an uncommon problem &#8211; pretty much every website requires content management, and it amazes me that Rails doesn&#8217;t come with something pre-built (OK, there are those that argue that Rails [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m currently working on a project that requires a built-in CMS solution to enable quick SEO and content modification by site administrators.  This is not an uncommon problem &#8211; pretty much every website requires content management, and it amazes me that Rails doesn&#8217;t come with something pre-built (OK, there are those that argue that <a href="http://rubyredbricks.com/2009/2/24/rails-as-cms">Rails is a CMS</a>, but there sure seems to be a lot of work involved in getting it there).  On the other hand, I can see why Rails doesn&#8217;t include a CMS, as it&#8217;s meant as a web framework, not a website<em> </em>framework<em>. </em></p>
<p>There are several great CMS systems for Rails out there (check out <a href="http://www.ajaxlines.com/ajax/stuff/article/top_ruby_cms.php">this overview</a>) &#8211; but <a href="http://comatose.rubyforge.org/">Comatose</a>, <a href="http://radiantcms.org/">Radiant</a> and <a href="http://refinerycms.com/">Refinery</a> are the front-runners.  Your options for integrating a CMS system into Rails pretty much fall into 3 categories <a href="http://aaronlongwell.com/2009/06/the-ruby-on-rails-cms-dilemma.html">[1]</a>:</p>
<ol>
<li>Two side-by-side applications. &#8211; Pair an off-the-shelf CMS with a custom built application. Copy/paste the visual elements, and loosely wire the two together with a subdomain or some kind of web proxy to share the URL structure</li>
<li>Extend the CMS &#8211; Build a proprietary plugin or extension for the CMS to implement the application features.</li>
<li>Soup-to-nuts custom application. Build a complete CMS as part of the project.</li>
<li>Use a Rails plugin CMS.</li>
</ol>
<p>For an in depth look at the problem posed by existing Rails CMS solutions, check out <a href="http://aaronlongwell.com/2009/06/the-ruby-on-rails-cms-dilemma.html">this article</a> (and thanks Aaron for the quote above).  The first option is not a great solution, as there is a lot of re-work and duplication, not to mention the potential for screw-ups (oops! who forgot to update the price list??).  #2 is a terrible idea because you&#8217;re stuck to the CMS you begin with, and #3 is plain wasteful.  #4 is definitely the best option, as it&#8217;s completely modular and does not interfere with your code business logic.</p>
<p>Comatose and Refinery both fall into the 4th and best option &#8211; Rails plugins. After looking at Comatose, it seemed that it was a bit simplistic for my needs (and it hasn&#8217;t been updated since 2008).  Refinery was much better, but still lacking in some areas.  My issue with Refinery is that you still have to hand-code a theme for the site, which makes it very difficult to separate the design from the implementation (especially if you want a web designer to make any of the changes for you).  And adding any new features or layouts requires intervention on the side of the programmer, not the designer. But the plugin-based system definitely offered some advantages, namely that I could code my regular Rails controllers and views as I normally would.</p>
<p>And that left <a href="http://radiantcms.org/">Radiant</a>, the 800-pound gorilla in the Rails CMS world.  Radiant is definitely the most mature Rails CMS out there, and its lengthy feature-set shows: its layout mechanism is beautiful to use via radiant XML tags, and its extensions mechanism makes it easy to add custom functionality. To this end, it&#8217;s possible for a non-technical person to completely change the look of a site without touching a line of code.</p>
<p>However, it suffers from problem #2 outlined above &#8211; you have to extend Radiant, Radiant does not extend Rails.  This basically means that you need to code a custom extension to implement any of your business logic, which to me is highly unacceptable.</p>
<p>In the end, I chose to have my cake and eat it too &#8211; I hacked Radiant to make it behave like a plugin.  My recommendation for a Rails CMS?  If you&#8217;re in the market for a simple CMS with not a lot of custom application functionality, then Refinery is your best bet.</p>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Enhanced by Zemanta" href="http://www.zemanta.com/"><img class="zemanta-pixie-img" style="border: none; float: right;" src="http://img.zemanta.com/zemified_e.png?x-id=419010e2-256c-4964-a1f9-9eb8f2f4d643" alt="Enhanced by Zemanta" /></a><span class="zem-script more-related pretty-attribution"><script src="http://static.zemanta.com/readside/loader.js" type="text/javascript"></script></span></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.scottmontgomerie.com/01/rails-cms-plugins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hello world!</title>
		<link>http://blog.scottmontgomerie.com/06/hello-world/</link>
		<comments>http://blog.scottmontgomerie.com/06/hello-world/#comments</comments>
		<pubDate>Wed, 23 Jun 2010 19:19:17 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.scottmontgomerie.com/?p=1</guid>
		<description><![CDATA[Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!]]></description>
			<content:encoded><![CDATA[<p>Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.scottmontgomerie.com/06/hello-world/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

