<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[Newtriks LTD]]></title>
  <link href="http://newtriks.com/atom.xml" rel="self"/>
  <link href="http://newtriks.com/"/>
  <updated>2012-02-21T09:34:56+00:00</updated>
  <id>http://newtriks.com/</id>
  <author>
    <name><![CDATA[Simon Bailey]]></name>
    <email><![CDATA[simon@newtriks.com]]></email>
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[Everyday I'm Shufflin]]></title>
    <link href="http://newtriks.com/2012/01/25/everyday-im-shufflin/"/>
    <updated>2012-01-25T20:36:00+00:00</updated>
    <id>http://newtriks.com/2012/01/25/everyday-im-shufflin</id>
    <content type="html"><![CDATA[<center><img class="aligncenter" src="http://thesethings.blogg.se/images/2011/lmfao-party-rock-anthem_154303165.jpg" alt="" /></center>


<p>A while ago now I ported my site from WordPress to the awesome <a href="http://octopress.org/" title="Octopress">Octopress</a>. I have also been shufflin&#8217; assets and moving demo&#8217;s and code over to a <a href="https://github.com/newtriks/newtriks-blog-code-examples" title="Examples">repos</a> on my <a href="https://github.com/newtriks/" title="github">github</a> account. So please
 feel free to either leave a comment or ping me pointing out anything that may have gone astray?</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Message Exchanging Using AS3-Signals]]></title>
    <link href="http://newtriks.com/2012/01/25/message-exchanging-using-as3-signals/"/>
    <updated>2012-01-25T20:35:00+00:00</updated>
    <id>http://newtriks.com/2012/01/25/message-exchanging-using-as3-signals</id>
    <content type="html"><![CDATA[<blockquote><p>Decide what you want, decide what you are willing to exchange for it.
Establish your priorities and go to work.</p>

<p><em>H. L. Hunt</em></p></blockquote>

<p>One question I see quite a lot when it comes to architecting an application using <a href="http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller" title="MVC">MVC</a> is how to get data into the view from the model and keeping that data current. The simplest and
quickest routes to achieve this is to create a reference to the model within a view mediator and either bind or directly get the data. This is an approach I indeed <a href="http://newtriks.com/2010/03/01/databinding-a-proxy-to-a-mediator/" title="Databinding a Proxy to a Mediator">blogged</a> about but is a
technique I quickly moved away from. Here is how I now manage this.</p>

<!--more-->


<p>I am a staunch advocate of <a href="https://github.com/robertpenner/as3-signals" title="AS3-Signals">AS3-Signals</a> and use them extensively in all my applications nowadays. Whilst contemplating how to best manage data within an modular application that was rapidly
growing it was <a href="http://www.xxcoder.net/" title="Stray">Stray</a> as usual, who pointed me to a technique that I use consistently now due to its simplicity, cleanliness and strong typing the response Signal and payload.</p>

<p>A suggested simple example could be a view mediator has been registered <strong>after</strong> a user logs in and the view wants to display the name of the currently logged in user which is stored in the model
. Using AS3-Signals a <a href="http://en.wikipedia.org/wiki/Request-response" title="Request-response">request-response</a> approach can be used where the mediator can dispatch a request Signal for the username within the onRegister() method (if using <a href="http://www.robotlegs.org/" title="robotlegs">robotlegs</a>),
then a command can retrieve the data from the model and dispatch a Signal response with the username.</p>

<h4>Example in a Robotlegs application scenario:</h4>

<p>The first key factor to this logic is the requesting Signal needs to create and pass as a payload the response Signal. This can simply be a plain ol&#8217; Signal or a custom Signal you have created.</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>public function RequestSignal()
</span><span class='line'>{
</span><span class='line'>    super(ResponseSignal);
</span><span class='line'>}
</span><span class='line'>
</span><span class='line'>public function createResponse():ResponseSignal
</span><span class='line'>{
</span><span class='line'>    return new ResponseSignal(String);
</span><span class='line'>}</span></code></pre></td></tr></table></div></figure>


<p>As you can see the ResponseSignal is expecting to pass a String value as its payload.</p>

<p>The Mediator would dispatch the injected instance of the RequestSignal with the response Signal as the payload. A handler method will need to be setup for the response.</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>public function submitRequest():void
</span><span class='line'>{
</span><span class='line'>    var response:ResponseSignal=requestSignal.createResponse();
</span><span class='line'>    response.addOnce(onResponse);
</span><span class='line'>    requestSignal.dispatch(response);
</span><span class='line'>}
</span><span class='line'>
</span><span class='line'>public function onResponse(username:String):void
</span><span class='line'>{
</span><span class='line'>    view.username=username;
</span><span class='line'>}</span></code></pre></td></tr></table></div></figure>


<p>And finally a command would be mapped to the RequestSignal to manage the retrieving of the model data and dispatching of the response Signal.</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>[Inject]
</span><span class='line'>public var responseSignal:ResponseSignal;
</span><span class='line'>
</span><span class='line'>override public function execute():void
</span><span class='line'>{
</span><span class='line'>    responseSignal.dispatch(model.username);
</span><span class='line'>}</span></code></pre></td></tr></table></div></figure>


<p>Full example application code can be found <a href="https://github.com/newtriks/newtriks-blog-code-examples/tree/master/exchange-using-as3signals" title="Example Code">here on github</a></p>

<p>I have found this to be a really nice standardised approach to exchanging messages throughout my applications, thanks once again to <a href="https://twitter.com/stray_and_ruby" title="Stray">Stray</a> and <a href="https://twitter.com/robpenner" title="Rob Penner">Rob Penner</a>.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Automating Deployment Using Git]]></title>
    <link href="http://newtriks.com/2011/12/01/automated-deployment-using-git/"/>
    <updated>2011-12-01T20:00:00+00:00</updated>
    <id>http://newtriks.com/2011/12/01/automated-deployment-using-git</id>
    <content type="html"><![CDATA[<blockquote><p>How many developers out there are still manually deploying project files to their remote server?</p></blockquote>

<p>In my experience, automated deployment is typically declared as a <em>nice to have</em> but not usually a task where time actually gets set aside to complete. This post is focusing on what I would term as the simplest essence of automated deployment. The sequence of steps:</p>

<ol>
<li><strong>Compile</strong> e.g. generating project files using rake or compiling a swf.</li>
<li><strong>Commit</strong> i.e. pushing to a git repository.</li>
<li><strong>Transfer</strong> e.g. copying local files to a remote server.</li>
</ol>


<p><strong>Heads Up</strong></p>

<p>This is not covering the full CI setup, versioning, etc, this is simply a small (time saving) step for those developers who are still pushing projects manually. Further fun stuff like CI and automated builds comes in another post ;)</p>

<!--more-->


<p>On the surface (for a simple project), all we are doing using the automated logic within this blog post is avoiding the transfer of local files to a remote server. However, for a project which starts to get slightly more complex for example deploying to different server directories e.g development, staging and production this approach starts to really shine. And in my experience it is the FTP&#8217;ing of files that I found swiftly became the mundane pain in the proverbial!</p>

<p>The project could be of any type you choose, whether a rails project, wordpress blog or flash app it&#8217;s all good. What you do need is the project in version control and this blog post focuses on <a href="http://en.wikipedia.org/wiki/Git_(software)" title="GIT">using git</a>.</p>

<h4>Here&#8217;s what we are going to cover</h4>

<ul>
<li>Setup the (remote) server-side web directories.</li>
<li>Create a remote git repository (our hub) for the project.</li>
<li>Write a post-update git hook to deploy our project files to defined serverside directories.</li>
<li>Setup our initial local project setup.</li>
<li>Add our local project to git.</li>
<li>Test deployment to dev.</li>
<li>Test deployment to production.</li>
</ul>


<p>The scenario involves having two branches in your git repository, a <em>master</em> and a <em>develop</em> branch. Similary on your remote server you would have two directories under your wwwroot, I have called mine <em>example</em> (mapped to the domain <em>example.com</em>) and <em>example_dev</em> (mapped to the domain <em>dev.example.com</em>). Also on the server I have installed <a href="http://en.wikipedia.org/wiki/Git_(software)" title="GIT">git</a> and setup a user account named <em>git</em>. Here I presume you have ssh access to your remote server i.e. using your git account i.e. ssh git@mydomain.com.</p>

<h3>Remote server web configuration</h3>

<p>Navigate to your webroot directory and create two new directories as detailed above. Create your publically accessible directories under each site and ensure they have appropriate <a href="http://en.wikipedia.org/wiki/Chmod" title="Chmod">permissions</a> (I simply open up access of these example public folders, you can restrict as you see fit):</p>

<pre><code>cd /srv/www/
mkdir -p example/public_html
mkdir -p example_dev/public_html
chgrp -R users example
chgrp -R users example_dev
chmod 777 example/public_html
chmod 777 example_dev/public_html
</code></pre>

<h3>Remote server git configuration</h3>

<p>Login to your server under your git user account (or once on your server sudo su - git) and enter the following (replacing example with the project name of your choice) to create our project hub repository:</p>

<pre><code>mkdir example.git &amp;&amp; cd example.git
git init --bare
</code></pre>

<h3>Configure git hooks</h3>

<p>Still under the git user account:</p>

<pre><code>vim hooks/post-update
</code></pre>

<p> Within this post-update file enter the following ensuring you change the root files to your defined directory names:</p>

<pre><code>#!/bin/sh

echo $1
echo "*UPDATE*"


case " $1 " in
*'refs/heads/develop'*)
        GIT_WORK_TREE=/srv/www/example_dev git checkout develop public_html
        echo
        echo "Dev was pulled"
        echo
        ;;
esac

case " $1 " in
*'refs/heads/master'*)
        GIT_WORK_TREE=/srv/www/example git checkout master public_html
        echo
        echo "Master was pulled"
        echo
        ;;
esac
</code></pre>

<p>When there is a push from our local repository to the remote hub repository, this logic will determine which branch we pushed to i.e. <em>develop</em> or <em>master</em> and checkout the files from the public_html directory into the appropriate web root. There is a little visual feedback in the console to highlight what branch has been checked out.</p>

<p>Lastly we must ensure this post-update file is executable:</p>

<pre><code>chmod +x hooks/post-update
</code></pre>

<h3>Local project configuration</h3>

<p>Create a new project directory and navigate on in:</p>

<pre><code>mkdir newtriks.com &amp;&amp; cd newtriks.com
</code></pre>

<h3>Local project git configuration</h3>

<p>Initialise a new git repository and commit a newly created test file. Finally add your remote hub url as the local respository <a href="http://gitref.org/remotes/" title="Git remote">remote alias</a> and push to the master branch.</p>

<pre><code>git init
echo 'Hello master!' &gt; index.html
git add index.html
git commit -q -m'Initial pimp hit'
git remote add web git@[your ip]:example.git
git push web +master:refs/heads/master
</code></pre>

<h3>Testing deployment to production</h3>

<p>If you navigate in your browser to the production domain i.e. example.com, you should see <strong>Hello master!</strong></p>

<h3>Local develop branch configuration</h3>

<p>Create and checkout a new branch within your project named <em>develop</em>. Update the index.html file and commit then push to the hubs develop branch.</p>

<pre><code>git checkout -b develop
echo 'Hello, develop!' &gt; index.html
git add index.html
git commit -m'Test dev pimp hit'
git push web develop
</code></pre>

<h3>Testing deployment to development</h3>

<p>If you navigate in your browser to the development domain i.e. dev.example.com, you should see <strong>Hello develop!</strong>!</p>

<p>Hopefully all works for you and your now comfortable with this initial start in automated deployment using git.</p>

<h3>Resources</h3>

<p>Thanks to these links and their authors for getting me started with this approach:</p>

<ul>
<li><a href="http://joemaller.com/990/a-web-focused-git-workflow/#comment-259589452" title="Git workflow">A web-focused Git workflow | Joe Maller</a></li>
<li><a href="http://danielmiessler.com/study/git/" title="Git primer">A Git Primer | danielmiessler.com</a></li>
<li><a href="http://toroid.org/ams/git-website-howto" title="Git website - how to">A Git Website | http://toroid.org</a></li>
</ul>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Looking for Sponsors - DIFC London to Brighton Cycle 2011]]></title>
    <link href="http://newtriks.com/2011/08/16/looking-for-sponsors-difc-london-to-brighton-cycle-2011/"/>
    <updated>2011-08-16T15:20:29+01:00</updated>
    <id>http://newtriks.com/2011/08/16/looking-for-sponsors-difc-london-to-brighton-cycle-2011</id>
    <content type="html"><![CDATA[<p>My wife and I have entered the <a href="http://www.doitforcharity.com/difc-london-to-brighton-cycle-2011.aspx" target="_blank">DIFC London to Brighton Cycle 2011</a> (54 miles) for the <a href="http://www.justgiving.com/hopscotchkidneyfund" target="_blank">HopScotch Kidney Fund</a>:</p>

<blockquote><p>Hopscotch Kidney Fund for Children is a charity dedicated to helping children with kidney disease. It helps by offering fun and exciting events and activities for children. It also offers financial grants to parents for specific items needed at home to help their child and grants for parents in times of medical emergencies.</p></blockquote>

<center><img class="aligncenter" src="http://3.bp.blogspot.com/-kjONsNXmYng/Te-TrkJDx-I/AAAAAAAABNw/rw2qtcaBdT8/s1600/crash_p1.jpg" alt="" /></center>


<p>Please help raise money for this charity by making a donation via our <a href="http://t.co/wA4cbdZ" target="_blank">Just Giving Page</a>.  Thank you.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[An Introduction To Gator-AS3-RobotLegs]]></title>
    <link href="http://newtriks.com/2011/08/16/an-introduction-to-gator-as3-robotlegs/"/>
    <updated>2011-08-16T13:03:07+01:00</updated>
    <id>http://newtriks.com/2011/08/16/an-introduction-to-gator-as3-robotlegs</id>
    <content type="html"><![CDATA[<p><strong>NOTE</strong>
There have been some pretty cool advancements made to Gator recently, however this has meant that gems and code bases are out of sync. I will update things here once we have resolved dependency issues.</p>

<p>I am a huge fan of <a href="http://en.wikipedia.org/wiki/Automatic_programming" target="_blank">generators</a> as they for me, are a massive time saving tool in my day to day development. I have heard the arguments against them but personally, they speed up my work flow significantly for the repetitive tasks such as file/package creation and the initial injection of basic class code. As an added bonus my Unit Test classes also get generated and in some instances they are specific to the actual class type, it&#8217;s a no brainer for me to use these type of tools.</p>

<h3>A little history</h3>

<p>Up until now I have used <a href="http://www.projectsprouts.org" target="_blank">Project Sprouts</a> for both my project builds and generators and I still think its an amazing resource. However, there were a few minor issues and complexities (as a Ruby noob) I encountered on the generators which got myself and <a href="http://www.devboy.org/" target="_blank">Dominic</a> chatting on IM about potential solutions. Dominic <a href="http://groups.google.com/group/projectsprouts/browse_thread/thread/7496965251314bd4?hl=en" target="_blank">highlighted</a> an initial hurdle which resulted in Luke Bayes kindly taking time out to explain generators thus giving us an insight into the inner workings of Project Sprouts. The main problem with diving in and changing Project Sprouts was due to it being ultimately extremely powerful, but complex under the hood for someone like myself, simply put we just needed some classes generated.</p>

<!--more-->


<p>Dominic found that <a href="http://rubyonrails.org/" target="_blank">Ruby on Rails</a> also had generators and used a tool called <a href="https://github.com/wycats/thor" target="_blank">Thor</a> to facilitate this. Within a ridiculously short period of time Dominic had created a basic working model which he named <a href="https://github.com/devboy/gator" target="_blank">Gator</a>. This swiftly got <a href="https://groups.google.com/group/gator-generator/browse_thread/thread/b42340a5f48dd5a5?hl=en" target="_blank">segregated</a> into a further library specifically for AS3 and MXML named <a href="https://github.com/devboy/gator-as3" target="_blank">gator-as3</a>.</p>

<h3>Gator-as3</h3>

<p>The main use case scenario for generators in my development is when using the <a href="http://robotlegs" target="_blank">Robotlegs</a> framework e.g. generating a view with it&#8217;s corresponding mediator plus unit tests. Another scenario is creating the typical directory structure of a project I use regularly, this became one of the first nuts Dominic cracked.</p>

<p><strong>Project Templates</strong></p>

<p><em>Please remember that gator and gator-as3 is all work in progress</em></p>

<p>Currently you can install something named a project template (naming conventions may change - I like project skeleton or Gator Bone). This basically is a directory structure which you instruct gator to install and then on creating a new project can be included and generated. Lets see this in action:</p>

<p><em>This article presumes you have Ruby installed on your dev environment, I use Ruby 1.9.2-p180.</em></p>

<p>1) Create a directory named RobotLegsTemplate and create the following directory structure including a simple README.md (this file can be omitted if you so choose):</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>RobotLegsTemplate/
</span><span class='line'>  src/
</span><span class='line'>      com/
</span><span class='line'>          newtriks/
</span><span class='line'>              controller/
</span><span class='line'>              models/
</span><span class='line'>              README.md
</span><span class='line'>              views/</span></code></pre></td></tr></table></div></figure>


<p>2) On command line install gator-as3 (this will also install gator):</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>gem install gator-as3 --pre</span></code></pre></td></tr></table></div></figure>


<p>3) Install the template changing your path to the template accordingly:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>gator project install /Users/newtriks/Development/dev/gator/RobotLegsTemplate</span></code></pre></td></tr></table></div></figure>


<p>This will store your template in ~/.gator/templates/projects/.</p>

<p>4) Now create a new project based on this new template:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>gator project new gator_example RobotLegsTemplate</span></code></pre></td></tr></table></div></figure>


<p>Bam, you should now have a brand new project with the templates directory structure!</p>

<p><strong>RobotLegs Generators</strong></p>

<p>So the next step for me was to start porting across some of the generators I use in my daily development i.e. RobotLegs generators.  I have created <a href="https://github.com/newtriks/gator-as3-robotlegs" target="_blank">gator-as3-robotlegs on Github</a> and so far covered the absolute basics needed for using RobotLegs within your project, this is all work in progress :)</p>

<p>1) Create a new directory named robotlegs_gator.</p>

<p>2) Gator projects need a configuration file where you (a) require the libraries i.e. gator-as3-robotlegs so they can be used within your project (b) define various project settings i.e. directory structure for Gator. So create the configuration file which has to be named <strong>gator.rb</strong> within your project root and add the following contents replacing your name and values as you see fit:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>require &quot;gator/as3/generators&quot; 
</span><span class='line'>require &quot;gator/as3/generators/test/asunit4&quot;
</span><span class='line'>require &quot;gator/as3/robotlegs/generators&quot;
</span><span class='line'>require &quot;gator/as3/robotlegs/generators/test/asunit4&quot;
</span><span class='line'>
</span><span class='line'>project Gator::Project::ProjectBase.new
</span><span class='line'>project.name = &quot;MyProject&quot;
</span><span class='line'>project.options[:authors] = [&quot;newtriks&quot;]
</span><span class='line'>project.layout[:source,:main,:as3] = &quot;src&quot;
</span><span class='line'>project.layout[:source,:test,:as3] = &quot;test&quot;</span></code></pre></td></tr></table></div></figure>


<p>This will tell Gator to use a directory structure as follows: <strong>[project root]/src</strong> &amp; <strong>[project root]/test</strong>.</p>

<p>3) Install my gator-a3-robotlegs ruby gem:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>gem install gator-as3-robotlegs --pre</span></code></pre></td></tr></table></div></figure>


<p>4) Navigate into your project on command line and type the following to generate a view component (AS3) and mediator:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>gator generate as3 robotlegs view_with_mediator com.newtriks.controller.CustomView --test</span></code></pre></td></tr></table></div></figure>


<p>This should generate the following:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>gator_example/
</span><span class='line'>  gator.rb
</span><span class='line'>  src/
</span><span class='line'>      com/
</span><span class='line'>          newtriks/
</span><span class='line'>              controller/
</span><span class='line'>                  components/
</span><span class='line'>                      CustomView.as
</span><span class='line'>                  mediators/
</span><span class='line'>                      CustomViewMediator.as
</span><span class='line'>  test/
</span><span class='line'>      AllTests.as
</span><span class='line'>      com/
</span><span class='line'>          newtriks/
</span><span class='line'>              controller/
</span><span class='line'>                  components/
</span><span class='line'>                      CustomViewTest.as
</span><span class='line'>                  mediators/
</span><span class='line'>                      CustomViewMediatorTest.as</span></code></pre></td></tr></table></div></figure>


<p>Nice huh?!</p>

<p>Currently I append certain names to particular templates generated i.e. Mediator, Service, Command so the following:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>gator generate as3 robotlegs view_with_mediator com.newtriks.controller.CustomView --test</span></code></pre></td></tr></table></div></figure>


<p>Appends the &#8216;Mediator&#8217; string to the classname within the actual generator, this will be customisable in the future and with the ease generators and templates can be created you can custom make your own to your hearts content. Another point to add for the view/mediator generation is the views will be placed into a components directory and the mediator into mediators directory. This was something I pushed out on twitter recently and found that the general consensus leaned towards this architecture, but as above, this can easily be modified.</p>

<p>The <strong>&#8211;test</strong> parameter passed tells the generator to create the corresponding test, omit this to just create the class without a test.</p>

<p><strong>More commands available for RobotLegs</strong></p>

<p>Generate a RobotLegs Command Class:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>gator generate as3 robotlegs command com.newtriks.controller.Startup --test</span></code></pre></td></tr></table></div></figure>


<p>Generate a View Class:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>gator generate as3 robotlegs view com.newtriks.views.CustomView --test</span></code></pre></td></tr></table></div></figure>


<p>Generate a RobotLegs Mediator Class:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>gator generate as3 robotlegs mediator com.newtriks.views.CustomMediator --test</span></code></pre></td></tr></table></div></figure>


<p>Generate a RobotLegs Model (extends Actor) Class:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>gator generate as3 robotlegs model com.newtriks.models.Login --test</span></code></pre></td></tr></table></div></figure>


<p>Generate a RobotLegs Service (extends Actor) Class:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>gator generate as3 robotlegs service com.newtriks.services.Remote --test</span></code></pre></td></tr></table></div></figure>


<p>Command to generate a standard AS3 class:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>gator generate as3 klass com.newtriks.Custom --test</span></code></pre></td></tr></table></div></figure>


<p><strong>TDD</strong></p>

<p>As mentioned above passing in the value &#8211;test auto creates the corresponding Unit Test for the generated class. I use ASUnit4 for my testing and therefore have created a library of generators and templates as seen <a href="https://github.com/newtriks/gator-as3-robotlegs/tree/master/lib/gator/as3/robotlegs/generators/test/asunit4" target="_blank">here</a>. However, if you look on the <a href="https://github.com/devboy/gator-as3/tree/master/lib/gator/as3/generators/test" target="_blank">gator-as3 repos</a> you will see a FlexUnit set of generators and templates (in development).  Simply changing the require in your gator.rb from:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>require &quot;gator/as3/generators/test/asunit4&quot;</span></code></pre></td></tr></table></div></figure>


<p>to:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>require &quot;gator/as3/generators/test/flexunit4&quot;</span></code></pre></td></tr></table></div></figure>


<p>Will instruct Gator to generate tests using FlexUnit4 instead of ASUnit4! How cool is that?!  You can add whatever testing framework you want and structure your templates how you see fit&#8230;</p>

<p>I hope you will get some benefit from using Gator and have fun getting stuck in and having a play, any issues, requests or general feedback for anything Gator related then please go via the <a href="https://groups.google.com/group/gator-generator?hl=en" target="_blank">Gator Google group</a>.</p>

<h3>Further reading</h3>

<ul>
<li><a href="https://groups.google.com/group/gator-generator?hl=en" target="_blank>Gator Google group</a></li>
<li><a href="https://github.com/devboy/gator-as3" target="_blank">gator-as3 on Github</a></li>
<li><a href="https://rubygems.org/gems/gator-as3" target="_blank">gator-as3 on RubyGems.org</a></li>
<li><a href="https://github.com/newtriks/gator-as3-robotlegs" target="_blank">gator-as3-robotlegs on Github</a></li>
<li><a href="https://rubygems.org/gems/gator-as3-robotlegs" target="_blank">gator-as3-robotlegs on RubyGems.org</a></li>
</ul>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Example AS3 Modular Application Using RobotLegs & Signals]]></title>
    <link href="http://newtriks.com/2011/08/12/example-as3-modular-application-using-robotlegs-signals/"/>
    <updated>2011-08-12T12:52:50+01:00</updated>
    <id>http://newtriks.com/2011/08/12/example-as3-modular-application-using-robotlegs-signals</id>
    <content type="html"><![CDATA[<p>How many of you Flex and ActionScript developers are architecting your applications in a <a href="http://www.webopedia.com/TERM/M/modular_architecture.html" target="_blank">modular</a> fashion? By modules I mean compartmentalising specific application logic and not necessarily using Spark (or MX) <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/spark/modules/Module.html" target="_blank">modules</a>. If I answer my own question I would say sporadically up until recently but now I approach project architecture in a modular based format with <a href="http://opensource.adobe.com/wiki/display/cairngorm/Creating+Functional+Areas" target="_blank">multi functional areas</a> (thanks once again to <a href="http://twitter.com/#!/stray_and_ruby" target="_blank">@Stray_and_ruby</a> for the heads up on this link).</p>

<!--more-->


<p>If you clicked on the link above you will see a definition of modular as:</p>

<blockquote><p>[Modular Architecture] Refers to the design of any system composed of separate components that can be connected together. The beauty of modular architecture is that you can replace or add any one component (module) without affecting the rest of the system. The opposite of a modular architecture is an integrated architecture, in which no clear divisions exist between components.</p></blockquote>

<p>In reality when approaching your project it can be difficult to decide which logic should be separated out as a module, but I have found that the more you embark on the modular route the easier this decision becomes, there is no hard and fast rule to follow. I will not go into specific benefits in using a modular approach in Flex/ActionScript development as there are plenty of articles on the internet, if you would like an introduction into Flex modules and RobotLegs then read <a href="http://joelhooks.com/2010/05/02/modular-robotlegs/" target="_blank">Joel&#8217;s informative post</a>.</p>

<p>The example I built is on GitHub as a repository named <a href="https://github.com/newtriks/AS3ModularRobotLegsExample" target="_blank">AS3ModularRobotLegsExample</a> and has a <a href="https://github.com/newtriks/AS3ModularRobotLegsExample/blob/master/README.mdown" target="_blank">README</a> detailing all the necessary information to get you up and running, including all the links to the required libraries etc.</p>

<p>I have used both Modular utilities on RobotLegs applications and both have their merits, however, I primarily started using the utilities in Flex applications with the latest versions of RobotLegs and As3 Signals so settled on Joel&#8217;s fork. After using that particular fork in Flex applications with no issues, I was concerned that there would be potential obstacles using it in a pure AS3 project as it appeared from the example geared towards Flex Modules. It works absolutely fine though but there are slight changes in the example Joel provides hence my creating the <a href="https://github.com/newtriks/AS3ModularRobotLegsExample" target="_blank">AS3ModularRobotLegsExample</a>.</p>

<p>After reading around the links I provided above I think the main areas to familiarise yourself within the example would be the module loading logic therefore I recommend looking at the unit tests:</p>

<ul>
<li><a href="https://github.com/newtriks/AS3ModularRobotLegsExample/blob/master/test/com/newtriks/restricted/shell/restricted/controller/LoadModulesCommandTest.as" target="_blank">LoadModulesCommandTest class</a></li>
<li><a href="https://github.com/newtriks/AS3ModularRobotLegsExample/blob/master/test/com/newtriks/restricted/shell/restricted/controller/UnloadModulesCommandTest.as" target="_blank">UnloadModulesCommandTest class</a></li>
<li><a href="https://github.com/newtriks/AS3ModularRobotLegsExample/blob/master/test/com/newtriks/restricted/shell/restricted/models/ModuleStoreTest.as" target="_blank">ModuleStoreTest class</a></li>
<li><a href="https://github.com/newtriks/AS3ModularRobotLegsExample/blob/master/test/com/newtriks/restricted/shell/restricted/models/ModuleDictionaryTest.as" target="_blank">ModuleDictionaryTest class</a></li>
</ul>


<p>As I stated in the <a href="https://github.com/newtriks/AS3ModularRobotLegsExample/blob/master/README.mdown" target="_blank">README</a> my chosen approach to module loading is one of many and mine is not necessarily the optimal method.</p>

<p>I am now working on a Flex 4.5 example and how to use <a href="https://github.com/devboy/gator-as3" target="_blank">Gator</a> to generate the project as whole to save having to build this core logic manually plus the classes and corresponding Unit Tests.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Configuring a CI server with GIT on Ubuntu (Amazon EC2)]]></title>
    <link href="http://newtriks.com/2011/07/19/configuring-a-ci-server-with-git-on-ubuntu-amazon-ec2/"/>
    <updated>2011-07-19T13:30:35+01:00</updated>
    <id>http://newtriks.com/2011/07/19/configuring-a-ci-server-with-git-on-ubuntu-amazon-ec2</id>
    <content type="html"><![CDATA[<p>I would say that the majority of Flash Platform developers have now used source control.</p>

<blockquote><p>As a developer are you testing locally, committing to source control and finally manually deploying your SWF&#8217;s to staging and production environments?</p>

<p>Do you work on applications as part of a team?</p>

<p>Do you use Continuous Integration (CI) and automated builds?</p></blockquote>

<p>My answer was yes to all of the above except unfortunately the CI process.  As you may well know from my blog and on <a href="http://twitter.com/#!/newtriks" target="_blank">twitter</a> I have a keen interest with <a href="http://www.newtriks.com/?p=1281" target="_blank">Project Sprouts</a> and recently have also looked at <a href="http://buildr.apache.org/" target="_blank">Buildr</a>, particulary <a href="http://www.devboy.org/" target="_blank">Dominic Graefen&#8217;s</a> AS3 port: <a href="https://github.com/devboy/buildr_as3" target="_blank"> Buildr-as3</a>.</p>

<p>Together with <a href="http://twitter.com/#!/devboy_org" target="_blank">Dominic </a>(share my pain) Graefen (thnx man), I have been determined to setup a CI server using <a href="http://jenkins-ci.org/" target="_blank">Jenkins</a> on an Amazon EC2 instance which compiles SWFs and runs FlexUnit tests, for example on commit to git.</p>

<p>This was not a straight forward task&#8230;in fact it was a <em>Grade A pain in the ar$e</em> but eventually (it would appear) I managed to refine the process down to achieve the goal.  Below are the steps that I have taken to set up an <a href="http://aws.amazon.com/ec2/" target="_blank">EC2 micro-instance</a> with Git, Jenkins, RVM, Ruby, VNC, standalone debugger Flash Player, Buildr-as3 and compile/run FlexUnit tests using a Flex 4 based example!  I have setup and torn down at least 6 instances to test and remove surplus instructions so hopefully it&#8217;s as lean as possible.</p>

<p>I am sure there could be further refinements made and on one of my test server setups I found I had some odd output which I need to work out why and where?</p>

<p>*(gflashplayer:1490): GLib-GObject-WARNING **: instance of invalid non-instantiatable type `(null)&#8217;</p>

<p>(gflashplayer:1490): GLib-GObject-CRITICAL <em>*: g_signal_handlers_disconnect_matched: assertion `G_TYPE_CHECK_INSTANCE (instance)&#8217; failed</em></p>

<p>But the tests run and all is happy.  Micro-instances and rvm/project builds are not fast and I found have a tendency to hang on the first run/install so <strong>perseverance</strong> is required, but once running, all seems sweet with the world.  Any further tips or guidance would be most welcomed!  Oh and if you want to see an example of using CI for your Flex/Flash project just take a peek at <a href="http://reflex.io/hudson/job/reflex/" target="blank">this super sweet example</a>.</p>

<!--more-->


<h2>EC2 Setup</h2>

<p><strong>Add SSH keys to EC2</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>http://alestic.com/2010/10/ec2-ssh-keys</span></code></pre></td></tr></table></div></figure>


<p><strong>Create EC2 instance from AMI (includes gitolite)</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>http://alestic.com/alestic-git/overview</span></code></pre></td></tr></table></div></figure>


<h2>Ubuntu Requirements</h2>

<p><strong>Includes basics from <a href="http://yakiloo.com/setup-requirements/" title="ubuntu setup requirements" target="_blank">setup requirements</a></strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>sudo apt-get update
</span><span class='line'>
</span><span class='line'>sudo apt-get upgrade
</span><span class='line'>
</span><span class='line'>sudo apt-get install build-essential dkms gcc linux-headers-$(uname -r) ncurses-dev zlibc zlib1g zlib1g-dev ia32-libs curl</span></code></pre></td></tr></table></div></figure>


<p><strong>Install necessary packages for ruby/rvm/buildr</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>sudo apt-get -y install unixodbc unixodbc-dev freetds-dev tdsodbc sqsh libxslt-dev libxml2-dev bison openssl libreadline6 libreadline6-dev git-core libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 autoconf libc6-dev</span></code></pre></td></tr></table></div></figure>


<h2>Jenkins Setup</h2>

<p><strong>Install Jenkins as per <a href="https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+on+Ubuntu" title="jenkins installation" target="_blank">jenkins installation</a></strong></p>

<p><em>Ensure port 8080 is open</em></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>cd /tmp
</span><span class='line'>wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -
</span><span class='line'>sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ &amp;gt; /etc/apt/sources.list.d/jenkins.list'
</span><span class='line'>sudo aptitude update
</span><span class='line'>sudo aptitude install jenkins</span></code></pre></td></tr></table></div></figure>


<p><strong>Configure Jenkins user</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>sudo adduser jenkins admin
</span><span class='line'>
</span><span class='line'>sudo passwd jenkins</span></code></pre></td></tr></table></div></figure>


<h2>RUBY/RVM Setup - logged in as jenkins user</h2>

<p><strong>Install RVM</strong></p>

<p><strong>Huge props to <a href="http://yakiloo.com/setup-jenkins-and-rvm/" target="_blank">this dudes article.</a></strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>sudo su - jenkins
</span><span class='line'>
</span><span class='line'>bash &amp;lt; &amp;lt;(curl -s https://rvm.beginrescueend.com/install/rvm)</span></code></pre></td></tr></table></div></figure>


<p><strong>Configure .bashrc &amp; .profile</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>touch ~/.bashrc
</span><span class='line'>touch ~/.profile</span></code></pre></td></tr></table></div></figure>


<p><strong>Copy below source to .bashrc and reload</strong></p>

<p><a href="https://raw.github.com/Yakiloo/UbuntuFiles/master/bashrc" title=".bashrc" target="_blank">.bashrc source</a></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>source ~/.bashrc</span></code></pre></td></tr></table></div></figure>


<p><strong>Copy below source to .profile and reload</strong></p>

<p><a href="https://raw.github.com/Yakiloo/UbuntuFiles/master/profile" title=".profile" target="_blank">.profile source</a></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>source ~/.profile</span></code></pre></td></tr></table></div></figure>


<h2>Java Setup</h2>

<p><strong>Install correct JDK</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>sudo apt-get install openjdk-6-jdk</span></code></pre></td></tr></table></div></figure>


<p><strong>Configure JAVA_HOME path</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>vi ~/.bashrc
</span><span class='line'>
</span><span class='line'># Set JAVA_HOME path
</span><span class='line'>JAVA_HOME=/usr/lib/jvm/java-6-openjdk
</span><span class='line'>export JAVA_HOME
</span><span class='line'>PATH=$PATH:$JAVA_HOME/bin
</span><span class='line'>export PATH</span></code></pre></td></tr></table></div></figure>


<p><strong>Reload .bashrc</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>source ~/.bashrc</span></code></pre></td></tr></table></div></figure>


<p><strong>Check path is correct</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>echo $JAVA_HOME</span></code></pre></td></tr></table></div></figure>


<p><strong>Reboot - not 100% necessary</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>sudo reboot</span></code></pre></td></tr></table></div></figure>


<h2>Ruby Setup</h2>

<p><strong>Install Ruby 1.9.2</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>rvm install 1.9.2-p180</span></code></pre></td></tr></table></div></figure>


<p><strong>note</strong> Takes a while on an EC2 micro-instance (seriously can take ages > 30mins)</p>

<p><strong>Set 1.9.2 as ruby default</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>rvm --default 1.9.2-p180</span></code></pre></td></tr></table></div></figure>


<p><strong>Prevent ri &amp; RDoc creation due to time - optional</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>sudo su - jenkins
</span><span class='line'>echo &quot;gem: --no-ri --no-rdoc&quot; &amp;gt;&amp;gt; ~/.gemrc</span></code></pre></td></tr></table></div></figure>


<h2>Gems Setup</h2>

<p><strong>Install Bundler</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>gem install bundler</span></code></pre></td></tr></table></div></figure>


<p><strong>Install buildr</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>JAVA_HOME=$JAVA_HOME gem install buildr</span></code></pre></td></tr></table></div></figure>


<p><strong>Install buildr-as3</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>gem install buildr-as3</span></code></pre></td></tr></table></div></figure>


<h2>Flash Setup</h2>

<p><strong>Install Standalone debugger FlashPlayer</strong></p>

<p><em>As root</em></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>cd /tmp
</span><span class='line'>
</span><span class='line'>wget http://download.macromedia.com/pub/flashplayer/updaters/10/flashplayer_10_sa_debug.tar.gz
</span><span class='line'>
</span><span class='line'>tar xzvf flashplayer_10_sa_debug.tar.gz
</span><span class='line'>
</span><span class='line'>sudo mv flashplayerdebugger /usr/bin
</span><span class='line'>
</span><span class='line'>sudo ln -s /usr/bin/flashplayerdebugger /usr/bin/gflashplayer
</span><span class='line'>
</span><span class='line'>rm flashplayer_10_sa_debug.tar.gz</span></code></pre></td></tr></table></div></figure>


<h2>VNC Setup</h2>

<p><strong>Install Vnc server</strong></p>

<p><em>Instructions sourced <a href="http://www.ehow.com/how_5089245_install-vnc-server-ubuntu.html" title="vnc server installation" target="_blank">here</a></em></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>sudo apt-get install vnc4server xinetd
</span><span class='line'>
</span><span class='line'>vnc4server</span></code></pre></td></tr></table></div></figure>


<p><em>Enter a password &amp; take notice of the number after the colon (:)</em></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>vnc4server -kill :1</span></code></pre></td></tr></table></div></figure>


<p><em>Replace the number &#8220;1&#8221; with the number from above.</em></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>sudo chmod 755 /etc/X11/xinit/xinitrc
</span><span class='line'>
</span><span class='line'>sudo apt-get install vncviewer</span></code></pre></td></tr></table></div></figure>


<p><strong>Enable for Vnc Jenkins</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>sudo su - jenkins
</span><span class='line'>
</span><span class='line'>vnc4server
</span><span class='line'>
</span><span class='line'>vnc4server -kill :[number after colon when started server]</span></code></pre></td></tr></table></div></figure>


<p><strong>Install XVNC plugin in jenkins</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>https://wiki.jenkins-ci.org/display/JENKINS/Xvnc+Plugin
</span><span class='line'>
</span><span class='line'>Jenkins &amp;gt; Manage Jenkins &amp;gt; Manage Plugins &amp;gt; Available</span></code></pre></td></tr></table></div></figure>


<p><strong>Reboot</strong></p>

<h2>Project Setup</h2>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>sudo reboot</span></code></pre></td></tr></table></div></figure>


<p><strong>Create a new project</strong></p>

<p>In Jenkins create a new free-style software project called SomeProject.</p>

<p><strong>Enable Xvnc for project</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>Project &amp;gt; Configure &amp;gt; Build Environment &amp;gt; Run Xvnc during build</span></code></pre></td></tr></table></div></figure>


<p><strong>Run a build</strong></p>

<p>To generate a workspace you need to run a build first</p>

<p><strong>Install unzip</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>sudo apt-get install unzip</span></code></pre></td></tr></table></div></figure>


<p><strong>Copy local workspace to remote</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>sudo su - jenkins
</span><span class='line'>
</span><span class='line'>cd jobs/SomeProject/</span></code></pre></td></tr></table></div></figure>


<p><em>You may want to guarantee the integrity of the following zip before performing wget</em></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>wget http://db.tt/Dx5LbUo</span></code></pre></td></tr></table></div></figure>


<p><strong>Unzip workspace and cleanup</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>rm -r workspace
</span><span class='line'>unzip [whatever wget saved it as mine was Dx5LbUo]
</span><span class='line'>rm -r [whatever wget saved it as mine was Dx5LbUo] __MACOSX</span></code></pre></td></tr></table></div></figure>


<p><strong>Run first build on command line - also takes a long time for first build</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>sudo su - jenkins
</span><span class='line'>cd ~/jobs/SomeProject/workspace
</span><span class='line'>buildr clean
</span><span class='line'>buildr test</span></code></pre></td></tr></table></div></figure>


<p><strong>Configure project build</strong></p>

<p>In Jenkins > Project > Configure > Add Build Step > Execute Shell</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>buildr clean
</span><span class='line'>buildr test</span></code></pre></td></tr></table></div></figure>


<p>Post Build Actions > Publish JUnit test result report</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>**/reports/flexunit4/*.xml</span></code></pre></td></tr></table></div></figure>


<p>And finally click Save at the bottom of the configuration page.</p>

<p><strong>Build Project</strong></p>

<p>Click Build Now</p>

<p><em>Note this build may take a couple of attempts</em></p>

<p><strong>Further reading</strong></p>

<ul>
<li><a href="http://buildr.apache.org/installing.html#linux" title="buildr linux installation" target="_blank">Buildr installation</a></li>
<li><a href="http://buildr.apache.org/scripts/install-linux.sh" title="buildr linux installation scripts" target="_blank">Buildr installation scripts</a></li>
</ul>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[End to End Testing Flex Applications Using RobotEyes]]></title>
    <link href="http://newtriks.com/2011/07/01/end-to-end-testing-flex-applications-using-roboteyes/"/>
    <updated>2011-07-01T11:29:44+01:00</updated>
    <id>http://newtriks.com/2011/07/01/end-to-end-testing-flex-applications-using-roboteyes</id>
    <content type="html"><![CDATA[<p>This blogpost is simply to promote that there is a fantastic utility named <a href="https://github.com/Stray/RobotEyes" target="_blank">RobotEyes</a> out there for end to end testing your AS3/Flex applications and provide a simple example to help get you started in the right direction.  I am currently writing a more in depth article on end to end testing AS3/Flex applications and therefore want to keep this post brief and to the point.</p>

<blockquote><p>Are you a Flex or AS3 developer?</p>

<p>Do you use TDD?</p>

<p>If yes for both then do you do end to end testing?</p></blockquote>

<p>For me the answer was no, that is until <a href="http://www.xxcoder.net/"  target="_blank">Stray</a> first walked me through the concept whilst also introducing me to her utility named RobotEyes to facilitate end to end testing.  I then proceeded to <a href="https://github.com/newtriks/RobotEyes"  target="_blank">fork</a> her RobotEyes repos and integrated the necessary logic to utilise the tool within a Flex project (see my <a href="https://github.com/newtriks/RobotEyes" target="_blank">RobotEyes Flex fork</a>).  There are other end to end tools for Flex out there but the major advantage for using RobotEyes as opposed to the other options are that RobotEyes actually integrates into your existing test cases, oh yeh!!!</p>

<figure class='code'><figcaption><span>AllTests.as </span></figcaption>
 <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
</pre></td><td class='code'><pre><code class='as'><span class='line'><span class="kd">import</span> <span class="nx">com</span><span class="p">.</span><span class="nx">newtriks</span><span class="p">.</span><span class="nx">views</span><span class="p">.</span><span class="nx">LoggerTest</span><span class="o">;</span>
</span><span class='line'><span class="kd">import</span> <span class="nx">com</span><span class="p">.</span><span class="nx">newtriks</span><span class="p">.</span><span class="nx">views</span><span class="p">.</span><span class="nx">SearchViewTest</span><span class="o">;</span>
</span><span class='line'><span class="kd">import</span> <span class="nx">com</span><span class="p">.</span><span class="nx">newtriks</span><span class="p">.</span><span class="nx">xendtoendtests</span><span class="p">.</span><span class="nx">SearchWithResponseTest</span><span class="o">;</span>
</span><span class='line'>
</span><span class='line'><span class="p">[</span><span class="nx">Suite</span><span class="p">]</span>
</span><span class='line'><span class="kd">public</span> <span class="kd">class</span> <span class="nx">AllTests</span>
</span><span class='line'><span class="p">{</span>
</span><span class='line'>    <span class="c1">// End to end in the test suite yo!</span>
</span><span class='line'>    <span class="kd">public</span> <span class="k">var</span> <span class="nx">search_with_response_test</span><span class="o">:</span><span class="nx">SearchWithResponseTest</span><span class="o">;</span>
</span><span class='line'>    <span class="kd">public</span> <span class="k">var</span> <span class="nx">search_view_test</span><span class="o">:</span><span class="nx">SearchViewTest</span><span class="o">;</span>
</span><span class='line'>    <span class="kd">public</span> <span class="k">var</span> <span class="nx">logger_test</span><span class="o">:</span><span class="nx">LoggerTest</span><span class="o">;</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>I have now constructed an <a href="https://github.com/newtriks/RobotEyes-flex-example" target="_blank">example</a> Flex 4 project to demonstrate an end to end test using RobotEyes.  To help grasp the concept I have tried to keep this example as simple as I possibly can.  The particular example introduces <a href="https://github.com/patternpark/asunit/tree/master/asunit-4.0"  target="_blank">ASUnit 4</a> so you may want to also have a look at my <a href="http://www.newtriks.com/?p=1303">previous blog post</a> as an introduction into ASUnit 4.  Please watch this space for further information on both RobotEyes and end to end testing AS3 and Flex applications.</p>

<p><a href="https://github.com/newtriks/RobotEyes-flex-example" target="_blank">RobotEyes Flex example</a></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[ActionScript 3 to Ruby Examples]]></title>
    <link href="http://newtriks.com/2011/06/30/actionscript-3-to-ruby-examples/"/>
    <updated>2011-06-30T12:19:26+01:00</updated>
    <id>http://newtriks.com/2011/06/30/actionscript-3-to-ruby-examples</id>
    <content type="html"><![CDATA[<p>I have been avidly attempting to learn <a href="http://en.wikipedia.org/wiki/Ruby_(programming_language)" target="_blank">Ruby</a> and to begin with, found writing out simple code comparisons for each language helped me visualise how Ruby came together better.  I thought these may prove useful to some other AS3 devs looking to have a play around with Ruby so am sharing them in this blog post.  I will aim to update them over time and welcome input and suggestions.  There are many resources out there for learning Ruby but for a quick overview I found <a href="http://projectsprouts.org/2011/01/20/ruby-for-actionscripters.html" target="_blank">Lukes</a> post and <a href="http://www.ruby-lang.org/en/documentation/quickstart/2/" target="_blank">Ruby in 20 minutes</a> were great!</p>

<!--more-->


<h3>ActionScript to Ruby Tips</h3>

<figure class='code'><figcaption><span>hello.as </span></figcaption>
 <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='as'><span class='line'><span class="kd">private</span> <span class="k">var</span> <span class="nx">name</span><span class="o">:</span><span class="nb">String</span><span class="o">=</span><span class="s2">&quot;Simon&quot;</span><span class="o">;</span>
</span></code></pre></td></tr></table></div></figure>




<figure class='code'><figcaption><span>hello.rb </span></figcaption>
 <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='rb'><span class='line'><span class="vi">@name</span><span class="o">=</span><span class="s2">&quot;Simon&quot;</span>
</span></code></pre></td></tr></table></div></figure>




<figure class='code'><figcaption><span>hello.as </span></figcaption>
 <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='as'><span class='line'><span class="k">var</span> <span class="nx">name</span><span class="o">:</span><span class="nb">String</span><span class="o">=</span><span class="s2">&quot;Simon&quot;</span><span class="o">;</span>
</span><span class='line'><span class="nf">trace</span><span class="p">(</span><span class="s2">&quot;Hello &quot;</span><span class="o">+</span><span class="nx">name</span><span class="p">);</span>
</span></code></pre></td></tr></table></div></figure>




<figure class='code'><figcaption><span>hello.rb </span></figcaption>
 <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='rb'><span class='line'><span class="nb">name</span><span class="o">=</span><span class="s2">&quot;Simon&quot;</span>
</span><span class='line'><span class="nb">puts</span> <span class="s2">&quot;Hello </span><span class="si">#{</span><span class="nb">name</span><span class="si">}</span><span class="s2">&quot;</span>
</span></code></pre></td></tr></table></div></figure>




<figure class='code'><figcaption><span>hello.as </span></figcaption>
 <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='as'><span class='line'><span class="kd">function</span> <span class="nx">dump</span><span class="p">(</span><span class="nx">name</span><span class="o">:</span><span class="nb">String</span><span class="o">=</span><span class="s2">&quot;World&quot;</span><span class="p">)</span>
</span><span class='line'><span class="p">{</span>
</span><span class='line'>    <span class="nf">trace</span><span class="p">(</span><span class="s2">&quot;Hello &quot;</span><span class="o">+</span><span class="nx">name</span><span class="p">);</span>
</span><span class='line'><span class="p">}</span>
</span><span class='line'>
</span><span class='line'><span class="nx">dump</span><span class="p">(</span><span class="s2">&quot;Simon&quot;</span><span class="p">);</span>
</span></code></pre></td></tr></table></div></figure>




<figure class='code'><figcaption><span>hello.rb </span></figcaption>
 <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class='rb'><span class='line'><span class="k">def</span> <span class="nf">dump</span><span class="p">(</span><span class="nb">name</span><span class="o">=</span><span class="s2">&quot;World&quot;</span><span class="p">)</span>
</span><span class='line'>    <span class="nb">puts</span> <span class="s2">&quot;Hello </span><span class="si">#{</span><span class="nb">name</span><span class="si">}</span><span class="s2">&quot;</span>
</span><span class='line'><span class="k">end</span>
</span><span class='line'>
</span><span class='line'><span class="n">dump</span> <span class="s2">&quot;Simon&quot;</span>
</span></code></pre></td></tr></table></div></figure>




<figure class='code'><figcaption><span>hello.as </span></figcaption>
 <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class='as'><span class='line'><span class="k">var</span> <span class="nx">_names</span><span class="o">:</span><span class="nb">Array</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;tom&quot;</span><span class="o">,</span> <span class="s2">&quot;dick&quot;</span><span class="o">,</span> <span class="s2">&quot;harry&quot;</span><span class="p">];</span>
</span><span class='line'><span class="k">for</span><span class="p">(</span><span class="k">var</span> <span class="nx">name</span><span class="o">:</span><span class="nb">String</span> <span class="k">in</span> <span class="nx">_names</span><span class="p">)</span>
</span><span class='line'><span class="p">{</span>
</span><span class='line'>    <span class="nf">trace</span><span class="p">(</span><span class="s2">&quot;Hello &quot;</span><span class="o">+</span><span class="nx">name</span><span class="p">);</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>




<figure class='code'><figcaption><span>hello.rb </span></figcaption>
 <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class='rb'><span class='line'><span class="n">names</span><span class="o">=[</span><span class="s2">&quot;tom&quot;</span><span class="p">,</span> <span class="s2">&quot;dick&quot;</span><span class="p">,</span> <span class="s2">&quot;harry&quot;</span><span class="o">]</span>
</span><span class='line'><span class="n">names</span><span class="o">.</span><span class="n">each</span> <span class="k">do</span> <span class="o">|</span><span class="nb">name</span><span class="o">|</span>
</span><span class='line'>    <span class="nb">puts</span> <span class="s2">&quot;Hello </span><span class="si">#{</span><span class="nb">name</span><span class="si">}</span><span class="s2">&quot;</span>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>




<figure class='code'><figcaption><span>hello.as </span></figcaption>
 <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='as'><span class='line'><span class="k">var</span> <span class="nx">_names</span><span class="o">:</span><span class="nb">Array</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;tom&quot;</span><span class="o">,</span> <span class="s2">&quot;dick&quot;</span><span class="o">,</span> <span class="s2">&quot;harry&quot;</span><span class="p">];</span>
</span><span class='line'><span class="nf">trace</span><span class="p">(</span><span class="s2">&quot;Hello &quot;</span><span class="o">+</span><span class="nx">_names</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="s2">&quot;, &quot;</span><span class="p">));</span>
</span></code></pre></td></tr></table></div></figure>




<figure class='code'><figcaption><span>hello.rb </span></figcaption>
 <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='rb'><span class='line'><span class="n">names</span><span class="o">=[</span><span class="s2">&quot;tom&quot;</span><span class="p">,</span> <span class="s2">&quot;dick&quot;</span><span class="p">,</span> <span class="s2">&quot;harry&quot;</span><span class="o">]</span>
</span><span class='line'><span class="nb">puts</span> <span class="s2">&quot;Hello </span><span class="si">#{</span><span class="n">names</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="s2">&quot;, &quot;</span><span class="p">)</span><span class="si">}</span><span class="s2">&quot;</span>
</span></code></pre></td></tr></table></div></figure>




<figure class='code'><figcaption><span>hello.as </span></figcaption>
 <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
</pre></td><td class='code'><pre><code class='as'><span class='line'><span class="k">var</span> <span class="nx">_names</span><span class="o">:</span><span class="nb">Array</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;tom&quot;</span><span class="o">,</span> <span class="s2">&quot;dick&quot;</span><span class="o">,</span> <span class="s2">&quot;harry&quot;</span><span class="p">];</span>
</span><span class='line'><span class="k">if</span><span class="p">(</span><span class="nx">_names</span><span class="o">==</span><span class="kc">null</span><span class="p">)</span>
</span><span class='line'><span class="p">{</span>
</span><span class='line'>    <span class="nf">trace</span><span class="p">(</span><span class="s2">&quot;nil&quot;</span><span class="p">);</span>
</span><span class='line'><span class="p">}</span>
</span><span class='line'><span class="k">else</span> <span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="nx">_names</span><span class="p">.</span><span class="nx">length</span><span class="p">)</span>
</span><span class='line'><span class="p">{</span>
</span><span class='line'>    <span class="nf">trace</span><span class="p">(</span><span class="s2">&quot;empty&quot;</span><span class="p">);</span>
</span><span class='line'><span class="p">}</span>
</span><span class='line'><span class="k">else</span>
</span><span class='line'><span class="p">{</span>
</span><span class='line'>    <span class="nf">trace</span><span class="p">(</span><span class="s2">&quot;Hello &quot;</span><span class="o">+</span><span class="nx">_names</span><span class="p">[</span><span class="mi">0</span><span class="p">]);</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>




<figure class='code'><figcaption><span>hello.rb </span></figcaption>
 <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
</pre></td><td class='code'><pre><code class='rb'><span class='line'><span class="n">names</span><span class="o">=[</span><span class="s2">&quot;tom&quot;</span><span class="p">,</span> <span class="s2">&quot;dick&quot;</span><span class="p">,</span> <span class="s2">&quot;harry&quot;</span><span class="o">]</span>
</span><span class='line'><span class="k">if</span> <span class="n">names</span><span class="o">.</span><span class="n">nil?</span>
</span><span class='line'>    <span class="nb">puts</span> <span class="s2">&quot;nil&quot;</span>
</span><span class='line'><span class="k">elsif</span> <span class="n">names</span><span class="o">.</span><span class="n">empty?</span>
</span><span class='line'>    <span class="nb">puts</span> <span class="s2">&quot;empty&quot;</span>
</span><span class='line'><span class="k">else</span>
</span><span class='line'>    <span class="nb">puts</span> <span class="s2">&quot;Hello </span><span class="si">#{</span><span class="n">names</span><span class="o">[</span><span class="mi">0</span><span class="o">]</span><span class="si">}</span><span class="s2">&quot;</span>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>




<figure class='code'><figcaption><span>hello.as </span></figcaption>
 <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
</pre></td><td class='code'><pre><code class='as'><span class='line'><span class="kd">private</span> <span class="k">var</span> <span class="nx">_foo</span><span class="o">:</span><span class="nb">String</span><span class="o">;</span>
</span><span class='line'><span class="kd">public</span> <span class="kd">function</span> <span class="kd">set</span> <span class="nx">foo</span><span class="p">(</span><span class="nx">value</span><span class="o">:</span><span class="nb">String</span><span class="p">)</span><span class="o">:</span><span class="nx">void</span>
</span><span class='line'><span class="p">{</span>
</span><span class='line'>    <span class="nx">_foo</span><span class="o">=</span><span class="nx">value</span><span class="o">;</span>
</span><span class='line'><span class="p">}</span>
</span><span class='line'>
</span><span class='line'><span class="kd">public</span> <span class="kd">function</span> <span class="kd">get</span> <span class="nx">foo</span><span class="p">()</span><span class="o">:</span><span class="nb">String</span>
</span><span class='line'><span class="p">{</span>
</span><span class='line'>    <span class="k">return</span> <span class="nx">_foo</span><span class="o">;</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>




<figure class='code'><figcaption><span>hello.rb </span></figcaption>
 <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='rb'><span class='line'><span class="kp">attr_accessor</span> <span class="ss">:foo</span>
</span></code></pre></td></tr></table></div></figure>




<figure class='code'><figcaption><span>hello.as </span></figcaption>
 <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
</pre></td><td class='code'><pre><code class='as'><span class='line'><span class="kd">public</span> <span class="kd">function</span> <span class="kd">set</span> <span class="nx">foo</span><span class="p">(</span><span class="nx">value</span><span class="o">:</span><span class="nb">String</span><span class="p">)</span><span class="o">:</span><span class="nx">void</span>
</span><span class='line'><span class="p">{</span>
</span><span class='line'>    <span class="nx">_foo</span><span class="o">=</span><span class="nx">value</span><span class="o">;</span>
</span><span class='line'><span class="p">}</span>
</span><span class='line'>
</span><span class='line'><span class="kd">public</span> <span class="kd">function</span> <span class="kd">get</span> <span class="nx">foo</span><span class="p">()</span><span class="o">:</span><span class="nb">String</span>
</span><span class='line'><span class="p">{</span>
</span><span class='line'>    <span class="k">return</span> <span class="nx">_foo</span><span class="o">;</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>




<figure class='code'><figcaption><span>hello.rb </span></figcaption>
 <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
</pre></td><td class='code'><pre><code class='rb'><span class='line'><span class="k">def</span> <span class="nf">foo</span><span class="o">=</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
</span><span class='line'>    <span class="vi">@foo</span> <span class="o">=</span> <span class="n">value</span>
</span><span class='line'><span class="k">end</span>
</span><span class='line'>
</span><span class='line'><span class="k">def</span> <span class="nf">foo</span>
</span><span class='line'>    <span class="vi">@foo</span>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>



]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Getting Started With Project Sprouts And IntelliJ IDEA - Part 1]]></title>
    <link href="http://newtriks.com/2011/06/16/getting-started-with-project-sprouts-and-intellij-idea-part-1/"/>
    <updated>2011-06-16T13:27:58+01:00</updated>
    <id>http://newtriks.com/2011/06/16/getting-started-with-project-sprouts-and-intellij-idea-part-1</id>
    <content type="html"><![CDATA[<p>In part one I will guide you on how to get the basics setup with <a title="Project Sprouts" href="http://projectsprouts.org/" target="_blank">Project Sprouts</a> and <a title="IntelliJ IDEA" href="http://www.jetbrains.com/idea/" target="_blank">IntelliJ IDEA</a> and end by running your rake task.  I am demonstrating these examples on Mac OS X, however there is nothing stopping you completing this on your own OS.  <!--more--><strong>Install RVM</strong> I advise installing <a title="RVM" href="https://rvm.beginrescueend.com/" target="_blank">Ruby Version Manager (RVM)</a> as there are potential versions of specific ruby gems that Sprouts uses which will need to be configured.  RVM allows you to have multiple ruby environments to allow for this flexibility in work flow.  Once you have followed the instructions to install RVM go ahead and install, use Ruby 1.9.2:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>$ rvm install 1.9.2
</span><span class='line'>$ rvm use 1.9.2</span></code></pre></td></tr></table></div></figure>


<p>To check which version of ruby your using and its installation location you can use the following:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>$ ruby -v
</span><span class='line'>$ which ruby</span></code></pre></td></tr></table></div></figure>


<p>To check the the version of Sprouts you have installed for the currently loaded Ruby version (also lists all other installed gems):</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>$ gem list</span></code></pre></td></tr></table></div></figure>


<p>My personal preference is to then set this specific version to be the <a title="RVM default ruby" href="http://beginrescueend.com/rubies/default/" target="_blank">default ruby</a> i.e. when I open Terminal this is the version that is used:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>$ rvm --default use 1.9.2</span></code></pre></td></tr></table></div></figure>


<p>To switch back simply use:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>$ rvm use system</span></code></pre></td></tr></table></div></figure>


<p><strong>Install Project Sprouts</strong> Now we have our ruby environment setup we can install Project Sprouts to a specific version of ruby.  Follow the instructions on the Project Sprouts website: <a title="Getting Started" href="http://projectsprouts.org/#getting-started" target="_blank">Getting Started</a> and go create a project shown in the installation example, have a little play familiarising yourself with Project Sprouts.  If you installed everything correctly you should see <strong>flashsdk (1.0.27.pre)</strong> and <strong>sprout (1.1.11.pre)</strong>:  When you run:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>$ gem list</span></code></pre></td></tr></table></div></figure>


<p><strong>Install IntelliJ IDEA</strong> Download and install <a title="IntelliJ IDEA" href="http://www.jetbrains.com/idea/download/index.html" target="_blank">IntelliJ IDEA 10.5 </a>(other versions will be fine running this example).  <strong>Create a new AS3 project</strong> Now this is an area I am trying to refine into a slightly smoother process by removing one of the steps, but for now roll with me.</p>

<ol>
<li>Open IntelliJ and <em>File &gt; Create Command-line Launcher</em> then follow the instructions.  This will enable us to launch IntelliJ in the current shell session and therefore target the specific RVM ruby version using IntelliJ&#8217;s command-line tool (super thanks to <a title="devboy_org" href="https://twitter.com/#!/devboy_org" target="_blank">@devboy_org</a> for this tip).</li>
</ol>


<p><strong>Create a new IntelliJ Project</strong></p>

<p>For now this is <em>not</em> the <em>ideal</em> process and I am working on a better solution.  Step one is <strong>only applicable</strong> if your using RVM and <strong>not your system default</strong> installation of Ruby.  I have found two ways to set up a project, the first is the quickest and easiest and I thought I would show another optional alternative (Option Two below).</p>

<p><strong>OPTION ONE</strong></p>

<p><strong>Step One:</strong></p>

<p>1: If not your default then using RVM set the specific ruby version where you installed Project Sprouts</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>rvm use 1.9.2</span></code></pre></td></tr></table></div></figure>


<p>2: Open IntelliJ IDEA from command line</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>idea .</span></code></pre></td></tr></table></div></figure>


<p>You will see a warning from IntelliJ basically stating there is no project setup.</p>

<p><strong>Step Two:</strong></p>

<p>1: Now go ahead and create a Flex/ActionScript project as per normal named <strong>SomeProject</strong>.
2: In IntelliJ go to <em>Tools > Run Command</em> or use the hot keys (for mac it&#8217;s) <em>SHIFT CMD X</em> to open the Command Line Tools window and run the following command to navigate up to the projects parent directory:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>cd ../</span></code></pre></td></tr></table></div></figure>


<p>3: If you created a Flex project then bring up the command window and type:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>sprout-flex SomeProject</span></code></pre></td></tr></table></div></figure>


<p>else if ActionScript:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>sprout-as3 SomeProject</span></code></pre></td></tr></table></div></figure>


<p>4: In the command window navigate into your project folder:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>cd SomeProject</span></code></pre></td></tr></table></div></figure>


<p>5: Install dependencies</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>bundle install</span></code></pre></td></tr></table></div></figure>


<p><strong>OPTION TWO</strong></p>

<p>Basically its a two step process where you first create a Flex/Actionscript project in IntelliJ as shown below and the secondly have to run the Project Sprouts generator for either a new as3 or flex project.  My <a title="Here's hoping" href="http://devnet.jetbrains.net/thread/305099" target="_blank">future aim</a> is to essentially create the IDEA project files using Project Sprouts at the same time as creating a new flex/as3 project and then auto load IntelliJ using the command-line launcher, all in one hit (similar to what is currently available for <a title="Maven" href="http://maven.apache.org/plugins/maven-idea-plugin/idea-mojo.html" target="_blank">Maven Plugin</a>)!  If anyone can help out pointing me in the right direction for generating IDEA files using rake then I would appreciate the help?</p>

<p><strong>Step One:</strong></p>

<p>Open IntelliJ and follow the below screen shots:</p>

<p>1: Create a new project from scratch</p>

<p><a href="http://assets.newtriks.com.s3.amazonaws.com/newtriks_blog/images/2011/06/step_1.png"><img class="aligncenter size-full wp-image-1294" title="step_1" src="http://assets.newtriks.com.s3.amazonaws.com/newtriks_blog/images/2011/06/step_1.png" alt="" width="625" height="387" /></a></p>

<p>2: Give your project a name</p>

<p><a href="http://assets.newtriks.com.s3.amazonaws.com/newtriks_blog/images/2011/06/step_2.png"><img class="aligncenter size-full wp-image-1295" title="step_2" src="http://assets.newtriks.com.s3.amazonaws.com/newtriks_blog/images/2011/06/step_2.png" alt="" width="625" height="521" /></a></p>

<p>3: Don&#8217;t bother creating a src directory as we can leave our Project Sprouts generator to do that</p>

<p><a href="http://assets.newtriks.com.s3.amazonaws.com/newtriks_blog/images/2011/06/step_3.png"><img class="aligncenter size-full wp-image-1296" title="step_3" src="http://assets.newtriks.com.s3.amazonaws.com/newtriks_blog/images/2011/06/step_3.png" alt="" width="625" height="168" /></a></p>

<p>4: Define your module Flex SDK and finish</p>

<p><a href="http://assets.newtriks.com.s3.amazonaws.com/newtriks_blog/images/2011/06/step_4.png"><img class="aligncenter size-full wp-image-1297" title="step_4" src="http://assets.newtriks.com.s3.amazonaws.com/newtriks_blog/images/2011/06/step_4.png" alt="" width="625" height="522" /></a></p>

<p><strong>Step Two:</strong></p>

<p>Open a new Terminal window and cd to where you created your new project:</p>

<p>1: Generate the project using sprouts</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>sprout-as3 SomeProject</span></code></pre></td></tr></table></div></figure>


<p>2: Move into the project directory</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>cd SomeProject</span></code></pre></td></tr></table></div></figure>


<p>3: Install dependencies</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>bundle install</span></code></pre></td></tr></table></div></figure>


<p>4: Open in IntelliJ IDEA</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>idea .</span></code></pre></td></tr></table></div></figure>


<p>Confirm that all our project files are in place!</p>

<p><a href="http://assets.newtriks.com.s3.amazonaws.com/newtriks_blog/images/2011/06/step_5.png"><img class="aligncenter size-full wp-image-1298" title="step_5" src="http://assets.newtriks.com.s3.amazonaws.com/newtriks_blog/images/2011/06/step_5.png" alt="" width="625" height="387" /></a></p>

<p><strong>Compile and run the project</strong></p>

<p>For this tutorial I am going to show one particular method to run the project <strong>rake</strong> file.  This is the simplest approach but if you have used RVM you must ensure you loaded the project in IntelliJ using the command-line launcher.</p>

<p>In IntelliJ go to <em>Tools > Run Command</em> or use the hot keys (for mac it&#8217;s) <em>SHIFT CMD X</em> to open the Command Line Tools window and either type <strong>rake</strong> or <strong>rake test</strong> and hit Enter.  You should hopefully now see your rake task being run and either the swf with your project or the swf with an ASUnit test runner.</p>

<p><strong><em> NOTE </em></strong></p>

<p>Versions used for this example:</p>

<ul>
<li>asunit4 (4.2.3.pre)</li>
<li>bundler (1.0.14)</li>
<li>flashsdk (1.0.29.pre)</li>
<li>rake (0.9.2)</li>
<li>rubygems-update (1.8.5)</li>
<li>rubyzip (0.9.4)</li>
<li>sprout (1.1.15.pre)</li>
</ul>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Getting Started With ASUnit4 Within IntelliJ IDEA]]></title>
    <link href="http://newtriks.com/2011/06/13/getting-started-with-asunit4-within-intellij-idea/"/>
    <updated>2011-06-13T13:28:25+01:00</updated>
    <id>http://newtriks.com/2011/06/13/getting-started-with-asunit4-within-intellij-idea</id>
    <content type="html"><![CDATA[<p>Last week I was setting up an example project for RobotEyes and was using <a title="ASUnit4" href="https://github.com/patternpark/asunit/tree/master/asunit-4.0" target="_blank">ASUnit4</a> which has had some tasty improvements made since version 3.  ASUnit is a collaborative effort between <a title="Luke Bayes" href="http://twitter.com/#!/search/lukebayes" target="_blank">@lukebayes</a> and <a title="Rob Penner" href="http://twitter.com/#!/robpenner" target="_blank">@robpenner</a> and has been my choice of unit testing framework for a while now.  In this blog post I will show you how to get ASUnit4 setup in IntelliJ IDEA and run a few tests taking advantage of some of the features for this new release.<!--more--></p>

<blockquote><p>AsUnit is the only open-source unit test framework for ActionScript that works with ActionScript 2, 2.5, 3.0, Flash Authoring (back to MX and up to CS4), Flex Builder, the Flex Framework (2 and 3), MTASC, MXMLC, and any version of Flash Player since version 6, including AIR and even FlashLite. We can even emit JUnit-compatible XML results. There is no dependency on any external tooling or framework.</p></blockquote>

<p>It just works, and it works everywhere.</p>

<p>AsUnit4 test framework works with Flash Players 9, 10 and Adobe AIR and any version of the Flex framework.
<a title="ASUnit3" href="https://github.com/patternpark/asunit/tree/master/asunit-3.0" target="_blank">ASUnit3</a> tests can still be run in the latest version using Legacy Runner  (thanks to <a title="robpenner" href="http://twitter.com/#!/robpenner" target="_blank">@robpenner</a> for <a title="gist" href="https://gist.github.com/728312#comments" target="_blank">pointing</a> to an <a title="TestCase" href="https://github.com/robertpenner/asunit/blob/master/asunit-4.0/src/asunit/framework/TestCase.as" target="_blank">example</a>).  In ASUnit4 there are a list of significant new features and improvements including (as <a title="Google Groups" href="http://groups.google.com/group/projectsprouts/browse_thread/thread/379b89b5a7e5127e" target="_blank">referenced</a> from Luke):
+ Injection using SwiftSuspenders.
+   Speed improvements.
+   Composition over inheritance.
+   It uses annotations providing enormous flexibility.
+    It can swap runners at runtime thus supports legacy test cases (or even - at some point - other framework&#8217;s test cases).
+    It&#8217;s much easier to build custom printers.
+   The async functionality is much cleaner.</p>

<p>We will create the classes manually for this blog post, however in reality I use <a title="Project Sprouts" href="http://projectsprouts.org/" target="_blank">Project Sprouts</a> to generate all my test classes, whats the point in doing it all manually?!</p>

<p><strong>Setup your flex project in IntelliJ IDEA</strong></p>

<p>I was about to do a screencast for setting up a flex project but remembered that both <a href="http://joelhooks.com/2010/03/21/intellij-idea-flex-and-actionscript-3-workflow-part-1-creating-a-flex-project/" target="_blank">@jhooks</a> and <a href="http://www.developria.com/2010/02/intellij-idea9-actionscript-3f.html" target="_blank">@codebum</a> have removed the need for you to listen to my (potentially irritating) voice by recording their own extensive tutorials, so if your unsure of how to get started with IntelliJ I recommend watching their screencasts!</p>

<p>My final project setup screen looks like the following:
<a href="http://assets.newtriks.com.s3.amazonaws.com/newtriks_blog/images/2011/06/Screen-shot-2011-06-10-at-15.52.241.png" target="_blank"><img class="aligncenter size-full wp-image-1319" title="Final setup" src="http://assets.newtriks.com.s3.amazonaws.com/newtriks_blog/images/2011/06/Screen-shot-2011-06-10-at-15.52.241.png" alt="Final setup" width="628" height="389" /></a>
<strong>Add Required Libraries to Project</strong></p>

<ol>
<li>Download <a title="ASUnit4" href="https://github.com/patternpark/asunit/tree/master/asunit-4.0" target="_blank">ASUnit4</a> and copy the <strong>asunit</strong> directory and all of its contents from the
<em>src</em> directory to the projects <em>src</em> directory.</li>
<li>Next create a <strong>lib</strong> directory in the project root and and copy into it: Reflection.swc and SwiftSuspenders-v1.5.1.swc.</li>
<li>Click the <em>Project Structure</em> icon (or use <em>cmd;</em> or <em>File &gt; Project Structure</em>) and  in <em>Project Setting</em> select <em>Module &gt; Dependencies. </em>Select <em>Add</em> &gt; <em>Library </em>&gt; * New Library
<em>&gt; </em>Actionscript/Flex<em>.  Name the library <strong>lib</strong> and click </em>Add Folders With SWC<em> browsing to your lib directory select it and click </em>OK <em>and then </em>OK* again to come out of the project settings panel.</li>
</ol>


<p><strong>Create a Test Runner and Test Suite</strong></p>

<ol>
<li>Within the project <strong>src</strong> create a new <em>MXML Component (Flex 4)</em> naming it <strong>FlexTestRunner</strong> and setting the <em>Parent Spark component</em> as <em>Application</em>.  Ensure the Class code looks as below:</li>
</ol>


<div><script src='https://gist.github.com/1019067.js?file='></script>
<noscript><pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
               xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;
               minWidth=&quot;800&quot;
               minHeight=&quot;600&quot;
               creationComplete=&quot;creationCompleteHandler(event)&quot;&gt;
    &lt;fx:Script&gt;
        &lt;![CDATA[
        import asunit.core.TextCore;

        import mx.core.UIComponent;
        import mx.events.FlexEvent;

        private var core:TextCore;

        private function creationCompleteHandler(event:FlexEvent):void
        {
            // Flex 4 complains when we use UIComponent from MXML... Boo.
            var visualContext:UIComponent=new UIComponent();
            addElement(visualContext);
            core=new TextCore();
            core.start(AllTests, null, visualContext);
        }
        ]]&gt;
    &lt;/fx:Script&gt;
&lt;/s:Application&gt;
</code></pre></noscript></div>


<ol>
<li>Next within the project <strong>test</strong> directory create a new ActionScript class and name it <strong>AllTests</strong> and ensure the Class code looks as below:</li>
</ol>


<div><script src='https://gist.github.com/1019096.js?file='></script>
<noscript><pre><code>package
{

    [Suite]
    public class AllTests
    {
        
    }
}
</code></pre></noscript></div>


<p><strong>Configure IntelliJ IDEA to use ASUnit4</strong></p>

<p>IntelliJ has not got in built support to compile and run ASUnit4 as it has for FlexUnit and so we have to perform two steps to compile and run:</p>

<ol>
<li>In your project root create a new directory called <strong>test</strong> then click the <em>Project Structure</em> icon (or use <em>cmd;</em> or <em>File &gt; Project Structure</em>) and  in
<em>Project Setting</em> select <em>Module</em>.  In the right hand panel under <em>Sources</em> select the newly created <strong>test</strong> directory and click the <em>Sources</em> button directly above the project file tree and click <em>OK</em> as shown below:
<img class="aligncenter size-full wp-image-1321" title="Setting test as a source" src="http://assets.newtriks.com.s3.amazonaws.com/newtriks_blog/images/2011/06/Screen-shot-2011-06-10-at-16.07.04.png" alt="Setting test as a source" width="625" height="167" /></li>
<li>Secondly we need to create a run configuration for our tests.  Select <em>Run</em> &gt; <em>Edit Configurations</em> and click the <em>plus icon</em> in the top left hand corner.  Select
<em>Flex</em> from the drop down menu and name the new configuration <strong>TestRunner</strong> check the Main Class radio button and click the button to the left to browse to the main class, select <strong>FlexTestRunner</strong> and click <em>OK</em>.  You run configuration should look like below:
<a href="http://assets.newtriks.com.s3.amazonaws.com/newtriks_blog/images/2011/06/Screen-shot-2011-06-10-at-16.49.55.png" target="_blank"><img class="aligncenter size-full wp-image-1328" title="Run Configuration" src="http://assets.newtriks.com.s3.amazonaws.com/newtriks_blog/images/2011/06/Screen-shot-2011-06-10-at-16.49.55.png" alt="Run Configuration" width="625" height="301" /></a></li>
</ol>


<p><strong>Start Writing Some Unit Tests</strong></p>

<p>Now we have IntelliJ IDEA and ASUnit4 all configured plus a Test Runner and Suite let&#8217;s start looking into how to create our first UnitTest.</p>

<p>If you <em>Run</em> your TestRunner now it should run your FlexTestRunner and display no tests were found or executed with a nice little green stripe along the bottom of the window (this turns red if failed tests).  All we are going to do now is keep it simple (no package directories) and test a component which has a TextInput and a Button, on click of the button it will validate the text entered (I will re-use this logic in my up and coming example on end to end tests in Flex using <a title="RobotEyes" href="https://github.com/newtriks/RobotEyes/tree/flex" target="_blank">RobotEyes</a>).</p>

<p><strong>1. Test the component class itself</strong></p>

<p>Create a new ActionScript Class called <strong>SearchViewTest </strong>within the <em>test</em> directory.  The first thing we are going to do is use the new logic in ASUnit4 to inject the visual context of the test suite into the test case.  This is a handy new feature making use of <a title="Swift Suspenders" href="https://github.com/tschneidereit/SwiftSuspenders" target="_blank">SwiftSuspenders</a> with the advantage being detailed nicely here by <a href="http://twitter.com/#!/stray_and_ruby" target="_blank">@stray_and_ruby</a>:</p>

<!-- p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Arial} -->


<blockquote><p>&#8230;the idea is that the visual context of the test suite can be injected into any visual test case, rather than (as in asunit 3) having to addChild to the test case itself which forced the test cases to extend Sprite and was a bit messy.
Create the injection point for the visual context as this is going to be testing out component on the display list, also add a private variable for the component we are going to test:</p></blockquote>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>[Inject]
</span><span class='line'>public var context:Sprite;
</span><span class='line'>
</span><span class='line'>private var searchView:SearchView;</span></code></pre></td></tr></table></div></figure>


<p>Now run the TestRunner, obviously this is going to flag up as a problem in our IDE as there is no SearchView component yet, so go ahead and create a new mxml component (parent spark component: Group) and name it <strong>SearchView</strong>.</p>

<p>Back to the test class we are going to add 3 core chunks of logic:
+ Before: Logic run before tests are actually initiated.
+   After: Logic run after tests completed.
+   Test: Actual test case to run.</p>

<p>All of the above are identified in our test class in the form of <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=metadata_3.html" target="_blank">Metadata</a> tags.  Update <strong>SearchViewTest</strong> so it is the same as below:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>[Before]
</span><span class='line'>        public function setUp():void
</span><span class='line'>        {
</span><span class='line'>            searchView=new SearchView();
</span><span class='line'>            context.addChild(searchView);
</span><span class='line'>        }
</span><span class='line'>
</span><span class='line'>        [After]
</span><span class='line'>        public function tearDown():void
</span><span class='line'>        {
</span><span class='line'>            searchView=null;
</span><span class='line'>        }
</span><span class='line'>
</span><span class='line'>        [Test]
</span><span class='line'>        public function instantiated():void
</span><span class='line'>        {
</span><span class='line'>            assertTrue(searchView is SearchView);
</span><span class='line'>        }</span></code></pre></td></tr></table></div></figure>


<p>So lets run this new test logic, but first we need to add the test case to our test suite <strong>AllTests</strong>:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>public var search_view_test:SearchViewTest;</span></code></pre></td></tr></table></div></figure>


<p>Now run the TestRunner and you should see the following:</p>

<p><a href="http://assets.newtriks.com.s3.amazonaws.com/newtriks_blog/images/2011/06/Screen-shot-2011-06-13-at-11.45.28.png"><img class="aligncenter size-full wp-image-1340" title="First running test" src="http://assets.newtriks.com.s3.amazonaws.com/newtriks_blog/images/2011/06/Screen-shot-2011-06-13-at-11.45.28.png" alt="First running test" width="501" height="396" /></a></p>

<p><strong>2. Test a text input of a specific id is on the components display list</strong></p>

<p>Swiftly back into our test class add:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>[Test]
</span><span class='line'>        public function search_view_has_search_textinput():void
</span><span class='line'>        {
</span><span class='line'>            assertNotNull(searchView.searchRequest_txt);
</span><span class='line'>        }</span></code></pre></td></tr></table></div></figure>


<p>Run TestRunner and you should get a compile error as we have not yet created the text input, so within <strong>SearchView</strong> add the following code:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"></pre></td><td class='code'><pre><code class=''></code></pre></td></tr></table></div></figure>


<p>Run TestRunner and it should now pass.</p>

<p><strong>3. </strong>Test a button of a specific id is on the components display list****</p>

<p>Add the following new test:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>[Test]
</span><span class='line'>        public function search_view_has_submitbutton():void
</span><span class='line'>        {
</span><span class='line'>            assertNotNull(searchView.submit_btn);
</span><span class='line'>        }</span></code></pre></td></tr></table></div></figure>


<p>Run TestRunner and you should get a compile error as we have not yet created the button, so within <strong>SearchView</strong> add the following code below the text input:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"></pre></td><td class='code'><pre><code class=''></code></pre></td></tr></table></div></figure>


<p>Run TestRunner and it should now pass.</p>

<p><strong>4. Test text input text populates correctly</strong></p>

<p>Add another test to confirm that text input text matches what is actually entered:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>[Test]
</span><span class='line'>        public function search_text_is_populated():void
</span><span class='line'>        {
</span><span class='line'>            assertSame(searchView.searchRequest_txt.text, &quot;Hello World&quot;);
</span><span class='line'>        }</span></code></pre></td></tr></table></div></figure>


<p>This test should Fail as we have not yet entered any text, so amend the above test as below:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>[Test]
</span><span class='line'>        public function search_text_is_populated():void
</span><span class='line'>        {
</span><span class='line'>            searchView.searchRequest_txt.text=&quot;Hello World&quot;;
</span><span class='line'>            assertSame(searchView.searchRequest_txt.text, &quot;Hello World&quot;);
</span><span class='line'>        }</span></code></pre></td></tr></table></div></figure>


<p>Run TestRunner and it should now pass.</p>

<p><strong>4. Test button dispatches a specific event</strong></p>

<p>In our final test we will confirm the submit button dispatches a specific event and to achieve this we shall inject the IAsync interface as provided by the framework:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>[Inject]
</span><span class='line'>        public var async:IAsync;</span></code></pre></td></tr></table></div></figure>


<p>And then finally add the following test and handler functions:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>[Test]
</span><span class='line'>        public function submit_button_dispatches_specific_eventname():void
</span><span class='line'>        {
</span><span class='line'>            searchView.addEventListener(&quot;submitSearchEvent&quot;, async.add(submitDispatchesSpecificEventType));
</span><span class='line'>            searchView.submit_btn.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
</span><span class='line'>        }
</span><span class='line'>
</span><span class='line'>        protected function submitDispatchesSpecificEventType(event:Event):void
</span><span class='line'>        {
</span><span class='line'>            assertSame(event.type, &quot;submitSearchEvent&quot;);
</span><span class='line'>        }</span></code></pre></td></tr></table></div></figure>


<p>In order of events what is happening here is:</p>

<ol>
<li>Adding an asynchronous handler function as the event handler to the view class for the expected dispatch of an event of type <em>submitSearchEvent</em> when the submit_btn is clicked. The async
handler uses the function <em>submitDispatchesSpecificEventType</em>.</li>
<li>Manually dispatch a click event from the submit_btn.</li>
<li>Check the event type passed into the async event handler.</li>
</ol>


<p>Your final test class should now look like this:</p>

<div><script src='https://gist.github.com/1022643.js?file='></script>
<noscript><pre><code>/** @author: Simon Bailey &lt;simon@newtriks.com&gt; */
package
{
    import asunit.asserts.assertNotNull;
    import asunit.asserts.assertSame;
    import asunit.asserts.assertTrue;
    import asunit.framework.IAsync;

    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.utils.setTimeout;

    public class SearchViewTest
    {
        [Inject]
        public var context:Sprite;

        [Inject]
        public var async:IAsync;

        private var searchView:SearchView;

        [Before]
        public function setUp():void
        {
            searchView=new SearchView();
            context.addChild(searchView);
        }

        [After]
        public function tearDown():void
        {
            searchView=null;
        }

        [Test]
        public function instantiated():void
        {
            assertTrue(searchView is SearchView);
        }

        [Test]
        public function search_view_has_search_textinput():void
        {
            assertNotNull(searchView.searchRequest_txt);
        }

        [Test]
        public function search_text_is_populated():void
        {
            searchView.searchRequest_txt.text=&quot;Hello World&quot;;
            assertSame(searchView.searchRequest_txt.text, &quot;Hello World&quot;);
        }

        [Test]
        public function submit_button_dispatches_specific_eventname():void
        {
            searchView.addEventListener(&quot;submitSearchEvent&quot;, async.add(submitDispatchesSpecificEventType));
            searchView.submit_btn.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
        }

        protected function submitDispatchesSpecificEventType(event:Event):void
        {
            assertSame(event.type, &quot;submitSearchEvent&quot;);
        }
    }
}</code></pre></noscript></div>


<p>Run TestRunner and it should fail.  So finally add the logic in the <strong>SearchView</strong> component that will handle the button click event dispatch of a specific event <em>submitSearchEvent</em>:</p>

<div><script src='https://gist.github.com/1022651.js?file='></script>
<noscript><pre><code>&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;s:Group xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;
         xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;&gt;
    &lt;fx:Metadata&gt;
        [Event(name='submitSearchEvent',type='flash.events.Event')]
    &lt;/fx:Metadata&gt;
    &lt;s:layout&gt;
        &lt;s:HorizontalLayout paddingLeft=&quot;10&quot;
                            paddingRight=&quot;10&quot;
                            paddingBottom=&quot;10&quot;
                            paddingTop=&quot;10&quot;/&gt;
    &lt;/s:layout&gt;
    &lt;fx:Script&gt;&lt;![CDATA[
        private function submit_btn_clickHandler(event:MouseEvent):void
        {
            dispatchEvent(new Event('submitSearchEvent'));
        }
        ]]&gt;&lt;/fx:Script&gt;
    &lt;s:TextInput id=&quot;searchRequest_txt&quot; width=&quot;200&quot;/&gt;
    &lt;s:Button id=&quot;submit_btn&quot; label=&quot;Search&quot; click=&quot;submit_btn_clickHandler(event)&quot;/&gt;
&lt;/s:Group&gt;
</code></pre></noscript></div>


<p>Run the TestRunner and it should pass!</p>

<p>Hopefully that should serve as a gentle introduction to ASUnit4.</p>

<p>Note: If for some reason your test fails due to a timeout on the async handler then just increase the handler timeout duration and it should pass.</p>

<p><em>Here are some further useful links and remember the tips are in the tests:</em></p>

<ol>
<li><a href="https://github.com/patternpark/asunit/blob/master/asunit-4.0/test/AsUnitRunner.as" target="_blank">AS3</a></li>
<li><a href="https://github.com/patternpark/asunit/blob/master/asunit-4.0/test/Flex3Runner.mxml" target="_blank">Flex 3</a></li>
<li><a href="https://github.com/patternpark/asunit/blob/master/asunit-4.0/test/Flex4Runner.mxml" target="_blank">Flex 4</a></li>
<li><a href="https://github.com/patternpark/asunit/blob/master/asunit-4.0/air/AIR2Runner.mxml" target="_blank">AIR 2</a></li>
<li><a href="https://github.com/patternpark/asunit/blob/master/asunit-4.0/test/AllTests.as" target="_blank">Test Suite</a></li>
<li><a href="https://github.com/patternpark/asunit/blob/master/asunit-4.0/test/asunit/framework/VisualTestCaseTest.as" target="_blank">Visual Test Case</a></li>
<li><a href="https://github.com/patternpark/asunit/blob/master/asunit-4.0/test/asunit/framework/AsyncMethodTest.as" target="_blank">Async Test Case</a></li>
<li><a href="http://asunit.org/docs/asunit3/asunit/framework/package-detail.html" target="_blank">ASUnit3 Docs</a></li>
<li>Keep an eye on my RobotLegs Project Sprout generators to save you a load of time creating components and their corresponding tests: <a href="https://github.com/newtriks/sprout-robotlegs"
target="_blank">https://github.com/newtriks/sprout-robotlegs</a></li>
</ol>


<p>A serious shout out to <a href="http://twitter.com/#!/stray_and_ruby" target="_blank">@stray_and_ruby</a> for all her patience and guidance in the realms of TDD, thank you!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Project/Class Generation using Project Sprouts and Alfred App]]></title>
    <link href="http://newtriks.com/2011/05/26/projectclass-generation-using-project-sprouts-and-alfred-app/"/>
    <updated>2011-05-26T11:33:53+01:00</updated>
    <id>http://newtriks.com/2011/05/26/projectclass-generation-using-project-sprouts-and-alfred-app</id>
    <content type="html"><![CDATA[<p>Recently I tweeted a <a title="Screenr" href="http://www.screenr.com/0by" target="_blank">Screencast</a> of an example creating AS3 projects/classes using <a title="Project Sprouts" href="http://projectsprouts.org/" target="_blank">ProjectSprouts</a> and <a title="Rake" href="http://rake.rubyforge.org/" target="_blank">Rake</a> via <a title="AlfredApp" href="http://www.alfredapp.com/" target="_blank">AlfredApp</a>.  I had a couple of requests to share my scripts and so I created a new github repos called <a title="Shell-Funk" href="https://github.com/newtriks/Shell-Funk" target="_blank">Shell-Funk</a>.  I must give a clear heads-up here that I am in no way a shell script or apple script ninja and these scripts work but I cannot guarantee how great they are and would welcome input on improving them.  They are also Mac OS X dependent.</p>

<p>Simply put Alfred App is:</p>

<blockquote><p>Alfred is a productivity application for Mac OS X, which aims to save you time in searching your local computer and the web.
And Project Sprouts is:
Project Sprouts is a highly cohesive, loosely coupled collection of features that take <em>some</em> of the suck out of programming.
So the two combined essentially mean super speed and efficiency for those mundane tasks i.e. creating new projects or classes etc.  The first script I put up creates a new AS3 project, downloads <a title="Generators" href="https://github.com/Stray/project-sprouts-robot-legs-bundle">Stray&#8217;s Project Sprouts generators</a> for <a title="Robotlegs" href="http://www.robotlegs.org/" target="_blank">Robotlegs</a> and opens up the newly created project in a Finder window.  Have a play and see what you think and also be sure to check out this <a title="Dirtdon" href="http://www.dirtdon.com/?p=886" target="_blank">amazing site</a> for further scripts to use with Alfred.</p></blockquote>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[SCP and SSH Solution on Amazon EC2 Linux AMI]]></title>
    <link href="http://newtriks.com/2011/04/06/scp-and-ssh-solution-on-amazon-ec2-linux-ami/"/>
    <updated>2011-04-06T10:54:21+01:00</updated>
    <id>http://newtriks.com/2011/04/06/scp-and-ssh-solution-on-amazon-ec2-linux-ami</id>
    <content type="html"><![CDATA[<p>A while back I setup a new Amazon EC2 <a href="http://aws.amazon.com/about-aws/whats-new/2010/09/09/announcing-micro-instances-for-amazon-ec2/" target="_blank">micro-instance</a> using Amazon&#8217;s own Linux AMI (based on Centos). On firing up the instance I attempted to run a simple scp command which ultimately failed. The reason I wanted to use the <a href="http://www.go2linux.org/scp-linux-command-line-copy-files-over-ssh" target="_blank">scp</a> command was to push and append to authorized_keys my own generated SSH key to my instance, this is a personal preference over the generated Key Pair (.pem) Amazon recommends you use.</p>

<p>As you may be aware, this particular setup also discourages (and as I recall prevents) a root password login, naturally for heightened security, so I had to do some digging. I soon discovered that using the cat command I could work around the issue and append my local public ssh key to the authorized_keys on the remote server. This is what it should look like:</p>

<!--more-->




<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>cat ~/.ssh/id_dsa.pub | ssh -i your-amazon-generated-key.pem ec2-user@your-amazon-instance-ip &quot;cat&gt;&gt; .ssh/authorized_keys&quot;</span></code></pre></td></tr></table></div></figure>


<p>You should then be able to SSH into your server using <a href="http://linux.about.com/od/commands/l/blcmdl1_ssh.htm" target="_blank">RSA based authentication</a> and ultimately regain the privilege to use the scp command.</p>

<p>Funnily enough <a href="https://twitter.com/vandergoog" target="_blank">@vandergoog</a> pointed out on <a href="http://twitter.com/vandergoog/status/34375221033046016" target="_blank">Twitter</a> a similar person undergoing the same issue whom also resolved it in the same manner, plus a <a href="http://bit.ly/i7QxLr" target="_blank">poll</a> was setup and there are a few votes for true, so I am not alone on this.</p>

<p>Please note that I am sure that this is due to some inherent Amazon/security logic that is both recommended plus beneficial and I am missing the boat on this one, any further insight from any hardcore Linux/SSH users would be appreciated.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[PlayaHater – FLV Player for Rapid Testing]]></title>
    <link href="http://newtriks.com/2011/04/06/playahater-%25e2%2580%2593-flv-player-for-rapid-testing/"/>
    <updated>2011-04-06T10:47:35+01:00</updated>
    <id>http://newtriks.com/2011/04/06/playahater-%e2%80%93-flv-player-for-rapid-testing</id>
    <content type="html"><![CDATA[<p>Last night I pushed up to my <a href="https://github.com/newtriks/PlayaHater" target="_blank">GitHub</a> account the source for an FLV player component (<a href="http://apps.newtriks.com/PlayaHater/" target="_blank">PlayaHater</a>) that I built based on and using <a href="http://www.minimalcomps.com/" target="_blank">Minimal Comps</a> by <a href="http://www.bit-101.com/blog/" target="_blank">Keith Peters</a>.</p>

<p><a href="http://assets.newtriks.com.s3.amazonaws.com/newtriks_blog/images/2011/04/Screen-shot-2011-04-06-at-11.46.10.png"><img src="http://assets.newtriks.com.s3.amazonaws.com/newtriks_blog/images/2011/04/Screen-shot-2011-04-06-at-11.46.10-300x249.png" alt="PlayaHater – FLV Player" title="PlayaHater – FLV Player" width="300" height="249" class="aligncenter size-medium wp-image-1259" /></a></p>

<!--more-->


<p>The idea was spawned whilst at Flash On The Beach and I was chatting to another Flash developer about OSMF. We were both not overly keen on the framework (in certain scenarios) and he went onto explain he re-uses the building blocks of an FLV player he built based on Minimal Comps, which I thought was a great idea. Feel free to fork and add to the project on <a href="https://github.com/newtriks/PlayaHater" target="_blank">GitHub</a> (improvements are welcomed) or download and use at your leisure for rapid testing within your projects. This is not intended to be a feature rich player to be used on live sites, its simply a light weight solution for developers involved with media related applications.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Passing an Array Argument To Shell Using CFExecute]]></title>
    <link href="http://newtriks.com/2011/04/06/passing-an-array-argument-to-shell-using-cfexecute/"/>
    <updated>2011-04-06T10:42:29+01:00</updated>
    <id>http://newtriks.com/2011/04/06/passing-an-array-argument-to-shell-using-cfexecute</id>
    <content type="html"><![CDATA[<p>Here&#8217;s a small post offering a solution to an issue I had recently. My goal was to <a href="http://www.cyberciti.biz/faq/run-execute-sh-shell-script/" target="_blank">run a shell script using cfexecute</a>, one of the arguments being an Array itself. If your passing arguments in this manner on Linux (my flavour) elements are copied into an array of <a href="http://linux.about.com/od/commands/l/blcmdln_exec.htm" target="_blank">exec()</a> arguments and I kept getting an error back from ColdFusion stating I was trying to pass off a complex object as a simple one (or something along those lines - makes sense). So the key was trying to fathom out how to pass my array of Strings to this Shell script, after a bit of trial and error I got it working by doing the following:<!--more-->
+ From Flex I now join the Array of Strings to form a space separated String e.g. myArrayOfStrings.join(&#8217; &#8216;);
+   I then create an Array of arguments in ColdFusion to pass to the Shell script:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>&lt;cfset args = arrayNew(1)&gt;
</span><span class='line'>&lt;cfset args[1] = #foo#&gt;
</span><span class='line'>&lt;cfset args[2] = #joined_strings#&gt;
</span><span class='line'>
</span><span class='line'>&lt;cfexecute name = &quot;myscript.sh&quot;
</span><span class='line'>             arguments = &quot;#args#&quot;
</span><span class='line'>                 variable=&quot;_result&quot;
</span><span class='line'>             errorVariable=&quot;_error&quot;
</span><span class='line'>                 timeout = &quot;99&quot;&gt;
</span><span class='line'>&lt;/cfexecute&gt;</span></code></pre></td></tr></table></div></figure>


<ul>
<li>And lastly in the Shell script I create an Array from the joined_strings argument, looping through this and performing necessary actions on each element:</li>
</ul>


<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>#!/bin/bash
</span><span class='line'>NAME=$1
</span><span class='line'>STR=$2
</span><span class='line'>STRINGS=(${STR[*]})
</span><span class='line'>echo: foo: $NAME
</span><span class='line'>for ix in ${!STRINGS[*]}
</span><span class='line'>do
</span><span class='line'>    echo &quot;${STRINGS[$ix]}&quot;
</span><span class='line'>done</span></code></pre></td></tr></table></div></figure>


<p>Output in Flex:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>[trace] foo: newtriks
</span><span class='line'>[trace] &quot;one&quot;
</span><span class='line'>[trace] &quot;two&quot;</span></code></pre></td></tr></table></div></figure>


<p>This is not my area of expertise so if anyone can offer better solutions they would be appreciated.</p>

<p>This <a href="http://www.linuxjournal.com/content/bash-arrays" target="_blank">link</a> helped with the final hurdle, thank you to the author!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Handling Property Changes in a Spark Custom ItemRenderer]]></title>
    <link href="http://newtriks.com/2011/04/06/handling-property-changes-in-a-spark-custom-itemrenderer/"/>
    <updated>2011-04-06T10:37:02+01:00</updated>
    <id>http://newtriks.com/2011/04/06/handling-property-changes-in-a-spark-custom-itemrenderer</id>
    <content type="html"><![CDATA[<p>I recently got asked about how I store and retrieve data within a Spark DataGroup using a custom ItemRenderer, with a particular focus on how to monitor property changes. There are a few ways to achieve this, particularly when it comes to storing and retrieving data, here is one simple example using a CheckBox within a custom ItemRenderer and observing the total selected CheckBoxes.</p>

<p>Here I will detail the main snippets of functionality, download the actual source (links at bottom of the post) to get the full picture.</p>

<!--more-->


<p>I tend to programme more in ActionScript as opposed to mxml, this is just my personal preference, however, lets do things a bit different and create a ValueObject using mxml and bind the selectedItems property to the selectedItems getter within custom List:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>&lt;fx:Declarations&gt;
</span><span class='line'>        &lt;!-- demo dataprovider --&gt;
</span><span class='line'>        &lt;fx:Array id=&quot;dp&quot;&gt;
</span><span class='line'>            &lt;vo:Item itemName=&quot;Iron Man&quot;/&gt;
</span><span class='line'>            &lt;vo:Item itemName=&quot;Spiderman&quot;/&gt;
</span><span class='line'>        &lt;/fx:Array&gt;
</span><span class='line'>        &lt;!-- Custom vo --&gt;
</span><span class='line'>        &lt;vo:CustomVO id=&quot;model&quot;&gt;
</span><span class='line'>            &lt;vo:selectedItems&gt;{itemList.selectedItems}&lt;/vo:selectedItems&gt;
</span><span class='line'>        &lt;/vo:CustomVO&gt;
</span><span class='line'>    &lt;/fx:Declarations&gt;</span></code></pre></td></tr></table></div></figure>


<p>In a custom List create a Bindable getter that the VO selectedItems property (see above) is bound to:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>[Bindable(event=&quot;propertyChange&quot;)]
</span><span class='line'>public function get selectedItems():Array
</span><span class='line'>{
</span><span class='line'>     return _items;
</span><span class='line'>}</span></code></pre></td></tr></table></div></figure>


<p>In the List create a handler for the dataChange Event:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>protected function handleCreationComplete(event:FlexEvent):void
</span><span class='line'>{
</span><span class='line'>    list.addEventListener(FlexEvent.DATA_CHANGE, handleItemSelected);
</span><span class='line'>}</span></code></pre></td></tr></table></div></figure>


<p>Still within the List add a method to loop through the data provider to retrieve all the currently selected items. This will change the selectedItems total count and update bindings by dispatching a propertyChange Event:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>protected function handleItemSelected(event:FlexEvent):void
</span><span class='line'>{
</span><span class='line'>    setSelectedItems();
</span><span class='line'>}
</span><span class='line'>
</span><span class='line'>protected function setSelectedItems():void
</span><span class='line'>{
</span><span class='line'>    var i:int;
</span><span class='line'>    var length:int=dataProvider.length;
</span><span class='line'>    var item:Item;
</span><span class='line'>    _items=[];
</span><span class='line'>    for(i=0; i&lt;length; i++)
</span><span class='line'>    {
</span><span class='line'>        item=dataProvider.getItemAt(i) as Item;
</span><span class='line'>        if(item.itemSelected)
</span><span class='line'>        {
</span><span class='line'>            _items.push(item);
</span><span class='line'>        }
</span><span class='line'>    }
</span><span class='line'>    dispatchEvent(new Event(&quot;propertyChange&quot;));
</span><span class='line'>}</span></code></pre></td></tr></table></div></figure>


<p>Within the custom ItemRenderer a data Object is going to be assigned a custom VO named Item with the following properties:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>public var itemName:String;
</span><span class='line'>public var itemSelected:Boolean=false;</span></code></pre></td></tr></table></div></figure>


<p>In the ItemRenderer assign a handler to the CheckBox change Event and update the data&#8217;s itemSelected property. If the itemSelected property has changed then dispatch a dataChange Event, this will ensure all the Bindings are kept in sync thus updating our custom VO in the main class.</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>protected function handleSelectionChange():void
</span><span class='line'>{
</span><span class='line'>    if(data.itemSelected==item_cb.selected) return;
</span><span class='line'>    data.itemSelected=item_cb.selected;
</span><span class='line'>    this.dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE, true));
</span><span class='line'>}</span></code></pre></td></tr></table></div></figure>


<p>This is a simple example as I stated above and there are many ways to achieve the final goal.</p>

<p>Hopefully this will help someone out there, and if you want to read more about Bindings then view my <a href="http://www.newtriks.com/?p=832">BindingUtils chain</a> and <a href="http://www.newtriks.com/?p=793">DataBinding a Proxy to a Mediator</a> posts.</p>

<p>View the <a href="http://demo.newtriks.com/flex/ItemRendererDataExample/">example</a>
[wpfilebase tag=file id=1]</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[ColdFusion Unit Testing with MXUnit and IntelliJ IDEA]]></title>
    <link href="http://newtriks.com/2011/01/13/coldfusion-unit-testing-with-mxunit-and-intellij-idea/"/>
    <updated>2011-01-13T13:05:40+00:00</updated>
    <id>http://newtriks.com/2011/01/13/coldfusion-unit-testing-with-mxunit-and-intellij-idea</id>
    <content type="html"><![CDATA[<p>This post will show you how to get quickly up and running Unit Testing with ColdFusion and IntelliJ IDEA.  As an example I will show you how to create a simple CFC with its corresponding unit test using MXUnit and then run the test locally in your browser.  This mirrors the project example in the similar post I made earlier on in the week: <a href="http://www.newtriks.com/?p=1119" target="_blank">ColdFusion Unit Testing with MXUnit and TextMate</a>.</p>

<!--more-->


<p>1) Install IntelliJ IDEA:</p>

<p><a href="http://www.jetbrains.com/idea/download/" target="_blank">jetbrains.com/idea/download/</a></p>

<p>2) Download and follow setup instructions for MXUnit (<a href="http://mxunit.org/" target="_blank">mxunit.org</a>).</p>

<p>3) Create a new project in IntelliJ: File > New Project.</p>

<p>4) Keep the default <em>Create project from scratch</em> option and click next.</p>

<p>5) Name your project <em>example_project</em> and ensure your project files location is in your ColdFusion root e.g. <em>/Users/newtriks/Sites/example_project</em></p>

<p>6) Ensure create module is selected and the module to use is the default Java Module and click next.</p>

<p>7) Select do not create a src directory and then click next and then finish.</p>

<p>8) Create an Application.cfc in the root of <em>example_project</em> by right clicking on the <em>example_project</em> directory > New > ColdFusion Tag Component and enter the following:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>&lt;cfcomponent output=&quot;false&quot;&gt;
</span><span class='line'>  &lt;!--- set up per application mappings ---&gt;
</span><span class='line'>  &lt;cfset this.mappings = {}&gt;
</span><span class='line'>  &lt;cfset this.mappings[&quot;/com&quot;] = GetDirectoryFromPath( GetCurrentTemplatePath() ) &amp; &quot;com&quot;&gt;
</span><span class='line'>&lt;/cfcomponent&gt;</span></code></pre></td></tr></table></div></figure>


<p>9) Create a new directory in <em>example_project</em> and name it <em>com</em>.</p>

<p>10) Within the newly created <em>com</em> directory create a new file named <em>App.cfc</em> and enter the following code:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>&lt;cfcomponent&gt;
</span><span class='line'>    &lt;cffunction name=&quot;addRapper&quot; 
</span><span class='line'>              access=&quot;remote&quot;
</span><span class='line'>              returntype=&quot;any&quot;&gt;
</span><span class='line'>      &lt;cfargument name=&quot;rapperName&quot; 
</span><span class='line'>                  type=&quot;string&quot; 
</span><span class='line'>                  required=&quot;true&quot; 
</span><span class='line'>                  hint=&quot;Name of a rapper&quot;&gt;
</span><span class='line'>      &lt;cfscript&gt;
</span><span class='line'>          var dummyResult=StructNew();
</span><span class='line'>          dummyResult.name=rapperName;
</span><span class='line'>            return dummyResult;
</span><span class='line'>      &lt;/cfscript&gt;
</span><span class='line'>  &lt;/cffunction&gt;
</span><span class='line'>&lt;/cfcomponent&gt;</span></code></pre></td></tr></table></div></figure>


<p>11) Create the following package structure:</p>

<p>example_project > test</p>

<p>12) Within the <em>test</em> directory create <em>AppTest.cfc</em> and enter the following:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>&lt;cfcomponent extends=&quot;mxunit.framework.TestCase&quot;&gt;
</span><span class='line'>  &lt;cffunction name=&quot;setUp&quot; returntype=&quot;void&quot; access=&quot;public&quot; hint=&quot;Setup prior to running tests&quot;&gt;
</span><span class='line'>      &lt;cfset obj = createObject(&quot;component&quot;,&quot;com.App&quot;)&gt;
</span><span class='line'>  &lt;/cffunction&gt;
</span><span class='line'>  &lt;cffunction name=&quot;tearDown&quot; returntype=&quot;void&quot; access=&quot;public&quot; hint=&quot;Tear down post running tests&quot;&gt;
</span><span class='line'>      &lt;!--- cleanup ---&gt;
</span><span class='line'>  &lt;/cffunction&gt;
</span><span class='line'>  &lt;cffunction name=&quot;testAddRapper&quot; returntype=&quot;void&quot; access=&quot;public&quot;&gt;
</span><span class='line'>      &lt;cfscript&gt;
</span><span class='line'>          var rapperName=&quot;Kool Keith&quot;;
</span><span class='line'>          var result = obj.addRapper(rapperName);
</span><span class='line'>          debug(result);
</span><span class='line'>          assertEquals(rapperName,result.NAME);
</span><span class='line'>      &lt;/cfscript&gt;
</span><span class='line'>  &lt;/cffunction&gt;
</span><span class='line'>&lt;/cfcomponent&gt;</span></code></pre></td></tr></table></div></figure>


<p>13) Select: Run > Edit Configurations and add a new configuration by clicking the plus icon in the top left corner.</p>

<p>14) Select ColdFusion in the list of available run configurations and name it <em>test-example</em>.</p>

<p>15) In the web path input field enter the below url (amend your localhost param accordingly) and click OK:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>http://localhost/example_project/test/AppTest.cfc?method=runTestRemote</span></code></pre></td></tr></table></div></figure>


<p>16) Select Run > Run or click the green triangle in the toolbar.  You should see the below image:
<a href="http://assets.newtriks.com.s3.amazonaws.com/newtriks_blog/images/2011/01/Screen-shot-2011-01-13-at-09.39.35.png"><img src="http://assets.newtriks.com.s3.amazonaws.com/newtriks_blog/images/2011/01/Screen-shot-2011-01-13-at-09.39.35.png" alt="MXunit Test" title="MXunit Test" width="647" height="212" class="aligncenter size-full wp-image-1214" /></a></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Create a Custom Generator With Project Sprouts V1]]></title>
    <link href="http://newtriks.com/2011/01/12/create-a-custom-generator-with-project-sprouts-v1/"/>
    <updated>2011-01-12T13:30:39+00:00</updated>
    <id>http://newtriks.com/2011/01/12/create-a-custom-generator-with-project-sprouts-v1</id>
    <content type="html"><![CDATA[<p>I have finally managed to find the time to dig deeper into the world of <a href="http://projectsprouts.org/" target="_blank">Project Sprouts</a> and am excited about the Version 1 release which hosts a collective of changes and improvements in comparison to its predecessor V 0.7.  If your unaware of Project Sprouts then I actively encourage you to visit their <a href="http://projectsprouts.org/" target="_blank">homepage</a> and have a read over what its all about.</p>

<p>Time saving utilities are crucial as a developer to help cut down on repetitive tedious tasks and also to help reduce errors.  Applications such as <a href="http://smilesoftware.com/TextExpander/" target="_blank">Text Expander</a> was one great time saving tool and then when I discovered <a href="http://blogs.jetbrains.com/idea/2010/01/flex-live-templates/" target="_blank">live templates</a> in <a href="http://www.jetbrains.com/idea/" target="_blank">IntelliJ IDEA</a>, I truly saw the rewards of code generation, especially when  combined with <a href="http://ant.apache.org/" target="_blank">ANT</a> for project builds.  Project Sprouts takes time saving to a completely new level, accelerating project development workflow in a well structured and logical format.</p>

<p>What I was keen on understanding was where it would help me the most (initially at least) and that is project and class <a href="http://projectsprouts.org/2010/12/31/using-generators.html" target="_blank">Generators</a> (also <a href="http://projectsprouts.org/docs/1.1/Sprout/Generator.html" target="_blank">read</a>).</p>

<blockquote><p>Sprout generators should be installed by RubyGems as command line applications on your system. After installing the flashsdk gem, you should have access to a variety of generators&#8230;..Some generators are expected to create new projects, others expect to run within existing projects.</p></blockquote>

<p><a href="http://www.xxcoder.net/" target="_blank">Stray</a> kindly hooked me up with her <a href="https://github.com/Stray/project-sprouts-robot-legs-bundle">RobotLegs bundle</a> to get me started (this is specific to V0.7 of Sprouts) and I also found the <a href="https://github.com/kristoferjoseph/sprout-robotlegs" target="_blank">library by Kristofer Joseph</a> which I understand <a href="http://twitter.com/lukebayes" target="_blank">Luke Bayes (Project Sprout creator)</a> has assisted on also.  Kristofer&#8217;s library has been updated for the V1 release of Project Sprouts and is in turn an excellent resource to understand the hooks required for using Generators in the latest Project Sprouts release (combined with reading the <a href="http://projectsprouts.org/docs/1.1/FlashSDK.html" target="_blank">documentation</a> and <a href="https://github.com/lukebayes/sprout-flashsdk" target="_blank">source</a> of the Sprout-FlashSDK Gem).</p>

<p>I wanted to gain an understanding of building my own Generators and wanted to help detail the steps necessary to achieve this task.  The rest of this post outlines how to create a custom class generator using a combination of command line (<em>note</em> I am on Mac OS X) and code editing (I use <a href="http://macromates.com/" target="_blank">TextMate</a>, feel free to choose your tool).  l define a custom Event template and write a Generator for it, including simple <a href="http://en.wikipedia.org/wiki/Test-driven_development" target="_blank">Unit Tests</a> and obviously a project example.</p>

<!--more-->


<p><strong>Pre-Requirements:</strong></p>

<ul>
<li>Download and install RVM: <a href="http://rvm.beginrescueend.com/" target="_blank">rvm.beginrescueend.com</a>.  This is not necessarily a requirement but saves a load of potential grief with permissions etc so is highly recommended.</li>
<li>Install follow instructions for ProjectSprouts setup: <a href="http://projectsprouts.org/" target="_blank">projectsprouts.org</a>.</li>
</ul>


<p><strong>1. Create a new Ruby project using the sprout-ruby generator:</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>Newtriks-MB:~ newtriks$ cd ~/Development/dev/
</span><span class='line'>
</span><span class='line'>Newtriks-MB:dev newtriks$ sprout-ruby CustomGenerators
</span><span class='line'>Created directory: ./custom_generators
</span><span class='line'>Created file:      ./custom_generators/Gemfile
</span><span class='line'>Created file:      ./custom_generators/Rakefile
</span><span class='line'>Created file:      ./custom_generators/custom_generators.gemspec
</span><span class='line'>Created directory: ./custom_generators/lib
</span><span class='line'>Created file:      ./custom_generators/lib/custom_generators.rb
</span><span class='line'>Created directory: ./custom_generators/lib/custom_generators
</span><span class='line'>Created file:      ./custom_generators/lib/custom_generators/base.rb
</span><span class='line'>Created directory: ./custom_generators/test
</span><span class='line'>Created directory: ./custom_generators/test/fixtures
</span><span class='line'>Created directory: ./custom_generators/test/unit
</span><span class='line'>Created file:      ./custom_generators/test/unit/custom_generators_test.rb
</span><span class='line'>Created file:      ./custom_generators/test/unit/test_helper.rb
</span><span class='line'>Created directory: ./custom_generators/bin
</span><span class='line'>Created file:      ./custom_generators/bin/custom-generators</span></code></pre></td></tr></table></div></figure>


<p><strong>2. CD into the newly created project and create a new Ruby Gem using sprout-generator:</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
<span class='line-number'>26</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>Newtriks-MB:dev newtriks$ cd custom_generators
</span><span class='line'> 
</span><span class='line'>Newtriks-MB:custom_generators newtriks$ sprout-generator MyEvent
</span><span class='line'>[INFO] It seems you already have a Gemfile in this project, please be sure it has the following content:
</span><span class='line'> 
</span><span class='line'>  gem &quot;sprout&quot;, &quot;&gt;= #{Sprout::VERSION::STRING}&quot;
</span><span class='line'> 
</span><span class='line'>  group :development do
</span><span class='line'>    gem &quot;shoulda&quot;
</span><span class='line'>    gem &quot;mocha&quot;
</span><span class='line'>  end
</span><span class='line'> 
</span><span class='line'>Skipped directory: ./bin
</span><span class='line'>Created file:      ./bin/my-event
</span><span class='line'>Skipped directory: ./lib
</span><span class='line'>Skipped directory: ./lib/
</span><span class='line'>Created directory: ./lib/generators
</span><span class='line'>Created file:      ./lib/generators/my_event_generator.rb
</span><span class='line'>Created directory: ./lib/generators/templates
</span><span class='line'>Created file:      ./lib/generators/templates/MyEvent.as
</span><span class='line'>Skipped directory: ./test
</span><span class='line'>Skipped directory: ./test/unit
</span><span class='line'>Created file:      ./test/unit/my_event_generator_test.rb
</span><span class='line'>Skipped file:      ./test/unit/test_helper.rb
</span><span class='line'>Skipped directory: ./test/fixtures
</span><span class='line'>Created directory: ./test/fixtures/generators</span></code></pre></td></tr></table></div></figure>


<p><strong>3. Keep things as simple as we can for now and only unit test the custom Event generation, so remove the custom_generators_test:</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>rm ./test/unit/custom_generators_test.rb</span></code></pre></td></tr></table></div></figure>


<p><strong>4. Run a rake test (we know this will fail):</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
<span class='line-number'>26</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>Newtriks-MB:custom_generators newtriks$ rake test
</span><span class='line'>(in /Users/newtriks/Development/dev/custom_generators)
</span><span class='line'>/Users/newtriks/.rvm/rubies/ruby-1.9.2-p136/bin/ruby -I&quot;lib:test/unit&quot; &quot;/Users/newtriks/.rvm/gems/ruby-1.9.2-p136/gems/rake-0.8.7/lib/rake/rake_test_loader.rb&quot; &quot;test/unit/my_event_generator_test.rb&quot;
</span><span class='line'>Loaded suite /Users/newtriks/.rvm/gems/ruby-1.9.2-p136/gems/rake-0.8.7/lib/rake/rake_test_loader
</span><span class='line'>Started
</span><span class='line'>E
</span><span class='line'>Finished in 0.006820 seconds.
</span><span class='line'> 
</span><span class='line'>  1) Error:
</span><span class='line'>test: A new MyEvent generator should generate a new MyEvent. (MyEventGeneratorTest):
</span><span class='line'>RuntimeError:  - 'This is your generator template' should include '(?-mix:Your content to assert here)'
</span><span class='line'>    /Users/newtriks/.rvm/gems/ruby-1.9.2-p136/gems/sprout-1.1.7.pre/lib/sprout/test_helper.rb:232:in `assert_matches'
</span><span class='line'>    test/unit/my_event_generator_test.rb:54:in `block (3 levels) in &lt;class:MyEventGeneratorTest&gt;'
</span><span class='line'>    /Users/newtriks/.rvm/gems/ruby-1.9.2-p136/gems/sprout-1.1.7.pre/lib/sprout/test_helper.rb:186:in `assert_file'
</span><span class='line'>    test/unit/my_event_generator_test.rb:51:in `block (2 levels) in &lt;class:MyEventGeneratorTest&gt;'
</span><span class='line'>    /Users/newtriks/.rvm/gems/ruby-1.9.2-p136/gems/shoulda-2.11.3/lib/shoulda/context.rb:382:in `call'
</span><span class='line'>    /Users/newtriks/.rvm/gems/ruby-1.9.2-p136/gems/shoulda-2.11.3/lib/shoulda/context.rb:382:in `block in create_test_from_should_hash'
</span><span class='line'>    /Users/newtriks/.rvm/gems/ruby-1.9.2-p136/gems/mocha-0.9.10/lib/mocha/integration/mini_test/version_142_and_above.rb:27:in `run'
</span><span class='line'> 
</span><span class='line'>1 tests, 2 assertions, 0 failures, 1 errors, 0 skips
</span><span class='line'> 
</span><span class='line'>Test run options: --seed 12221
</span><span class='line'>rake aborted!
</span><span class='line'>Command failed with status (1): [/Users/newtriks/.rvm/rubies/ruby-1.9.2-p13...]
</span><span class='line'> 
</span><span class='line'>(See full trace by running task with --trace)</span></code></pre></td></tr></table></div></figure>


<p><strong>Open project in TextMate (or IDE of your choice):</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>Newtriks-MB:custom_generators newtriks$ mate .</span></code></pre></td></tr></table></div></figure>


<p><strong><strong> EDIT WITHIN TEXTMATE </strong></strong></p>

<p><strong>5. Create a simple method to test for class creation:</strong></p>

<p>-> edit: test > unit > my_event_generator_test.rb</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>should &quot;generate a new MyEvent&quot; do
</span><span class='line'>    # provide example input:
</span><span class='line'>    @generator.input = &quot;MyEvent&quot;
</span><span class='line'>    @generator.execute
</span><span class='line'> 
</span><span class='line'>    input_dir = File.join @temp, &quot;my_event&quot;
</span><span class='line'>    assert_directory input_dir
</span><span class='line'> 
</span><span class='line'>    input_file = File.join input_dir, &quot;MyEvent.as&quot;
</span><span class='line'>    # test input dir exists
</span><span class='line'>    assert_directory input_dir
</span><span class='line'>    # test input create a class of the same name in input dir
</span><span class='line'>    assert_file File.join(@temp, 'my_event', 'MyEvent.as')
</span><span class='line'>end</span></code></pre></td></tr></table></div></figure>


<p><strong><strong> / END EDIT WITHIN TEXTMATE </strong></strong></p>

<p><strong>6. Run the rake test again:</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>Newtriks-MB:custom_generators newtriks$ rake test
</span><span class='line'>(in /Users/newtriks/Development/dev/custom_generators)
</span><span class='line'>/Users/newtriks/.rvm/rubies/ruby-1.9.2-p136/bin/ruby -I&quot;lib:test/unit&quot; &quot;/Users/newtriks/.rvm/gems/ruby-1.9.2-p136/gems/rake-0.8.7/lib/rake/rake_test_loader.rb&quot; &quot;test/unit/my_event_generator_test.rb&quot;
</span><span class='line'>Loaded suite /Users/newtriks/.rvm/gems/ruby-1.9.2-p136/gems/rake-0.8.7/lib/rake/rake_test_loader
</span><span class='line'>Started
</span><span class='line'>.
</span><span class='line'>Finished in 0.006958 seconds.
</span><span class='line'> 
</span><span class='line'>1 tests, 3 assertions, 0 failures, 0 errors, 0 skips
</span><span class='line'> 
</span><span class='line'>Test run options: --seed 36007</span></code></pre></td></tr></table></div></figure>


<p><strong>7. Test a build and install, note does not show up in gemlist:</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>Newtriks-MB:custom_generators newtriks$ gem build custom_generators.gemspec
</span><span class='line'>WARNING:  bin/custom-generators is missing #! line
</span><span class='line'>  Successfully built RubyGem
</span><span class='line'>  Name: custom_generators
</span><span class='line'>  Version: 0.0.0.pre
</span><span class='line'>  File: custom_generators-0.0.0.pre.gem
</span><span class='line'>Newtriks-MB:custom_generators newtriks$ gem install --local custom_generators
</span><span class='line'>Successfully installed custom_generators-0.0.0.pre
</span><span class='line'>1 gem installed
</span><span class='line'>Installing ri documentation for custom_generators-0.0.0.pre...
</span><span class='line'>Installing RDoc documentation for custom_generators-0.0.0.pre...</span></code></pre></td></tr></table></div></figure>




<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>Newtriks-MB:custom_generators newtriks$ gem list
</span><span class='line'> 
</span><span class='line'>*** LOCAL GEMS ***
</span><span class='line'> 
</span><span class='line'>archive-tar-minitar (0.5.2)
</span><span class='line'>asunit4 (4.2.2.pre)
</span><span class='line'>bundler (1.0.7)
</span><span class='line'>custom (0.0.4.pre, 0.0.3.pre, 0.0.2.pre, 0.0.1.pre)
</span><span class='line'>flashsdk (1.0.18.pre)
</span><span class='line'>mocha (0.9.10)
</span><span class='line'>open4 (1.0.1)
</span><span class='line'>rake (0.8.7)
</span><span class='line'>rubygems-update (1.4.2, 1.4.1)
</span><span class='line'>rubyzip (0.9.4)
</span><span class='line'>shoulda (2.11.3)
</span><span class='line'>sprout (1.1.7.pre)</span></code></pre></td></tr></table></div></figure>


<p><strong><strong> EDIT WITHIN TEXTMATE </strong></strong></p>

<p><strong>8. Increase our RubyGem version number:</strong></p>

<p>-> edit: lib > custom_generators.rb</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>VERSION = '0.0.1.pre'</span></code></pre></td></tr></table></div></figure>


<p><strong><strong> / END EDIT WITHIN TEXTMATE </strong></strong></p>

<p><strong>9. Build the custom gem:</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>Newtriks-MB:custom_generators newtriks$ gem build custom_generators.gemspec
</span><span class='line'>  Successfully built RubyGem
</span><span class='line'>  Name: custom_generators
</span><span class='line'>  Version: 0.0.0.pre
</span><span class='line'>  File: custom_generators-0.0.0.pre.gem</span></code></pre></td></tr></table></div></figure>


<p><strong>10. Locally install our custom gem:</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>Newtriks-MB:custom_generators newtriks$ gem install --local custom_generators
</span><span class='line'>Successfully installed custom_generators-0.0.1.pre
</span><span class='line'>1 gem installed
</span><span class='line'>Installing ri documentation for custom_generators-0.0.1.pre...
</span><span class='line'>Installing RDoc documentation for custom_generators-0.0.1.pre...</span></code></pre></td></tr></table></div></figure>


<p><strong>Note it is now displaying in the local gem list:</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>Newtriks-MB:custom_generators newtriks$ gem list
</span><span class='line'>*** LOCAL GEMS ***
</span><span class='line'>
</span><span class='line'>archive-tar-minitar (0.5.2)
</span><span class='line'>asunit4 (4.2.2.pre)
</span><span class='line'>bundler (1.0.7)
</span><span class='line'>custom_generators (0.0.1.pre)
</span><span class='line'>flashsdk (1.0.18.pre)
</span><span class='line'>mocha (0.9.10)
</span><span class='line'>open4 (1.0.1)
</span><span class='line'>rake (0.8.7)
</span><span class='line'>rubygems-update (1.4.2, 1.4.1)
</span><span class='line'>rubyzip (0.9.4)
</span><span class='line'>shoulda (2.11.3)
</span><span class='line'>sprout (1.1.7.pre)</span></code></pre></td></tr></table></div></figure>


<p><strong><strong> EDIT WITHIN TEXTMATE </strong></strong></p>

<p><strong>11. Start steps to extend the FlashSDK Gem, firstly define the dependency in the Gemfile:</strong></p>

<p>-> edit: Gemfile</p>

<p>Add:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>gem 'flashsdk', '&gt;= 1.0.13.pre'</span></code></pre></td></tr></table></div></figure>


<p><strong>Ensure the actual generator includes the library:</strong></p>

<p>-> edit: lib > custom_generators.rb</p>

<p>Add:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>require 'flashsdk'</span></code></pre></td></tr></table></div></figure>


<p><strong>12. Define the custom generator template, here we will simply create a custom event making use of the package_name and class_name variables:</strong></p>

<p>These package name and class name variables are processed by Sprouts using your arguments. There are several pre-processed variables you can use: full_class_name, class_name and package_name all use dot syntax (full_class_name is the package.Class value), while class_file and class_dir are path/file values relative to your source directory.</p>

<p>-> edit: lib > generators > templates > MyEvent.as</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>package &lt;%= package_name %&gt;{
</span><span class='line'>    import flash.events.Event;
</span><span class='line'> 
</span><span class='line'>    public class &lt;%= class_name %&gt; extends Event {
</span><span class='line'> 
</span><span class='line'>        public function &lt;%= class_name %&gt;(type:String,
</span><span class='line'>                bubbles:Boolean=false,
</span><span class='line'>                cancelable:Boolean=false) {
</span><span class='line'>            super(type, bubbles, cancelable);
</span><span class='line'>        }
</span><span class='line'> 
</span><span class='line'>        override public function clone():Event {
</span><span class='line'>            return new &lt;%= class_name %&gt;(type, bubbles, cancelable);
</span><span class='line'>        }
</span><span class='line'>    }
</span><span class='line'>}</span></code></pre></td></tr></table></div></figure>


<p>-> edit: lib > generators > my_event_generator.rb</p>

<p><strong>13. Update the logic within the custom event class generator, note extending the FlashSDK Gem</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>module CustomGenerators
</span><span class='line'>  ##
</span><span class='line'>  # This is where you describe your new Generator.
</span><span class='line'>  class MyEventGenerator &lt;FlashSDK Gem::ClassGenerator
</span><span class='line'> 
</span><span class='line'>    def manifest
</span><span class='line'>        directory class_directory do
</span><span class='line'>          template &quot;#{class_name}.as&quot;, 'MyEvent.as'
</span><span class='line'>        end
</span><span class='line'>    end
</span><span class='line'> 
</span><span class='line'>  end
</span><span class='line'>end</span></code></pre></td></tr></table></div></figure>


<p><strong>14. Amend the gem to include the FlashSDK Gem:</strong></p>

<p>-> edit: bin > my-event</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>#!/usr/bin/env ruby
</span><span class='line'>
</span><span class='line'>require 'rubygems'
</span><span class='line'>require 'flashsdk'
</span><span class='line'>require 'generators/my_event_generator'
</span><span class='line'>
</span><span class='line'>generator = CustomGenerators::MyEventGenerator.new
</span><span class='line'>generator.parse! ARGV
</span><span class='line'>generator.execute</span></code></pre></td></tr></table></div></figure>


<p><strong>15. Increase the version number of the gem:</strong></p>

<p>-> edit: lib > custom_generators.rb</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>VERSION = '0.0.2.pre'</span></code></pre></td></tr></table></div></figure>


<p><strong>16. Change our custom generator namespace:</strong></p>

<p>-> edit: test > unit > my_event_generator_test.rb</p>

<p>Change:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class=''><span class='line'># Instantiate the generator:
</span><span class='line'>@generator        = Sprout::MyEventGenerator.new</span></code></pre></td></tr></table></div></figure>


<p>To:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class=''><span class='line'># Instantiate the generator:
</span><span class='line'>@generator        = CustomGenerators::MyEventGenerator.new</span></code></pre></td></tr></table></div></figure>


<p><strong>17. Update the unit test method accordingly:</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>should &quot;generate a new CustomEvent using MyEvent template&quot; do
</span><span class='line'>    # provide example input:
</span><span class='line'>    @generator.input = &quot;CustomEvent&quot;
</span><span class='line'>    @generator.execute
</span><span class='line'> 
</span><span class='line'>    assert_file File.join(@temp, 'src', 'CustomEvent.as')
</span><span class='line'>end</span></code></pre></td></tr></table></div></figure>


<p><strong><strong> / END EDIT WITHIN TEXTMATE </strong></strong></p>

<p><strong>18. Install required gems:</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>Newtriks-MB:custom_generators newtriks$ bundle install
</span><span class='line'>Using rake (0.8.7) 
</span><span class='line'>Using archive-tar-minitar (0.5.2) 
</span><span class='line'>Using bundler (1.0.7) 
</span><span class='line'>Using open4 (1.0.1) 
</span><span class='line'>Using rubyzip (0.9.4) 
</span><span class='line'>Using sprout (1.1.7.pre) 
</span><span class='line'>Using flashsdk (1.0.18.pre) 
</span><span class='line'>Using mocha (0.9.10) 
</span><span class='line'>Using shoulda (2.11.3) 
</span><span class='line'>Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.</span></code></pre></td></tr></table></div></figure>


<p><strong>19. Test the generator:</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>Newtriks-MB:custom_generators newtriks$ rake test
</span><span class='line'>(in /Users/newtriks/Development/dev/custom_generators)
</span><span class='line'>/Users/newtriks/.rvm/rubies/ruby-1.9.2-p136/bin/ruby -I&quot;lib:test/unit&quot; &quot;/Users/newtriks/.rvm/gems/ruby-1.9.2-p136/gems/rake-0.8.7/lib/rake/rake_test_loader.rb&quot; &quot;test/unit/my_event_generator_test.rb&quot;
</span><span class='line'>Loaded suite /Users/newtriks/.rvm/gems/ruby-1.9.2-p136/gems/rake-0.8.7/lib/rake/rake_test_loader
</span><span class='line'>Started
</span><span class='line'>.
</span><span class='line'>Finished in 0.037701 seconds.
</span><span class='line'> 
</span><span class='line'>1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
</span><span class='line'> 
</span><span class='line'>Test run options: --seed 52964</span></code></pre></td></tr></table></div></figure>


<p><strong>20. Build the gem:</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>Newtriks-MB:custom_generators newtriks$ gem build custom_generators.gemspec
</span><span class='line'>  Successfully built RubyGem
</span><span class='line'>  Name: custom_generators
</span><span class='line'>  Version: 0.0.2.pre
</span><span class='line'>  File: custom_generators-0.0.2.pre.gem</span></code></pre></td></tr></table></div></figure>


<p><strong>21. Install the gem locally:</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>Newtriks-MB:custom_generators newtriks$ gem install --local custom_generators
</span><span class='line'>Successfully installed custom_generators-0.0.2.pre
</span><span class='line'>1 gem installed
</span><span class='line'>Installing ri documentation for custom_generators-0.0.2.pre...
</span><span class='line'>Installing RDoc documentation for custom_generators-0.0.2.pre...</span></code></pre></td></tr></table></div></figure>




<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>Newtriks-MB:custom_generators newtriks$ gem list
</span><span class='line'>*** LOCAL GEMS ***
</span><span class='line'>
</span><span class='line'>archive-tar-minitar (0.5.2)
</span><span class='line'>asunit4 (4.2.2.pre)
</span><span class='line'>bundler (1.0.7)
</span><span class='line'>custom_generators (0.0.2.pre, 0.0.1.pre)
</span><span class='line'>flashsdk (1.0.18.pre)
</span><span class='line'>mocha (0.9.10)
</span><span class='line'>open4 (1.0.1)
</span><span class='line'>rake (0.8.7)
</span><span class='line'>rubygems-update (1.4.2, 1.4.1)
</span><span class='line'>rubyzip (0.9.4)
</span><span class='line'>shoulda (2.11.3)
</span><span class='line'>sprout (1.1.7.pre)</span></code></pre></td></tr></table></div></figure>


<p><strong>22. Create a project to test the new generator:</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>Newtriks-MB:custom_generators newtriks$ cd ../
</span><span class='line'>
</span><span class='line'>Newtriks-MB:dev newtriks$ sprout-as3 EventTestProject
</span><span class='line'>Created directory: ./EventTestProject
</span><span class='line'>Created file:      ./EventTestProject/rakefile.rb
</span><span class='line'>Created file:      ./EventTestProject/Gemfile
</span><span class='line'>Created directory: ./EventTestProject/src
</span><span class='line'>Created file:      ./EventTestProject/src/EventTestProject.as
</span><span class='line'>Created file:      ./EventTestProject/src/EventTestProjectRunner.as
</span><span class='line'>Created directory: ./EventTestProject/assets
</span><span class='line'>Created directory: ./EventTestProject/assets/skins
</span><span class='line'>Created file:      ./EventTestProject/assets/skins/DefaultProjectImage.png
</span><span class='line'>Created directory: ./EventTestProject/lib
</span><span class='line'>Created directory: ./EventTestProject/bin
</span><span class='line'>
</span><span class='line'>Newtriks-MB:dev newtriks$ cd EventTestProject</span></code></pre></td></tr></table></div></figure>


<p><strong>23. Run my-event generator:</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>Newtriks-MB:EventTestProject newtriks$ my-event CustomEvent
</span><span class='line'>Skipped directory: ./src
</span><span class='line'>Created file:      ./src/CustomEvent.as</span></code></pre></td></tr></table></div></figure>


<p><strong>24. Destroy previous generator run logic:</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>Newtriks-MB:EventTestProject newtriks$ my-event CustomEvent --destroy
</span><span class='line'>Removed file:                ./src/CustomEvent.as
</span><span class='line'>Skipped remove directory:    ./src
</span><span class='line'>Skipped remove directory:    .</span></code></pre></td></tr></table></div></figure>


<p><strong>25. Re-run my-event generator within a package structure:</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>Newtriks-MB:EventTestProject newtriks$ my-event com.newtriks.events.CustomEvent
</span><span class='line'>Created directory: ./src/com/newtriks/events
</span><span class='line'>Created file:      ./src/com/newtriks/events/CustomEvent.as</span></code></pre></td></tr></table></div></figure>


<p><strong>Successful custom generator generated Class</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>package com.newtriks.events {
</span><span class='line'>  import flash.events.Event;
</span><span class='line'>
</span><span class='line'>    public class CustomEvent extends Event {
</span><span class='line'>
</span><span class='line'>        public function CustomEvent(type:String,
</span><span class='line'>              bubbles:Boolean=false,
</span><span class='line'>              cancelable:Boolean=false) {
</span><span class='line'>          super(type, bubbles, cancelable);
</span><span class='line'>        }
</span><span class='line'>      
</span><span class='line'>      override public function clone():Event {
</span><span class='line'>          return new CustomEvent(type, bubbles, cancelable);
</span><span class='line'>      }
</span><span class='line'>    }
</span><span class='line'>}</span></code></pre></td></tr></table></div></figure>


<p>Further reading:</p>

<p>Gem Bundler: <a href="http://gembundler.com/" target="_blank">gembundler.com</a></p>

<p>Many thanks to <a href="http://twitter.com/stray_and_ruby" target="_blank">@stray_and_ruby</a> and <a href="http://twitter.com/lukebayes" target="_blank">@lukebayes</a> for proof reading the code in this blog post.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[ColdFusion Unit Testing with MXUnit and TextMate]]></title>
    <link href="http://newtriks.com/2011/01/11/coldfusion-unit-testing-with-mxunit-and-textmate/"/>
    <updated>2011-01-11T14:56:05+00:00</updated>
    <id>http://newtriks.com/2011/01/11/coldfusion-unit-testing-with-mxunit-and-textmate</id>
    <content type="html"><![CDATA[<p>This post will show you how to get quickly up and running with ColdFusion, TextMate and MXUnit.  As an example I will show you how to create a simple CFC with its corresponding unit test using MXUnit and then run the test locally within TextMate&#8217;s preview window.</p>

<!--more-->


<p>1) Install TextMate:</p>

<p><a href="http://macromates.com/" target="_blank">macromates.com</a></p>

<p>2) Install the GetBundles tmbundle:</p>

<p><a href="https://github.com/adamsalter/GetBundles.tmbundle" target="_blank">github.com/adamsalter/GetBundles.tmbundle</a></p>

<p>3) In TextMate:</p>

<p>Bundles > GetBundle > Install Bundle.</p>

<p>This will generate a list of available bundles, scroll down the list to ColdFusion and follow instructions to install.</p>

<p>4) Download and follow setup instructions for MXUnit (<a href="http://mxunit.org/" target="_blank">mxunit.org</a>).</p>

<p>5) Create a new directory in your ColdFusion root and name it  <em>example_project</em>.</p>

<p>6) You can now either open TextMate and drag the <em>example_project</em> onto the dock icon, or in Terminal cd to <em>example_project</em> and type:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>mate .</span></code></pre></td></tr></table></div></figure>


<p>7) Create an Application.cfc in the root of <em>example_project</em> by right clicking on the <em>example_project</em> directory in TextMate&#8217;s gutter and enter the following:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>&lt;cfcomponent output=&quot;false&quot;&gt;
</span><span class='line'>  &lt;!--- set up per application mappings ---&gt;
</span><span class='line'>  &lt;cfset this.mappings = {}&gt;
</span><span class='line'>  &lt;cfset this.mappings[&quot;/com&quot;] = GetDirectoryFromPath( GetCurrentTemplatePath() ) &amp; &quot;com&quot;&gt;
</span><span class='line'>&lt;/cfcomponent&gt;</span></code></pre></td></tr></table></div></figure>


<p>8) Create a new directory in <em>example_project</em> and name it <em>com</em>.</p>

<p>9) Within the newly created <em>com</em> directory create a new file named <em>App.cfc</em> and enter the following code:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>&lt;cfcomponent&gt;
</span><span class='line'>    &lt;cffunction name=&quot;addRapper&quot; 
</span><span class='line'>              access=&quot;remote&quot;
</span><span class='line'>              returntype=&quot;any&quot;&gt;
</span><span class='line'>      &lt;cfargument name=&quot;rapperName&quot; 
</span><span class='line'>                  type=&quot;string&quot; 
</span><span class='line'>                  required=&quot;true&quot; 
</span><span class='line'>                  hint=&quot;Name of a rapper&quot;&gt;
</span><span class='line'>      &lt;cfscript&gt;
</span><span class='line'>          var dummyResult=StructNew();
</span><span class='line'>          dummyResult.name=rapperName;
</span><span class='line'>            return dummyResult;
</span><span class='line'>      &lt;/cfscript&gt;
</span><span class='line'>  &lt;/cffunction&gt;
</span><span class='line'>&lt;/cfcomponent&gt;</span></code></pre></td></tr></table></div></figure>


<p>10) Create the following package structure:</p>

<p>example_project > test</p>

<p>11) Within the <em>test</em> directory create <em>AppTest.cfc</em> and enter the following:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>&lt;cfcomponent extends=&quot;mxunit.framework.TestCase&quot;&gt;
</span><span class='line'>  &lt;cffunction name=&quot;setUp&quot; returntype=&quot;void&quot; access=&quot;public&quot; hint=&quot;Setup prior to running tests&quot;&gt;
</span><span class='line'>      &lt;cfset obj = createObject(&quot;component&quot;,&quot;com.App&quot;)&gt;
</span><span class='line'>  &lt;/cffunction&gt;
</span><span class='line'>  &lt;cffunction name=&quot;tearDown&quot; returntype=&quot;void&quot; access=&quot;public&quot; hint=&quot;Tear down post running tests&quot;&gt;
</span><span class='line'>      &lt;!--- cleanup ---&gt;
</span><span class='line'>  &lt;/cffunction&gt;
</span><span class='line'>  &lt;cffunction name=&quot;testAddRapper&quot; returntype=&quot;void&quot; access=&quot;public&quot;&gt;
</span><span class='line'>      &lt;cfscript&gt;
</span><span class='line'>          var rapperName=&quot;Kool Keith&quot;;
</span><span class='line'>          var result = obj.addRapper(rapperName);
</span><span class='line'>          debug(result);
</span><span class='line'>          assertEquals(rapperName,result.NAME);
</span><span class='line'>      &lt;/cfscript&gt;
</span><span class='line'>  &lt;/cffunction&gt;
</span><span class='line'>&lt;/cfcomponent&gt;</span></code></pre></td></tr></table></div></figure>


<p>12) In TextMate go to Bundles > Bundle Editor > Show Bundle Editor.</p>

<p>13)  Select HTML from the list, click on the bottom left + icon in the Bundle Editor selecting New Command.</p>

<p>14) Enter the following command text amending the url to point to your ColdFusion localhost:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>echo &quot;&lt;meta http-equiv='Refresh' content='0;
</span><span class='line'>    URL=http://localhost/~$USER${TM_FILEPATH#$HOME/Sites}?method=runTestRemote'&gt;&quot;</span></code></pre></td></tr></table></div></figure>


<p><a href="http://assets.newtriks.com.s3.amazonaws.com/newtriks_blog/images/2011/01/run_test_command.jpg"><img alt="Run Test Command" src="http://assets.newtriks.com.s3.amazonaws.com/newtriks_blog/images/2011/01/run_test_command.jpg" title="Run Test Command" class="aligncenter" width="600" height="426" /></a></p>

<p>15) Ensure the AppTest.cfc class is open and hit your shortcut keys specified for the newly created command to see the below window</p>

<p><a href="http://assets.newtriks.com.s3.amazonaws.com/newtriks_blog/images/2011/01/test_mxunit_textmate.jpg"><img src="http://assets.newtriks.com.s3.amazonaws.com/newtriks_blog/images/2011/01/test_mxunit_textmate.jpg" alt="MXUnit Result" title="MXUnit Result" width="600" height="540" class="aligncenter size-full wp-image-1148" /></a></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Record And Send a Free Xmas Greeting for Charity]]></title>
    <link href="http://newtriks.com/2010/12/16/record-and-send-a-free-xmas-greeting-for-charity/"/>
    <updated>2010-12-16T13:44:04+00:00</updated>
    <id>http://newtriks.com/2010/12/16/record-and-send-a-free-xmas-greeting-for-charity</id>
    <content type="html"><![CDATA[<p>The guys behind <a href="http://www.present.me" target="_blank">present.me</a> have kindly offered to donate to an orphanage in Haiti for every xmas card that is sent using an app I built here: <a href="http://xmas.present.me" target="_blank">xmas.present.me</a>.  The idea is simple, choose or upload a christmas card, record a 15 second greeting with your webcam and then send it to an email recipient/s.  Present.me will donate $0.10 per email sent, up to a whopping total of $25,000.  So go an record a greeting and have a merry xmas ya&#8217;ll!</p>
]]></content>
  </entry>
  
</feed>

