<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>MetaSkills.net</title>
 
 <link href="http://metaskills.net/" />
 <updated>2012-02-18T09:07:05-05:00</updated>
 <id>http://metaskills.net/</id>
 <author>
   <name>Ken Collins</name>
   <email>ken@metaskills.net</email>
 </author>

 
 <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/metaskills" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="metaskills" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry>
   <title>Pretty Console Logging With Guard::Jasmine &amp;amp; Black Coffee</title>
   <link href="http://metaskills.net/2012/02/01/pretty-console-logging-with-guardjasmine-black-coffee" />
   <updated>2012-02-01T00:00:00-05:00</updated>
   <id>http://metaskills.net/2012/02/01/pretty-console-logging-with-guardjasmine-black-coffee</id>
   <content type="html">
     <![CDATA[<p>
  OK I know I promised that we would start the dive into <a href="/2012/01/17/rails-and-spine-js-jasmine-testing-part-2/">testing your Spine.JS application using Jasmine(rice) in my last article</a>, but this is a good diversion. If you are new to my latest series on Spine.JS and Jasmine, scroll on down to the bottom to the related section and read back. However, for those that might be more familiar with Jasmine and specifically <a href="https://github.com/netzpirat/guard-jasmine">Guard::Jasmine</a> and ever felt the pain that debugging from that terminal window was lacking, read on! Even if your new to Guard::Jasmine and <a href="http://github.com/bradphelan/jasminerice">Jasminerice</a> I still suggest you setup these elegant hacks to make your testing go that much smoother.
</p>


<h2>So What Is The Problem?</h2>

<p>
  Guard::Jasmine allows you to continuously test your JavaScript right from the terminal window just like your Ruby code. The only drawback is that the console debugging is less than helpful. Guard::Jasmine will not allow you do view a string version of every object nor see line numbers of calling files. Both of these are invaluable when your stuck in a testing hole and just need to inspect a few objects. So if you are tired of seeing <code>[object Object]</code> in your Guard::Jasmine output, let's fix it right away.
</p>


<p>
  The first place we need to patch things up is Guard::Jasmine itself. In my <a href="/2012/01/17/rails-and-spine-js-jasmine-testing-part-2/">last article</a> I covered how to monkey patch Jasminerice in a <code>config/initializers/jasminerice.rb</code> file. My Guard::Jasmine freedom patch will be placed in that same file. Pasted below, this does two things vs the <a href="http://github.com/netzpirat/guard-jasmine/blob/master/lib/guard/jasmine/runner.rb">original</a>. First it changes the <code>report_specdoc_logs</code> method to not pass <code>true</code> to the <code>format_log_message</code> method. Second, the <code>format_log_message</code> method itself now has the message regular expression changed to a multi-line scan. It will also look out for a custom prefix tag and allow it to pass through. This is for our pretty objects. Anything else now outputs the message with the file and line number, something previously stripped by Guard::Jasmine.
</p>

<div class="highlight"><pre><code class="ruby"><span class="c1"># coding: utf-8</span>
<span class="k">if</span> <span class="n">defined?</span><span class="p">(</span><span class="no">Jasminerice</span><span class="p">)</span> <span class="o">&amp;&amp;</span> <span class="no">Jasminerice</span><span class="o">.</span><span class="n">environments</span><span class="o">.</span><span class="n">include?</span><span class="p">(</span><span class="no">Rails</span><span class="o">.</span><span class="n">env</span><span class="p">)</span>

  <span class="c1"># Other Jasminerice patches from:</span>
  <span class="c1"># http://metaskills.net/2012/01/17/rails-and-spine-js-jasmine-testing-part-2/</span>
  <span class="c1"># ...</span>
  
  <span class="c1"># Patch Guard::Jasmine to use a custom formatter for log messages that</span>
  <span class="c1"># allows multi-line objects to be printed with the line numbers.</span>
  <span class="k">module</span> <span class="nn">Guard</span>
    <span class="k">class</span> <span class="nc">Jasmine</span>
      <span class="k">module</span> <span class="nn">Runner</span>
        <span class="k">class</span> <span class="o">&lt;&lt;</span> <span class="nb">self</span>
        
          <span class="k">def</span> <span class="nf">report_specdoc_logs</span><span class="p">(</span><span class="n">spec</span><span class="p">,</span> <span class="n">options</span><span class="p">,</span> <span class="n">level</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">spec</span><span class="o">[</span><span class="s1">&#39;logs&#39;</span><span class="o">]</span> <span class="o">&amp;&amp;</span> <span class="p">(</span><span class="n">options</span><span class="o">[</span><span class="ss">:console</span><span class="o">]</span> <span class="o">==</span> <span class="ss">:always</span> <span class="o">||</span> <span class="p">(</span><span class="n">options</span><span class="o">[</span><span class="ss">:console</span><span class="o">]</span> <span class="o">==</span> <span class="ss">:failure</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="n">spec</span><span class="o">[</span><span class="s1">&#39;passed&#39;</span><span class="o">]</span><span class="p">))</span>
              <span class="n">spec</span><span class="o">[</span><span class="s1">&#39;logs&#39;</span><span class="o">].</span><span class="n">each</span> <span class="k">do</span> <span class="o">|</span><span class="n">log</span><span class="o">|</span>
                <span class="no">Formatter</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="n">indent</span><span class="p">(</span><span class="s2">&quot;    • </span><span class="si">#{</span> <span class="n">format_log_message</span><span class="p">(</span><span class="n">log</span><span class="p">)</span> <span class="si">}</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">level</span><span class="p">))</span>
              <span class="k">end</span>
            <span class="k">end</span>
          <span class="k">end</span>
          
          <span class="k">def</span> <span class="nf">format_log_message</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">message</span> <span class="o">=~</span> <span class="sr">/(.*?) in http.+?assets\/(.*)\?body=\d+\s\((line\s\d+)/m</span>
              <span class="n">pp_prefix</span> <span class="o">=</span> <span class="s1">&#39;[myLog]&#39;</span>
              <span class="n">msg</span><span class="p">,</span> <span class="n">file</span><span class="p">,</span> <span class="n">line</span> <span class="o">=</span> <span class="vg">$1</span><span class="p">,</span> <span class="vg">$2</span><span class="p">,</span> <span class="vg">$3</span>
              <span class="k">if</span> <span class="n">msg</span><span class="o">.</span><span class="n">starts_with?</span> <span class="n">pp_prefix</span>
                <span class="n">msg</span><span class="o">.</span><span class="n">sub</span> <span class="n">pp_prefix</span><span class="p">,</span> <span class="s1">&#39;&#39;</span>
              <span class="k">else</span>
                <span class="s2">&quot;</span><span class="si">#{</span><span class="n">msg</span><span class="si">}</span><span class="s2"> in </span><span class="si">#{</span><span class="n">file</span><span class="si">}</span><span class="s2"> on </span><span class="si">#{</span><span class="n">line</span><span class="si">}</span><span class="s2">&quot;</span>
              <span class="k">end</span>
            <span class="k">else</span>
              <span class="n">message</span>
            <span class="k">end</span>
          <span class="k">end</span>
          
        <span class="k">end</span>
      <span class="k">end</span>
    <span class="k">end</span>
  <span class="k">end</span>
  
<span class="k">end</span>
</code></pre>
</div>


<h2>A JavaScript Pretty Print Library</h2>

<p>
  So now that we have Guard::Jasmine not stripping multi-line console messages to one line and printing file and line numbers, we are ready to hook into it. But first we need a JavaScript library that pretty prints objects for us and wrap this all up behind our own interface to <code>console.log</code>. During my research I found a library called jsDump and decided to <a href="https://github.com/NV/jsDump">use a fork of the project on github</a>. So go download that file and place it in <code>vendor/assets/javascripts/jsDump.js</code> of your Rails project. Next you will want to add it to your <code>spec/javascripts/spec.js</code> manifest like so. My below example is pulled right from my previous article and I have placed jsDump right after my jasmine files.
</p>

<div class="highlight"><pre><code class="javascript"><span class="err">#</span><span class="o">=</span> <span class="nx">require</span> <span class="nx">jasminerice</span>
<span class="err">#</span><span class="o">=</span> <span class="nx">require</span> <span class="nx">mock</span><span class="o">-</span><span class="nx">ajax</span>
<span class="err">#</span><span class="o">=</span> <span class="nx">require</span> <span class="nx">jsDump</span>
<span class="err">#</span><span class="o">=</span> <span class="nx">require</span> <span class="nx">application</span>
<span class="err">#</span><span class="o">=</span> <span class="nx">require</span> <span class="nx">jasmine</span><span class="o">-</span><span class="nx">myapp</span>
<span class="err">#</span><span class="o">=</span> <span class="nx">require_tree</span> <span class="p">.</span><span class="o">/</span><span class="nx">lib</span><span class="o">/</span>
<span class="err">#</span><span class="o">=</span> <span class="nx">require_tree</span> <span class="p">.</span><span class="o">/</span><span class="nx">models</span><span class="o">/</span>
<span class="err">#</span><span class="o">=</span> <span class="nx">require_tree</span> <span class="p">.</span><span class="o">/</span><span class="nx">controllers</span><span class="o">/</span>
<span class="err">#</span><span class="o">=</span> <span class="nx">require_tree</span> <span class="p">.</span><span class="o">/</span><span class="nx">views</span><span class="o">/</span>
</code></pre>
</div>


<h2>Logging Helpers - Using BlackCoffee</h2>

<p>
  In my last article I mentioned how I would talk more about the <code>jasmine-myapp</code> file in the manifest above. Now is the time. I recommend that this file is place to write all your top level helpers and functions for Jasmine or any other testing libraries in your JavaScript stack. Think of this file as your Ruby <code>test_helper.rb</code> or your own extensions to <code>ActiveSupport::TestCase</code>. My advice is that these functions all be written to pollute the time level namespace as other Jasmine helpers do, like the <code>beforeEach</code> and <code>clearAjaxRequests</code>. This makes things easier but be conscious of that decision and write functions keeping that in mind.
</p>

<p>
  The only thing working against is is Sprockets/Tilt rendering CoffeeScript files in their own closure. Which is something you should really not fight! But in this case I think it is fine to have this particular file avoid that. Which allows us to (a) write our helper code in CoffeeScript and (b) use these functions as helpers in the global space like other Jasmine helpers. So enter my <a href="http://github.com/metaskills/sprockets-blackcoffee">Sprockets BlackCoffee</a> gem. This is a simple gem that exposes a CoffeeScript template that uses the <code>--bare</code> option to keep your file from being wrapped in a closure. All you have to do is give the file a <code>.js.black_coffee</code> extension and it will just work. So let's assume you have a <code>spec/javascripts/jasmine-myapp.js.black_coffee</code> created and the gem installed like so.
</p>


<div class="highlight"><pre><code class="ruby"><span class="n">group</span> <span class="ss">:assets</span> <span class="k">do</span>
  <span class="c1"># ...</span>
  <span class="n">gem</span> <span class="s1">&#39;sprockets-blackcoffee&#39;</span>
<span class="k">end</span>
</code></pre>
</div>

<p>
  Finally, here are examples of my logging helpers in the <code>jasmine-myapp</code> file. The <code>myLogParser</code> uses jsDump to get back a pretty formatted string of any object if that object is not already a string. The primary logging helper <code>myLog</code> will prefix your message with <code>[myLog]</code> so the Guard::Jasmine recognizes the message and outputs only the object. The last helper <code>myLogLine</code> will do just like the other, but will allow the file and line number tobe printed too.
</p>

<div class="highlight"><pre><code class="ruby"><span class="n">myLog</span> <span class="o">=</span> <span class="p">(</span><span class="n">obj</span><span class="p">)</span> <span class="o">-&gt;</span>
  <span class="n">console</span><span class="o">.</span><span class="n">log</span> <span class="s2">&quot;[myLog]</span><span class="si">#{</span><span class="n">myLogParser</span><span class="p">(</span><span class="n">obj</span><span class="p">)</span><span class="si">}</span><span class="s2">&quot;</span>

<span class="n">myLogLine</span> <span class="o">=</span> <span class="p">(</span><span class="n">obj</span><span class="p">)</span> <span class="o">-&gt;</span>
  <span class="n">hmLogParser</span><span class="p">(</span><span class="n">obj</span><span class="p">)</span>

<span class="n">myLogParser</span> <span class="o">=</span> <span class="p">(</span><span class="n">obj</span><span class="p">)</span> <span class="o">-&gt;</span>
  <span class="k">if</span> <span class="n">typeof</span> <span class="n">obj</span> <span class="n">is</span> <span class="s1">&#39;string&#39;</span> <span class="k">then</span> <span class="n">obj</span> <span class="k">else</span> <span class="n">jsDump</span><span class="o">.</span><span class="n">parse</span> <span class="n">obj</span>
</code></pre>
</div>


<h2>In Practice</h2>

<p>
  Here is an example of a Jasmine spec where I was using console.log before the patches above and what it would output to the terminal.
</p>

<div class="highlight"><pre><code class="ruby"><span class="c1">#= include spec_helper</span>

<span class="n">describe</span> <span class="s1">&#39;User&#39;</span><span class="p">,</span> <span class="o">-&gt;</span>

  <span class="n">it</span> <span class="s1">&#39;has been configured with proper attributes&#39;</span><span class="p">,</span> <span class="o">-&gt;</span>
    <span class="vi">@user</span> <span class="o">=</span> <span class="kp">new</span> <span class="no">User</span> <span class="nb">id</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span> <span class="n">email</span><span class="p">:</span> <span class="s1">&#39;bob@test.com&#39;</span>
    <span class="n">console</span><span class="o">.</span><span class="n">log</span> <span class="vi">@user</span><span class="o">.</span><span class="n">attributes</span><span class="p">()</span>
    <span class="n">expect</span><span class="p">(</span><span class="vi">@user</span><span class="o">.</span><span class="n">email</span><span class="p">)</span><span class="o">.</span><span class="n">toEqual</span> <span class="s1">&#39;bob@test.com&#39;</span>
</code></pre>
</div>

<pre class="code">
User
  ✘ has been configured with proper attributes
    ➤ Expected 'foo@bar.com' to equal 'bob@test.com'.
    • [object Object]
ERROR: 1 specs, 1 failures
in 0.653 seconds  
</pre>

<p>
  There is the totally helpful <code>[object Object]</code>. But if we now change our code to leverage out patches and change console.log to <code>hmLog @user.attributes()</code> to use our helper. We will get this. If you need a pretty object with line numbers. Just use <code>hmLogLine</code>.
</p>

<pre class="code">
User
  ✘ has been configured with proper attributes
    ➤ Expected 'foo@bar.com' to equal 'bob@test.com'.
    • {
       "email": "foo@bar.com",
       "id": 2
    }
ERROR: 1 specs, 1 failures
in 0.653 seconds
</pre>


<p>
  I hope this is helpful to anyone using Guard::Jasmine with a desire to see better output. If you continue to follow my series, my next post will be a deeper dive into Jasmine testing of Spine.JS applications.
</p>



<h2>Related</h2>

<ul>
  <li><a href="/2012/01/15/rails-and-spine-js-using-the-coffeescript-source/">Rails &amp; Spine.JS - Using The CoffeeScript Source</a></li>
  <li><a href="/2012/01/16/rails-and-spine-js-jasmine-testing-part-1/">Rails &amp; Spine.JS - Jasmine Testing Part 1</a></li>
  <li><a href="/2012/01/17/rails-and-spine-js-jasmine-testing-part-2/">Rails &amp; Spine.JS - Jasmine Testing Part 2</a></li>
  <li><a href="/2012/02/01/pretty-console-logging-with-guardjasmine-black-coffee/">Pretty Console Logging With Guard::Jasmine &amp; BlackCoffee</a></li>  
</ul>


<h2>Resources</h2>

<ul>
  <li><a href="http://github.com/metaskills/sprockets-blackcoffee">Sprockets BlackCoffee Gem</a></li>
  <li><a href="http://github.com/netzpirat/guard-jasmine">Guard::Jasmine - Automatically tests your Jasmine specs on Rails.</a></li>
  <li><a href="http://github.com/bradphelan/jasminerice">Jasminerice - Pain free CoffeeScript testing under Rails 3.1.</a></li>
</ul>

]]>
    </content>
 </entry>
 
 <entry>
   <title>Rails &amp;amp; Spine.JS - Jasmine Testing Part 2</title>
   <link href="http://metaskills.net/2012/01/17/rails-and-spine-js-jasmine-testing-part-2" />
   <updated>2012-01-17T00:00:00-05:00</updated>
   <id>http://metaskills.net/2012/01/17/rails-and-spine-js-jasmine-testing-part-2</id>
   <content type="html">
     <![CDATA[<p>
  So this is the third part to my mini series on Rails and <a href="http://spinejs.com/">Spine.JS</a>. Part one <a href="/2012/01/15/rails-and-spine-js-using-the-coffeescript-source/">covers an initial setup</a> and how to include Spine.JS into your Rails project while part two is actually the <a href="/2012/01/16/rails-and-spine-js-jasmine-testing-part-1/">first of a tome on how to test</a> your Spine.JS application. Assuming you have covered the bases there, lets get right down to business and review some of the elegant hacks &trade; yours truly came up with while testing my own Spine.jS application using <a href="http://github.com/guard/guard">Guard</a> and <a href="http://github.com/bradphelan/jasminerice">Jasminerice</a>. 
</p>


<h2>That Engine Is Gonna Need An Overhaul</h2>

<p>
  So did I mention that Jasminerice is a Rails engine and that you can run your tests by accessing the <code>/jasmine</code> URL in your development environment's browser? Good. As uncool as browser testing is, sometimes that it useful. For instance <code>console.log</code> statements will not show up in your Guard's test output. But hopefully that is an edge case and you are really using <a href="http://github.com/netzpirat/guard-jasmine">guard-jasmine</a> and watching your specs run in the terminal window. The question now becomes how can I leverage Jasminerice and its associated engine to really test my Spine.JS application with a full-fledged DOM? The answer is simple, let's hack the Jasminerice engine to load up our application while running the Jasmine specs.
</p>


<h2>A Review Of Jasmine And HTML Fixtures</h2>

<p>
  This might be a bit contraversial (or maybe just wrong) but I would like to examine why we might hack the Jasminerice engine for a few minutes. Jasmine bills itself as behavior-driven development for JavaScript, to which I disagree. I think Jasmine first and foremost is an all-purpose testing framework. Depending on how you use it determines what it becomes. In my case, I have been doing a lot of unit testing of my Spine.JS models and supporting libs as I learn the framework and build my system. So my usage now could be called TDD at both a unit and functional level. Later on, I plan on doing higher level integration testing with Jasmine, at this time it will be my BDD tool. Normally I do not get caught up in symantics but I think it is important to understand a few lexical terms before I start showing off how I use Jasmine to test my Spine.JS application. 
</p>

<p>
  Now that I have set my higher order bit for Jasmine as my unit, functional and itegration testing framework for Spine.JS &ndash; I would like to show how my solution below might differ from other practices. Experienced Jasmine users rave about extensions that allow you to load HTML fixtures to functionally test units of code. In fact, the Jasminerice gem includes a custom version of the <a href="https://github.com/velesin/jasmine-jquery">jasmine-jquery</a> library which among other things allows you to do just that. Let me be clear on this, there is nothing wrong with that! As with all things software, proper solutions depends on what you are doing and need. In my case, I believe that testing your Spine.JS application with Rails only needs to hook into your existing application without the need for fixtures and excessive mocking and stubbing.
</p>

<p>
  My basis for this argument is founded on a few principas that I believe all rich client side JavaScript applications should follow. Most important, the application is a single page load and all other calls to the server happen from that one page via AJAX. Every other part of your Rails application then becomes an API client to the JavaScript application. All views are client side only, most likely in a <code>JST</code> namespace.
</p>


<h2>Hacking Jasminerice</h2>

<p>
  Turns out this is really easy since Jasminerice is just a simple Rails engine with few moving parts. It has a <code>SpecController</code> that renders a basic layout which requires your application's JavaScript assets along with Jasmine. The goal is to tell it to render your single application page that loads up your Spine.JS app with a few additional hacks. When done, we are going to have Jasminerice in your full control. This means we get the same CSS and JavaScript as our real application along with a solid foundation to extend Jasminerice at our whim. This leaves us with a clean canvas suitable for Jasmine unit, functional and integraiton testing all wrapped up into one.
</p>


<div class="highlight"><pre><code class="ruby"><span class="c1"># In: config/initializers/jasminerice.rb</span>

<span class="k">module</span> <span class="nn">Jasminerice</span>
  
  <span class="k">module</span> <span class="nn">MyApplication</span>
    <span class="kp">extend</span> <span class="no">ActiveSupport</span><span class="o">::</span><span class="no">Concern</span>
    <span class="n">included</span> <span class="k">do</span>
      <span class="n">delegate</span> <span class="ss">:foo_path</span><span class="p">,</span> <span class="n">to</span><span class="p">:</span> <span class="o">::</span><span class="no">Rails</span><span class="o">.</span><span class="n">application</span><span class="o">.</span><span class="n">routes_url_helpers</span>
    <span class="k">end</span>
    <span class="k">def</span> <span class="nf">jasminerice?</span>
      <span class="kp">true</span>
    <span class="k">end</span>
    <span class="k">def</span> <span class="nf">current_user</span>
      <span class="vi">@current_user</span> <span class="o">||=</span> <span class="no">User</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
    <span class="k">end</span>
  <span class="k">end</span>
  
  <span class="no">ApplicationHelper</span><span class="o">.</span><span class="n">send</span> <span class="ss">:include</span><span class="p">,</span> <span class="no">MyApplication</span>
  
  <span class="k">class</span> <span class="nc">SpecController</span> <span class="o">&lt;</span> <span class="no">Jasminerice</span><span class="o">::</span><span class="no">ApplicationController</span>
    <span class="k">def</span> <span class="nf">index</span>
      <span class="n">render</span> <span class="n">template</span><span class="p">:</span> <span class="s1">&#39;users/home&#39;</span><span class="p">,</span> <span class="n">layout</span><span class="p">:</span> <span class="s1">&#39;application&#39;</span>
    <span class="k">end</span>
  <span class="k">end</span>
  
<span class="k">end</span> <span class="k">if</span> <span class="n">defined?</span><span class="p">(</span><span class="no">Jasminerice</span><span class="p">)</span> <span class="o">&amp;&amp;</span> <span class="no">Jasminerice</span><span class="o">.</span><span class="n">environments</span><span class="o">.</span><span class="n">include?</span><span class="p">(</span><span class="no">Rails</span><span class="o">.</span><span class="n">env</span><span class="p">)</span>
</code></pre>
</div>

<p>
  There we go, a simple example pulled from my current project. What we are doing here is freedom-patching that spec controller's index action to render both a template and layout from your application. I also have a <code>MyApplication</code> module which I include in the <code>Jasminerice::ApplicationHelper</code> for a few methods that my application view code would expect. In this case a <code>current_user</code> method and some delegation of URL helpers to the root Rails application. Do not get hung up on what user is returned there too. It is mostly moot as all AJAX calls will be stubbed. Lastly, I made a <code>jasminerice?</code> view helper and a matching one that I have in my own <code>ApplicationHelper</code> which returns false. I will show why and how this all fits together later on.
</p>

<p>
  Now that we have full control and some reflection for Jasminerice, let's reviw our appliation's main layout. Here is an example of my <code>app/views/layouts/application.html.haml</code> file.
</p>

<div class="highlight"><pre><code class="ruby"><span class="o">!!!</span> <span class="mi">5</span>
<span class="o">%</span><span class="n">html</span><span class="p">{</span><span class="ss">:lang</span> <span class="o">=&gt;</span> <span class="s1">&#39;en&#39;</span><span class="p">}</span>
  <span class="o">%</span><span class="n">head</span>
    <span class="o">%</span><span class="n">meta</span><span class="p">{</span><span class="ss">:charset</span> <span class="o">=&gt;</span> <span class="s1">&#39;utf-8&#39;</span><span class="p">}</span>
    <span class="o">=</span> <span class="n">csrf_meta_tags</span>
    <span class="o">%</span><span class="n">title</span> <span class="no">My</span> <span class="no">Application</span>
    <span class="o">-</span> <span class="k">if</span> <span class="n">jasminerice?</span>
      <span class="o">=</span> <span class="n">stylesheet_link_tag</span> <span class="s1">&#39;spec&#39;</span>
      <span class="o">=</span> <span class="n">javascript_include_tag</span> <span class="s1">&#39;spec&#39;</span>
    <span class="o">-</span> <span class="k">else</span>
      <span class="o">=</span> <span class="n">stylesheet_link_tag</span> <span class="s1">&#39;application&#39;</span>
      <span class="o">=</span> <span class="n">javascript_include_tag</span> <span class="s1">&#39;application&#39;</span>
      <span class="o">%</span><span class="n">script</span> <span class="n">jQuery</span><span class="p">(</span><span class="n">function</span><span class="p">(){</span> <span class="no">MyApp</span><span class="o">.</span><span class="n">App</span><span class="o">.</span><span class="n">Home</span><span class="o">.</span><span class="n">init</span><span class="p">();</span> <span class="p">});</span>
  <span class="o">%</span><span class="n">body</span>
    <span class="o">%</span><span class="n">section</span><span class="p">{</span><span class="nb">id</span><span class="p">:</span> <span class="s1">&#39;app&#39;</span><span class="p">,</span> <span class="n">data</span><span class="p">:</span> <span class="p">{</span><span class="nb">id</span><span class="p">:</span> <span class="n">current_user</span><span class="o">.</span><span class="n">id</span><span class="p">}}</span>
</code></pre>
</div>

<p>
  It is really that simple! It has a single condition that says if Jasminerice is loading this page, use the top level <code>spec</code> CSS and JavaScript asset manifest. If not, render my main application's CSS and JavaScript manifests. You will also notice that I decouple my Spine's application initialization from the main JS files and only initialize the app on page load when not running in Jasminerce. This allows us to stub AJAX calls in specs then initialization the Spine.JS app when we are fully ready. So now, let us take a look at what both the <code>spec/javascripts/spec.css</code> and <code>spec/javascripts/spec.js</code> manifests may look like.
</p>

<div class="highlight"><pre><code class="css"><span class="c">/*</span>
<span class="c"> *= require jasmine</span>
<span class="c"> *= require application</span>
<span class="c"> */</span>
<span class="nc">.jasmine_reporter</span> <span class="p">{</span> <span class="k">display</span><span class="o">:</span> <span class="k">none</span><span class="p">;</span> <span class="p">}</span>
</code></pre>
</div>

<div class="highlight"><pre><code class="javascript"><span class="err">#</span><span class="o">=</span> <span class="nx">require</span> <span class="nx">jasminerice</span>
<span class="err">#</span><span class="o">=</span> <span class="nx">require</span> <span class="nx">mock</span><span class="o">-</span><span class="nx">ajax</span>
<span class="err">#</span><span class="o">=</span> <span class="nx">require</span> <span class="nx">application</span>
<span class="err">#</span><span class="o">=</span> <span class="nx">require</span> <span class="nx">jasmine</span><span class="o">-</span><span class="nx">myapp</span>
<span class="err">#</span><span class="o">=</span> <span class="nx">require_tree</span> <span class="p">.</span><span class="o">/</span><span class="nx">lib</span><span class="o">/</span>
<span class="err">#</span><span class="o">=</span> <span class="nx">require_tree</span> <span class="p">.</span><span class="o">/</span><span class="nx">models</span><span class="o">/</span>
<span class="err">#</span><span class="o">=</span> <span class="nx">require_tree</span> <span class="p">.</span><span class="o">/</span><span class="nx">controllers</span><span class="o">/</span>
<span class="err">#</span><span class="o">=</span> <span class="nx">require_tree</span> <span class="p">.</span><span class="o">/</span><span class="nx">views</span><span class="o">/</span>
</code></pre>
</div>

<p>
  These should be self explanatory. The <code>spec.css</code> manifest requires the jasmine styles, then our application's styles. It then hides the Jasmine reporter element. The <code>spec.js</code> manifest does something similiar, It first requires the jasminerice manifest, a Jasmine helper called <a href="https://github.com/pivotal/jasmine-ajax">jasmine-ajax</a> but poorly named mock-ajax, then your application's JavaScript followed by a personal Jasmine helper that we will discuss later. The last lines include all the spec files in each of the lib, models, controller and views directories located in the parent <code>spec/javascripts</code> directory.
</p>

<p>
  Congratulations! You are now in full control of both Spine.JS and Jasmine(rice) and how your specs are executed. You have a fully styled DOM that you can happily ignore as you test your unit code. And when the time comes, you can leverage that and you full Spine.JS application from a high level integration perspective. Tune in for my last part which will give some working examples of how to test your Spine.JS application with Jasmine.
</p>


<h2>Related</h2>

<ul>
  <li><a href="/2012/01/15/rails-and-spine-js-using-the-coffeescript-source/">Rails &amp; Spine.JS - Using The CoffeeScript Source</a></li>
  <li><a href="/2012/01/16/rails-and-spine-js-jasmine-testing-part-1/">Rails &amp; Spine.JS - Jasmine Testing Part 1</a></li>
  <li><a href="/2012/01/17/rails-and-spine-js-jasmine-testing-part-2/">Rails &amp; Spine.JS - Jasmine Testing Part 2</a></li>
  <li><a href="/2012/02/01/pretty-console-logging-with-guardjasmine-black-coffee/">Pretty Console Logging With Guard::Jasmine &amp; BlackCoffee</a></li>  
</ul>


<h2>Resources</h2>

<ul>
  <li><a href="http://spinejs.com/">Spine.JS - Build Awesome JavaScript MVC Applications</a></li>
  <li><a href="http://github.com/bradphelan/jasminerice">Jasminerice - Pain free CoffeeScript testing under Rails 3.1</a></li>
  <li><a href="http://github.com/pivotal/jasmine-ajax">Jasmine AJAX - A library for faking Ajax responses in your Jasmine suite.</a></li>
</ul>


]]>
    </content>
 </entry>
 
 <entry>
   <title>Rails &amp;amp; Spine.JS - Jasmine Testing Part 1</title>
   <link href="http://metaskills.net/2012/01/16/rails-and-spine-js-jasmine-testing-part-1" />
   <updated>2012-01-16T00:00:00-05:00</updated>
   <id>http://metaskills.net/2012/01/16/rails-and-spine-js-jasmine-testing-part-1</id>
   <content type="html">
     <![CDATA[<p>
  In my <a href="/2012/01/15/rails-and-spine-js-using-the-coffeescript-source/">previous article</a> I talked a little bit about why I decided to use Spine.JS and how to include the CoffeeScript source into your Rails project using git submodules. Now I would like to talk about testing your brand new Spine.JS application. Afterward, be sure to <a href="/2012/01/17/rails-and-spine-js-jasmine-testing-part-2/">read the second part</a> to this article which covers more advanced aspects of your Spine.JS application specs.
</p>


<h2>Testing JavaScript</h2>

<p>
  OK, so like any good programmer, you want to test your JavaScript web application, but how? Like most, I kept finding that <a href="http://pivotal.github.com/jasmine/">Jasmine</a> was the de facto testing framework that most Rails developers were using. For the newly aquatinted, Jasmine describes itself as behavior-driven and sports a clean spec style using <code>describe</code> and <code>it</code> blocks similar to RSpec or MiniTest::Spec. But maybe you, like me, quickly dismissed Jasmine since you sure as hell were not going to hit refresh or F5 in your browser every time you wanted to run your damn specs. After all, this is 2012 and Rails developers do not test with a browser! So why should I start now?
</p>

<p>
  Luckily I am a big fan of Ruby's <a href="https://github.com/guard/guard">Guard</a> gem, a simple library that responds to file system events. The guard project literally has TONS of other guard gems that automate everything from running test files to restarting your development server. Thankfully my search for JavaScript testing with Guard in mind brought me right back to Jasmine. Enter the <a href="https://github.com/netzpirat/guard-jasmine">guard-jasmine</a> gem and the wonderful world of a headless JavaScript testing piped right down to your terminal window!
</p>



<h2>Guard, Jasmine &amp; Jasminerice</h2>

<p>
  So this is our holy trinity and to be honest, there are a lot of moving parts under the stack. Things will seem to get complicated quick, but don't worry. I will give you a brief overview of the moving parts and then get right down to the basics of how you can start using Guard and Jasmine to test your Sine.JS application. 
</p>

<p>
  First, let's cover Guard. It is a simple gem that uses a <code>Guardfile</code> at the root of your project to control how other guards are triggered. I'll give you an example Guardfile later. But for starters, <a href="https://github.com/guard/guard">read the documentation</a> on what special libraries may be needed for file system events or notifications on your specific platform. In my case, I us Mac OS X and purchased the latest Growl 1.3. So my example <code>Gemfile</code> below will have the <a href="https://rubygems.org/gems/ruby_gntp">ruby_gntp</a> gem included in the spec.
</p>

<p>
  Next up is the guard-jasmine gem. My instructions assume you are running a Rails 3.1 or 3.2 app and that you are taking full advantage of the asset pipeline and CoffeeScript. Many of these details can be found on the <a href="https://github.com/netzpirat/guard-jasmine">guard-jamine's Rails 3.1 setup</a> section of their readme page. The underlying components of guard-jasmine are two a libs named <a href="https://github.com/bradphelan/jasminerice">Jasminerice</a> and <a href="http://www.phantomjs.org/">PhantomJS</a>. Jasminerice is a simple Rails engine that brings in the Jasmine source files to the asset pipeline while running a rack app mounted to <code>/jasmine</code> to run your specs from your current application. PhantomJS is yet another headless WebKit based on Qt that has a rich JavaScript API which guard-jasmine delegates to. Is your head spinning? Mine was too.
</p>


<h2>Put It All Together</h2>

<p>
  Here is the bullet train to getting this stack up and running. First, you will need to get PhantomJS installed. If Homebrew is your thing, just do <code>$ brew install phantomjs</code>. Or you can <a href="http://code.google.com/p/phantomjs/downloads/list">download one of their precompiled binaries</a> for your specific platform. This is what I opted to do and I just placed the phantomjs in my <code>PATH</code> somewhere.
</p>

<p>
  Next, we need to get the gems in our <code>Gemfile</code>. Here is how mine are setup. I have them in both the <code>:develpment</code> and <code>:test</code> groups since Jasminerice runs in both of those Rails environments. I also have that ruby_gntp dependency since I am using Growl on Mac OS X, YMMV.
</p>

<div class="highlight"><pre><code class="ruby"><span class="n">group</span> <span class="ss">:development</span><span class="p">,</span> <span class="ss">:test</span> <span class="k">do</span>
  <span class="n">gem</span> <span class="s1">&#39;jasminerice&#39;</span>
  <span class="n">gem</span> <span class="s1">&#39;guard-jasmine&#39;</span>
  <span class="n">gem</span> <span class="s1">&#39;ruby_gntp&#39;</span>
<span class="k">end</span>
</code></pre>
</div>

<p>
  So that was easy, now on to our <code>Guardfile</code>. Here is mine below. Notice how I put my JavaScript related guards into a <code>js</code> group? This is a seldom used feature of Guard and it means I can monitor only my jasmine specs by starting guard off using <code>$ guard -g js</code> and my other guards in my <code>ruby</code> group, like minitest, will be ignored.
</p>

<div class="highlight"><pre><code class="ruby"><span class="n">group</span> <span class="s1">&#39;js&#39;</span> <span class="k">do</span>

  <span class="n">guard</span> <span class="s1">&#39;jasmine&#39;</span> <span class="k">do</span>
    <span class="n">watch</span><span class="p">(</span><span class="sr">%r{app/assets/javascripts/myapp/index\.js\.coffee$}</span><span class="p">)</span>  <span class="p">{</span> <span class="s2">&quot;spec/javascripts&quot;</span> <span class="p">}</span>
    <span class="n">watch</span><span class="p">(</span><span class="sr">%r{app/assets/javascripts/myapp/(.+)\.js\.coffee$}</span><span class="p">)</span>   <span class="p">{</span> <span class="o">|</span><span class="n">m</span><span class="o">|</span> <span class="s2">&quot;spec/javascripts/</span><span class="si">#{</span><span class="n">m</span><span class="o">[</span><span class="mi">1</span><span class="o">]</span><span class="si">}</span><span class="s2">_spec.js.coffee&quot;</span> <span class="p">}</span>
    <span class="n">watch</span><span class="p">(</span><span class="sr">%r{spec/javascripts/(.+)_spec\.js\.coffee$}</span><span class="p">)</span>          <span class="p">{</span> <span class="o">|</span><span class="n">m</span><span class="o">|</span> <span class="s2">&quot;spec/javascripts/</span><span class="si">#{</span><span class="n">m</span><span class="o">[</span><span class="mi">1</span><span class="o">]</span><span class="si">}</span><span class="s2">_spec.js.coffee&quot;</span> <span class="p">}</span>
    <span class="n">watch</span><span class="p">(</span><span class="sr">%r{spec/javascripts/spec\.js$}</span><span class="p">)</span>                       <span class="p">{</span> <span class="s2">&quot;spec/javascripts&quot;</span> <span class="p">}</span>
    <span class="n">watch</span><span class="p">(</span><span class="sr">%r{spec/javascripts/spec_helper\.js$}</span><span class="p">)</span>                <span class="p">{</span> <span class="s2">&quot;spec/javascripts&quot;</span> <span class="p">}</span>
    <span class="n">watch</span><span class="p">(</span><span class="sr">%r{spec/javascripts/jasmine-myapp.*}</span><span class="p">)</span>                 <span class="p">{</span> <span class="s2">&quot;spec/javascripts&quot;</span> <span class="p">}</span>
  <span class="k">end</span>

<span class="k">end</span>
</code></pre>
</div>

<p>
  This setup assumes a few things. First that you are only testing your Spine.JS application and that those files are in the <code>app/assets/javascripts/myapp</code> directory. That myapp directory could just be <code>app</code> in your case if you used the <a href="http://github.com/maccman/spine-rails">spine-rails</a> gem without the <code>--app</code> option. In my case, that folder is named <code>homemarks</code>. This Guardfile also assumes that your JavaScript app and specs are CoffeeScript files and that specs are in the <code>spec/javascripts</code> folder specified by Jasminerice. You are going to want to follow some file naming convention now too. For example if you have a Spine.JS app file in <code>app/assets/javascripts/myapp/models/post.js.coffee</code>, then you are going to want the matching spec in <code>spec/javascripts/models/post_spec.js.coffee</code>. So saving each of those files will trigger that specific spec to run. There are also so some watchers on important root files like your spec.js sprockets manifest and your Spine.JS app index. Changing any of those files will result in your entire spec suite running again. 
</p>


<h2>To Be Continued...</h2>

<p>
  I will go into more details on the <code>spec_helper.js</code> and <code>jasmine-myapp</code> files above in <a href="/2012/01/17/rails-and-spine-js-jasmine-testing-part-2/">the second part</a> of this article. For now you should be set to start writing specs like the one below and seeing them run by either visiting the <code>/jasmine</code> URL of your running Rails application or by using Guard in your terminal window.
</p>

<div class="highlight"><pre><code class="ruby"><span class="n">describe</span> <span class="s1">&#39;App&#39;</span><span class="p">,</span> <span class="o">-&gt;</span>
  
  <span class="n">it</span> <span class="s1">&#39;sets el&#39;</span><span class="p">,</span> <span class="o">-&gt;</span>
    <span class="n">expect</span><span class="p">(</span><span class="no">MyApp</span><span class="o">.</span><span class="n">Application</span><span class="o">.</span><span class="n">el</span><span class="p">)</span><span class="o">.</span><span class="n">toEqual</span> <span class="err">$</span><span class="p">(</span><span class="s1">&#39;#app&#39;</span><span class="p">)</span>

  <span class="n">it</span> <span class="s1">&#39;sets the userId as a property on itself&#39;</span><span class="p">,</span> <span class="o">-&gt;</span>
    <span class="n">expect</span><span class="p">(</span><span class="no">MyApp</span><span class="o">.</span><span class="n">Application</span><span class="o">.</span><span class="n">userId</span><span class="p">)</span><span class="o">.</span><span class="n">toEqual</span> <span class="vi">@bob</span><span class="o">.</span><span class="n">id</span>
</code></pre>
</div>

<p>
  <a href="/2012/01/17/rails-and-spine-js-jasmine-testing-part-2/">Continue to part two...</a>
</p>



<h2>Related</h2>

<ul>
  <li><a href="/2012/01/15/rails-and-spine-js-using-the-coffeescript-source/">Rails &amp; Spine.JS - Using The CoffeeScript Source</a></li>
  <li><a href="/2012/01/16/rails-and-spine-js-jasmine-testing-part-1/">Rails &amp; Spine.JS - Jasmine Testing Part 1</a></li>
  <li><a href="/2012/01/17/rails-and-spine-js-jasmine-testing-part-2/">Rails &amp; Spine.JS - Jasmine Testing Part 2</a></li>
  <li><a href="/2012/02/01/pretty-console-logging-with-guardjasmine-black-coffee/">Pretty Console Logging With Guard::Jasmine &amp; BlackCoffee</a></li>  
</ul>


<h2>Resources</h2>

<ul>
  <li><a href="http://spinejs.com/">Spine.JS - Build Awesome JavaScript
  MVC Applications</a></li>
  <li><a href="http://pivotal.github.com/jasmine/">Jasmine - BDD for JavaScript. (I disagree, TDD too!)</a></li>
  <li><a href="http://github.com/netzpirat/guard-jasmine">Guard Jasmine - Automated Jasmine tests to your console.</a></li>
  <li><a href="http://github.com/bradphelan/jasminerice">Jasminerice - Pain free CoffeeScript testing under Rails 3.1</a></li>
  <li><a href="http://www.phantomjs.org/">PhantomJS - Headless WebKit with JavaScript API.</a></li>
</ul>

]]>
    </content>
 </entry>
 
 <entry>
   <title>Rails &amp;amp; Spine.JS - Using The CoffeeScript Source</title>
   <link href="http://metaskills.net/2012/01/15/rails-and-spine-js-using-the-coffeescript-source" />
   <updated>2012-01-15T00:00:00-05:00</updated>
   <id>http://metaskills.net/2012/01/15/rails-and-spine-js-using-the-coffeescript-source</id>
   <content type="html">
     <![CDATA[<p>
  Our <a href="http://addyosmani.com/blog/short-musings-on-javascript-mv-tech-stacks/">options for JavaScript MVC frameworks</a> are numerous these days. While working on the third major rewrite of my personal bookmarking application, <a href="http://homemarks.com/">HomeMarks</a>, I decided to learn <a href="http://documentcloud.github.com/backbone/">Backbone.js</a>. Thankfully a local friend of mine <a href="https://twitter.com/#!/brennandunn/status/153487553062907905">recommended</a> that I try <a href="http://spinejs.com/">Spine.JS</a>. I was immediately hooked! 
</p>


<h2>Why Spine.JS?</h2>

<p>
  Spine.JS is is authored in <a href="http://coffeescript.org/">CoffeeScript</a> and that is a big deal for me. I will never write raw JavaScript again, which I consider, the deprecated syntax. So a JavaScript MVC framework that is written in CoffeeScript means I can read the source, learn from it and even debug it if necessary. Sure, I can read raw JavaScript or just rely on documentation. But nothing beats reading source code. A practice I think good developers follow. So here is an example of the <a href="https://github.com/documentcloud/backbone/blob/master/backbone.js#L151">Backbone.js model source</a> compared to reading <a href="https://github.com/maccman/spine/blob/master/src/spine.coffee#L83">Spine.JS model source</a> and I think you will see the difference.
</p>

<p>
  Source code legibilty is not the only reason to use Spine.JS. It is also very lightweight and requires no other JavaScript dependencies. Take for example Backbone.js which requies the use of <a href="http://documentcloud.github.com/underscore/">Underscore.js</a> and think for a moment why. Underscore.js makes mundane tasks in JavaScript like itterators and event binding much more friendly. But this is all moot when you are using CoffeeScipt's loops and comprehensions. And take my advice, CoffeeScript has so much more to offer. One of my personal favorites is the existential operator!
</p>



<h2>Coffee Time!</h2>

<p>
  So, are you with me and want to try out Spine? Great! But do not rush in and use the <a href="http://github.com/maccman/spine-rails">spine-rails</a> gem. Sure it gives you a nice way to require the Spine JavaScript files in the asset pipeline and some fancy generators. But when you break it down, there are better ways to get Spine's source files and who the hell uses generators? I mean, the only useful one is the initial <code>rails g spine:new</code> generator. Past the initial project setup, the spine-rails gem really does nothing but lock you down to an explicit version of Spine tied to that gem release. 
</p>

<p>
  I highly advise that new-comers to Spine start off with the spine-rails gem and its new project generator. Then quickly switch to just including the spine source using a git submodule. This will give you the benefit of using the source CoffeeScript files and tracking Spine's git repo which is getting good active development. So let's live on the edge and read some source. First uninstall the spine-rails gem if you have it and add the Spine project as a git submodule to your git repo.
</p>

<pre class="command">
$ mkdir -p vendor/assets/javascripts
$ git submodule add git://github.com/maccman/spine.git vendor/assets/javascripts/spine
</pre>

<p>
  This adds the Spine project to your <code>vendor/assets/javascripts/spine</code> directory. Which means it can now be leveraged by Rails asset pipeline using Sprockets. So if you had used the spine-rails generator above and had your spine requires in <code>app/assets/javascripts/app/index.js.coffee</code>, you would now be able to change what should have looked like this:
</p>

<div class="highlight"><pre><code class="ruby"><span class="c1">#= require spine</span>
<span class="c1">#= require spine/manager</span>
<span class="c1">#= require spine/ajax</span>
<span class="c1">#= require spine/route</span>
</code></pre>
</div>

<p>
  To something like the following. Since the <code>spine/lib</code> directory is where the source CoffeeScript files from our submodule above and Sprockets will render these just fine, it all just works!
</p>

<div class="highlight"><pre><code class="ruby"><span class="c1">#= require spine/lib/spine</span>
<span class="c1">#= require spine/lib/manager</span>
<span class="c1">#= require spine/lib/ajax</span>
<span class="c1">#= require spine/lib/route</span>
</code></pre>
</div>

<p>
  So now you can easily update your Spine dependency using a simple git workflow with the added benefit that you can open up any of the source CoffeeScript files and learn Spine from the inside out. You can even change the source or put in console debugging to see what is happening and your application files will recompile via Sprockets on the next request.
</p>


<h2>Related</h2>

<ul>
  <li><a href="/2012/01/15/rails-and-spine-js-using-the-coffeescript-source/">Rails &amp; Spine.JS - Using The CoffeeScript Source</a></li>
  <li><a href="/2012/01/16/rails-and-spine-js-jasmine-testing-part-1/">Rails &amp; Spine.JS - Jasmine Testing Part 1</a></li>
  <li><a href="/2012/01/17/rails-and-spine-js-jasmine-testing-part-2/">Rails &amp; Spine.JS - Jasmine Testing Part 2</a></li>
  <li><a href="/2012/02/01/pretty-console-logging-with-guardjasmine-black-coffee/">Pretty Console Logging With Guard::Jasmine &amp; BlackCoffee</a></li>  
</ul>


<h2>Resources</h2>

<ul>
  <li><a href="http://spinejs.com/">Spine.JS - Build Awesome JavaScript
  MVC Applications</a></li>
  <li><a href="http://coffeescript.org/">CoffeeScript - A little language that compiles into JavaScript.</a></li>
  <li><a href="http://github.com/maccman/spine-rails">The Spine Rails Gem</a></li>
</ul>


]]>
    </content>
 </entry>
 
 <entry>
   <title>LESS Is More - Using Twitter's Bootstrap In The Rails 3.1 Asset Pipeline</title>
   <link href="http://metaskills.net/2011/09/26/less-is-more-using-twitter-bootstrap-in-the-rails-3-1-asset-pipeline" />
   <updated>2011-09-26T00:00:00-04:00</updated>
   <id>http://metaskills.net/2011/09/26/less-is-more-using-twitter-bootstrap-in-the-rails-3-1-asset-pipeline</id>
   <content type="html">
     <![CDATA[<p>
  <span class="floatr ml20 mb20">
    <img src="/assets/less.png" alt="LESS - The Dynamic Stylesheet language" width="199" height="81" />
  </span>
  This weekend I decided to experiment with <a href="http://lesscss.org/">LESS CSS</a> by replacing the existing <a href="http://sass-lang.com/">Sass</a> and <a href="http://compass-style.org/">Compass</a> code that had been built thus far a small project. Why? Three basic reasons. First, I wanted to see how LESS stacked up. Second, I was intrigued by some of LESS' features, in particular <a href="http://lesscss.org/#-namespaces">their namespace support.</a> Lastly, I wanted to use <a href="http://twitter.github.com/bootstrap/">Twitter's Bootstrap</a> project as a baseline for my design. Since Rails 3.1 has been out for some time, I was expecting the move to LESS to go considerably smoother than my <a href="/2011/07/29/use-compass-sass-framework-files-with-the-rails-3.1.0.rc5-asset-pipeline/">pre-release attempts with Compass and Sass<a/>. I was wrong.
</p>

<p>
  So the tilt gem already supported LESS templates and that means that Sprockets and the asset pipeline rendering technically did too. But there was <a href="https://github.com/cowboyd/less.rb/issues/8">no official less-rails gem</a> that setup a standard configuration for other gems to hook into. This meant that libraries that distributed the Twitter Bootstrap assets were often hard to use or had inconsistent results. For example, it was not possible to load the Bootstrap's assets in such as way that let you build on top of the LESS mixins they had build. Nor were those assets namespaced in such a way that would allow you to have a <code>modal.less</code> asset as it would have conflicted with Bootstrap's version. So since I apparently have a bunch of free time and I hate building on top of a bad foundation, I set out to learn both <code>Rails::Railtie</code> and <code>Rails::Engine</code> to build the proper tools for LESS and Bootstrap in the Rails 3.1 asset pipeline.
</p>


<h2>New LESS Gems</h2>

<p>
  I introduce you to both the new <a href="http://github.com/metaskills/less-rails">less-rails</a> and <a href="http://github.com/metaskills/less-rails-bootstrap">less-rails-bootstrap</a> gems. Take a look at the source code if you ever wanted to learn how to implement a simple Rails::Railtie or Engine. But assuming you want to use Twitter's Bootstrap, here are a few examples to get you started. First just bundle up to less-rails-bootstrap, it will automatically pull in less-rails and less.rb via their dependencies. BTW, I am going to keep the semantic versioning of the less-rails-bootstrap gem in sync with the major and minor versions of the Bootstrap project.
</p>

<div class="highlight"><pre><code class="ruby"><span class="n">gem</span> <span class="s1">&#39;less-rails-bootstrap&#39;</span><span class="p">,</span> <span class="s1">&#39;~&gt; 1.3.0&#39;</span>
</code></pre>
</div>

<p>
  From here, the easiest way to use Bootstrap is to require it in your <code>application.css</code> file. Doing so will compile the complete LESS libraries files for Bootstrap. Note how we namespace the files using a simple directory structure.
</p>

<div class="highlight"><pre><code class="css"><span class="c">/*</span>
<span class="c"> *= require twitter/bootstrap</span>
<span class="c">*/</span>

<span class="nf">#foo</span> <span class="p">{</span>
  <span class="c">/* Your styles... */</span>
<span class="p">}</span>
</code></pre>
</div>

<p>
  Alternatively, in a file with the <code>.css.less</code> extension, you can import the entire Bootstrap LESS framework. This will allow you to use Bootstrap's variables and mixins in your CSS that follows. Remember, unlike other CSS frameworks, requiring or importing Bootstrap will include all the CSS for building a bootstrapped website. If you only want variables or mixins, you will have to import those discreet files, see next section.
</p>

<div class="highlight"><pre><code class="css"><span class="k">@import</span> <span class="s2">&quot;twitter/bootstrap&quot;</span><span class="p">;</span>

<span class="nf">#foo</span> <span class="p">{</span>
  <span class="o">.</span><span class="k">border</span><span class="o">-</span><span class="n">radius</span><span class="p">(</span><span class="m">4px</span><span class="p">);</span>
<span class="p">}</span>
</code></pre>
</div>

<p>
  Maybe all you want to use are the variables and mixins that come with Twitter Bootstrap. No problem, just import them individually from you own <code>.css.less</code> file. In this case only the <code>#foo</code> selector is output.
</p>

<div class="highlight"><pre><code class="css"><span class="k">@import</span> <span class="s2">&quot;twitter/bootstrap/variables&quot;</span><span class="p">;</span>
<span class="k">@import</span> <span class="s2">&quot;twitter/bootstrap/mixins&quot;</span><span class="p">;</span>

<span class="nc">.myButton</span><span class="o">(</span><span class="k">@radius</span><span class="o">:</span> <span class="nt">5px</span><span class="o">)</span> <span class="p">{</span>
  <span class="nc">.border-radius</span><span class="o">(</span><span class="k">@radius</span><span class="o">)</span><span class="p">;</span>
<span class="p">}</span>

<span class="nf">#foo</span> <span class="p">{</span>
  <span class="o">.</span><span class="n">myButton</span><span class="p">(</span><span class="m">10px</span><span class="p">);</span>
<span class="p">}</span>
</code></pre>
</div>

<p>
  Using the <a href="http://twitter.github.com/bootstrap/#javascript">Bootstrap JavaScript</a> files is just as easy. Again, you can include all them with a single directive from your <code>application.js</code> file. Optionally, you can require only the files you need like <code>require twitter/bootstrap/modal</code>.
</p>

<div class="highlight"><pre><code class="javascript"><span class="c1">//= require twitter/bootstrap</span>

<span class="nx">$</span><span class="p">(</span><span class="nb">document</span><span class="p">).</span><span class="nx">ready</span><span class="p">(</span><span class="kd">function</span><span class="p">(){</span>
  <span class="c1">//...</span>
<span class="p">});</span>
</code></pre>
</div>

<p>
  The less-rails project has already started getting some good feedback. Soon we hope to implement all the features that you may have used in the sass-rails project, <a href="https://github.com/metaskills/less-rails/issues/1">like asset pipeline helpers</a>. One last thing, I wanted to say thanks to <a href="https://github.com/nmerouze">Nicolas Mérouze</a> for opening up the old less-rails gem space on rubygems.org for the new gem!
</p>

<h2>Resources</h2>

<ul>
  <li><a href="http://lesscss.org/">LESS - The Dynamic Stylesheet Language</a></li>
  <li><a href="http://github.com/metaskills/less-rails">LESS-Rails - Official Support For LESS In Rails</a></li>
  <li><a href="http://github.com/metaskills/less-rails-bootstrap">LESS-Rails-Bootstrap - CSS toolkit from Twitter For Rails 3.1 Asset Pipeline</a></li>
  <li><a href="http://github.com/cowboyd/less.rb">LESS.rb - LESS CSS Rendering From Ruby</a></li>
  <li><a href="http://sass-lang.com/">Sass - Syntactically Awesome Stylesheets</a></li>
  <li><a href="http://github.com/rails/sass-rails">Sass-Rails - Official Support For Sass In Rails</a></li>
  <li><a href="http://compass-style.org/">Compass - An Open-Source CSS Authoring Framework</a></li>
  <li><a href="http://twitter.github.com/bootstrap/">Bootstrap - A Toolkit From Twitter Designed To Kickstart Development</a></li>
</ul>

]]>
    </content>
 </entry>
 
 <entry>
   <title>Keep Trying</title>
   <link href="http://metaskills.net/2011/09/17/keep-trying" />
   <updated>2011-09-17T00:00:00-04:00</updated>
   <id>http://metaskills.net/2011/09/17/keep-trying</id>
   <content type="html">
     <![CDATA[<p>
  <span class="photofancy floatr ml20 mb20">
    <img src="/assets/evilruby.jpg" alt="Ruby Is Evil!" width="248" height="195" />
  </span>
  One part of Objective-C that I like is being able to send messages to nil objects safely and more so their <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/KeyValueCoding/Articles/KeyValueCoding.html">KVC</a> and <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/KeyValueObserving/KeyValueObserving.html">KVO</a> patterns. In Ruby I often use the <code>#try</code> method to safely send messages to objects that may be nil at runtime. But one thing I always wanted was a nice way to send a key path, basically a string of methods signatures, to an object in the same way. I give you my simple <code>#try_keypath</code> method :)
</p>

<div class="highlight"><pre><code class="ruby"><span class="k">class</span> <span class="nc">Object</span>
  <span class="k">def</span> <span class="nf">try_keypath</span><span class="p">(</span><span class="nb">methods</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">block</span><span class="p">)</span>
    <span class="nb">methods</span><span class="o">.</span><span class="n">to_s</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;.&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">inject</span><span class="p">(</span><span class="nb">self</span><span class="p">)</span> <span class="p">{</span> <span class="o">|</span><span class="n">result</span><span class="p">,</span> <span class="nb">method</span><span class="o">|</span> <span class="n">result</span><span class="o">.</span><span class="n">try</span><span class="p">(</span><span class="nb">method</span><span class="p">)</span> <span class="p">}</span>
  <span class="k">end</span>
<span class="k">end</span>

<span class="k">class</span> <span class="nc">NilClass</span>
  <span class="k">def</span> <span class="nf">try_keypath</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">)</span>
    <span class="kp">nil</span>
  <span class="k">end</span>
<span class="k">end</span>
</code></pre>
</div>

<p>
  Yup, it is that simple. Let's see how this would work. Here are a few basic classes that randomly return nested objects. So staring with the <code>Foo</code> object, we have the possibility to get to some deeply nested info.
</p>

<div class="highlight"><pre><code class="ruby"><span class="k">class</span> <span class="nc">Foo</span>
  <span class="k">def</span> <span class="nf">bar</span>
    <span class="nb">rand</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span> <span class="o">?</span> <span class="no">Bar</span><span class="o">.</span><span class="n">new</span> <span class="p">:</span> <span class="kp">nil</span>
  <span class="k">end</span>
<span class="k">end</span>

<span class="k">class</span> <span class="nc">Bar</span>
  <span class="k">def</span> <span class="nf">batz</span>
    <span class="s1">&#39;wohoo&#39;</span>
  <span class="k">end</span>
  <span class="k">def</span> <span class="nf">deep</span>
    <span class="no">Deep</span><span class="o">.</span><span class="n">new</span>
  <span class="k">end</span>
<span class="k">end</span>

<span class="k">class</span> <span class="nc">Deep</span>
  <span class="k">def</span> <span class="nf">info</span>
    <span class="p">{</span><span class="ss">:winning</span> <span class="o">=&gt;</span> <span class="kp">true</span><span class="p">}</span>
  <span class="k">end</span>
<span class="k">end</span>
</code></pre>
</div>

<p>
  Finally, here is how it would look and return different results. Man I love Ruby!
</p>

<div class="highlight"><pre><code class="ruby"><span class="no">Foo</span><span class="o">.</span><span class="n">new</span><span class="o">.</span><span class="n">try</span> <span class="ss">:bar</span> <span class="c1"># =&gt; #&lt;Bar:0x108d7dfd0&gt;</span>
<span class="no">Foo</span><span class="o">.</span><span class="n">new</span><span class="o">.</span><span class="n">try</span> <span class="ss">:bar</span> <span class="c1"># =&gt; #&lt;Bar:0x108d7ddf0&gt;</span>
<span class="no">Foo</span><span class="o">.</span><span class="n">new</span><span class="o">.</span><span class="n">try</span> <span class="ss">:bar</span> <span class="c1"># =&gt; nil</span>
<span class="no">Foo</span><span class="o">.</span><span class="n">new</span><span class="o">.</span><span class="n">try</span> <span class="ss">:bar</span> <span class="c1"># =&gt; nil</span>
<span class="no">Foo</span><span class="o">.</span><span class="n">new</span><span class="o">.</span><span class="n">try</span> <span class="ss">:bar</span> <span class="c1"># =&gt; #&lt;Bar:0x108d7d4b8&gt;</span>
<span class="no">Foo</span><span class="o">.</span><span class="n">new</span><span class="o">.</span><span class="n">try</span> <span class="ss">:bar</span> <span class="c1"># =&gt; nil</span>

<span class="no">Foo</span><span class="o">.</span><span class="n">new</span><span class="o">.</span><span class="n">try_keypath</span> <span class="s1">&#39;bar.batz&#39;</span> <span class="c1"># =&gt; &quot;wohoo&quot;</span>
<span class="no">Foo</span><span class="o">.</span><span class="n">new</span><span class="o">.</span><span class="n">try_keypath</span> <span class="s1">&#39;bar.batz&#39;</span> <span class="c1"># =&gt; &quot;wohoo&quot;</span>
<span class="no">Foo</span><span class="o">.</span><span class="n">new</span><span class="o">.</span><span class="n">try_keypath</span> <span class="s1">&#39;bar.batz&#39;</span> <span class="c1"># =&gt; nil</span>
<span class="no">Foo</span><span class="o">.</span><span class="n">new</span><span class="o">.</span><span class="n">try_keypath</span> <span class="s1">&#39;bar.batz&#39;</span> <span class="c1"># =&gt; nil</span>
<span class="no">Foo</span><span class="o">.</span><span class="n">new</span><span class="o">.</span><span class="n">try_keypath</span> <span class="s1">&#39;bar.batz&#39;</span> <span class="c1"># =&gt; nil</span>
<span class="no">Foo</span><span class="o">.</span><span class="n">new</span><span class="o">.</span><span class="n">try_keypath</span> <span class="s1">&#39;bar.batz&#39;</span> <span class="c1"># =&gt; &quot;wohoo&quot;</span>

<span class="no">Foo</span><span class="o">.</span><span class="n">new</span><span class="o">.</span><span class="n">try_keypath</span> <span class="s1">&#39;bar.deep.info&#39;</span> <span class="c1"># =&gt; nil</span>
<span class="no">Foo</span><span class="o">.</span><span class="n">new</span><span class="o">.</span><span class="n">try_keypath</span> <span class="s1">&#39;bar.deep.info&#39;</span> <span class="c1"># =&gt; {:winning=&gt;true}</span>
<span class="no">Foo</span><span class="o">.</span><span class="n">new</span><span class="o">.</span><span class="n">try_keypath</span> <span class="s1">&#39;bar.deep.info&#39;</span> <span class="c1"># =&gt; nil</span>
<span class="no">Foo</span><span class="o">.</span><span class="n">new</span><span class="o">.</span><span class="n">try_keypath</span> <span class="s1">&#39;bar.deep.info&#39;</span> <span class="c1"># =&gt; nil</span>
<span class="no">Foo</span><span class="o">.</span><span class="n">new</span><span class="o">.</span><span class="n">try_keypath</span> <span class="s1">&#39;bar.deep.info&#39;</span> <span class="c1"># =&gt; {:winning=&gt;true}</span>
<span class="no">Foo</span><span class="o">.</span><span class="n">new</span><span class="o">.</span><span class="n">try_keypath</span> <span class="s1">&#39;bar.deep.info&#39;</span> <span class="c1"># =&gt; nil</span>
</code></pre>
</div>


]]>
    </content>
 </entry>
 
 <entry>
   <title>Revisiting My Design Past</title>
   <link href="http://metaskills.net/2011/09/11/revisiting-my-design-past" />
   <updated>2011-09-11T00:00:00-04:00</updated>
   <id>http://metaskills.net/2011/09/11/revisiting-my-design-past</id>
   <content type="html">
     <![CDATA[<p>
  Not many people know that I used to be a designer back in the mid 90's. Some of you all may have ventured deep into the colophon section of my site and read <a href="/pages/resume.html">my resume</a> which has visual clues of that history. Either way, this page is dedicated to those that had no idea a programmer like myself could come from a design background. Besides, I think it would be cool to share some of my old portfolio pieces.
</p>

<h2>Beer Labels</h2>

<p>
  Every good starving artist needs a watering hole. Mine used to be the <a href="http://maps.google.com/maps/place?client=safari&rls=en&oe=UTF-8&um=1&ie=UTF-8&q=Taphouse+Grill+Norfolk&fb=1&gl=us&hq=Taphouse+Grill&hnear=0x89ba973a5322ca45:0xab99107fce7a1e0a,Norfolk,+VA&cid=13700420888534827238">Tap House Grill At Ghent</a>. Doing menu and beer tap design was a great way to pay for the basic staples of life, food and beer! Most of my friends worked there as well. Even after all these years, The Taphouse Grill still seems to be going strong in the same location. So here are a few of those beer tap designs. The "Sex Ina Canoe" tap was a joke against Yuengling Lager and referenced the joke, What does American beer and sex in canoe have in common?
</p>

<img src="/assets/design/beer_labels.png" alt="My Beer Label Designs For The Taphouse Grill In Norfolk, Virginia" width="774" height="327" />


<h2>Logos</h2>

<p>
  On top of doing tons of 4-color brochure and package design, I used to love doing logo work. The one for the Virginia Stage Company was never used and the middle was a logo for my old online moniker before MetaSkills. The last logo was for a friend's Mother's clothing company with heavy art direction.
</p>

<img src="/assets/design/logos.png" alt="My Misc Logo Work" width="774" height="273" />


<h2>Drawing Collaborations</h2>

<p>
  One thing I really enjoyed doing was working with illustrations by my friend Jeff Stephenson. He sketched tons of different things while making his way thru the day. I believe some of his drawings were purely cathartic or helped him cope in one way or another. Most times I would rescue them from the trash bin and scan them in for artwork. The first below is a t-shirt design for the Taphouse Grill's Cindo De Micro event. I remember piecing different illustrations together with some heavily inspired artwork I gathered while shopping for frozen burritos to eat that night. The end result was awesome. Lastly, what can I about Superfly Bundt Cackes? I think the wings came out nicely.
</p>

<div class="center mb20">
  <span class="photofancy">
    <img src="/assets/design/cinco_de_micro.jpg" alt="The Cinco De Micro Taphouse Grill T-Shirt Collaboration With Jeff Stephenson" width="542" height="390" />
  </span>
</div>

<div class="center">
  <span class="photofancy">
    <img src="/assets/design/superfly_bundt_cakes.jpg" alt="Superfly Bundt Cakes Was Just A Silly Experiment" width="561" height="426" />
  </span>
</div>


<h2>Experimental</h2>

<p>
  Even designers have to perform occupational maintenance. I was always reading design articles (before blogs were invented) and learning the different techniques and power of PhotoShop 4 and its numerous plug-ins. Below is a mixed bag of those results.
</p>

<div class="center mb20">
  <span class="photofancy">
    <img src="/assets/design/shocking.jpg" alt="Shocking Design Expierment For Lighting Effect In PhotoShop" width="695" height="132" />
  </span>
</div>

<div class="center mb20">
  <span class="photofancy">
    <img src="/assets/design/virus.jpg" alt="Virus Design Expierment With Text And Backgrounds" width="559" height="419" />
  </span>
</div>

<div class="center">
  <span class="photofancy">
    <img src="/assets/design/laugh_soup.jpg" alt="A Laugh Soup CD Design Expierment With Text And Backgrounds" width="462" height="450" />
  </span>
</div>


<h2>Design Is Important</h2>

<p>
  I think it is critical that every designer or programmer have a basic skill in the other field. It adds tons of value and streamlines communication across the disciplines. For me however, I have made a career decision that I will never open a PSD file again or try to facilitate the design role. I can if I have to, but not doing it all the time means that the time I do spend designing is not as efficient as someone else in that role. My place is now spent pushing pixels via code!
</p>


]]>
    </content>
 </entry>
 
 <entry>
   <title>How Do You Encapsulate Your JavaScript</title>
   <link href="http://metaskills.net/2011/09/06/how-do-you-encapsulate-your-javascript" />
   <updated>2011-09-06T00:00:00-04:00</updated>
   <id>http://metaskills.net/2011/09/06/how-do-you-encapsulate-your-javascript</id>
   <content type="html">
     <![CDATA[<p>
  I ask this question a lot! To Job candidates, friends, and almost any developer that says they work with JavaScript. I believe how you encapsulate your JavaScript is a good indicator on your level of expertise with the language. I find that most beginners have come to JavaScript via jQuery and often define their functions at the top level namespace in some application.js file. These functions are loosely organized and often have no way of sharing simple object state and behavior. A good object oriented programmer would never write their application code like that. JavaScript should be no different and I think jQuery has a part in the blame of those not knowing this.
</p>

<p>
  I've <a href="/2008/08/18/in-hell-oo-for-homemarks/">been writing rich object oriented JavaScript</a> for the better part of 4 years now using <a href="http://www.prototypejs.org/">Prototype.js</a>. That framework has always championed encapsulating your web application's behavior using a <a href="http://prototypejs.org/learn/class-inheritance">standard class and inheritance notation</a>. Sam Stephenson, the author of Prototype.js, did a good job trying to educate what real JavaScript Object Notation (JSON) is about and how you can encapsulate behavior using Prototype's Class structure while paying homage to <a href="http://dean.edwards.name/weblog/2006/03/base/">Dean Edward's Base.js</a> to which it owes its origins.
</p>

<p>
  So jQuery is the proper winner and choice for anyone wanting to use a JavaScript framework to make working with the DOM in web sites easier. It has awesome event handling and delegation. So many things that Prototype.js lacked. It even has great documentation. About the only bad thing about jQuery is the widely different interfaces to it's AJAX functions and the arguments passed to their callbacks. Oh, and they totally screwed new JavaScript developers by not sheperding them into learning some sort of way to encapsulate their object behavior. So this article is for those that are not using <a href="http://jashkenas.github.com/coffee-script/">CoffeeScript's class system</a>, <a href="http://documentcloud.github.com/backbone/">Backbone.js's class system</a>, or jQuery's deeply nested plugin class system that is hidden away. So lets get to fixing that. Here is 32 lines of dirt simple JavaScript inheritance.
</p>

<div class="highlight"><pre><code class="javascript"><span class="cm">/* Simple JavaScript Class</span>
<span class="cm">   By John Resig. MIT Licensed. &lt;http://ejohn.org/blog/simple-javascript-inheritance/&gt; */</span>
<span class="p">(</span><span class="kd">function</span><span class="p">(){</span>
  <span class="kd">var</span> <span class="nx">initializing</span> <span class="o">=</span> <span class="kc">false</span><span class="p">,</span> <span class="nx">fnTest</span> <span class="o">=</span> <span class="sr">/xyz/</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="kd">function</span><span class="p">(){</span><span class="nx">xyz</span><span class="p">;})</span> <span class="o">?</span> <span class="sr">/\b_super\b/</span> <span class="o">:</span> <span class="sr">/.*/</span><span class="p">;</span>
  <span class="k">this</span><span class="p">.</span><span class="nx">JQClass</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(){};</span>
  <span class="nx">JQClass</span><span class="p">.</span><span class="nx">extend</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">prop</span><span class="p">)</span> <span class="p">{</span>
    <span class="kd">var</span> <span class="nx">_super</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">prototype</span><span class="p">;</span>
    <span class="nx">initializing</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
    <span class="kd">var</span> <span class="nx">prototype</span> <span class="o">=</span> <span class="k">new</span> <span class="k">this</span><span class="p">();</span>
    <span class="nx">initializing</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
    <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">name</span> <span class="k">in</span> <span class="nx">prop</span><span class="p">)</span> <span class="p">{</span>
      <span class="nx">prototype</span><span class="p">[</span><span class="nx">name</span><span class="p">]</span> <span class="o">=</span> <span class="k">typeof</span> <span class="nx">prop</span><span class="p">[</span><span class="nx">name</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;function&quot;</span> <span class="o">&amp;&amp;</span> 
        <span class="k">typeof</span> <span class="nx">_super</span><span class="p">[</span><span class="nx">name</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;function&quot;</span> <span class="o">&amp;&amp;</span> <span class="nx">fnTest</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">prop</span><span class="p">[</span><span class="nx">name</span><span class="p">])</span> <span class="o">?</span>
        <span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">name</span><span class="p">,</span> <span class="nx">fn</span><span class="p">){</span>
          <span class="k">return</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
            <span class="kd">var</span> <span class="nx">tmp</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_super</span><span class="p">;</span>
            <span class="k">this</span><span class="p">.</span><span class="nx">_super</span> <span class="o">=</span> <span class="nx">_super</span><span class="p">[</span><span class="nx">name</span><span class="p">];</span>
            <span class="kd">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="nx">fn</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="nx">arguments</span><span class="p">);</span>        
            <span class="k">this</span><span class="p">.</span><span class="nx">_super</span> <span class="o">=</span> <span class="nx">tmp</span><span class="p">;</span>
            <span class="k">return</span> <span class="nx">ret</span><span class="p">;</span>
          <span class="p">};</span>
        <span class="p">})(</span><span class="nx">name</span><span class="p">,</span> <span class="nx">prop</span><span class="p">[</span><span class="nx">name</span><span class="p">])</span> <span class="o">:</span>
        <span class="nx">prop</span><span class="p">[</span><span class="nx">name</span><span class="p">];</span>
    <span class="p">}</span>
    <span class="kd">function</span> <span class="nx">JQClass</span><span class="p">()</span> <span class="p">{</span>
      <span class="k">if</span> <span class="p">(</span> <span class="o">!</span><span class="nx">initializing</span> <span class="o">&amp;&amp;</span> <span class="k">this</span><span class="p">.</span><span class="nx">init</span> <span class="p">)</span>
        <span class="k">this</span><span class="p">.</span><span class="nx">init</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="nx">arguments</span><span class="p">);</span>
    <span class="p">}</span>
    <span class="nx">JQClass</span><span class="p">.</span><span class="nx">prototype</span> <span class="o">=</span> <span class="nx">prototype</span><span class="p">;</span>
    <span class="nx">JQClass</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">constructor</span> <span class="o">=</span> <span class="nx">JQClass</span><span class="p">;</span>
    <span class="nx">JQClass</span><span class="p">.</span><span class="nx">extend</span> <span class="o">=</span> <span class="nx">arguments</span><span class="p">.</span><span class="nx">callee</span><span class="p">;</span>
    <span class="k">return</span> <span class="nx">JQClass</span><span class="p">;</span>
  <span class="p">};</span>
<span class="p">})();</span>
</code></pre>
</div>

<p>
  It is <a href="http://ejohn.org/blog/simple-javascript-inheritance/">worth reading the comments</a> John Resig's blog post for this piece of work as well as the full documentation. My code example above names this <code>JQClass</code> to avoid namespace collisions with other frameworks. Here is a simple example of its usage.
</p>

<div class="highlight"><pre><code class="javascript"><span class="c1">// Your namespace.</span>

<span class="kd">var</span> <span class="nx">MyApp</span> <span class="o">=</span> <span class="p">{</span>
  <span class="nx">models</span><span class="o">:</span> <span class="p">{}</span>
<span class="p">};</span>

<span class="c1">// Simple object example for page flash.</span>

<span class="nx">MyApp</span><span class="p">.</span><span class="nx">models</span><span class="p">.</span><span class="nx">flash</span> <span class="o">=</span> <span class="nx">JQClass</span><span class="p">.</span><span class="nx">extend</span><span class="p">({</span>
  
  <span class="nx">init</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">aPage</span><span class="p">)</span> <span class="p">{</span>
    <span class="k">this</span><span class="p">.</span><span class="nx">page</span> <span class="o">=</span> <span class="nx">$</span><span class="p">(</span><span class="nx">aPage</span><span class="p">);</span>
    <span class="k">this</span><span class="p">.</span><span class="nx">alertDiv</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">page</span><span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="s1">&#39;div.flash.alert&#39;</span><span class="p">);</span>
    <span class="k">this</span><span class="p">.</span><span class="nx">noticeDiv</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">page</span><span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="s1">&#39;div.flash.notice&#39;</span><span class="p">);</span>
  <span class="p">},</span>
  
  <span class="nx">alert</span><span class="o">:</span>  <span class="kd">function</span><span class="p">(</span><span class="nx">content</span><span class="p">)</span> <span class="p">{</span> <span class="k">this</span><span class="p">.</span><span class="nx">_doFlashFor</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">alertDiv</span><span class="p">,</span><span class="nx">content</span><span class="p">);</span> <span class="p">},</span>
  
  <span class="nx">notice</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">content</span><span class="p">)</span> <span class="p">{</span> <span class="k">this</span><span class="p">.</span><span class="nx">_doFlashFor</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">noticeDiv</span><span class="p">,</span><span class="nx">content</span><span class="p">);</span> <span class="p">},</span>
  
  <span class="nx">clear</span><span class="o">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
    <span class="err">#</span> <span class="p">...</span>
  <span class="p">},</span>
  
  <span class="nx">_doFlashFor</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">flash</span><span class="p">,</span> <span class="nx">content</span><span class="p">)</span> <span class="p">{</span>
    <span class="nx">$</span><span class="p">.</span><span class="nx">mobile</span><span class="p">.</span><span class="nx">silentScroll</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span>
    <span class="k">this</span><span class="p">.</span><span class="nx">clear</span><span class="p">();</span>
    <span class="nx">flash</span><span class="p">.</span><span class="nx">html</span><span class="p">(</span><span class="nx">content</span><span class="p">);</span>
    <span class="nx">flash</span><span class="p">.</span><span class="nx">show</span><span class="p">();</span>
  <span class="p">}</span>
  
<span class="p">});</span>
</code></pre>
</div>


<p>
  This code example is pulled from a jQuery mobile project I recently finished. The real usage of the flash objects would be numerous as there would be one per page and I have a top level delegate object that finds the active page and finds or create the flash DOM elements. But this should be a good enough example to show why you might choose a simple class and object inheritance system vs putting all your logic in <code>$(document).ready({})</code> scopes. There are tons of ways to write good OO JavaScript and I hope some find this useful and explore some other ways.
</p>


]]>
    </content>
 </entry>
 
 <entry>
   <title>jQuery Mobile &amp;amp; Rails</title>
   <link href="http://metaskills.net/2011/08/24/jquery-mobile-and-rails" />
   <updated>2011-08-24T00:00:00-04:00</updated>
   <id>http://metaskills.net/2011/08/24/jquery-mobile-and-rails</id>
   <content type="html">
     <![CDATA[<p>
  <img class="floatr" src="/assets/jquery_mobile_rails.png"/>
  I just finished my first dive into using <a href="http://jquerymobile.com/">jQuery Mobile</a> with a Rails application and wanted to share some techniques that came out along the way. Hopefully these will help you if your are using jQuery Mobile with Rails or want to test your mobile application's integration layer. This post assumes you are somewhat familiar with jQuery Mobile and its basic concepts. So let's jump right in with a series of helpful tips.
</p>



<h2>A Mobile Layout</h2>

<p>
  In my application, I decided to use use a route namespace of "mobile" vs a sub-domain for all controllers and views to reside in. Do what works for you, but I find that using namespaces both helps keep my code organized and simple to maintain. Either way, you should have a layout specific for your mobile application. Mine is in <code>app/views/layout/mobile.html.haml</code>. As you can see here, I use HAML, so all view examples will be using it vs ERB. Here is a general layout.
</p>

<div class="highlight"><pre><code class="ruby"><span class="o">!!!</span> <span class="mi">5</span>
<span class="o">%</span><span class="n">html</span><span class="p">{</span><span class="ss">:lang</span> <span class="o">=&gt;</span> <span class="s1">&#39;en&#39;</span><span class="p">}</span>
  <span class="o">%</span><span class="n">head</span>
    <span class="o">%</span><span class="n">meta</span><span class="p">{</span><span class="ss">:charset</span> <span class="o">=&gt;</span> <span class="s1">&#39;utf-8&#39;</span><span class="p">}</span>
    <span class="o">%</span><span class="n">meta</span><span class="p">{</span><span class="ss">:name</span> <span class="o">=&gt;</span> <span class="s1">&#39;viewport&#39;</span><span class="p">,</span> <span class="ss">:content</span> <span class="o">=&gt;</span> <span class="s1">&#39;width=device-width, initial-scale=1&#39;</span><span class="p">}</span>
    <span class="o">%</span><span class="n">meta</span><span class="p">{</span><span class="ss">:name</span> <span class="o">=&gt;</span> <span class="s1">&#39;format-detection&#39;</span><span class="p">,</span> <span class="ss">:content</span> <span class="o">=&gt;</span> <span class="s1">&#39;telephone=no&#39;</span><span class="p">}</span>
    <span class="o">%</span><span class="n">title</span><span class="o">=</span> <span class="s1">&#39;My Mobile App&#39;</span>
    <span class="o">%</span><span class="n">link</span><span class="p">{</span><span class="ss">:rel</span> <span class="o">=&gt;</span> <span class="s1">&#39;stylesheet&#39;</span><span class="p">,</span> <span class="ss">:href</span> <span class="o">=&gt;</span> <span class="s1">&#39;http://code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.min.css&#39;</span><span class="p">}</span>
    <span class="o">%</span><span class="n">script</span><span class="p">{</span><span class="ss">:src</span> <span class="o">=&gt;</span> <span class="s1">&#39;http://code.jquery.com/jquery-1.6.2.min.js&#39;</span><span class="p">}</span>
    <span class="o">%</span><span class="n">script</span><span class="p">{</span><span class="ss">:src</span> <span class="o">=&gt;</span> <span class="s1">&#39;http://code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.min.js&#39;</span><span class="p">}</span>
  <span class="o">%</span><span class="n">body</span>
    <span class="o">=</span> <span class="k">yield</span><span class="p">(</span><span class="ss">:layout</span><span class="p">)</span>
</code></pre>
</div>

<p>
  A few key points here. First, the meta tag for the <code>viewport</code> is recommended as a good base. The other meta tag for <code>format-detection</code> is to disable automatic detection and linking of phone numbers. Phone number detection is way too aggressive and often just links random numbers with periods and hyphens. This means if you want a phone number to call when touched, you will have to use the <code>tel:</code> link format with the phone number afterward. I recommend the aid of something like the <a href="https://github.com/floere/phony">phony</a> gem for validating and parsing phone number formats. Lastly, the title attribute in the head is really moot. The jQuery Mobile framework will dynamically change the page title as new page DOM elements are loaded in.
</p>



<h2>Mobile Page IDs</h2>

<p>
  A typical jQuery Mobile app will have one full page load. All other pages thereafter are loaded via AJAX and inserted into the DOM. Their docs suggest that every page (and form) have a unique id attribute. These ids can be used to link to the DOM page element when navigating around preloaded pages. Simple apps can get by with a few ids like "#home", "#contact_us", "#etc". But if you have a large application, you need a better system to keep track of things.
</p>

<p>
  Thankfully if you are building your Rails applications in a RESTful manner, it is easy to leverage the route link helpers to generate your page ids. In the example below, I created a method called <code>mobile_page_id</code> that I placed into a <a href="http://weblog.jamisbuck.org/2007/1/17/concerns-in-activerecord">shared concerns module directory</a>. From here I mix this into my test helper, and application's view helper. It is that damn useful! You are going to want to use this everywhere!
</p>

<div class="highlight"><pre><code class="ruby"><span class="c1"># File: app/concerns/mobile_concerns.rb</span>
<span class="k">module</span> <span class="nn">MobileConcerns</span>  
  <span class="k">module</span> <span class="nn">Helpers</span>
    <span class="k">def</span> <span class="nf">mobile_page_id</span><span class="p">(</span><span class="n">path</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">path</span><span class="p">)</span>
      <span class="n">path</span><span class="o">.</span><span class="n">sub</span><span class="p">(</span><span class="sr">/\A\/mobile\//</span><span class="p">,</span><span class="s1">&#39;&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">gsub</span><span class="p">(</span><span class="s2">&quot;/&quot;</span><span class="p">,</span><span class="s1">&#39;_&#39;</span><span class="p">)</span>
    <span class="k">end</span>
  <span class="k">end</span>  
<span class="k">end</span>

<span class="c1"># Mix into your applications helper.</span>
<span class="k">module</span> <span class="nn">ApplicationHelper</span>
  <span class="kp">include</span> <span class="no">MobileConcerns</span><span class="o">::</span><span class="no">Helpers</span>
<span class="k">end</span>

<span class="c1"># Mix into your test helper of choice.</span>
<span class="k">class</span> <span class="nc">MobileStoriesTest</span> <span class="o">&lt;</span> <span class="no">ActionController</span><span class="o">::</span><span class="no">IntegrationTest</span>
  <span class="kp">include</span> <span class="no">MobileConcerns</span><span class="o">::</span><span class="no">Helpers</span>
<span class="k">end</span>
</code></pre>
</div>

<p>
  The <code>mobile_page_id</code> method is primarily for views. I will cover its usage in testing further down. When called without an argument, it will take the current request path and translate it to a string suitable for a page id. So if you were rendering a <code>/mobile/users/10/avatar</code> page, the id would be <code>users_10_avatar</code>. If your application follows RESTful resources in your routes, this can pay dividends. When needed, you can pass a <code>*_path</code> helper method to get the same id. In this example the same id would come back for <code>mobile_page_id(mobile_user_avatar_path(@user))</code>. Remember, I am using a "mobile" namespace in my examples and hence my method above strips that out, flavor this helper to your needs. Here is an example of what you might find in <code>app/views/users/avatar.html.haml</code> using the mobile_page_id. You can see here that I am also setting a title local that is used in the <code>%h1</code> tag and the <code>data-title</code> page element attribute. Doing this will show the same title in the header bar as well as the page title.
</p>

<div class="highlight"><pre><code class="ruby"><span class="o">-</span> <span class="n">title</span> <span class="o">=</span> <span class="s2">&quot;User Profile&quot;</span>

<span class="o">%</span><span class="n">div</span><span class="p">{</span><span class="ss">:id</span> <span class="o">=&gt;</span> <span class="n">mobile_page_id</span><span class="p">,</span> <span class="ss">:data</span> <span class="o">=&gt;</span> <span class="p">{</span><span class="ss">:role</span> <span class="o">=&gt;</span> <span class="s1">&#39;page&#39;</span><span class="p">,</span> <span class="ss">:title</span> <span class="o">=&gt;</span> <span class="n">title</span><span class="p">}}</span>

  <span class="o">%</span><span class="n">div</span><span class="p">{</span><span class="ss">:data</span> <span class="o">=&gt;</span> <span class="p">{</span><span class="ss">:role</span> <span class="o">=&gt;</span> <span class="s1">&#39;header&#39;</span><span class="p">}}</span>
    <span class="o">%</span><span class="n">h1</span><span class="o">=</span> <span class="n">title</span>
  <span class="o">%</span><span class="n">div</span><span class="p">{</span><span class="ss">:data</span> <span class="o">=&gt;</span> <span class="p">{</span><span class="ss">:role</span> <span class="o">=&gt;</span> <span class="s1">&#39;content&#39;</span><span class="p">}}</span>
    <span class="n">edit</span> <span class="n">your</span> <span class="n">profile</span><span class="o">.</span><span class="n">.</span><span class="o">.</span>
  <span class="o">%</span><span class="n">div</span><span class="p">{</span><span class="ss">:data</span> <span class="o">=&gt;</span> <span class="p">{</span><span class="ss">:role</span> <span class="o">=&gt;</span> <span class="s1">&#39;footer&#39;</span><span class="p">}}</span><span class="sr"></span>
<span class="sr">    /...</span>
</code></pre>
</div>



<h2>Easy Data Attributes</h2>

<p>
  The jQuery Mobile framework will have you typing a lot of data-* attributes into your elements. It uses these from basic page behavior to UI themes. They are literally needed everywhere. If your typing out raw HTML these data attributes get old pretty quick. Thankfully both HAML and the latest Rails 3.1 tag helpers can keep things clean. Both allow hashes to be passed to the data attribute. Keys are dasherized and values are JSON-encoded except for string and symbols.
</p>

<div class="highlight"><pre><code class="ruby"><span class="c1"># HAML Shorthand For:</span>
<span class="c1"># &lt;div id=&quot;foo&quot; data-role=&quot;page&quot; data-title=&quot;Title&quot; data-rel=&quot;dialog&quot;&gt;&lt;/div&gt;</span>

<span class="o">%</span><span class="n">div</span><span class="p">{</span><span class="ss">:id</span> <span class="o">=&gt;</span> <span class="s1">&#39;foo&#39;</span><span class="p">,</span> <span class="ss">:data</span> <span class="o">=&gt;</span> <span class="p">{</span><span class="ss">:role</span> <span class="o">=&gt;</span> <span class="s1">&#39;page&#39;</span><span class="p">,</span> <span class="ss">:title</span> <span class="o">=&gt;</span> <span class="s1">&#39;Title&#39;</span><span class="p">,</span> <span class="ss">:rel</span> <span class="o">=&gt;</span> <span class="s1">&#39;dialog&#39;</span><span class="p">}}</span>

<span class="c1"># Rails 3.1 Tag Helpers</span>
<span class="c1"># &lt;div data-name=&quot;Stephen&quot; data-city-state=&quot;[&amp;quot;Chicago&amp;quot;,&amp;quot;IL&amp;quot;]&quot; /&gt;</span>

<span class="n">tag</span><span class="p">(</span><span class="s2">&quot;div&quot;</span><span class="p">,</span> <span class="ss">:data</span> <span class="o">=&gt;</span> <span class="p">{</span><span class="ss">:name</span> <span class="o">=&gt;</span> <span class="s1">&#39;Stephen&#39;</span><span class="p">,</span> <span class="ss">:city_state</span> <span class="o">=&gt;</span> <span class="sx">%w(Chicago IL)</span><span class="p">})</span>
</code></pre>
</div>



<h2>Dynamically Setting Layout</h2>


<p>
  Remember how jQuery Mobile only loads the entire page once and then inserts all following pages using AJAX? This means that views after the initial page load do not need the layout when rendered. Depending on the setup of your mobile application, it could become a chore telling each action to conditionally render the layout or not. Imagine a page refresh or a user bookmarking a deep resource node of your mobile app. Thankfully with a little Rails-fu, we can conditionally set the layout to false if the request is an <code>HTTP GET</code> from an AJAX request. Below is an example of my base mobile controller that all mobile controllers inherit from. Now every action is able to load the entire mobile layout or not.
</p>

<div class="highlight"><pre><code class="ruby"><span class="k">class</span> <span class="nc">Mobile</span><span class="o">::</span><span class="no">BaseController</span> <span class="o">&lt;</span> <span class="no">ApplicationController</span>

  <span class="no">LAYOUT</span> <span class="o">=</span> <span class="s1">&#39;mobile&#39;</span><span class="o">.</span><span class="n">freeze</span>
  <span class="n">layout</span> <span class="no">LAYOUT</span>
  <span class="n">around_filter</span> <span class="ss">:dynamically_assign_layout</span>
  
  <span class="kp">private</span>
  
  <span class="k">def</span> <span class="nf">dynamically_assign_layout</span>
    <span class="nb">self</span><span class="o">.</span><span class="n">class</span><span class="o">.</span><span class="n">layout</span> <span class="kp">false</span> <span class="k">if</span> <span class="n">request</span><span class="o">.</span><span class="n">get?</span> <span class="o">&amp;&amp;</span> <span class="n">request</span><span class="o">.</span><span class="n">xhr?</span>
    <span class="k">yield</span>
  <span class="k">ensure</span>
    <span class="nb">self</span><span class="o">.</span><span class="n">class</span><span class="o">.</span><span class="n">layout</span> <span class="no">LAYOUT</span>
  <span class="k">end</span>
  
<span class="k">end</span>
</code></pre>
</div>



<h2>Integration Testing &amp; Capybara-Webkit</h2>

<aside class="flash_info">
  UPDATE: After this article I posted a gist titled <a href="https://gist.github.com/1172519">Never sleep() using Capybara!</a> that details how to deal with CSS animations and AJAX requests using Capybara. Check it out too!
</aside>

<p>
  Those that know me are familiar that I do not use RSpec or Test::Unit but instead opt for a simple testing framework built into Ruby 1.9, <a href="/2011/03/26/using-minitest-spec-with-rails/">MiniTest::Spec</a>. I also use the <a href="https://github.com/thoughtbot/capybara-webkit">Capybara-WebKit</a> driver for my acceptance testing in both <a href="https://github.com/metaskills/holygrail_rails23">Rails 2.3</a> and <a href="https://github.com/metaskills/holygrail_rails31">Rails 3.1</a>'s standard integration test layer. Reference the <code>integration_test_helper.rb</code> file in each link above to learn how to use Capybara-WebKit with your rails app. Thanks to Wyatt Greene for his <a href="http://techiferous.com/2010/04/using-capybara-in-rails-3/">original article</a> on the matter. 
</p>

<p>
  So why the fuss? Well Capybara-WebKit is a headless WebKit browser that you can direct right from your test suite. What makes it so awesome is that it renders web pages with full JavaScript support and is much faster than selenium based Capybara drivers. Since jQuery Mobile is entirely based on JavaScript with HTML &amp; CSS3 - Capybara-WebKit is a perfect candidate to acceptance test your mobile application. The only gotcha is scoping your Capybara actions to a certain page that is dynamically loaded into the DOM. No problem! This is easily solvable using the page ids from the <code>mobile_page_id</code> helper method I mentioned above. So whatever your testing framework, here are a few helpers that are critical. Assume these are mixed into your test helper.
</p>

<div class="highlight"><pre><code class="ruby"><span class="kp">private</span>

<span class="kp">include</span> <span class="no">MobileConcerns</span><span class="o">::</span><span class="no">Helpers</span> <span class="c1"># Mentioned above.</span>

<span class="k">def</span> <span class="nf">current_page_id</span><span class="p">(</span><span class="n">path</span><span class="o">=</span><span class="kp">nil</span><span class="p">)</span>
  <span class="n">path</span> <span class="o">=</span> <span class="n">path</span> <span class="o">||</span> <span class="n">current_path</span>
  <span class="s2">&quot;div#</span><span class="si">#{</span><span class="n">mobile_page_id</span><span class="p">(</span><span class="n">path</span><span class="p">)</span><span class="si">}</span><span class="s2">.ui-page-active&quot;</span>
<span class="k">end</span>

<span class="k">def</span> <span class="nf">current_page</span><span class="p">(</span><span class="n">path</span><span class="o">=</span><span class="kp">nil</span><span class="p">)</span>
  <span class="n">find</span><span class="p">(</span><span class="n">current_page_id</span><span class="p">(</span><span class="n">path</span><span class="p">))</span>
<span class="k">end</span>

<span class="k">def</span> <span class="nf">within_current_page</span><span class="p">(</span><span class="n">path</span><span class="o">=</span><span class="kp">nil</span><span class="p">)</span>
  <span class="n">within</span><span class="p">(</span><span class="n">current_page_id</span><span class="p">(</span><span class="n">path</span><span class="p">))</span> <span class="p">{</span> <span class="k">yield</span> <span class="p">}</span>
<span class="k">end</span>
</code></pre>
</div>

<p>
  So let's go over these. First is the <code>current_page_id</code> method. Most of the time you are going to pass a path argument to this method, since the Capybara's <code>current_path</code> will only work correctly on the first page load, not each following AJAX page load which would change the location hash. See how this is using the <code>mobile_page_id</code> helper mixed in and described above? Next is the <code>current_page</code> helper. It finds the passed path/id with Capybara's find method. The <code>within_current_page</code> leverages Capybara's <code>within</code> helper to scope your action to that particular DOM element. Here is a classic example using these.
</p>

<div class="highlight"><pre><code class="ruby"><span class="n">should</span> <span class="s1">&#39;be able to navigate to logged in user page and change email&#39;</span> <span class="k">do</span>
  <span class="n">login_as</span> <span class="vi">@user</span>
  <span class="n">visit</span> <span class="n">mobile_homepage_path</span>
  <span class="n">click_on</span> <span class="s1">&#39;My Account&#39;</span>
  <span class="n">user_path</span> <span class="o">=</span> <span class="n">mobile_user_path</span><span class="p">(</span><span class="vi">@user</span><span class="p">)</span>
  <span class="n">assert</span> <span class="n">current_page</span><span class="p">(</span><span class="n">user_path</span><span class="p">)</span>
  <span class="c1"># Change email</span>
  <span class="n">new_email</span> <span class="o">=</span> <span class="no">Forgery</span><span class="p">(</span><span class="ss">:email</span><span class="p">)</span><span class="o">.</span><span class="n">address</span>
  <span class="n">within_current_page</span><span class="p">(</span><span class="n">user_path</span><span class="p">)</span> <span class="k">do</span>
    <span class="n">fill_in</span> <span class="s1">&#39;email&#39;</span><span class="p">,</span> <span class="ss">:with</span> <span class="o">=&gt;</span> <span class="n">new_email</span>
    <span class="n">click_button</span> <span class="s1">&#39;Save Changes&#39;</span>
  <span class="k">end</span>
  <span class="vi">@user</span><span class="o">.</span><span class="n">reload</span><span class="o">.</span><span class="n">email</span><span class="o">.</span><span class="n">must_equal</span> <span class="n">new_email</span>
<span class="k">end</span>
</code></pre>
</div>

<p>
  Hopefully you can see how this simple page id foundation can help you better test your jQuery Mobile app with Capybara-WebKit. What an awesome tool! I sometimes find it hard to believe we are now at the point where we can easily test this much JavaScript in a headless browser directed by Ruby.
</p>



<h2>Resources</h2>

<ul>
  <li><a href="http://jquerymobile.com/">jQuery Mobile</a></li>
  <li><a href="http://weblog.jamisbuck.org/2007/1/17/concerns-in-activerecord">Concerns Module Pattern</a></li>
  <li><a href="https://github.com/thoughtbot/capybara-webkit">Capybara-WebKit</a></li>
  <li><a href="https://github.com/metaskills/holygrail_rails23">Rails 2.3 App w/Capybara-WebKit Integration</a></li>
  <li><a href="https://github.com/metaskills/holygrail_rails31">Rails 3.1 App w/Capybara-WebKit Integration</a></li>
  <li><a href="http://techiferous.com/2010/04/using-capybara-in-rails-3/">Wyatt Green's Using Capybara In Rails 3</a></li>
  <li><a href="/2011/03/26/using-minitest-spec-with-rails/">Using MiniTest::Spec With Rails</a></li>
</ul>




]]>
    </content>
 </entry>
 
 <entry>
   <title>Use Compass Sass Framework Files With The Rails 3.1.0.rc5 Asset Pipeline</title>
   <link href="http://metaskills.net/2011/07/29/use-compass-sass-framework-files-with-the-rails-3.1.0.rc5-asset-pipeline" />
   <updated>2011-07-29T00:00:00-04:00</updated>
   <id>http://metaskills.net/2011/07/29/use-compass-sass-framework-files-with-the-rails-3.1.0.rc5-asset-pipeline</id>
   <content type="html">
     <![CDATA[<aside class="flash_info">
  UPDATE: Now that Rails 3.1 is out, just use the <a href="http://rubygems.org/gems/compass">latest compass</a> or pre-release. No hacks needed!
</aside>

<p>
  This is a simple update to my <a href="/2011/05/18/use-compass-sass-framework-files-with-the-rails-3.1-asset-pipeline/">original article</a> for using compass's <code>.scss</code> files with the asset pipeline. This assumes you had this setup working in Rails 3.1.0.rc4, but should be helpful to anybody. The good news is that most everything is wired up.
</p>

<p>
  First, you are going to need to update your Gemfile. Follow the latest conventions and make sure you have a <code>:assets</code> group. Use the example below. With the exception of the compass addition to their "rails31" branch, this is what a Rails 3.1.0.rc5 project would generate. It is a good idea to put all your asset pipeline related gems in this group. As the comment says, these would not be required for production as the assumption is would precompile your static assets on deploys. Note, make sure your bundle for sass-rails installs the matching rc5 too.
</p>


<div class="highlight"><pre><code class="ruby"><span class="c1"># Gems used only for assets and not required</span>
<span class="c1"># in production environments by default.</span>
<span class="n">group</span> <span class="ss">:assets</span> <span class="k">do</span>
  <span class="n">gem</span> <span class="s1">&#39;sass-rails&#39;</span><span class="p">,</span> <span class="s2">&quot;~&gt; 3.1.0.rc&quot;</span>
  <span class="n">gem</span> <span class="s1">&#39;coffee-rails&#39;</span><span class="p">,</span> <span class="s2">&quot;~&gt; 3.1.0.rc&quot;</span>
  <span class="n">gem</span> <span class="s1">&#39;uglifier&#39;</span>
  <span class="n">gem</span> <span class="s1">&#39;compass&#39;</span><span class="p">,</span> <span class="ss">:git</span> <span class="o">=&gt;</span> <span class="s1">&#39;git://github.com/chriseppstein/compass.git&#39;</span><span class="p">,</span> <span class="ss">:branch</span> <span class="o">=&gt;</span> <span class="s1">&#39;rails31&#39;</span>
<span class="k">end</span>
</code></pre>
</div>

<p>
  Now here is a crazy gotcha. Rails 3.1.0.rc5 has changed the application.rb bundler line a little to account for this new :assets group. Find the bundler line and make sure it looks like this.
</p>

<div class="highlight"><pre><code class="ruby"><span class="no">Bundler</span><span class="o">.</span><span class="n">require</span> <span class="o">*</span><span class="no">Rails</span><span class="o">.</span><span class="n">groups</span><span class="p">(</span><span class="ss">:assets</span><span class="p">)</span> <span class="k">if</span> <span class="n">defined?</span><span class="p">(</span><span class="no">Bundler</span><span class="p">)</span>
</code></pre>
</div>

<p>
  Lastly, we need to get the compass files in the the load path. The sass-rails gem has set us up for this. I choose to hook into it using my <code>config/initializers/sass.rb</code> like so. I imagine that compass will be doing this on its own at some point in the future too. After this you should be all set!
</p>

<div class="highlight"><pre><code class="ruby"><span class="no">Rails</span><span class="o">.</span><span class="n">configuration</span><span class="o">.</span><span class="n">sass</span><span class="o">.</span><span class="n">tap</span> <span class="k">do</span> <span class="o">|</span><span class="n">config</span><span class="o">|</span>
  <span class="n">config</span><span class="o">.</span><span class="n">load_paths</span> <span class="o">&lt;&lt;</span> <span class="s2">&quot;</span><span class="si">#{</span><span class="no">Gem</span><span class="o">.</span><span class="n">loaded_specs</span><span class="o">[</span><span class="s1">&#39;compass&#39;</span><span class="o">].</span><span class="n">full_gem_path</span><span class="si">}</span><span class="s2">/frameworks/compass/stylesheets&quot;</span>
<span class="k">end</span>
</code></pre>
</div>

]]>
    </content>
 </entry>
 
 <entry>
   <title>Free The Enterprise With Ruby &amp; Master Your Own Domain</title>
   <link href="http://metaskills.net/2011/07/01/free-the-enterprise-with-ruby-and-master-your-own-domain" />
   <updated>2011-07-01T00:00:00-04:00</updated>
   <id>http://metaskills.net/2011/07/01/free-the-enterprise-with-ruby-and-master-your-own-domain</id>
   <content type="html">
     <![CDATA[<p>
  <span class="photofancy floatr mb30 ml30">
    <img class="" src="/assets/ftewr_talk.jpg" width="400" height="300" alt="Free The Enterprise With Ruby & Master Your Own Domain - Title Slide"/>
  </span>
  <span class="photofancy floatr mb30 ml30">
    <img class="" src="/assets/ftewr_time.jpg" width="400" height="300" alt="Free The Enterprise With Ruby & Master Your Own Domain - Our Time Together"/>
  </span>
  
  For anyone that did not attend the first <a href="http://madexpo.us/">MADExpo (Mid-Atlantic Developer Expo)</a> this week, here are <a href="http://www.slideshare.net/metaskills/free-the-enterprise-with-ruby-master-your-own-domain">my slides posted on slideshare</a>. This talk centers around 3 basic sections.
</p>

<p>
  The first is general Open Source and what it can do for you as a software developer to increase your skills and general knowledge. Second, it covers some key open source projects I have been working on. Specifically for <a href="https://github.com/rails-sqlserver">SQL Server and and ActiveRecord</a> which includes projects like <a href="https://github.com/rails-sqlserver/tiny_tds">TinyTDS</a> and the latest accomplishments the <a href="http://www.engineyard.com/blog/2011/sql-server-10xs-faster-with-rails-3-1/">SQL Server adapter had done for prepared statement support in Rails 3.1</a>. 
</p>

<p>
  Lastly, I go over what tools have recently been developed specifically for the Windows community to make using Ruby &amp; Rails an easy experience. One is the great <a href="http://railsinstaller.org/">Rails Installer</a> project by Wayne E. Sequin and Luis Lavena. Basically a one click installer for everything from Git, Ruby, Rails, MySQL, TinyTDS &amp; the SQL Server adapter. I even did a new Rails 3.1 project called <a href="https://github.com/rails-sqlserver/AdventureWorks.Ruby">AdventureWorks.Ruby</a> which shows you how to get up and running with your legacy SQL Server databases. Specifically the hardest point, cloning your legacy schema to a fresh test database via the standard Rails' rake tasks.
</p>




]]>
    </content>
 </entry>
 
 <entry>
   <title>Bind jQuery Event Handlers To This Object With CoffeeScript</title>
   <link href="http://metaskills.net/2011/05/22/bind-jquery-event-handlers-to-this-object-with-coffeescript" />
   <updated>2011-05-22T00:00:00-04:00</updated>
   <id>http://metaskills.net/2011/05/22/bind-jquery-event-handlers-to-this-object-with-coffeescript</id>
   <content type="html">
     <![CDATA[<p>
  Friends have told me that rich domain objects are seldom wielded when using jQuery to enhance behavior on web pages. I myself have always loved JavaScript as a rich dynamic language first and something for the DOM second. Hence most of my client-side JavaScript follows a robust object-oriented approach similar to Ruby. This is the main reason I have used Prototype.js for so long.
</p>

<p>
  Since Rails announced both jQuery and CoffeeScript as the defaults in version 3.1, I decided it was high time I starting learning both. I had always known that jQuery bound the <code>this</code> keyword in event handlers to the DOM object. Something I found totally confusing and unacceptable to someone dealing with their own objects to encapsulate behavior. Today I found two ways of dealing with my problem, a jQuery way and a CoffeeScript way. First a code example. 
</p>


<div class="highlight"><pre><code class="ruby"><span class="k">class</span> <span class="nc">MyObject</span>
  
  <span class="n">constructor</span><span class="p">:</span> <span class="o">-&gt;</span>
    <span class="vi">@myDomElement</span> <span class="o">=</span> <span class="err">$</span><span class="p">(</span><span class="s1">&#39;#myDomElement&#39;</span><span class="p">)</span>
    <span class="err">@</span><span class="o">.</span><span class="n">_initBehavior</span>

  <span class="n">handler</span><span class="p">:</span> <span class="p">(</span><span class="n">event</span><span class="p">)</span> <span class="o">-&gt;</span>
    <span class="n">console</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">this</span><span class="p">)</span>
    <span class="kp">false</span>

  <span class="n">_initBehavior</span><span class="p">:</span> <span class="o">-&gt;</span>
    <span class="err">$</span><span class="p">(</span><span class="n">window</span><span class="p">)</span><span class="o">.</span><span class="n">resize</span> <span class="vi">@handler</span>

<span class="n">jQuery</span> <span class="o">-&gt;</span>
  <span class="n">window</span><span class="o">.</span><span class="n">myObject</span> <span class="o">=</span> <span class="kp">new</span> <span class="no">MyObject</span><span class="p">();</span>
</code></pre>
</div>

<p>
  Here is a simple class using CoffeeScript's methods. It initializes itself with a static property <code>this.myDomElement</code> to some DOM element on the page with an id of "myDomElement". It then attaches an event handler to the window's resize event and logs <code>this</code> along the way. Simple stuff, the only problem will be that the object logged will not be an instance of MyObject, but the raw DOM element, in this case the window object. One way of fixing this is to use <a href="http://api.jquery.com/jQuery.proxy/">jQuery's proxy</a> function like so
</p>

<div class="highlight"><pre><code class="ruby"><span class="n">_initBehavior</span><span class="p">:</span> <span class="o">-&gt;</span>
  <span class="err">$</span><span class="p">(</span><span class="n">window</span><span class="p">)</span><span class="o">.</span><span class="n">resize</span> <span class="n">jQuery</span><span class="o">.</span><span class="n">proxy</span><span class="p">(</span><span class="vi">@handler</span><span class="p">,</span><span class="n">this</span><span class="p">)</span>
</code></pre>
</div>

<p>
  This works, but seems a little verbose to me and can clutter up your event initialization code. The other way is to use CoffeeScript's fat arrow operator. An <a href="http://jashkenas.github.com/coffee-script/">excerpt from their project page</a> explains it well.
</p>

<blockquote>
  The fat arrow => can be used to both define a function, and to bind it to the current value of this, right on the spot. This is helpful when using callback-based libraries like Prototype or jQuery, for creating iterator functions to pass to each, or event-handler functions to use with bind. Functions created with the fat arrow are able to access properties of the this where they're defined.
</blockquote>

<p>
  So all we have to do is change <code>-></code> to <code>=></code> for any of our callbacks or event handlers and now <code>this</code> is our own object and not the DOM element. Hot damn!
</p>

<div class="highlight"><pre><code class="ruby"><span class="k">class</span> <span class="nc">MyObject</span>
  
  <span class="n">constructor</span><span class="p">:</span> <span class="o">-&gt;</span>
    <span class="vi">@myDomElement</span> <span class="o">=</span> <span class="err">$</span><span class="p">(</span><span class="s1">&#39;#myDomElement&#39;</span><span class="p">)</span>
    <span class="err">@</span><span class="o">.</span><span class="n">_initBehavior</span>

  <span class="n">handler</span><span class="p">:</span> <span class="p">(</span><span class="n">event</span><span class="p">)</span> <span class="o">=&gt;</span>
    <span class="n">console</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">this</span><span class="p">)</span>
    <span class="kp">false</span>

  <span class="n">_initBehavior</span><span class="p">:</span> <span class="o">-&gt;</span>
    <span class="err">$</span><span class="p">(</span><span class="n">window</span><span class="p">)</span><span class="o">.</span><span class="n">resize</span> <span class="vi">@handler</span>

<span class="n">jQuery</span> <span class="o">-&gt;</span>
  <span class="n">window</span><span class="o">.</span><span class="n">myObject</span> <span class="o">=</span> <span class="kp">new</span> <span class="no">MyObject</span><span class="p">();</span>
</code></pre>
</div>




]]>
    </content>
 </entry>
 
 <entry>
   <title>The Browser Is Dead?</title>
   <link href="http://metaskills.net/2011/05/21/the-browser-is-dead" />
   <updated>2011-05-21T00:00:00-04:00</updated>
   <id>http://metaskills.net/2011/05/21/the-browser-is-dead</id>
   <content type="html">
     <![CDATA[<p>
  <span class="photofancy floatr mr10 mb30 ml30">
    <img class="" src="/assets/the_browser_is_dead.png" width="368" height="2969" alt="Converstation between DHH And Dave Thomas on Rails 3.1"/>
  </span>
  This <a href="https://twitter.com/#!/pragdave/status/62510978893492224">twitter post by Dave Thomas</a> sparked an interesting back and forth with DHH on how Rails 3.1 could be more opinionated towards web development for the browser. A short time before &ndash; it was announced that Rails would include CoffeeScript and Sass as defaults for JavaScript and CSS authoring. FWIW, both of these new defaults are in my opinion the best of the breed fore each task. If you have not done so, I suggest taking a quick read down this thread that I put together with screenshots from my Twitter.app.
</p>

<p>
  The topic is one I have thought often about over the past 6 years. I started writing Rails applications before 1.0 was released and I have seen the changes and felt each one. Having written both web and native iOS apps for <a href="http://homemarks.com">HomeMarks.com</a> and retooling the whole application for each major Rails version, I think it gives me a good insight into the pain here. For instance when <a href="http://ajaxian.com/archives/rails-rjs-for-ajax-101">RJS in Rails</a> first came out, HomeMarks took extreme advantage of it in very clever ways. Pushing rendered partials out and communicating to the browser's JavaScript environment was fun and rewarding at the time. It also felt really DRY at times.
</p>

<p>
  As I started to <a href="/2008/08/18/in-hell-oo-for-homemarks/">learn more advanced JavaScript techniques</a> for organizing my rich client code, I ended up rewriting HomeMarks again under the poorly named moniker <a href="/2008/05/24/the-ajax-head-design-pattern/">"The AJAX Head Design Pattern"</a>. It even caught a little bit of attention by the Ajaxian and <a href="http://voodootikigod.com/ajax-head-design-pattern">Chris Williams</a>. Essentially what I ended up building was my own minimal <a href="http://documentcloud.github.com/backbone/">backbone.js</a> in that I had a rich MVC layer all written in JavaScript. This usage of Rails as an API foundation on top of a rich JavaScript application was in my opinion a few years ahead of the average curve. Though it was very rewarding from a JavaScript as a language first, DOM second development perspective &amp; it yielded a very clean way to leverage the same RESTful controller actions used by JavaScript in the browser with a <a href="/2010/02/12/synchronizing-core-data-with-rails-3-0-0-pre/">native iOS app that integrated with Core Data</a>, it still felt like an over achievement or harder than it had to be.
</p>

<p>
  So as I embark on my third complete rewrite of HomeMarks, I have to think about my tools and techniques again and what the end goal may look like. I have thrown away thousands of lines of OO-JavaScript written in Prototype.js and <a href="https://gist.github.com/973483">started rewriting them in CoffeeScript</a>. Though there are still some tough decisions to be made on what my complete stack will look like and how HomeMarks v3 will hopefully again push the new web forward, I cant help but to agree with both Dave and DHH. I also share James A Rosen's opinion summed up in <a href="http://twitter.com/#!/jamesarosen/status/70544535373086720">this tweet</a>.

  <blockquote style="width:220px;">
    If I had known that RailsConf would be How-to-Use-Rails-as-a-Backend-for-Javascript-Conf, I would've gone!
  </blockquote>
</p>]]>
    </content>
 </entry>
 
 <entry>
   <title>Use Compass Sass Framework Files With The Rails 3.1 Asset Pipeline</title>
   <link href="http://metaskills.net/2011/05/18/use-compass-sass-framework-files-with-the-rails-3.1-asset-pipeline" />
   <updated>2011-05-18T00:00:00-04:00</updated>
   <id>http://metaskills.net/2011/05/18/use-compass-sass-framework-files-with-the-rails-3.1-asset-pipeline</id>
   <content type="html">
     <![CDATA[<aside class="flash_info">
  UPDATE: Now that Rails 3.1 is out, just use the <a href="http://rubygems.org/gems/compass">latest compass</a> or pre-release. No hacks needed!
</aside>

<p>
  The Sprockets 2 gem along with the Tilt gem make it really easy to write JavaScript or CSS using any templating language you desire. The rails defaults are CoffeeScript and Sass. About the <a href="https://github.com/chriseppstein/compass/tree/stable/frameworks/compass/stylesheets">best collection of Sass framework files</a> for easy cross-browser CSS authoring are packaged in the compass framework. Compass even has <a href="http://compass-style.org/reference/compass/css3/">great documentation</a> for using their Sass framework. But what if you want to use those within the asset pipeline provided by Rails? Easy enough!
</p>

<p>
  First, bundle up the compass, but do not require it. Add this to your <code>Gemfile</code>.
</p>

<div class="highlight"><pre><code class="ruby"><span class="n">gem</span> <span class="s1">&#39;compass&#39;</span><span class="p">,</span> <span class="ss">:require</span> <span class="o">=&gt;</span> <span class="kp">false</span>
</code></pre>
</div>

<p>
  Next, add a Sass initializer in <code>config/initializers/sass.rb</code> and fill it in with the code below. This will add two more load paths to the Sass engine. The first is your default rails/sprockets asset path for stylesheets. It simply let's you build a deep folder structure in that directory and use relative paths from each file. The second will put the entire compass Sass framework files into the Sass load path.
</p>

<div class="highlight"><pre><code class="ruby"><span class="no">Sass</span><span class="o">::</span><span class="no">Engine</span><span class="o">::</span><span class="no">DEFAULT_OPTIONS</span><span class="o">[</span><span class="ss">:load_paths</span><span class="o">].</span><span class="n">tap</span> <span class="k">do</span> <span class="o">|</span><span class="n">load_paths</span><span class="o">|</span>
  <span class="n">load_paths</span> <span class="o">&lt;&lt;</span> <span class="s2">&quot;</span><span class="si">#{</span><span class="no">Rails</span><span class="o">.</span><span class="n">root</span><span class="si">}</span><span class="s2">/app/assets/stylesheets&quot;</span>
  <span class="n">load_paths</span> <span class="o">&lt;&lt;</span> <span class="s2">&quot;</span><span class="si">#{</span><span class="no">Gem</span><span class="o">.</span><span class="n">loaded_specs</span><span class="o">[</span><span class="s1">&#39;compass&#39;</span><span class="o">].</span><span class="n">full_gem_path</span><span class="si">}</span><span class="s2">/frameworks/compass/stylesheets&quot;</span>
<span class="k">end</span>
</code></pre>
</div>

<p>
  Now in your rails <code>app/assets/stylesheets/foo.scss</code> file you can use Sass' <code>@import</code> with paths to the compass framework.
</p>

<div class="highlight"><pre><code class="css"><span class="k">@import</span> <span class="s2">&quot;compass/css3/opacity&quot;</span><span class="p">;</span>
<span class="nf">#mylogo</span> <span class="p">{</span> <span class="o">@</span><span class="n">include</span> <span class="k">opacity</span><span class="p">(</span><span class="m">0</span><span class="o">.</span><span class="m">5</span><span class="p">);</span> <span class="p">}</span>
</code></pre>
</div>

<p>
  That is an example loading up the opacity helpers. Your generated css file will look like this! CSS is never going to be the same again!
</p>

<div class="highlight"><pre><code class="css"><span class="nf">#mylogo</span> <span class="p">{</span>
  <span class="o">-</span><span class="n">ms</span><span class="o">-</span><span class="n">filter</span><span class="o">:</span> <span class="s2">&quot;progid:DXImageTransform.Microsoft.Alpha(Opacity=50)&quot;</span><span class="p">;</span>
  <span class="n">filter</span><span class="o">:</span> <span class="n">progid</span><span class="o">:</span><span class="n">DXImageTransform</span><span class="o">.</span><span class="n">Microsoft</span><span class="o">.</span><span class="n">Alpha</span><span class="p">(</span><span class="n">Opacity</span><span class="o">=</span><span class="m">50</span><span class="p">);</span>
  <span class="k">opacity</span><span class="o">:</span> <span class="m">0</span><span class="o">.</span><span class="m">5</span><span class="p">;</span> <span class="p">}</span>
</code></pre>
</div>




]]>
    </content>
 </entry>
 
 <entry>
   <title>Speaking At MADExpo</title>
   <link href="http://metaskills.net/2011/05/06/speaking_at_madexpo" />
   <updated>2011-05-06T00:00:00-04:00</updated>
   <id>http://metaskills.net/2011/05/06/speaking_at_madexpo</id>
   <content type="html">
     <![CDATA[<p>
  Over the past few months I have been actively working with both <a href="http://twitter.com/#!/luislavena">Luis Lavena</a> and <a href="http://twitter.com/#!/wayneeseguin">Wayne E Seguin</a> to incorporate both <a href="https://github.com/rails-sqlserver/tiny_tds">TinyTDS</a> and the <a href="https://github.com/rails-sqlserver/activerecord-sqlserver-adapter">SQL Server Adapter</a> into the latest release of the <a href="http://railsinstaller.org/">Rails Installer for Windows</a>. Like them, I firmly believe that Ruby's success is tightly bound to how well we can bring these tools to the Windows platform. So despite that I have no love for the Windows – I do want to see Ruby succeed and help spread the gospel. To this end, I have been working really hard at making both TinyTDS and the adapter a superb backend for ActiveRecord. In fact today, I just released a 3.1 beta that takes advantage of the new prepared statement support.
</p>

<p>
  <span class="photofancy floatr ml20">
    <img src="/assets/madexpo.png" alt="MADExpo: Mid Atlantic Developer Expo" width="240" height="80" />
  </span>
  To go one step further in helping Ruby, I have decided to speak at a local conference called the <a href="http://madexpo2011-collins.eventbrite.com/">Mid Atlantic Developer Expo</a> or just MADExpo. The <a href="http://madexpo.us/Sessions/84">details for my talk
</a> are below and if you find any of the <a href="http://madexpo.us/agenda">other talks</a> interesting, I highly advise you to grab a ticket and help me bring the message of Ruby right to the belly of the beast!
</p>


<h2>Free The Enterprise With Ruby &amp; Master Your Own Domain</h2>

<p>On the heals of Luis Lavena's RailsConf talk "<a href="http://en.oreilly.com/rails2011/public/schedule/detail/19499"><em>Infiltrating Ruby Onto The Enterprise Death Star Using Guerilla Tactics</em></a>" comes a local and frank talk about the current state of Open Source Software (OSS) participation from Windows developers. Learn what OSS is, what motivates its contributors, and how OSS can make you a stronger developer. Be prepared to fall in love with writing software again!</p>

<p>We will start off with a 101 introduction to both the Ruby programming language and the Ruby on Rails web application framework. You will learn about ActiveRecord, a powerful ORM that maps rich objects to your databases, and the latest components to use it with SQL Server. As a Rails core contributor and author of the SQL Server stack, I will give you a modern insight into both that will allow you to leverage your legacy data with Ruby.</p>

<p>Lastly, I will review the bleeding edge tools being actively created for Windows developers to ease the transition to Ruby, Rails and OSS from a POSIX driven world. Many things have changed. It is time to learn and perform some occupational maintenance.</p>



]]>
    </content>
 </entry>
 
 
</feed>

