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

<channel>
	<title>Simply Excited - Technology, Outdoor and Design &#187; Ruby</title>
	<atom:link href="http://scoop.simplyexcited.co.uk/category/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://scoop.simplyexcited.co.uk</link>
	<description>Technology, Design and Outdoor</description>
	<lastBuildDate>Fri, 23 Dec 2011 11:33:22 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Ruby 1.9 Tips</title>
		<link>http://scoop.simplyexcited.co.uk/2011/02/07/ruby-1-9-tips/</link>
		<comments>http://scoop.simplyexcited.co.uk/2011/02/07/ruby-1-9-tips/#comments</comments>
		<pubDate>Mon, 07 Feb 2011 09:22:30 +0000</pubDate>
		<dc:creator>pyrat</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://scoop.simplyexcited.co.uk/2011/02/07/ruby-1-9-tips/</guid>
		<description><![CDATA[	A runnable script to show off a lot of ruby 1.9 features. Hopefully this will increase the takeup of 1.9 as it is now stable enough to use for real in production.

	

	Courtesy of igrigorik.
 ]]></description>
			<content:encoded><![CDATA[	<p>A runnable script to show off a lot of ruby 1.9 features. Hopefully this will increase the takeup of 1.9 as it is now stable enough to use for real in production.</p>

	<p><script src="https://gist.github.com/809804.js?file=ruby-1.9-tips.rb"></script></p>

	<p>Courtesy of igrigorik.</p>
 ]]></content:encoded>
			<wfw:commentRss>http://scoop.simplyexcited.co.uk/2011/02/07/ruby-1-9-tips/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Currency Rates Library</title>
		<link>http://scoop.simplyexcited.co.uk/2011/01/26/currency-rates-library/</link>
		<comments>http://scoop.simplyexcited.co.uk/2011/01/26/currency-rates-library/#comments</comments>
		<pubDate>Wed, 26 Jan 2011 15:04:36 +0000</pubDate>
		<dc:creator>pyrat</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://scoop.simplyexcited.co.uk/2011/01/26/currency-rates-library/</guid>
		<description><![CDATA[	

	The Rub

	I needed a way of grabbing up to date currency information and an easy way to convert currencies using these up to date rates.

	Normally this information requires signing up for premium accounts or writing web scrapers to do this for you.

	It turns out that the European bank provides a daily xml for free that [...]]]></description>
			<content:encoded><![CDATA[	<p><img src="http://s3.amazonaws.com/excitedmedia/coins.jpg" alt="" border="0" /></p>

	<h3>The Rub</h3>

	<p>I needed a way of grabbing up to date currency information and an easy way to convert currencies using these up to date rates.</p>

	<p>Normally this information requires signing up for premium accounts or writing web scrapers to do this for you.</p>

	<p>It turns out that the European bank provides a daily xml for free that contains this information. It is specific to the euro but is fairly trivial to convert this into conversion rates for any of the other currency as the base currency.</p>

	<h3>Currency Rates is born</h3>

	<p>
<div class="wp_syntax"><div class="code"><pre class="bash">gem <span style="color: #c20cb9; font-weight: bold;">install</span> currency_rates</pre></div></div>
</p>



	<p>It is a simple class for getting up to date currency rates in an array. You pass a base currency which the rates will be calculated against. Connects to the european bank to get a daily breakdown of the rates.</p>

	<p>Deliberately lightweight to allow you to build on top of.</p>

	<h3>Example</h3>

	<p>
<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#008000; font-style:italic;">#!/usr/bin/env ruby</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'currency_rates'</span>
&nbsp;
parser = <span style="color:#6666ff; font-weight:bold;">CurrencyRates::Parser</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'GBP'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> parser.<span style="color:#9900CC;">engage</span>.<span style="color:#9900CC;">inspect</span></pre></div></div>
</p>



	<p>Valid values for the initialize call are:</p>

<pre>
"USD"
"JPY"
"BGN"
"CZK"
"DKK"
"EEK"
"GBP"
"HUF"
"LTL"
"LVL"
"PLN"
"RON"
"SEK"
"CHF"
"NOK"
"HRK"
"RUB"
"TRY"
"AUD"
"BRL"
"CAD"
"CNY"
"HKD"
"IDR"
"INR"
"KRW"
"MXN"
"MYR"
"NZD"
"PHP"
"SGD"
"THB"
"ZAR"
"EUR"
</pre>

	<p>Example result array:</p>

	<p>
<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;currency&quot;</span>=&gt;<span style="color:#996600;">&quot;USD&quot;</span>, <span style="color:#996600;">&quot;rate&quot;</span>=&gt;<span style="color:#996600;">&quot;1.58482&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;currency&quot;</span>=&gt;<span style="color:#996600;">&quot;JPY&quot;</span>, <span style="color:#996600;">&quot;rate&quot;</span>=&gt;<span style="color:#996600;">&quot;130.28671&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;currency&quot;</span>=&gt;<span style="color:#996600;">&quot;BGN&quot;</span>, <span style="color:#996600;">&quot;rate&quot;</span>=&gt;<span style="color:#996600;">&quot;2.26562&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;currency&quot;</span>=&gt;<span style="color:#996600;">&quot;CZK&quot;</span>, <span style="color:#996600;">&quot;rate&quot;</span>=&gt;<span style="color:#996600;">&quot;28.05560&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;currency&quot;</span>=&gt;<span style="color:#996600;">&quot;DKK&quot;</span>, <span style="color:#996600;">&quot;rate&quot;</span>=&gt;<span style="color:#996600;">&quot;8.63284&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;currency&quot;</span>=&gt;<span style="color:#996600;">&quot;ILS&quot;</span>, <span style="color:#996600;">&quot;rate&quot;</span>=&gt;<span style="color:#996600;">&quot;5.71573&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;currency&quot;</span>=&gt;<span style="color:#996600;">&quot;GBP&quot;</span>, <span style="color:#996600;">&quot;rate&quot;</span>=&gt;<span style="color:#996600;">&quot;1.00000&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;currency&quot;</span>=&gt;<span style="color:#996600;">&quot;HUF&quot;</span>, <span style="color:#996600;">&quot;rate&quot;</span>=&gt;<span style="color:#996600;">&quot;317.67159&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;currency&quot;</span>=&gt;<span style="color:#996600;">&quot;LTL&quot;</span>, <span style="color:#996600;">&quot;rate&quot;</span>=&gt;<span style="color:#996600;">&quot;3.99977&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;currency&quot;</span>=&gt;<span style="color:#996600;">&quot;LVL&quot;</span>, <span style="color:#996600;">&quot;rate&quot;</span>=&gt;<span style="color:#996600;">&quot;0.81552&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;currency&quot;</span>=&gt;<span style="color:#996600;">&quot;PLN&quot;</span>, <span style="color:#996600;">&quot;rate&quot;</span>=&gt;<span style="color:#996600;">&quot;4.48653&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;currency&quot;</span>=&gt;<span style="color:#996600;">&quot;RON&quot;</span>, <span style="color:#996600;">&quot;rate&quot;</span>=&gt;<span style="color:#996600;">&quot;4.94642&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;currency&quot;</span>=&gt;<span style="color:#996600;">&quot;SEK&quot;</span>, <span style="color:#996600;">&quot;rate&quot;</span>=&gt;<span style="color:#996600;">&quot;10.26180&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;currency&quot;</span>=&gt;<span style="color:#996600;">&quot;CHF&quot;</span>, <span style="color:#996600;">&quot;rate&quot;</span>=&gt;<span style="color:#996600;">&quot;1.49690&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;currency&quot;</span>=&gt;<span style="color:#996600;">&quot;NOK&quot;</span>, <span style="color:#996600;">&quot;rate&quot;</span>=&gt;<span style="color:#996600;">&quot;9.11266&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;currency&quot;</span>=&gt;<span style="color:#996600;">&quot;HRK&quot;</span>, <span style="color:#996600;">&quot;rate&quot;</span>=&gt;<span style="color:#996600;">&quot;8.58558&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;currency&quot;</span>=&gt;<span style="color:#996600;">&quot;RUB&quot;</span>, <span style="color:#996600;">&quot;rate&quot;</span>=&gt;<span style="color:#996600;">&quot;47.14741&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;currency&quot;</span>=&gt;<span style="color:#996600;">&quot;TRY&quot;</span>, <span style="color:#996600;">&quot;rate&quot;</span>=&gt;<span style="color:#996600;">&quot;2.50090&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;currency&quot;</span>=&gt;<span style="color:#996600;">&quot;AUD&quot;</span>, <span style="color:#996600;">&quot;rate&quot;</span>=&gt;<span style="color:#996600;">&quot;1.58992&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;currency&quot;</span>=&gt;<span style="color:#996600;">&quot;BRL&quot;</span>, <span style="color:#996600;">&quot;rate&quot;</span>=&gt;<span style="color:#996600;">&quot;2.64361&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;currency&quot;</span>=&gt;<span style="color:#996600;">&quot;CAD&quot;</span>, <span style="color:#996600;">&quot;rate&quot;</span>=&gt;<span style="color:#996600;">&quot;1.57892&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;currency&quot;</span>=&gt;<span style="color:#996600;">&quot;CNY&quot;</span>, <span style="color:#996600;">&quot;rate&quot;</span>=&gt;<span style="color:#996600;">&quot;10.43290&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;currency&quot;</span>=&gt;<span style="color:#996600;">&quot;HKD&quot;</span>, <span style="color:#996600;">&quot;rate&quot;</span>=&gt;<span style="color:#996600;">&quot;12.33837&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;currency&quot;</span>=&gt;<span style="color:#996600;">&quot;IDR&quot;</span>, <span style="color:#996600;">&quot;rate&quot;</span>=&gt;<span style="color:#996600;">&quot;14323.90385&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;currency&quot;</span>=&gt;<span style="color:#996600;">&quot;INR&quot;</span>, <span style="color:#996600;">&quot;rate&quot;</span>=&gt;<span style="color:#996600;">&quot;72.43649&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;currency&quot;</span>=&gt;<span style="color:#996600;">&quot;KRW&quot;</span>, <span style="color:#996600;">&quot;rate&quot;</span>=&gt;<span style="color:#996600;">&quot;1770.37938&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;currency&quot;</span>=&gt;<span style="color:#996600;">&quot;MXN&quot;</span>, <span style="color:#996600;">&quot;rate&quot;</span>=&gt;<span style="color:#996600;">&quot;19.10177&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;currency&quot;</span>=&gt;<span style="color:#996600;">&quot;MYR&quot;</span>, <span style="color:#996600;">&quot;rate&quot;</span>=&gt;<span style="color:#996600;">&quot;4.83614&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;currency&quot;</span>=&gt;<span style="color:#996600;">&quot;NZD&quot;</span>, <span style="color:#996600;">&quot;rate&quot;</span>=&gt;<span style="color:#996600;">&quot;2.06591&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;currency&quot;</span>=&gt;<span style="color:#996600;">&quot;PHP&quot;</span>, <span style="color:#996600;">&quot;rate&quot;</span>=&gt;<span style="color:#996600;">&quot;70.20678&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;currency&quot;</span>=&gt;<span style="color:#996600;">&quot;SGD&quot;</span>, <span style="color:#996600;">&quot;rate&quot;</span>=&gt;<span style="color:#996600;">&quot;2.02989&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;currency&quot;</span>=&gt;<span style="color:#996600;">&quot;THB&quot;</span>, <span style="color:#996600;">&quot;rate&quot;</span>=&gt;<span style="color:#996600;">&quot;48.82247&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;currency&quot;</span>=&gt;<span style="color:#996600;">&quot;ZAR&quot;</span>, <span style="color:#996600;">&quot;rate&quot;</span>=&gt;<span style="color:#996600;">&quot;11.25607&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;currency&quot;</span>=&gt;<span style="color:#996600;">&quot;EUR&quot;</span>, <span style="color:#996600;">&quot;rate&quot;</span>=&gt;<span style="color:#996600;">&quot;1.15841&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#93;</span></pre></div></div>
</p>



	<p>Code is also available on <a href="https://github.com/pyrat/currency_rates" title="">github</a></p>
 ]]></content:encoded>
			<wfw:commentRss>http://scoop.simplyexcited.co.uk/2011/01/26/currency-rates-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google Storage Interoperability With Amazon S3</title>
		<link>http://scoop.simplyexcited.co.uk/2010/06/27/google-storage-interoperability-with-amazon-s3/</link>
		<comments>http://scoop.simplyexcited.co.uk/2010/06/27/google-storage-interoperability-with-amazon-s3/#comments</comments>
		<pubDate>Sun, 27 Jun 2010 13:22:28 +0000</pubDate>
		<dc:creator>pyrat</dc:creator>
				<category><![CDATA[Api]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://scoop.simplyexcited.co.uk/2010/06/27/google-storage-interoperability-with-amazon-s3/</guid>
		<description><![CDATA[	
A google server

	Google storage was recently released as an open beta for developers to work with. All in all it seems like an Amazon S3 clone and whilst they have their REST api for integration they also support the Amazon S3 api.

	Originally I was planning on writing a ruby wrapper of this api but decided [...]]]></description>
			<content:encoded><![CDATA[	<p><img src="http://img.skitch.com/20100627-g7cd8p168w7rq3wa9fbjhs46m2.jpg" alt="" border="0" /><br />
<strong>A google server</strong></p>

	<p><a href="http://code.google.com/apis/storage/" title="">Google storage</a> was recently released as an open beta for developers to work with. All in all it seems like an Amazon S3 clone and whilst they have their <span class="caps">REST</span> api for integration they also support the Amazon S3 api.</p>

	<p>Originally I was planning on writing a ruby wrapper of this api but decided to see if I could modify with existing <a href="http://github.com/marcel/aws-s3" title="">aws-s3</a> gem to work with google storage.</p>

	<p>After some in depth reading of both apis and understanding of the aws-s3 gem I have modified it to also work with google storage.</p>

	<p>My <a href="http://github.com/pyrat/aws-s3" title="">github fork</a> contains these modifications.</p>

	<p>To use:</p>

	<p>
<div class="wp_syntax"><div class="code"><pre class="ruby">&nbsp;
  <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'aws/s3'</span>
  <span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#6666ff; font-weight:bold;">AWS::S3</span>
&nbsp;
  Base.<span style="color:#9900CC;">establish_connection</span>!<span style="color:#006600; font-weight:bold;">&#40;</span>
      <span style="color:#ff3333; font-weight:bold;">:access_key_id</span>     =&gt; <span style="color:#996600;">'abc'</span>,
      <span style="color:#ff3333; font-weight:bold;">:secret_access_key</span> =&gt; <span style="color:#996600;">'123'</span>,
      <span style="color:#ff3333; font-weight:bold;">:default_host</span> =&gt; <span style="color:#996600;">&quot;commondatastorage.googleapis.com&quot;</span>
    <span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>
</p>



	<p>Note the addition of the <strong>default_host</strong> to connect to google instead of <span class="caps">AWS</span>.</p>

	<p>From then on you can use the gem as normal as is described in the Readme.</p>
 ]]></content:encoded>
			<wfw:commentRss>http://scoop.simplyexcited.co.uk/2010/06/27/google-storage-interoperability-with-amazon-s3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Deploy when github goes down</title>
		<link>http://scoop.simplyexcited.co.uk/2008/11/27/deploy-when-github-goes-down/</link>
		<comments>http://scoop.simplyexcited.co.uk/2008/11/27/deploy-when-github-goes-down/#comments</comments>
		<pubDate>Thu, 27 Nov 2008 21:16:33 +0000</pubDate>
		<dc:creator>pyrat</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://scoop.cheerfactory.co.uk/2008/11/27/deploy-when-github-goes-down/</guid>
		<description><![CDATA[	
You are not screwed

	As git is distributed, the repository on your local machine is good enough to deploy from.

	First start a git server on your local machine.

	
  git daemon --base-path=/projects/rails_apps/ --export-all




	Then change your capistrano recipe to deploy with the copy command and change the repo to point to your local machine.

	
  set :deploy_via, [...]]]></description>
			<content:encoded><![CDATA[	<p><img src="http://www.smarts.co.uk/Ireland/images/stories/services/crisis_management.jpg" alt="" border="0" /><br />
<em>You are not screwed</em></p>

	<p>As git is distributed, the repository on your local machine is good enough to deploy from.</p>

	<p>First start a git server on your local machine.</p>

	<p>
<div class="wp_syntax"><div class="code"><pre class="bash">  git daemon --base-<span style="color: #007800;">path=</span>/projects/rails_apps/ --export-all</pre></div></div>
</p>



	<p>Then change your capistrano recipe to deploy with the copy command and change the repo to point to your local machine.</p>

	<p>
<div class="wp_syntax"><div class="code"><pre class="bash">  <span style="color: #000000; font-weight: bold;">set</span> :deploy_via, :copy
  <span style="color: #000000; font-weight: bold;">set</span> :repository <span style="color: #ff0000;">'git://127.0.0.1/proj_name'</span></pre></div></div>
</p>



	<p>Where in this example the code resides at */projects/rails_apps/proj_name*</p>

	<p>Now capistrano will deploy from your local repository, thus avoiding the currently melted <a href="http://github.com" title="">github</a></p>

	<p>There are other options which have been listed by chris wanstrath in the <a href="http://ozmm.org/posts/when_github_goes_down.html" title="">following article</a></p>
 ]]></content:encoded>
			<wfw:commentRss>http://scoop.simplyexcited.co.uk/2008/11/27/deploy-when-github-goes-down/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Google Sitemap Generator</title>
		<link>http://scoop.simplyexcited.co.uk/2008/02/26/google-sitemap-generator/</link>
		<comments>http://scoop.simplyexcited.co.uk/2008/02/26/google-sitemap-generator/#comments</comments>
		<pubDate>Tue, 26 Feb 2008 13:06:39 +0000</pubDate>
		<dc:creator>pyrat</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[]]></category>

		<guid isPermaLink="false">http://scoop.cheerfactory.co.uk/2008/02/26/google-sitemap-generator/</guid>
		<description><![CDATA[	

	Google sitemaps are nice for telling google what is where. Often clients want it for SEO or you have a site which has new content all the time and you want to keep google up to date.

	Whatever the reason is thats you are interested in these little xml files, the following code allows you to [...]]]></description>
			<content:encoded><![CDATA[	<p><img src="http://scoop.simplyexcited.co.uk/wp-content/uploads/2008/02/maps-are-good.jpg" alt="maps are good" border="0" /></p>

	<p>Google sitemaps are nice for telling google what is where. Often clients want it for <span class="caps">SEO</span> or you have a site which has new content all the time and you want to keep google up to date.</p>

	<p>Whatever the reason is thats you are interested in these little xml files, the following code allows you to generate a sitemap for a dynamic site in ruby.</p>

	<p>Firstly the class:</p>

	<p>
<div class="wp_syntax"><div class="code"><pre class="ruby">  <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'net/http'</span>
  <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'uri'</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># A class specific to the application which generates a google sitemap from</span>
  <span style="color:#008000; font-style:italic;"># the contents of the database.</span>
  <span style="color:#008000; font-style:italic;"># Author: Alastair Brunton</span>
  <span style="color:#9966CC; font-weight:bold;">class</span> GoogleSitemapGenerator
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> initialize<span style="color:#006600; font-weight:bold;">&#40;</span>base_url, sources<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#0066ff; font-weight:bold;">@base_url</span> = base_url
      <span style="color:#0066ff; font-weight:bold;">@sources</span> = sources 
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#008000; font-style:italic;"># The main generator method which in turn adds to the path_array from the different</span>
    <span style="color:#008000; font-style:italic;"># sources.</span>
    <span style="color:#008000; font-style:italic;"># Sources are: pages, events, properties</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> generate
      path_ar = <span style="color:#CC0066; font-weight:bold;">Array</span>.<span style="color:#9900CC;">new</span>
      <span style="color:#0066ff; font-weight:bold;">@sources</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> |source|
        <span style="color:#008000; font-style:italic;"># initialize the class and call the get_paths method on it.</span>
        path_ar = path_ar + <span style="color:#CC0066; font-weight:bold;">eval</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;#{source}.get_paths&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
      xml = generate_xml<span style="color:#006600; font-weight:bold;">&#40;</span>path_ar<span style="color:#006600; font-weight:bold;">&#41;</span>
      save_file<span style="color:#006600; font-weight:bold;">&#40;</span>xml<span style="color:#006600; font-weight:bold;">&#41;</span>
      update_google
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#008000; font-style:italic;"># This creates the xml document.</span>
  	<span style="color:#9966CC; font-weight:bold;">def</span> generate_xml<span style="color:#006600; font-weight:bold;">&#40;</span>path_ar<span style="color:#006600; font-weight:bold;">&#41;</span>
  		xml_str = <span style="color:#996600;">&quot;&quot;</span>
  		xml = <span style="color:#6666ff; font-weight:bold;">Builder::XmlMarkup</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:target</span> =&gt; xml_str<span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
  		xml.<span style="color:#9900CC;">instruct</span>!
  			xml.<span style="color:#9900CC;">urlset</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:xmlns</span>=&gt;<span style="color:#996600;">'http://www.google.com/schemas/sitemap/0.84'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>
    			path_ar.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> |path|
      	    xml.<span style="color:#9900CC;">url</span> <span style="color:#006600; font-weight:bold;">&#123;</span>
        	    	xml.<span style="color:#9900CC;">loc</span><span style="color:#006600; font-weight:bold;">&#40;</span>@base_url + path<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:url</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        			xml.<span style="color:#9900CC;">lastmod</span><span style="color:#006600; font-weight:bold;">&#40;</span>path<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:last_mod</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        			xml.<span style="color:#9900CC;">changefreq</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'weekly'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
     			 <span style="color:#006600; font-weight:bold;">&#125;</span>
    			<span style="color:#9966CC; font-weight:bold;">end</span>
  			<span style="color:#006600; font-weight:bold;">&#125;</span>	
  		xml_str
  	<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  	<span style="color:#008000; font-style:italic;"># Saves the xml file to disc. This could also be used to ping the webmaster tools</span>
  	<span style="color:#9966CC; font-weight:bold;">def</span> save_file<span style="color:#006600; font-weight:bold;">&#40;</span>xml<span style="color:#006600; font-weight:bold;">&#41;</span>
  		<span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>RAILS_ROOT + <span style="color:#996600;">'/public/sitemap.xml'</span>, <span style="color:#996600;">&quot;w+&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> |f|
  			f.<span style="color:#9900CC;">write</span><span style="color:#006600; font-weight:bold;">&#40;</span>xml<span style="color:#006600; font-weight:bold;">&#41;</span>	
  		<span style="color:#9966CC; font-weight:bold;">end</span>		
  	<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  	<span style="color:#008000; font-style:italic;"># Notify google of the new sitemap</span>
  	<span style="color:#9966CC; font-weight:bold;">def</span> update_google
  	    sitemap_uri = <span style="color:#0066ff; font-weight:bold;">@base_url</span> + <span style="color:#996600;">'/sitemap.xml'</span>
  	    escaped_sitemap_uri = <span style="color:#CC00FF; font-weight:bold;">URI</span>.<span style="color:#9900CC;">escape</span><span style="color:#006600; font-weight:bold;">&#40;</span>sitemap_uri<span style="color:#006600; font-weight:bold;">&#41;</span>
  	    <span style="color:#6666ff; font-weight:bold;">Net::HTTP</span>.<span style="color:#9900CC;">get</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'www.google.com'</span>,
  	                  <span style="color:#996600;">'/webmasters/sitemaps/ping?sitemap='</span> +
  	                  escaped_sitemap_uri<span style="color:#006600; font-weight:bold;">&#41;</span>
  	<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>
</p>



	<p>You will notice that an array of strings are passed when calling the generator. These are names of object which implement the get_paths method. An example get_paths class method is as follows:</p>

	<p>
<div class="wp_syntax"><div class="code"><pre class="ruby">  <span style="color:#008000; font-style:italic;"># for the google sitemap</span>
   <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">get_paths</span>
     path_ar = <span style="color:#CC0066; font-weight:bold;">Array</span>.<span style="color:#9900CC;">new</span>
     Property.<span style="color:#9900CC;">live_properties</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> |property|
       path_ar &lt;&lt; <span style="color:#006600; font-weight:bold;">&#123;</span>:url =&gt; <span style="color:#996600;">&quot;/property/#{property.to_param}&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:last_mod</span> =&gt; property.<span style="color:#9900CC;">updated_at</span>.<span style="color:#9900CC;">strftime</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'%Y-%m-%d'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
     <span style="color:#9966CC; font-weight:bold;">end</span>
     path_ar
   <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>
</p>



	<p>Basically, you need an array of hashes which each contain the url and the last_mod.</p>

	<p>To call this little beastie it is best done from a cron on the production server. An example rake task to do this is as follows:</p>

	<p>
<div class="wp_syntax"><div class="code"><pre class="ruby">  namespace <span style="color:#ff3333; font-weight:bold;">:google_sitemap</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    desc <span style="color:#996600;">&quot;Generate a google sitemap from the site.&quot;</span>
    task<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:generate</span> =&gt; <span style="color:#ff3333; font-weight:bold;">:environment</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      sources = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'Page'</span>, <span style="color:#996600;">'Event'</span>, <span style="color:#996600;">'Property'</span><span style="color:#006600; font-weight:bold;">&#93;</span>
      sitemap = GoogleSitemapGenerator.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'http://www.your_url.com'</span>, sources<span style="color:#006600; font-weight:bold;">&#41;</span>
      sitemap.<span style="color:#9900CC;">generate</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>
</p>



	<p><strong>Remember</strong> when you are calling it from a cron to pass the <span class="caps">RAILS</span>_ENV. This generator does rely on rails but you could convert it to only rely on ruby by modifying the rake task and changing the <span class="caps">RAILS</span>_ROOT reference in the <strong>save_file</strong> method. Probably can be made to work with Merb but I am unsure of how merb and rake work together. Will hopefully get my hands dirty with Merb sometime soon.</p>

	<p>
<div class="wp_syntax"><div class="code"><pre class="bash">   <span style="color: #7a0874; font-weight: bold;">cd</span> /var/www/apps/site/current /usr/bin/rake <span style="color: #007800;">RAILS_ENV=</span>production google_sitemap:generate</pre></div></div>
</p>


 ]]></content:encoded>
			<wfw:commentRss>http://scoop.simplyexcited.co.uk/2008/02/26/google-sitemap-generator/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Throw your own exceptions</title>
		<link>http://scoop.simplyexcited.co.uk/2008/02/24/throw-your-own-exceptions/</link>
		<comments>http://scoop.simplyexcited.co.uk/2008/02/24/throw-your-own-exceptions/#comments</comments>
		<pubDate>Sun, 24 Feb 2008 17:52:48 +0000</pubDate>
		<dc:creator>pyrat</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://scoop.cheerfactory.co.uk/2008/02/24/throw-your-own-exceptions/</guid>
		<description><![CDATA[	

	Throwing and catching exceptions can be a good design pattern in your rails app. Especially when you want to be able to deal with the unexpected in a clean way. Overuse is a no no as with most techniques but it is nice here and there.

	I find that a good idea is to make your [...]]]></description>
			<content:encoded><![CDATA[	<p><img src="http://scoop.simplyexcited.co.uk/wp-content/uploads/2008/02/exceptions.jpg" alt="exceptions" border="0" /></p>

	<p>Throwing and catching exceptions can be a good design pattern in your rails app. Especially when you want to be able to deal with the unexpected in a clean way. Overuse is a no no as with most techniques but it is nice here and there.</p>

	<p>I find that a good idea is to make your own exceptions when writing a rails app. This means that standard low level exceptions which often should not be caught are not.</p>

	<p>eg.</p>

	<p>(in config/initializers/custom_config.rb)</p>

	<p>
<div class="wp_syntax"><div class="code"><pre class="ruby">  <span style="color:#9966CC; font-weight:bold;">class</span> ApplicationError &lt; <span style="color:#CC00FF; font-weight:bold;">RuntimeError</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>
</p>



	<p>This way in your application code you can do something like the following</p>

	<p>
<div class="wp_syntax"><div class="code"><pre class="ruby">  <span style="color:#9966CC; font-weight:bold;">begin</span>
    <span style="color:#0066ff; font-weight:bold;">@user</span> = User.<span style="color:#9900CC;">find_by_password_reset_code</span><span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:id</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#CC0066; font-weight:bold;">raise</span> ApplicationError <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@user</span>.<span style="color:#0000FF; font-weight:bold;">nil</span>?
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">rescue</span> ApplicationError =&gt; msg
    flash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:message</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;Sorry - That is an invalid password reset code. Please check your code and try again. (Perhaps your email client inserted a carriage return?&quot;</span>
    redirect_to logins_url
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>
</p>



	<p>In other news I have started testing deploying with git and capistrano. It is blazingly fast even for a full checkout. I cant get :remote_cache deploy via working due to an ancient version of git on <span class="caps">LTS 6</span>.06. But event with full checkout this is faster than deploy_via :remote_cache with subversion! (This is with 2 slices on a local network.)</p>
 ]]></content:encoded>
			<wfw:commentRss>http://scoop.simplyexcited.co.uk/2008/02/24/throw-your-own-exceptions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Hpricot 0.6 Caveat Setting Attributes</title>
		<link>http://scoop.simplyexcited.co.uk/2008/02/06/hpricot-06-caveat-setting-attributes/</link>
		<comments>http://scoop.simplyexcited.co.uk/2008/02/06/hpricot-06-caveat-setting-attributes/#comments</comments>
		<pubDate>Wed, 06 Feb 2008 10:25:07 +0000</pubDate>
		<dc:creator>pyrat</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://scoop.cheerfactory.co.uk/2008/02/06/hpricot-06-caveat-setting-attributes/</guid>
		<description><![CDATA[	Watch out with Hpricot 0.6 it doesnt seem to work properly with setting attributes. Use 0.5 instead.


sudo gem install hpricot -v0.5

 ]]></description>
			<content:encoded><![CDATA[	<p>Watch out with Hpricot 0.6 it doesnt seem to work properly with setting attributes. Use 0.5 instead.</p>

<pre>
sudo gem install hpricot -v0.5
</pre>
 ]]></content:encoded>
			<wfw:commentRss>http://scoop.simplyexcited.co.uk/2008/02/06/hpricot-06-caveat-setting-attributes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Rupdf &#8211; Simple Ruby PDF Rails Plugin</title>
		<link>http://scoop.simplyexcited.co.uk/2007/12/15/rupdf-simple-ruby-pdf-rails-plugin/</link>
		<comments>http://scoop.simplyexcited.co.uk/2007/12/15/rupdf-simple-ruby-pdf-rails-plugin/#comments</comments>
		<pubDate>Sat, 15 Dec 2007 12:37:07 +0000</pubDate>
		<dc:creator>pyrat</dc:creator>
				<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://scoop.cheerfactory.co.uk/2007/12/15/rupdf-simple-ruby-pdf-rails-plugin/</guid>
		<description><![CDATA[	

	This is a plugin which I have developed internally with Iformis. I realised it would be nice to share yet another pdf plugin with the rails community. This is designed to render pdfs with layouts. This is especially useful when working on projects where the pdf has to conform to a set design and where [...]]]></description>
			<content:encoded><![CDATA[	<p><img src="http://scoop.simplyexcited.co.uk/wp-content/uploads/2007/11/rupdf.jpg" alt="Rupdf" border="0" /></p>

	<p>This is a plugin which I have developed internally with <a href="http://www.iformis.com" title="">Iformis</a>. I realised it would be nice to share yet another pdf plugin with the rails community. This is designed to render pdfs with layouts. This is especially useful when working on projects where the pdf has to conform to a set design and where the data is presented in a generate report style. Banks often operate their tools in this manner.</p>

	<p>Simple <span class="caps">PDF</span> reporting rails plugin designed to render layout based pdfs. Built on top of Ruport which is in turn built on top of pdf-writer.</p>

	<p>Requires Ruport</p>

	<p>Step 1: Install Ruport</p>

	<p>
<div class="wp_syntax"><div class="code"><pre class="bash">gem <span style="color: #c20cb9; font-weight: bold;">install</span> ruport</pre></div></div>
</p>



	<p>Step 2: Install the plugin (from <span class="caps">RAILS</span>_ROOT)</p>

	<p>
<div class="wp_syntax"><div class="code"><pre class="bash">./script/plugin <span style="color: #c20cb9; font-weight: bold;">install</span> http://iformis.svnrepository.com/svn/rupdf</pre></div></div>
</p>



	<p>Step 3: Create a class extending Rupdf::Base</p>

	<p>Note: The only methods calls required are define_header, define_body and define_footer<br />
The other methods are helper methods. Remember that html doesnt work in the body.</p>

	<p>
<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#9966CC; font-weight:bold;">class</span> Simple &lt; <span style="color:#6666ff; font-weight:bold;">Rupdf::Base</span>
&nbsp;
  define_variables <span style="color:#ff3333; font-weight:bold;">:report_title</span>
  renders <span style="color:#ff3333; font-weight:bold;">:pdf</span>, <span style="color:#ff3333; font-weight:bold;">:for</span> =&gt; <span style="color:#6666ff; font-weight:bold;">Rupdf::Renderer</span>
&nbsp;
  define_header <span style="color:#9966CC; font-weight:bold;">do</span>
    add_header<span style="color:#006600; font-weight:bold;">&#40;</span>report_title<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  define_body <span style="color:#9966CC; font-weight:bold;">do</span>
    add_text<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;hello man<span style="color:#000099;">\n</span><span style="color:#000099;">\n</span><span style="color:#000099;">\n</span>&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    add_text<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;bye man.&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    add_text<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;bye man.&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    add_text<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;hello man<span style="color:#000099;">\n</span><span style="color:#000099;">\n</span><span style="color:#000099;">\n</span>&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    add_text<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;bye man.&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    add_text<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;hello man<span style="color:#000099;">\n</span><span style="color:#000099;">\n</span><span style="color:#000099;">\n</span>&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    add_text<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;bye man.&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    <span style="color:#008000; font-style:italic;"># add image (path defined at runtime)</span>
    image<span style="color:#006600; font-weight:bold;">&#40;</span>smile_path<span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    add_text<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;hello man<span style="color:#000099;">\n</span><span style="color:#000099;">\n</span><span style="color:#000099;">\n</span>&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    add_text<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;bye man.&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    add_text<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;hello man<span style="color:#000099;">\n</span><span style="color:#000099;">\n</span><span style="color:#000099;">\n</span>&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  define_footer <span style="color:#9966CC; font-weight:bold;">do</span>
    footer_text = %<span style="color:#006600; font-weight:bold;">&#40;</span>
    This is the beautiful footer text.
    <span style="color:#006600; font-weight:bold;">&#41;</span>
    add_footer<span style="color:#006600; font-weight:bold;">&#40;</span>footer_text<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
&nbsp;
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> add_header<span style="color:#006600; font-weight:bold;">&#40;</span>title<span style="color:#006600; font-weight:bold;">&#41;</span>
    rounded_text_box<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;&lt;b&gt;#{title}&lt;/b&gt;&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> |o|
      header_color = <span style="color:#6666ff; font-weight:bold;">Color::RGB</span>.<span style="color:#9900CC;">from_html</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;#FFDE16&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      o.<span style="color:#9900CC;">fill_color</span> = header_color
      o.<span style="color:#9900CC;">stroke_color</span> = header_color
      o.<span style="color:#9900CC;">radius</span>     = <span style="color:#006666;">0</span>
      o.<span style="color:#9900CC;">width</span>      = options.<span style="color:#9900CC;">header_width</span> || <span style="color:#006666;">550</span>
      o.<span style="color:#9900CC;">height</span>     = options.<span style="color:#9900CC;">header_height</span> || <span style="color:#006666;">80</span>
      o.<span style="color:#9900CC;">font_size</span>  = options.<span style="color:#9900CC;">header_font_size</span> || <span style="color:#006666;">12</span>
      o.<span style="color:#9900CC;">x</span>          = pdf_writer.<span style="color:#9900CC;">absolute_right_margin</span> - o.<span style="color:#9900CC;">width</span>
      o.<span style="color:#9900CC;">y</span>          = pdf_writer.<span style="color:#9900CC;">absolute_top_margin</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
&nbsp;
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> add_footer<span style="color:#006600; font-weight:bold;">&#40;</span>text, options = <span style="color:#0000FF; font-weight:bold;">nil</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">unless</span> options
      options = OpenStruct.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:font_size</span> =&gt; <span style="color:#006666;">6</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    rounded_text_box<span style="color:#006600; font-weight:bold;">&#40;</span>text<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> |o|
      footer_color = <span style="color:#6666ff; font-weight:bold;">Color::RGB</span>.<span style="color:#9900CC;">from_html</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;#EAECEE&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      o.<span style="color:#9900CC;">fill_color</span> = footer_color
      o.<span style="color:#9900CC;">stroke_color</span> = footer_color
      o.<span style="color:#9900CC;">radius</span>     = <span style="color:#006666;">0</span>
      o.<span style="color:#9900CC;">width</span>      = options.<span style="color:#9900CC;">header_width</span> || <span style="color:#006666;">550</span>
      o.<span style="color:#9900CC;">height</span>     = options.<span style="color:#9900CC;">header_height</span> || <span style="color:#006666;">60</span>
      o.<span style="color:#9900CC;">font_size</span>  = options.<span style="color:#9900CC;">font_size</span> || <span style="color:#006666;">12</span>
      o.<span style="color:#9900CC;">x</span>          = pdf_writer.<span style="color:#9900CC;">absolute_right_margin</span> - o.<span style="color:#9900CC;">width</span>
      o.<span style="color:#9900CC;">y</span>          = pdf_writer.<span style="color:#9900CC;">absolute_bottom_margin</span> + o.<span style="color:#9900CC;">height</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>
</p>




	<p>Step 4: Tie it into a controller and pass the variables at runtime.</p>

	<p>
<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#9966CC; font-weight:bold;">class</span> TestController &lt; ApplicationController
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> pdf
    simple = Simple.<span style="color:#9900CC;">new</span>
    pdf = <span style="color:#6666ff; font-weight:bold;">Rupdf::Renderer</span>.<span style="color:#9900CC;">render_pdf</span> <span style="color:#9966CC; font-weight:bold;">do</span> |o|
      o.<span style="color:#9900CC;">report_title</span> = <span style="color:#996600;">'This is a test of a var being passed.'</span>
      o.<span style="color:#9900CC;">smile_path</span> = RAILS_ROOT + <span style="color:#996600;">'/public/images/smile.jpg'</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    send_pdf<span style="color:#006600; font-weight:bold;">&#40;</span>pdf<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>
</p>



	<p>The send_pdf function sends the rendered pdf to the browser.</p>

	<p>If you need to perform more complicated pdf rendering operation<br />
please refer to the <span class="caps">API </span>Documentation for pdf-writer. The <span class="caps">API</span> docs for<br />
ruport will also be useful if you are involved in presenting tabular<br />
data from activerecord.</p>

	<p>Example programming code along with how to call it is supplied in the<br />
examples directory. I suggest you use these as a base for pdf generation code you write.</p>

	<p>This has been tested with both Rails 1.2 and Rails 2.01. Thanks for listening.</p>
 ]]></content:encoded>
			<wfw:commentRss>http://scoop.simplyexcited.co.uk/2007/12/15/rupdf-simple-ruby-pdf-rails-plugin/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Tinder Continuous Integration to Campfire Script</title>
		<link>http://scoop.simplyexcited.co.uk/2007/11/30/tinder-continuous-integration-to-campfire-script/</link>
		<comments>http://scoop.simplyexcited.co.uk/2007/11/30/tinder-continuous-integration-to-campfire-script/#comments</comments>
		<pubDate>Fri, 30 Nov 2007 17:43:24 +0000</pubDate>
		<dc:creator>pyrat</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://scoop.cheerfactory.co.uk/2007/11/30/tinder-continuous-integration-to-campfire-script/</guid>
		<description><![CDATA[	

	Recently signal vs noise showcased how their continuous integration tool posts to campfire using the tinder api. Well I thought that it looked cool so have thrown together a quick and dirty ruby script to do it as well.

	It will integrate with anything which has an RSS feed. Cruisecontrol.rb does and works nicely. Its a [...]]]></description>
			<content:encoded><![CDATA[	<p><img src="http://scoop.simplyexcited.co.uk/wp-content/uploads/2007/11/campfire.jpg" alt="Campfire" border="0" /></p>

	<p>Recently signal vs noise showcased how their continuous integration tool posts to campfire using the tinder api. Well I thought that it looked cool so have thrown together a quick and dirty ruby script to do it as well.</p>

	<p>It will integrate with anything which has an <span class="caps">RSS</span> feed. Cruisecontrol.rb does and works nicely. Its a bit rough around the edges but works as is. Run it from the crontab and you are sorted.</p>

	<p>Improvements welcome.</p>

	<p>Here is a screenshot of it posting on campfire:</p>

	<p><img src="http://scoop.simplyexcited.co.uk/wp-content/uploads/2007/11/ci_grab.jpg" alt="Ci Grab" border="0" /></p>

	<p>Here is the code:</p>

	<p>
<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#008000; font-style:italic;">#!/usr/bin/ruby</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'active_record'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'simple-rss'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'open-uri'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'tinder'</span>
<span style="color:#9966CC; font-weight:bold;">include</span> Tinder
&nbsp;
<span style="color:#008000; font-style:italic;"># Author: Alastair Brunton</span>
<span style="color:#008000; font-style:italic;"># http://www.simplyexcited.co.uk</span>
<span style="color:#008000; font-style:italic;"># Rss to Campfire</span>
&nbsp;
campfire_domain = <span style="color:#996600;">'simplyexcited'</span>
campfire_email = <span style="color:#996600;">'cheer@cheerfactory.co.uk'</span>
campfire_password = <span style="color:#996600;">'xxxx'</span>
feeds = %w<span style="color:#006600; font-weight:bold;">&#40;</span>http://feedserver/edflats.<span style="color:#9900CC;">rss</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
&nbsp;
<span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>.<span style="color:#9900CC;">logger</span> = <span style="color:#CC00FF; font-weight:bold;">Logger</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>STDERR<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>.<span style="color:#9900CC;">colorize_logging</span> = <span style="color:#0000FF; font-weight:bold;">false</span>
&nbsp;
<span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>.<span style="color:#9900CC;">establish_connection</span><span style="color:#006600; font-weight:bold;">&#40;</span>
<span style="color:#ff3333; font-weight:bold;">:adapter</span> =&gt; <span style="color:#996600;">&quot;mysql&quot;</span>,
<span style="color:#ff3333; font-weight:bold;">:username</span> =&gt; <span style="color:#996600;">&quot;username&quot;</span>,
<span style="color:#ff3333; font-weight:bold;">:password</span> =&gt; <span style="color:#996600;">&quot;password&quot;</span>,
<span style="color:#ff3333; font-weight:bold;">:database</span> =&gt; <span style="color:#996600;">&quot;ci_to_campfire&quot;</span>
<span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># uncomment this section the first time to create the table</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># ActiveRecord::Schema.define do</span>
<span style="color:#008000; font-style:italic;">#    create_table :items do |table|</span>
<span style="color:#008000; font-style:italic;">#        table.column :feed_identifier, :string</span>
<span style="color:#008000; font-style:italic;">#        table.column :title, :string</span>
<span style="color:#008000; font-style:italic;">#        table.column :link, :string</span>
<span style="color:#008000; font-style:italic;">#        table.column :description, :text</span>
<span style="color:#008000; font-style:italic;">#    end</span>
<span style="color:#008000; font-style:italic;"># end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> Item &lt; <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> to_s
    %<span style="color:#006600; font-weight:bold;">&#40;</span>Theres been some action:\n
    <span style="color:#008000; font-style:italic;">#{self.title}\n\n</span>
    <span style="color:#008000; font-style:italic;">#{self.description}</span>
    <span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
&nbsp;
campfire = Campfire.<span style="color:#9900CC;">new</span> campfire_domain
campfire.<span style="color:#9900CC;">login</span> campfire_email, campfire_password
room = campfire.<span style="color:#9900CC;">find_room_by_name</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'The Office'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
feeds.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> |rss_url|
  rss_user_agent = <span style="color:#996600;">&quot;RSS to Campfire&quot;</span>
&nbsp;
  rss_items = SimpleRSS.<span style="color:#9900CC;">parse</span> <span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>rss_url ,<span style="color:#996600;">&quot;User-Agent&quot;</span> =&gt; rss_user_agent<span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">for</span> item <span style="color:#9966CC; font-weight:bold;">in</span> rss_items.<span style="color:#9900CC;">items</span>
&nbsp;
    Item.<span style="color:#9900CC;">transaction</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      <span style="color:#9966CC; font-weight:bold;">unless</span> existing_item = Item.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:all</span>, <span style="color:#ff3333; font-weight:bold;">:conditions</span> =&gt; <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;link=? AND feed_identifier=?&quot;</span>, item.<span style="color:#9900CC;">link</span>, rss_url<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">first</span>
        new_item = Item.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span> =&gt; item.<span style="color:#9900CC;">title</span>, <span style="color:#ff3333; font-weight:bold;">:link</span> =&gt; item.<span style="color:#9900CC;">link</span>, <span style="color:#ff3333; font-weight:bold;">:description</span> =&gt; item.<span style="color:#9900CC;">description</span>, <span style="color:#ff3333; font-weight:bold;">:feed_identifier</span> =&gt; rss_url<span style="color:#006600; font-weight:bold;">&#41;</span>
        room.<span style="color:#9900CC;">paste</span><span style="color:#006600; font-weight:bold;">&#40;</span>new_item.<span style="color:#9900CC;">to_s</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
room.<span style="color:#9900CC;">leave</span>
campfire.<span style="color:#9900CC;">logout</span></pre></div></div>
</p>


 ]]></content:encoded>
			<wfw:commentRss>http://scoop.simplyexcited.co.uk/2007/11/30/tinder-continuous-integration-to-campfire-script/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>2 techniques for rails testing without fixtures</title>
		<link>http://scoop.simplyexcited.co.uk/2007/11/13/2-techniques-for-rails-testing-without-fixtures/</link>
		<comments>http://scoop.simplyexcited.co.uk/2007/11/13/2-techniques-for-rails-testing-without-fixtures/#comments</comments>
		<pubDate>Tue, 13 Nov 2007 22:09:38 +0000</pubDate>
		<dc:creator>pyrat</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://scoop.cheerfactory.co.uk/2007/11/13/2-techniques-for-rails-testing-without-fixtures/</guid>
		<description><![CDATA[	

	After it taking me 6 months to be converted to TDD, the last 6 months I have been improving my skills in the TDD arena. After developing some fairly complex systems I was finding fixtures to be far too brittle and was relying on the ar_fixtures plugin to generate fixture data.

	The thing is, this isn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[	<p><img src="http://scoop.simplyexcited.co.uk/wp-content/uploads/2007/11/fixtures.jpg" alt="fixtures" border="0" /></p>

	<p>After it taking me 6 months to be converted to <span class="caps">TDD</span>, the last 6 months I have been improving my skills in the <span class="caps">TDD</span> arena. After developing some fairly complex systems I was finding fixtures to be far too brittle and was relying on the <a href="http://nubyonrails.com/articles/dump-or-slurp-yaml-reference-data" title="">ar_fixtures</a> plugin to generate fixture data.</p>

	<p>The thing is, this isn&#8217;t right. You shouldn&#8217;t be generating the fixtures from data created by untested code!</p>

	<p>To get straight to the point, the following 2 techniques are great for fixture-less testing.</p>

	<h3>1. Have a phat test_helper.rb</h3>

	<p>Use transactional fixtures.</p>

	<p>In your test_helper.rb you should be extracting out all the object creation code so you can use it over multiple tests.</p>

	<p>eg.</p>

	<p>
<div class="wp_syntax"><div class="code"><pre class="ruby">  <span style="color:#9966CC; font-weight:bold;">def</span> create_property<span style="color:#006600; font-weight:bold;">&#40;</span>options=<span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    Property.<span style="color:#9900CC;">create</span>!<span style="color:#006600; font-weight:bold;">&#40;</span>
    <span style="color:#006600; font-weight:bold;">&#123;</span>
      <span style="color:#ff3333; font-weight:bold;">:title</span> =&gt; <span style="color:#996600;">'Flat in Skye'</span>,
      <span style="color:#ff3333; font-weight:bold;">:address_line_1</span> =&gt; <span style="color:#996600;">'Flat 2/1'</span>,
      <span style="color:#ff3333; font-weight:bold;">:address_line_2</span> =&gt; <span style="color:#996600;">'75 Old Dumbarton Road'</span>,
      <span style="color:#ff3333; font-weight:bold;">:city</span> =&gt; <span style="color:#996600;">'Glasgow'</span>,
      <span style="color:#ff3333; font-weight:bold;">:postcode</span> =&gt; <span style="color:#996600;">'G3 8RG'</span>,
      <span style="color:#ff3333; font-weight:bold;">:short_description</span> =&gt; <span style="color:#996600;">'Great flat in Yorkhill'</span>,
      <span style="color:#ff3333; font-weight:bold;">:full_description</span> =&gt; <span style="color:#996600;">'This is in a great location and has top views of the university'</span>,
      <span style="color:#ff3333; font-weight:bold;">:min_people</span> =&gt; <span style="color:#006666;">1</span>,
      <span style="color:#ff3333; font-weight:bold;">:max_people</span> =&gt; <span style="color:#006666;">10</span>,
      <span style="color:#ff3333; font-weight:bold;">:tag_list</span> =&gt; <span style="color:#996600;">&quot;Dishwasher<span style="color:#000099;">\n</span>TV&quot;</span>,
      <span style="color:#ff3333; font-weight:bold;">:landlord_id</span> =&gt; <span style="color:#006666;">1</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_live</span> =&gt; <span style="color:#0000FF; font-weight:bold;">true</span>
    <span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">merge</span><span style="color:#006600; font-weight:bold;">&#40;</span>options<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>
</p>



	<p>This is great because in my tests I can run something like.</p>

	<p>
<div class="wp_syntax"><div class="code"><pre class="ruby">  <span style="color:#9966CC; font-weight:bold;">def</span> test_special_dom
    <span style="color:#CC0066; font-weight:bold;">p</span> = create_property<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:is_live</span> =&gt; <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    special_dom = <span style="color:#CC0066; font-weight:bold;">p</span>.<span style="color:#9900CC;">special_dom</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'new'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    assert_not_nil<span style="color:#006600; font-weight:bold;">&#40;</span>special_dom<span style="color:#006600; font-weight:bold;">&#41;</span>
    assert_equal<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;property_#{p.id}_new&quot;</span>, special_dom<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>
</p>



	<p>This means that the setup and tear down for this test is done in the test method meaning I know exactly what I am working with. If you look at line 2 you will see you I can override the default options in the test method by passing a hash of new options. This is the beauty of the merge method in test_helper.rb</p>

	<h3>2. Use the setup method in both unit and functional tests.</h3>

	<p>This is not only great for logging in users, but it also is great for running the data creation methods before you run the test and make all your test methods a little more <span class="caps">DRY</span>.</p>

	<p>eg.</p>

	<p>
<div class="wp_syntax"><div class="code"><pre class="ruby">  <span style="color:#9966CC; font-weight:bold;">def</span> setup
    <span style="color:#0066ff; font-weight:bold;">@controller</span> = LandlordAjaxController.<span style="color:#9900CC;">new</span>
    <span style="color:#0066ff; font-weight:bold;">@request</span>    = <span style="color:#6666ff; font-weight:bold;">ActionController::TestRequest</span>.<span style="color:#9900CC;">new</span>
    <span style="color:#0066ff; font-weight:bold;">@response</span>   = <span style="color:#6666ff; font-weight:bold;">ActionController::TestResponse</span>.<span style="color:#9900CC;">new</span>
    <span style="color:#0066ff; font-weight:bold;">@property</span> = create_property
    login_landlord
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>
</p>



	<p>Now all my tests in this functional test can use the @property object.</p>

	<p>eg.</p>

	<p>
<div class="wp_syntax"><div class="code"><pre class="ruby">  <span style="color:#9966CC; font-weight:bold;">def</span> test_back_calendar
    xhr <span style="color:#ff3333; font-weight:bold;">:post</span>, <span style="color:#ff3333; font-weight:bold;">:back_calendar</span>, <span style="color:#ff3333; font-weight:bold;">:property_id</span> =&gt; <span style="color:#0066ff; font-weight:bold;">@property</span>.<span style="color:#9900CC;">id</span>, <span style="color:#ff3333; font-weight:bold;">:month_date</span> =&gt; <span style="color:#CC00FF; font-weight:bold;">Date</span>.<span style="color:#9900CC;">today</span>.<span style="color:#9900CC;">to_s</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:db</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    assert_rjs <span style="color:#ff3333; font-weight:bold;">:replace_html</span>, <span style="color:#996600;">'months'</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>
</p>



	<p>Thats all for now. If you have any more tips for fixtureless testing please add them to the comments.</p>
 ]]></content:encoded>
			<wfw:commentRss>http://scoop.simplyexcited.co.uk/2007/11/13/2-techniques-for-rails-testing-without-fixtures/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Upgrading Ruby on Ubuntu Dapper</title>
		<link>http://scoop.simplyexcited.co.uk/2007/11/02/upgrading-ruby-on-ubuntu-dapper/</link>
		<comments>http://scoop.simplyexcited.co.uk/2007/11/02/upgrading-ruby-on-ubuntu-dapper/#comments</comments>
		<pubDate>Fri, 02 Nov 2007 08:58:15 +0000</pubDate>
		<dc:creator>pyrat</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[vps]]></category>

		<guid isPermaLink="false">http://scoop.cheerfactory.co.uk/2007/11/02/upgrading-ruby-on-ubuntu-dapper/</guid>
		<description><![CDATA[	

	Ubuntu Dapper will only install ruby as high as 1.8.4 which is not ideal sometimes. To upgrade an existing ruby installation to 1.8.6 do the following.

	
  sudo apt-get install build-essential
sudo apt-get install libreadline5 libreadline5-dev
wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.6.tar.gz
tar -xzf ruby-1.8.6.tar.gz
cd ruby-1.8.6
./configure --prefix=/usr/local --enable-pthread --with-readline-dir=/usr/local
make
sudo make install



	Even if you had rubygems you need to install it and all [...]]]></description>
			<content:encoded><![CDATA[	<p><img src="http://scoop.simplyexcited.co.uk/wp-content/uploads/2007/11/dapper.jpg" alt="dapper" border="0" /></p>

	<p>Ubuntu Dapper will only install ruby as high as 1.8.4 which is not ideal sometimes. To upgrade an existing ruby installation to 1.8.6 do the following.</p>

	<p>
<div class="wp_syntax"><div class="code"><pre class="bash">  <span style="color: #c20cb9; font-weight: bold;">sudo</span> apt-get <span style="color: #c20cb9; font-weight: bold;">install</span> build-essential
<span style="color: #c20cb9; font-weight: bold;">sudo</span> apt-get <span style="color: #c20cb9; font-weight: bold;">install</span> libreadline5 libreadline5-dev
<span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #c20cb9; font-weight: bold;">ftp</span>://<span style="color: #c20cb9; font-weight: bold;">ftp</span>.ruby-lang.org/pub/ruby/<span style="color: #000000;">1.8</span>/ruby<span style="color: #000000;">-1.8</span><span style="color: #000000;">.6</span>.<span style="color: #c20cb9; font-weight: bold;">tar</span>.gz
<span style="color: #c20cb9; font-weight: bold;">tar</span> -xzf ruby<span style="color: #000000;">-1.8</span><span style="color: #000000;">.6</span>.<span style="color: #c20cb9; font-weight: bold;">tar</span>.gz
<span style="color: #7a0874; font-weight: bold;">cd</span> ruby<span style="color: #000000;">-1.8</span><span style="color: #000000;">.6</span>
./configure --<span style="color: #007800;">prefix=</span>/usr/<span style="color: #7a0874; font-weight: bold;">local</span> --enable-pthread --with-readline-<span style="color: #007800;">dir=</span>/usr/<span style="color: #7a0874; font-weight: bold;">local</span>
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>
</p>


	<p>Even if you had rubygems you need to install it and all your gems! Again.</p>

	<p>
<div class="wp_syntax"><div class="code"><pre class="bash">   <span style="color: #c20cb9; font-weight: bold;">wget</span> http://rubyforge.org/frs/download.php/<span style="color: #000000;">35283</span>/rubygems<span style="color: #000000;">-1.1</span><span style="color: #000000;">.1</span>.tgz
<span style="color: #c20cb9; font-weight: bold;">tar</span> -xzf rubygems<span style="color: #000000;">-1.1</span><span style="color: #000000;">.1</span>.tgz
<span style="color: #7a0874; font-weight: bold;">cd</span> rubygems<span style="color: #000000;">-1.1</span><span style="color: #000000;">.1</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> ruby setup.rb</pre></div></div>
</p>


	<p>Now this is where you need to do a little fix. Openssl will not work out of the box and some application need it so you should just set it up now.</p>

	<p><strong>Note:</strong> If apt-get libssl-dev complains about a not found run: sudo apt-get update</p>

	<p>
<div class="wp_syntax"><div class="code"><pre class="bash">  <span style="color: #c20cb9; font-weight: bold;">sudo</span> apt-get <span style="color: #c20cb9; font-weight: bold;">install</span> libopenssl-ruby
<span style="color: #c20cb9; font-weight: bold;">sudo</span> apt-get <span style="color: #c20cb9; font-weight: bold;">install</span> libssl-dev
&nbsp;
<span style="color: #7a0874; font-weight: bold;">cd</span> ~/src/ruby<span style="color: #000000;">-1.8</span><span style="color: #000000;">.6</span>/ext/openssl
ruby extconf.rb
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>
</p>


	<p>And thats it!</p>
 ]]></content:encoded>
			<wfw:commentRss>http://scoop.simplyexcited.co.uk/2007/11/02/upgrading-ruby-on-ubuntu-dapper/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Twitter for SMS Notification</title>
		<link>http://scoop.simplyexcited.co.uk/2007/10/10/twitter-for-sms-notification/</link>
		<comments>http://scoop.simplyexcited.co.uk/2007/10/10/twitter-for-sms-notification/#comments</comments>
		<pubDate>Wed, 10 Oct 2007 08:58:17 +0000</pubDate>
		<dc:creator>pyrat</dc:creator>
				<category><![CDATA[Chat]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://scoop.cheerfactory.co.uk/2007/10/10/twitter-for-sms-notification/</guid>
		<description><![CDATA[	

	This is more of an idea than something I have needed yet but I don&#8217;t see why it wouldn&#8217;t work.

	
		Open a twitter account if you haven&#8217;t already got one.
		Open another twitter account and call it something_notifier or something fun like that.
		Setup your mobile on the first account and set it up to follow the notifier [...]]]></description>
			<content:encoded><![CDATA[	<p><img src="http://scoop.simplyexcited.co.uk/wp-content/uploads/2007/10/twitter.jpg" alt="Twitter" border="0" /></p>

	<p>This is more of an idea than something I have needed yet but I don&#8217;t see why it wouldn&#8217;t work.</p>

	<ul>
		<li>Open a <a href="http://www.twitter.com" title="">twitter</a> account if you haven&#8217;t already got one.</li>
		<li>Open another twitter account and call it something_notifier or something fun like that.</li>
		<li>Setup your mobile on the first account and set it up to follow the notifier account and receive <span class="caps">SMS</span> notifications when it updates.</li>
		<li>Test this.</li>
		<li>Now whenever the notifier twitter account it updated you will receive a text with the contents of the update.</li>
	</ul>

	<p>For example, the next step could be to install a twitter <span class="caps">API</span> implementation on your servers then update twitter if something catastrophic happens. Remember to alter the privacy settings and set it so that only your followers can see your updates.</p>

	<p>But I&#8217;m sure there are loads of uses for this; any ideas? Although <span class="caps">SMS</span> messaging from the internet is easy in the <span class="caps">USA</span>, its a lot more complicated in the UK and Europe.</p>
 ]]></content:encoded>
			<wfw:commentRss>http://scoop.simplyexcited.co.uk/2007/10/10/twitter-for-sms-notification/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Apache Configuration Tool</title>
		<link>http://scoop.simplyexcited.co.uk/2007/09/28/apache-configuration-tool/</link>
		<comments>http://scoop.simplyexcited.co.uk/2007/09/28/apache-configuration-tool/#comments</comments>
		<pubDate>Fri, 28 Sep 2007 10:16:13 +0000</pubDate>
		<dc:creator>pyrat</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[vps]]></category>

		<guid isPermaLink="false">http://scoop.cheerfactory.co.uk/2007/09/28/apache-configuration-tool/</guid>
		<description><![CDATA[	

	I have been doing a bit of sysadmin stuff with iformis recently which has involved a bit of virtual host configuration for a number of sites. Although Nginx is top for rails, apache is still the king of PHP.

	We use apache in a debian / ubuntu environment so I have gone and written a wee [...]]]></description>
			<content:encoded><![CDATA[	<p><img src="http://scoop.simplyexcited.co.uk/wp-content/uploads/2007/09/apache_gunshipflickr.jpg" alt="apache-gunship-flickr" border="0" /></p>

	<p>I have been doing a bit of sysadmin stuff with <a href="http://www.iformis.com" title="">iformis</a> recently which has involved a bit of virtual host configuration for a number of sites. Although Nginx is top for rails, apache is still the king of <span class="caps">PHP</span>.</p>

	<p>We use apache in a debian / ubuntu environment so I have gone and written a wee gem to make vhost configuration a bit easier.</p>

	<p>1. Install apacheconf</p>

	<p><code><br />
sudo gem install apacheconf<br />
</code></p>


	<p>2. Setup <span class="caps">YAML </span>Config</p>

	<p><code><br />
site_name: fun<br />
server_name: fun.com<br />
server_alias: www.fun.com<br />
document_root: /var/www/apps/fun<br />
</code></p>

	<p>3. Run apacheconf</p>

	<p><code><br />
apacheconf --enable fun.yml<br />
</code></p>

	<p>4. There is no step 4!</p>

	<p><img src="http://scoop.simplyexcited.co.uk/wp-content/uploads/2007/09/apacheconf.jpg" alt="Apacheconf" border="0" /></p>

	<p>Please contact me with any issues and ideas for improvements.</p>
 ]]></content:encoded>
			<wfw:commentRss>http://scoop.simplyexcited.co.uk/2007/09/28/apache-configuration-tool/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Example Monit Configuration with Mongrel</title>
		<link>http://scoop.simplyexcited.co.uk/2007/09/15/example-monit-configuration-with-mongrel/</link>
		<comments>http://scoop.simplyexcited.co.uk/2007/09/15/example-monit-configuration-with-mongrel/#comments</comments>
		<pubDate>Sat, 15 Sep 2007 20:53:43 +0000</pubDate>
		<dc:creator>pyrat</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[vps]]></category>

		<guid isPermaLink="false">http://scoop.cheerfactory.co.uk/2007/09/15/example-monit-configuration-with-mongrel/</guid>
		<description><![CDATA[	Monit is great for keeping your services online. I use them for keeping my collection of slices online when I am asleep.
The example monitrc is a great starting point of listing the services which you should be monitoring.

	One thing: monit can have its own little http server which runs internally. This is off in the [...]]]></description>
			<content:encoded><![CDATA[	<p>Monit is great for keeping your services online. I use them for keeping my collection of slices online when I am asleep.<br />
The <a href="http://pastie.caboo.se/13355" title="">example monitrc</a> is a great starting point of listing the services which you should be monitoring.</p>

	<p>One thing: monit can have its own little http server which runs internally. This is off in the example config as you have to explicitly enable it.</p>

	<p>I hope to release a monit config generator gem in the near future which makes this a lot quicker.</p>
 ]]></content:encoded>
			<wfw:commentRss>http://scoop.simplyexcited.co.uk/2007/09/15/example-monit-configuration-with-mongrel/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ruby Code Beautify Textmate</title>
		<link>http://scoop.simplyexcited.co.uk/2007/08/25/ruby-code-beautify-textmate/</link>
		<comments>http://scoop.simplyexcited.co.uk/2007/08/25/ruby-code-beautify-textmate/#comments</comments>
		<pubDate>Sat, 25 Aug 2007 22:59:32 +0000</pubDate>
		<dc:creator>pyrat</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[s3]]></category>

		<guid isPermaLink="false">http://scoop.cheerfactory.co.uk/2007/08/25/ruby-code-beautify-textmate/</guid>
		<description><![CDATA[	Ruby code beautification bundle item

	Also my modification to the Amazon S3Sync ruby library was accepted. Now everyone can enjoy a YAML config file rather than using environment variables.

	Also my modification the Nginx config generator to add SSL support was also accepted. Get in.
 ]]></description>
			<content:encoded><![CDATA[	<p><a href="http://blog.neontology.com/posts/2006/05/10/beautiful-ruby-in-textmate" title="">Ruby code beautification bundle item</a></p>

	<p>Also my modification to the Amazon S3Sync ruby library was accepted. Now everyone can enjoy a <span class="caps">YAML</span> config file rather than using environment variables.</p>

	<p>Also my modification the Nginx config generator to add <span class="caps">SSL</span> support was also accepted. Get in.</p>
 ]]></content:encoded>
			<wfw:commentRss>http://scoop.simplyexcited.co.uk/2007/08/25/ruby-code-beautify-textmate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Install Old Capistrano 1.4.1</title>
		<link>http://scoop.simplyexcited.co.uk/2007/08/20/install-old-capistrano-141/</link>
		<comments>http://scoop.simplyexcited.co.uk/2007/08/20/install-old-capistrano-141/#comments</comments>
		<pubDate>Mon, 20 Aug 2007 10:25:37 +0000</pubDate>
		<dc:creator>pyrat</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://scoop.cheerfactory.co.uk/2007/08/20/install-old-capistrano-141/</guid>
		<description><![CDATA[	sudo gem install -v 1.4.1 capistrano

	In case you dont have the time to update your recipe and are setting up a new machine.
 ]]></description>
			<content:encoded><![CDATA[	<p><code>sudo gem install -v 1.4.1 capistrano</code></p>

	<p>In case you dont have the time to update your recipe and are setting up a new machine.</p>
 ]]></content:encoded>
			<wfw:commentRss>http://scoop.simplyexcited.co.uk/2007/08/20/install-old-capistrano-141/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Deploying with Capistrano VPS</title>
		<link>http://scoop.simplyexcited.co.uk/2007/07/04/deploying-with-capistrano-vps/</link>
		<comments>http://scoop.simplyexcited.co.uk/2007/07/04/deploying-with-capistrano-vps/#comments</comments>
		<pubDate>Wed, 04 Jul 2007 11:21:32 +0000</pubDate>
		<dc:creator>pyrat</dc:creator>
				<category><![CDATA[Guides]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://scoop.cheerfactory.co.uk/2007/07/04/deploying-with-capistrano-vps/</guid>
		<description><![CDATA[	

	It has taken me a while to move from the custom checkout scripts that I use for rails deployment to move to the capistrano way of doing things. I am so excited about it that I have decided to write this blog post.

	This is not a definitive guide to rails deployment with capistrano but is [...]]]></description>
			<content:encoded><![CDATA[	<p><img src="http://scoop.simplyexcited.co.uk/images/capistrano.jpg" /></p>

	<p>It has taken me a while to move from the custom checkout scripts that I use for rails deployment to move to the capistrano way of doing things. I am so excited about it that I have decided to write this blog post.</p>

	<p>This is not a definitive guide to rails deployment with capistrano but is the way I do things when deploying to <a href="http://www.slicehost.com">slicehost</a> for an application which we will be releasing in the not too distant future. This should work out for other vps servers and can be modified for shared hosting where you dont have as many permissions such as sudo access. Also I am basically a capistrano beginner so take what I say with a pinch of salt.</p>

	<p>Firstly, if you are not familiar with capistrano I recommend purchasing the <a href="http://www.peepcode.com">peepcode</a> episode titled <a href="http://peepcode.com/products/capistrano-concepts">Capistrano Concepts</a><br />
<h2>Your using source control right?</h2><br />
The first step is to make sure that you are using source control. The source control system of choice in the rails world is subversion. Capistrano works with quite a few other scm applications but subversion is by far the most common.</p>

	<p>So you need to have your application in a repository somewhere which your deployment box can access. You should also setup the repository to work with the rails app (ignore log files, ignore database.yml, ignore *.pid files etc.) There is a great rake task for <a href="http://pastie.caboo.se/73224.txt">setting up subversion on rails</a><br />
<h2>You have installed and setup your vps?</h2><br />
Lets say you have setup your vps and plan to deploy with an nginx / mongrel_cluster rails stack. There is a good guide at <a href="http://www.usefuljaja.com/">usefuljaja</a> for doing this.</p>

	<p>You have also setup ssh key authentication to avoid typing in passwords all the time. You are also just deploying to a single server and only have one mongrel process to start with.</p>

	<p>For installing and setting up nginx for your deployment its best just to install nginx from source and use the <a href="http://errtheblog.com/post/3908">nginx config generator</a>  to configure nginx for your deployment. I am also loving the no_www option which redirects requests to www.example.org&#226;&#8224;&#8217;example.org. Is it just me or do other people hate www.*</p>

	<p>Setting up a deploy user on the <span class="caps">VPS</span> is also recommended for cleanliness.<br />
<h2>You have setup a database and there is a domain you can run this off?</h2><br />
You need to setup the database in your production environment. A url to deploy to would also be nice, maybe you are still in development and you can use a static dyndns.org free domain to get started.<br />
<h2>Install capistrano and railsmachine</h2><br />
sudo gem install railsmachine &#226;&#8364;&#8221;include-dependencies</p>

	<p>This is a great little collection of capistrano tasks to organise the deployment by convention over configuration.<br />
<h2>Setup your rails app and deploy</h2><br />
cd {RAILS_ROOT}<br />
cap&#226;&#8364;&#8221;apply-to .</p>

	<p>This creates a deploy.rb in your /config directory where you can setup the deployment. My deployment script can be found over at <a href="http://pastie.caboo.se/75985">pastie</a></p>

	<p>The tasks defined in the two bottom tasks are defined in a mycaptasks.rb file which I can move around projects. You could also set it up as an svn:external in your project if you want to be more <span class="caps">DRY</span>. It is also up on <a href="http://pastie.caboo.se/75987">pastie</a></p>

	<p>Now run:<br />
cap setup</p>

	<p>This sets up the folder structure that capistrano uses.</p>

	<p>Now:<br />
cap cold_deploy</p>

	<p>To check everything is working ok.</p>

	<p>Now:<br />
cap deploy<em>_with_</em>migrations</p>

	<p>This will build up your new database assuming you work withe database migrations.</p>

	<p>From now on<br />
cap deploy</p>

	<p>To deploy your app.<br />
<h2>Its in source control</h2><br />
Because the deploy scripts are contained within the source control it works great in a distributed work environment so other developers can work with your project and deploy in a common way. It brings deployment into a convention rather than custom built and often nasty deployment methods which exist out there.<br />
<h2>Cheers for now</h2><br />
This has been a skim at deploying with capistrano and I urge you to check out the other and probably a lot better learning resources out there.</p>
 ]]></content:encoded>
			<wfw:commentRss>http://scoop.simplyexcited.co.uk/2007/07/04/deploying-with-capistrano-vps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Everyday Scripting with Ruby &#8211; Book Review</title>
		<link>http://scoop.simplyexcited.co.uk/2007/06/24/everyday-scripting-with-ruby-book-review/</link>
		<comments>http://scoop.simplyexcited.co.uk/2007/06/24/everyday-scripting-with-ruby-book-review/#comments</comments>
		<pubDate>Sun, 24 Jun 2007 20:19:19 +0000</pubDate>
		<dc:creator>pyrat</dc:creator>
				<category><![CDATA[Chat]]></category>
		<category><![CDATA[Guides]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://scoop.cheerfactory.co.uk/2007/06/24/everyday-scripting-with-ruby-book-review/</guid>
		<description><![CDATA[	

	I recently finished Everyday Scripting with Ruby   written by Brian Marick

	Apart from using the pickaxe as a reference this is the first book on pure ruby that I have read. One big advantage that this book has is it uses ruby in a different context instead of the &#226;&#8364;&#339;rails way&#226;&#8364;? that I am [...]]]></description>
			<content:encoded><![CDATA[	<p><img src="http://scoop.simplyexcited.co.uk/images/evsr.jpg" /></p>

	<p>I recently finished <a href="http://www.pragmaticprogrammer.com/titles/bmsft/">Everyday Scripting with Ruby</a>   written by <a href="http://www.testing.com/">Brian Marick</a></p>

	<p>Apart from using the pickaxe as a reference this is the first book on pure ruby that I have read. One big advantage that this book has is it uses ruby in a different context instead of the &#226;&#8364;&#339;rails way&#226;&#8364;? that I am used to.</p>

	<p>Over the last year I have been writing more and more scripts; mostly in Ruby and Bash. I have written everything from basic copy scripts to a more complicated website crawler called the harvester. I wont speak any more about the harvester as I am not proud of its application! It was great to read a book about the black art of scripting and get a strong grasp of how Ruby can be utilised in this context.</p>

	<p>I thoroughly recommend getting this book and reading it cover to cover. The book starts easy then progresses in difficulty so is more of a cover to cover read than a reference. Apart from the chapter on regular expressions which is the most detailed description of ruby regular expressions I have seen to date.<br />
<h2><span class="caps">TDD</span></h2><br />
Brian also mentions <a href="http://en.wikipedia.org/wiki/Test_driven_development"><span class="caps">TDD</span></a> very early on and manages to do well to enforce it throughout the book. I definitely go for the <span class="caps">TDD</span> approach when developing rails applications and plugins (wrote my first last week!) but have yet to use it for script development.</p>

	<p>I am of the mind that <span class="caps">TDD</span> is great if you go as far as to start extracting methods to a class. If however, you are just writing a simple single stream script as I mostly do, it is not worthwhile writing tests for something simple and throw-away.<br />
<h2>Driving the Browser</h2><br />
(http://www.openqa.org/selenium/)<br />
There is an interesting section in browser control which I did not know about. There is <a href="http://wtr.rubyforge.org/">Watir</a> and <a href="http://www.openqa.org/selenium/">Selenium</a> which can be used to control browsers from within ruby.</p>

	<p>There is also the <strong>mechanize</strong> ruby gem which can be used to build simple crawlers. This is interesting when you think about what is possible. I remember back in the day Alistair Burns and I wrote a bot for planetarion which would login every few hours and then send an email to your phone if you were under attack. We wrote it in <span class="caps">PHP4</span> and it was a fairly dirty script. Nowadays you could do the same in ruby in an embarrassingly little amount of lines.<br />
<h2>Modules, Classes and Monkey Patching</h2><br />
There is a great description of the above and when you should do each. Shoud what you are writing be a module or a class. Do you just monkey patch to solve the problem? All is explained here.</p>

	<p>Top marks for this book. Buy it if you can.</p>
 ]]></content:encoded>
			<wfw:commentRss>http://scoop.simplyexcited.co.uk/2007/06/24/everyday-scripting-with-ruby-book-review/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Texter a text replacement program for windows and productivity</title>
		<link>http://scoop.simplyexcited.co.uk/2007/05/29/texter-a-text-replacement-program-for-windows-and-productivity/</link>
		<comments>http://scoop.simplyexcited.co.uk/2007/05/29/texter-a-text-replacement-program-for-windows-and-productivity/#comments</comments>
		<pubDate>Tue, 29 May 2007 11:58:23 +0000</pubDate>
		<dc:creator>pyrat</dc:creator>
				<category><![CDATA[Chat]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://scoop.cheerfactory.co.uk/2007/05/29/texter-a-text-replacement-program-for-windows-and-productivity/</guid>
		<description><![CDATA[	

	I bet you have to type the same thing over and over in electronic communication day on day.

	Be it signing emails, typing your address or even whole email replies texter is really floating my boat at the moment.

	It allows you to abbreviate things into a few keystrokes. So for example in any text entry interface [...]]]></description>
			<content:encoded><![CDATA[	<p><img src="http://scoop.simplyexcited.co.uk/images/door.jpg" /></p>

	<p>I bet you have to type the same thing over and over in electronic communication day on day.</p>

	<p>Be it signing emails, typing your address or even whole email replies <a href="http://lifehacker.com/software/texter/lifehacker-code-texter-windows-238306.php">texter</a> is really floating my boat at the moment.</p>

	<p>It allows you to abbreviate things into a few keystrokes. So for example in any text entry interface I can type <strong>gladdr</strong> then <em>enter</em> and it replaces this will my full address.</p>

	<p>Add this to the keyboard <a href="http://mail.google.com/support/bin/answer.py?ctx=%67mail&#038;hl=en_GB&#038;answer=6594">shortcuts</a> that gmail provides and you are on fire with blazing productivity.</p>

	<p>Another cool thing I read in the great prag book <a href="http://www.pragmaticprogrammer.com/titles/bmsft/">Everyday Scripting with Ruby</a> is to devote time everyday to making yourself more efficient. Attempting to remove all the repetitive tasks as much a possible from your everyday &#226;&#8364;&#339;workflow&#226;&#8364;? is doing wonders for what I can accomplish on a day to day basis.</p>

	<p>I&#226;&#8364;&#8482;ll post a review of <strong>Everyday Scripting with Ruby</strong> when I&#226;&#8364;&#8482;ve finished it.</p>
 ]]></content:encoded>
			<wfw:commentRss>http://scoop.simplyexcited.co.uk/2007/05/29/texter-a-text-replacement-program-for-windows-and-productivity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Gettext to Translate Your Rails Application</title>
		<link>http://scoop.simplyexcited.co.uk/2007/04/20/using-gettext-to-translate-your-rails-application/</link>
		<comments>http://scoop.simplyexcited.co.uk/2007/04/20/using-gettext-to-translate-your-rails-application/#comments</comments>
		<pubDate>Fri, 20 Apr 2007 22:32:02 +0000</pubDate>
		<dc:creator>pyrat</dc:creator>
				<category><![CDATA[Chat]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://scoop.cheerfactory.co.uk/2007/04/20/using-gettext-to-translate-your-rails-application/</guid>
		<description><![CDATA[	The version of this document is optimized for Ruby-GetText 1.9.0 and Rails 1.2.
This is hosted here because the ruby manuals server seems to have died. Central documentation would be nice :-p

	Introduction
Stand on the shoulders of Giants
Gettext is a great tool for translating user interfaces of applications into different languages. It has been around for a [...]]]></description>
			<content:encoded><![CDATA[	<p><p style="color: red">The version of this document is optimized for Ruby-GetText 1.9.0 and Rails 1.2.</p><br />
<p style="color: red">This is hosted here because the ruby manuals server seems to have died. Central documentation would be nice :-p</p></p>

	<p><h2>Introduction</h2><br />
<h3>Stand on the shoulders of Giants</h3><br />
<a href="http://www.gnu.org/software/gettext/">Gettext</a> is a great tool for translating user interfaces of applications into different languages. It has been around for a long time and is very well established for this task. Gettext helps you to open up your application to a much wider user base than you would normaly reach in only one language. Since it is used in many open source projects it has a lot of useful tools you can use to your own advantage. It would be possible to &#226;&#8364;&#339;roll your own&#226;&#8364;? solution, but this would consume a large amount of time. Time you would lose for the development of your app. And this is not something you would want, right?</p>

	<p>So in this tutorial I am going to show you how to effectively use Gettext for all your translation needs in your Ruby on Rails application.<br />
<h3>What can Gettext do for you?</h3><br />
Here is a quick explanation of Gettext for those of you who haven&#226;&#8364;&#8482;t worked with it, yet. Gettext is a set of tools that provide help when translating strings in your software. It gives you (straight from the <a href="http://www.gnu.org/software/gettext/manual/html_node/gettext_2.html#SEC2">gettext manual</a>):<br />
<ul></p>
	<p><li>A set of conventions about how programs should be written to support message catalogs.</li><br />
<li>A directory and file naming organization for the message catalogs themselves.</li><br />
<li>A runtime library supporting the retrieval of translated messages.</li><br />
<li>A few stand-alone programs to massage in various ways the sets of translatable strings, or already translated strings.</li><br />
</ul></p>
	<p>The only thing you have to do to your program sources is wrap all translatable strings with a method call: <code>gettext(text)</code> or shorter <code>_(text)</code>. Example:</p>

Without gettext:
<pre>notice = &amp;#226;&amp;#8364;&amp;#732;Thank you for buying our product.&amp;#226;&amp;#8364;&amp;#8482;</pre>
With gettext:
<pre>notice = _(&amp;#226;&amp;#8364;&amp;#732;Thank you for buying our product.&amp;#226;&amp;#8364;&amp;#8482;)</pre>
If you have wrapped everything between the method call Gettext will provide you with the tools to extract these messages (called a harvester) from your source code and save the results to a portable file format. A runtime library will allow you to display a translated message whenever _() is called.
In essence this is what Gettext does. It can do a couple of more things (like update / merge message catalogs, handling plurals, &#226;&#8364;&#166;) but essentially it tries to make it as easy and as unobtrusive as possible to translate the language strings in your source code and then get out of your way.
<h2>Preperation is everything&#226;&#8364;&#8221;use <span class="caps">UTF</span>-8 everywhere</h2>
<h3>Edit your files with <span class="caps">UTF</span>-8 only</h3>
The <span class="caps">W3C</span> has an awesome page with all you need to know about character sets (choosing, declaring, serving, editing, &#226;&#8364;&#166;) and other important stuff concerning internationalization on their site called <a href="http://www.w3.org/International/resource-index.html"><span class="caps">W3C I18N </span>Topic Index</a>. There you will find a lot of good help and suggestions on everything you need to know about general internationalization topics. You really want to spend at least a couple of hours reading through the resources they offer or link to.

If you happen to use <span class="caps">VIM</span> like I do you can put these two lines in your <code>.vimrc</code> and it will from then on treat your files as <span class="caps">UTF</span>-8 and convert everything to <span class="caps">UTF</span>-8 whenever you save a file:
<pre>set encoding=utf8
set fileencoding=utf8</pre>
If your editor of choice doesn&#226;&#8364;&#8482;t provide support for <span class="caps">UTF</span>-8 it is probably time to get a new one <img src='http://scoop.simplyexcited.co.uk/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />
<h3>Feed your database with <span class="caps">UTF</span>-8</h3>
If I need a database I usually go for MySQL. At least most of the time. Since version 4.1.x MySQL has very good support for different character sets. Please read the extensive <a href="http://www.quepublishing.com/articles/printerfriendly.asp?p=328641&#038;rl=1">MySQL Character Set Support</a> article. It will give you a very good idea about the kind of support MySQL has to offer.

Here is a table definition I use in a current project:
<pre>CREATE TABLE `pages` (
`id` int(10) unsigned NOT NULL auto&lt;em&gt;increment,
`title` varchar(255) default NULL,
`keywords` varchar(255) default NULL,
`description` varchar(255) default NULL,
`block1` text,
`block2` text,
`block3` text,
`block4` text,
`block5` text,
`lang` varchar(10) NOT NULL default &amp;#226;&amp;#8364;&amp;#8482;en&lt;/em&gt;EN&amp;#226;&amp;#8364;&amp;#8482;,
`category` varchar(255) default NULL,
`path` varchar(255) default &amp;#226;&amp;#8364;&amp;#732;/&amp;#226;&amp;#8364;&amp;#8482;,
`updated&lt;em&gt;at` datetime default NULL,
`created&lt;/em&gt;at` datetime default NULL,
`published&lt;em&gt;at` datetime default NULL,
`layout` varchar(255) default &amp;#226;&amp;#8364;&amp;#732;main.rhtml&amp;#226;&amp;#8364;&amp;#8482;,
`template` varchar(255) default NULL,
`access` tinyint(3) unsigned default &amp;#226;&amp;#8364;&amp;#732;3&amp;#226;&amp;#8364;&amp;#8482;,
`version` int(10) unsigned default &amp;#226;&amp;#8364;&amp;#732;1&amp;#226;&amp;#8364;&amp;#8482;,
`is&lt;/em&gt;published` tinyint(3) unsigned default &amp;#226;&amp;#8364;&amp;#732;0&amp;#226;&amp;#8364;&amp;#8482;,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;</pre>
There is nothing really special about it except the <code>DEFAULT CHARSET=utf8</code> in the last line. It will make MySQL use <span class="caps">UTF</span>-8 for every field that holds text like <code>varchar</code> and <code>text</code>.

Add the following line to your <code>database.yml</code> to connect with <span class="caps">UTF</span>-8.
<pre>encoding: UTF8</pre>
If you use another maybe more mature and feature rich database like PostgreSQL <span class="caps">UTF</span>-8 support should also be available. Just make sure you configure everything upfront, because it might save you time later on.

	<p>If you still think you are going to tack on support for <span class="caps">UTF</span>-8 later you might reconsider after reading David&#226;&#8364;&#8482;s and Jamis&#226;&#8364;&#8482; experiences: <a href="http://www.loudthinking.com/arc/000415.html">Forty-four grueling hours (or Welcome to 37s!) by David Heinemeier Hansson</a> and <a href="http://weblog.jamisbuck.org/2005/3/5/on-the-job">On the job by Jamis Buck</a>.</p>

	<p>If for any reason you need to use anything other than <span class="caps">UTF</span>-8 you might want to know that you can use the Iconv module to convert between different character sets. This module should be installed by default on most distributions. If it is not it is usually easy to get. Just be sure to get it if you need charcter set conversion. On Debian you might need a <code>apt-get install libiconv-ruby</code> to get started. Here is a little example stolen from <a href="http://pragmaticprogrammer.com/titles/ruby/">Pickaxe 2</a> page 686:</p>

Example: Convert <em>ol&#195;&#169;</em> from <span class="caps">UTF</span>-8 to <span class="caps">ISO</span>-8859-1
<pre>$ irb&amp;#226;&amp;#8364;&amp;#8220;riconv
&gt;&gt; Iconv.conv(&amp;#226;&amp;#8364;&amp;#732;ISO-8859-1&amp;#226;&amp;#8364;&amp;#8482;, &amp;#226;&amp;#8364;&amp;#732;UTF-8&amp;#226;&amp;#8364;&amp;#8482;, &amp;#226;&amp;#8364;&amp;#339;ol303251&amp;#226;&amp;#8364;?)
=&gt; &amp;#226;&amp;#8364;&amp;#339;ol351&amp;#226;&amp;#8364;?</pre>
<h3>Installing Ruby-GetText</h3>
After everything in your setup will accept <span class="caps">UTF</span>-8 we can go ahead and install Gettext support in Ruby. We will use the <a href="http://gettext.rubyforge.org/">Ruby-GetText-Package</a> which is a Ruby implementation of the Gettext interface that also has some c-bindings for the Locale.

If you have rubygems, you can easily install Ruby-GetText:
<pre>$ gem install gettext
Select which gem to install for your platform (&amp;#226;&amp;#8364;&amp;#166;)
1. gettext 1.9.0 (ruby)
2. gettext 1.9.0 (mswin32)
&amp;#226;&amp;#8364;&amp;#166;&gt;</pre>
Be sure to choose option 2 if you want Ruby-GetText to work on native Windows (with <a href="http://rubyforge.org/projects/rubyinstaller/">One-Click Ruby Installer</a>) as you are most likely not able to compile otherwise. For all other platforms use 1.

	<p>Alternative: If you need the source you can get it from the author&#226;&#8364;&#8482;s site: <a href="http://gettext.rubyforge.org/">Ruby-GetText-Package</a>. Besides <a href="http://ponx.s5.xrea.com/hiki/ruby-gettext.html#Install">installation instructions</a> you will find a small <a href="http://ponx.s5.xrea.com/hiki/ruby-gettext-howto.html"><span class="caps">HOWTO</span></a>, <a href="http://ponx.s5.xrea.com/hiki/ruby-gettext-api.html"><span class="caps">API </span>Reference</a> and documentation on <a href="http://ponx.s5.xrea.com/hiki/ruby-gettext-tools.html">how to use provided tools</a>.</p>

	<p>Check the sample Rails application that is delivered with Ruby-GetText. If you installed via RubyGems it is most likely here: /usr/lib/ruby/gems/1.8/gems/gettext-1.9.0/samples/rails/, but it could be somewhere else depending on where your Ruby is installed. Later I will call that path $RUBYGETTEXT<em><span class="caps">RAILS</span></em><span class="caps">SAMPLE</span>. So keep this in mind when you read.<br />
<h3>Create the &#226;&#8364;&#339;po&#226;&#8364;? directory structure</h3><br />
Create a <code>po</code> dir right in your $RAILS_ROOT. In it you will create a subdir for every language/dialect combination (actually the second part of this abbreviation stands for &#226;&#8364;&#339;geographic region&#226;&#8364;?, but I will just call it dialect throughout this document). If you don&#226;&#8364;&#8482;t know the right code for your language you can seek help at the <a href="http://www.w3.org/International/resource-index.html#lang">Language section of the <span class="caps">W3C I18N </span>Topic Index</a>.</p>

Ultimately your directory structure is going to look like this:
<pre>simplepages@colinux: /home/simplepages/rails/po:
$ d&amp;#226;&amp;#8364;&amp;#8220;T
/home/simplepages/rails/po/:
|-myapp.pot
|-de&lt;em&gt;DE/:
| `-myapp.po
|-en&lt;/em&gt;GB/:
| `-myapp.po
|-en&lt;em&gt;US/:
| `-myapp.po
|-fr&lt;/em&gt;FR/:
| `-myapp.po
|-fr_CH/:
| `-myapp.po
`-ja/:
`-myapp.po</pre>
The <code>myapp.pot</code> file is the original file created by the <code>rgettext</code> script introduced later. The po files will contain the translation messages that your application is going to use depending on the language that is requested.
<h3>Convert pofiles to mofiles</h3>
After creating pofiles, you need to convert them to mofiles.
If you haven&#226;&#8364;&#8482;t yet, please read the the <a href="http://www.gnu.org/software/gettext/manual/html_node/gettext_5.html#SEC5"><span class="caps">GNU </span>Gettext manual with the explanation of what mo and po stands for</a>.

Add the code below to Rakefile:
<pre>simplepages@colinux: /home/simplepages/rails/Rakefile
require &amp;#226;&amp;#8364;&amp;#732;gettext/utils&amp;#226;&amp;#8364;&amp;#8482;
desc &amp;#226;&amp;#8364;&amp;#339;Create mo-files for L10n&amp;#226;&amp;#8364;?
task :makemo do
GetText.create_mofiles(true, &amp;#226;&amp;#8364;&amp;#339;po&amp;#226;&amp;#8364;?, "locale")
end</pre>
Then,
<pre>$ rake makemo</pre>
It will create locale directories and subdirectroies such as:
<pre>simplepages@colinux: /home/simplepages/rails/locale:
$ d&amp;#226;&amp;#8364;&amp;#8220;T
/home/simplepages/rails/locale/:
|-de&lt;em&gt;DE/:
| `-LC&lt;/em&gt;MESSAGES/:
| |-myapp.mo
|-en&lt;em&gt;GB/:
| `-LC&lt;/em&gt;MESSAGES/:
| |-myapp.mo
|-en&lt;em&gt;US/:
| `-LC&lt;/em&gt;MESSAGES/:
| |-myapp.mo
|-fr&lt;em&gt;FR/:
| `-LC&lt;/em&gt;MESSAGES/:
| |-myapp.mo
|-fr&lt;em&gt;CH/:
| `-LC&lt;/em&gt;MESSAGES/:
| |-myapp.mo
`-ja/:
`-LC_MESSAGES/:
|-myapp.mo</pre>
These files are used by Ruby-GetText. You don&#226;&#8364;&#8482;t need to touch these files.
<h2>Tools of trade</h2>
<h3>Gettext</h3>
You will need to install Gettext. On Debian I would do <code>apt-get install gettext</code> to do that. It contains a couple of tools that will be handy later on, most importantly <code>msgmerge</code> which can merge different po files so updating your message files will be a snap and <code>msginit</code>which can set default values to the header of pofile in your locale.
<h3>Ruby-GetText and rgettext</h3>
After you have installed Ruby-GetText and tools you should able to call <code>rgettext</code> on the command line. rgettext is a replacement for <code>xgettext</code> which comes with the main Gettext application. Beyond <code>xgettext</code>, <code>rgettext</code> supports not only ruby scripts(.rb) but also <span class="caps">ERB</span> files (.rhtml), ActiveRecord(.rb) directly.
<h4>ActiveRecord support
<code>rgettext</code> extracts all the table names and field names within subclasses of ActiveRecord::Base.</h4>
Notice: You need to run your database server and configure the config/database.xml correctly before executing <code>rgettext</code>.
<h3>poEdit</h3>
<a href="http://www.poedit.net">poEdit</a> is a great tool to manage and edit your translations. It gives you a nice graphical frontend to translate all your messages. It is available for many different platforms. A nice side effect about using an easy to use <span class="caps">GUI</span> tool is that you can tell non-programmers to install it, open the po file and just start translating. They might have nothing to do with the coding in your project but will be able to help you translate your software. So if your grandma can translate English to Chinese she can maybe help you with your software project <img src='http://scoop.simplyexcited.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />
<h2>Collecting messages</h2>
Add the code below to Rakefile:
<pre>simplepages@colinux: /home/simplepages/rails/Rakefile
desc &amp;#226;&amp;#8364;&amp;#339;Update pot/po files to match new version.&amp;#226;&amp;#8364;?
task :updatepo do
MY&lt;em&gt;APP&lt;/em&gt;TEXT&lt;em&gt;DOMAIN = &amp;#226;&amp;#8364;&amp;#339;myapp&amp;#226;&amp;#8364;?
MY&lt;/em&gt;APP&lt;em&gt;VERSION = &amp;#226;&amp;#8364;&amp;#339;myapp 1.1.0&amp;#226;&amp;#8364;?
GetText.update&lt;/em&gt;pofiles(YOUR&lt;em&gt;APP&lt;/em&gt;TEXT&lt;em&gt;DOMAIN,
Dir.glob(&amp;#226;&amp;#8364;&amp;#339;/&lt;strong&gt;/&lt;/strong&gt;.{rb,rhtml}&amp;#226;&amp;#8364;?),
MY&lt;/em&gt;APP_VERSION)
end</pre>
Running this task will either create or update your <code>po/myapp.pot</code> and <code>po/&lt;strong&gt;/myapp.po&lt;/strong&gt;</code><strong> files in the relevant directories. It will go through all the important directories of your rails app and harvest all the Gettext strings in files ending in </strong>.rb, *.rhtml.
<pre>$ rake updatepo</pre>
<h3>Translating and compiling with and without poEdit</h3>
After you have successfully harvested your files you should have a <code>myapp.po</code> file in every locale dir. Now you need to translate them. Since the <code>myapp.po</code> files are mere text files you could just use your favourite text editors to translate them. Given that your text editor can edit in <span class="caps">UTF</span>-8 mode and you know the escaping rules of Gettext this is all you actually need. Open the file, translate the text and save it. After you have saved the file compile it. Gettext doesn&#226;&#8364;&#8482;t work with the text files (<code>myapp.po</code>) directly. It wants a compiled version of it (<code>myapp.mo</code>). Use the <code>rake makemo</code> command to compile:
<pre>simplepages@colinux: /home/simplepages/rails/po/de_DE:
$ ls
myapp.posimplepages@colinux: /home/simplepages/rails:
$ rake makemo

	<p>simplepages@colinux: /home/simplepages/rails/locale/de&lt;em&gt;DE/LC&lt;/em&gt;MESSAGES:<br />
$ ls<br />
myapp.mo</pre><br />
However, it is way more comfortable to use an application like poEdit for this. With poEdit you can also easily open up the <code>myapp.po</code> file. It will give you a nice side by side view your original strings and the translated version, telling what is already translated and what is not. You click on a message and start translating it in a special field. Hit the save button and poEdit will automatically compile the <code>myapp.mo</code> file for you (check the preferences if it doesn&#226;&#8364;&#8482;t do it by default). That&#226;&#8364;&#8482;s it. With a compiled <code>myapp.mo</code> you can start to teach your rails app how to translate your user interface.</p>

	<p>See <a href="http://ponx.s5.xrea.com/hiki/ruby-gettext-translate.html">Documents for Translators</a> for more details to translate the po-file.</p>

When creating a po file it is useful to include header information at the top of the po file. This adds useful information such as character set, last translator etc. If you are not using poEdit add something similar to the top of the po file.
<pre>msgid &amp;#226;&amp;#8364;&amp;#339;"
msgstr "&amp;#226;&amp;#8364;?
&amp;#226;&amp;#8364;&amp;#339;POT-Creation-Date: 2007-02-19 17:15-0000n&amp;#226;&amp;#8364;?
&amp;#226;&amp;#8364;&amp;#339;PO-Revision-Date: 2003-04-03 10:49--500n&amp;#226;&amp;#8364;?
&amp;#226;&amp;#8364;&amp;#339;Last-Translator: Alastair Brunton n&amp;#226;&amp;#8364;?
&amp;#226;&amp;#8364;&amp;#339;Language-Team: fr_FR n&amp;#226;&amp;#8364;?
&amp;#226;&amp;#8364;&amp;#339;MIME-Version: 1.0n&amp;#226;&amp;#8364;?
&amp;#226;&amp;#8364;&amp;#339;Content-Type: text/plain; charset=UTF-8n&amp;#226;&amp;#8364;?
&amp;#226;&amp;#8364;&amp;#339;Content-Transfer-Encoding: 8bitn&amp;#226;&amp;#8364;?</pre>
<h2>Implementing Ruby-GetText into your rails app</h2>
By now you should have a translated and compiled <code>myapp.mo</code> in your locale dir. For example my German translation of SimplePages is at <code>$RAILS&lt;em&gt;ROOT/locale/de&lt;/em&gt;DE/LC_MESSAGES/myapp.mo</code>.
<h3>Including Ruby-GetText</h3>
Edit application.rb to bind textdomain to your application.
<pre>simplepages@colinux: /home/simplepages/rails/app/controllers/application.rb:
require &amp;#226;&amp;#8364;&amp;#732;gettext/rails&amp;#226;&amp;#8364;&amp;#8482;class ApplicationController &lt; ActionController::Base
init&lt;em&gt;gettext &amp;#226;&amp;#8364;&amp;#339;myapp&amp;#226;&amp;#8364;?
	<p>#init&lt;/em&gt;gettext &amp;#226;&amp;#8364;&amp;#339;myapp&amp;#226;&amp;#8364;?, &amp;#226;&amp;#8364;&amp;#339;UTF-8&amp;#226;&amp;#8364;?, &amp;#226;&amp;#8364;&amp;#339;text/html&amp;#226;&amp;#8364;? # &lt;= Also you can set charset and content_type.<br />
end</pre><br />
In this sample, the textdomain name is &#226;&#8364;&#339;myapp&#226;&#8364;?. Replace it as you like to fit your application. Maybe you want to have different textdomains for your site and the admin section.<br />
<h3>Selecting the scope of your textdomain</h3><br />
<ol></p>
	<p><li>If you call <code>bindtextdomain</code> in ApplicationControler, the textdomain applies to the entire application.</li><br />
<li>If you call <code>bindtextdomain</code> in any other controller with a different textdomain, this textdomain only applies to this specific controller. For example if you call a different textdomain in <code>myapp&lt;em&gt;controller.rb&lt;/em&gt;</code><em> it will only be used in <code>myapp</code></em>controller.rb.</li><br />
</ol></p>
	<p>The textdomains are applied to each controller/view/model.<br />
<h3>Choosing the right language on every request</h3><br />
Since we are developing a web application we want to be able to choose the current language by request. Additionally we might want to offer the user the possibilty to choose the language from a menu.</p>

	<p>Ruby-GetText chooses the current language by following these rules in the given order:<br />
<ol></p>
	<p><li>the first value passed to the &#226;&#8364;&#732;locale&#226;&#8364;&#8482; parameter of GetText.bindtextdomain method call</li><br />
<li>&#226;&#8364;&#732;lang&#226;&#8364;&#8482; value of <code>QUERY_STRING</code></li><br />
<li>&#226;&#8364;&#732;lang&#226;&#8364;&#8482; value of the Cookie</li><br />
<li>the value of <code>HTTP&lt;em&gt;ACCEPT&lt;/em&gt;LANGUAGE</code></li><br />
<li>or default &#226;&#8364;&#732;en&#226;&#8364;&#8482; (English).</li><br />
</ol></p>
	<p>The script <code>$RUBYGETTEXT&lt;em&gt;RAILS&lt;/em&gt;SAMPLE/vendor/plugins/lang_helper.rb</code> is a sample that selects locale using the cookie value of the user.</p>

It may be useful to implement a simple controller action to change between languages eg.
<pre>class CookieController &lt; ApplicationController
def set&lt;em&gt;cookie
code = params[:id]
cookies[:lang] =
{
:value =&gt; code,
:expires =&gt; Time.now + 1.year,
:path =&gt; &amp;#226;&amp;#8364;&amp;#732;/&amp;#226;&amp;#8364;&amp;#8482;
}
redirect&lt;/em&gt;to home_url
end
end</pre>
So <code>/cookie/set&lt;em&gt;cookie/fr&lt;/em&gt;FR</code> would change the language to French.
<h3>Using the Locale in your templates</h3>
Depending on the selected locale you will want to customize the language and character set in your templates.

File: <code>$RAILS_ROOT/app/view/layouts/main.rhtml</code>
<pre>&amp;#226;&amp;#8364;&amp;#339;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&amp;#226;&amp;#8364;?&gt;

= Locale.charset %&gt;" /&gt;
&amp;#226;&amp;#8364;&amp;#166;</pre>
<h3>Have your own textdomain for plugin applications</h3>
If you are a plugin developer and want to have your own textdomain, you need to separate the Class/Module from ActionView::Base/ApplicationController.
<pre>simplepages@colinux: /home/simplepages/rails/vendor/plugins/gettext/lib/gettext_plugin.rb:
require &amp;#226;&amp;#8364;&amp;#732;gettext/rails&amp;#226;&amp;#8364;&amp;#8482;module LangHelper
	<ol>
		<li>If you need to bind yet another textdomain to your plugin.</li>
			<li>Separate the name space from ActionView::Base/ApplicationController.<br />
class YetanotherTextDomain<br />
include GetText::Rails</li>
	</ol>

	<p>def initialize</p>
	<ol>
		<li>You need to call bindtextdomain in an instance of ActionView::Base.</li>
			<li>The locale is used a same values which define ApplicationController#init&lt;em&gt;gettext instead of</li>
			<li>the textdomain.<br />
bindtextdomain("gettext&lt;/em&gt;plugin")<br />
end</li>
	</ol>

	<p>def show&lt;em&gt;language(actionview)<br />
langs = ["en"] + Dir.glob(File.join(RAILS&lt;/em&gt;ROOT,&amp;#226;&amp;#8364;&amp;#339;locale/*&amp;#226;&amp;#8364;?)).collect{|item| File.basename(item)}<br />
langs.delete("CVS")<br />
langs.uniq!<br />
ret = &amp;#226;&amp;#8364;&amp;#339;<br />
&lt;h4&gt;&amp;#226;&amp;#8364;? + &lt;em&gt;&amp;#226;&amp;#8364;&amp;#339;Select locale&amp;#226;&amp;#8364;?) + &amp;#226;&amp;#8364;&amp;#339;&lt;/em&gt;&lt;/h4&gt;<br />
&lt;em&gt;&amp;#226;&amp;#8364;?<br />
langs.sort.each do |lang|<br />
ret &lt;&lt; actionview.link&lt;/em&gt;to(&amp;#226;&amp;#8364;&amp;#339;#{lang}]&amp;#226;&amp;#8364;?, :action =&gt; &amp;#226;&amp;#8364;&amp;#339;cookie_locale&amp;#226;&amp;#8364;?, :lang =&gt; lang)<br />
end<br />
ret<br />
enddef cookie_locale(cookies, flash, params)<br />
cookies["lang"] = params["lang"]<br />
flash[:notice] = _(&amp;#226;&amp;#8364;&amp;#732;Cookie "lang" is set: %s&amp;#226;&amp;#8364;&amp;#8482;) % params["lang"]<br />
end<br />
end</p>

	<ol>
		<li>This function shows supported languages with link to set cookie</li>
			<li>action (cookie&lt;em&gt;locale).<br />
def show&lt;/em&gt;language<br />
YetanotherTextDomain.new.show_language(self)<br />
end</li>
	</ol>

	<ol>
		<li>This function is called when the language link is set.<br />
def cookie&lt;em&gt;locale<br />
YetanotherTextDomain.new.cookie&lt;/em&gt;locale(cookies, flash, params)<br />
redirect_to :action =&gt; &amp;#226;&amp;#8364;&amp;#732;list&amp;#226;&amp;#8364;&amp;#8482;<br />
end<br />
end</pre><br />
Simply put <code>gettext_plugin.po</code> into the po directory.<br />
<h2>Conclusion</h2><br />
That&#226;&#8364;&#8482;s it. If you have your translated message catalogs (<code>myapp.mo</code>) in all the right places your application should show your message strings in your favourite language.</li>
	</ol>

	<p>You can now easily start to translate your application into all the different languages you want. I hope this guide helps you to get started. There are certainly many more aspects of internationalization that you will have to learn and apply. Remember that this is only one of many possible ways to do it. If you find any mistakes, shortcomings or have good suggestions on how to improve this guide I would be more than happy to hear from you.</p>

	<p>If you want you can download the <a href="http://www.digitale-wertschoepfung.de/artikel/gettext/gettext.txt">original Textile document</a>, make modifications and send them back to me. I will be sure to include you in the credits section.</p>

	<p>Sascha Ebach<br />
<a href="mailto:se%20at%20digitale-wertschoepfung%20dot%20de">se at digitale-wertschoepfung dot de</a><br />
<h3>Credits</h3><br />
<ul></p>
	<p><li><a href="http://www.loudthinking.com">David Heinemeier Hansson</a> for creating the best web application framework that has ever existed P-E-R-I-O-D</li><br />
<li>Masao Mutoh&#226;&#8364;&#8220;The Author of Ruby-GetText: <a href="mailto:mutoh%20at%20highway%20dot%20ne%20dot%20jp">mutoh at highway dot ne dot jp</a>. Thanks to Masao for extending the old version and making it more flexible.</li><br />
<li><a href="http://www.simplyexcited.co.uk">Alastair Brunton</a> for providing some sorely needed modifications to this article.</li><br />
</ul></p>
<h3>Author</h3>
Sascha Ebach is the owner and lead developer of a small <a href="http://www.digitale-wertschoepfung.de">web design and development shop</a> <a href="http://www.digitale-wertschoepfung.de">Digitale Wertsch&#195;&#182;pfung</a> in Cologne, Germany. Together with his two partners he develops and designs complete online solutions for small to medium sized businesses. Up until the surfacing of Rails he used to develop everything in <span class="caps">PHP</span> although he has already fallen deeply in love with Ruby since version 1.6.2 came out. For him it is very clear that Rails and Ruby will be <strong>The Future Way</strong> of developing web applications and he already looks forward to the day when he has ported his last line of <span class="caps">PHP</span> to Ruby.
<h2>Appendix A: Downloads</h2>
<h3>Used files</h3>
Download the archive with files and scripts I use and talk about in this guide. The file includes the complete skeleton of files that you need to get started.
<pre>/home/simplepages/using-gettext-with-rails/:
|-app/:
| `-controllers/:
| `-application.rb (the ApplicationController with the .init&lt;em&gt;gettext method)
`-po/: (sample directory structure)
|-de&lt;/em&gt;DE/:
|-en&lt;em&gt;GB/:
`-en&lt;/em&gt;US/:</pre>
<a href="http://www.digitale-wertschoepfung.de/artikel/gettext/using-gettext-with-rails.tgz">Download using-gettext-with-rails.tgz</a>
 ]]></content:encoded>
			<wfw:commentRss>http://scoop.simplyexcited.co.uk/2007/04/20/using-gettext-to-translate-your-rails-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

