<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
    xmlns:admin="http://webns.net/mvcb/"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:content="http://purl.org/rss/1.0/modules/content/">

    <channel>
    
    <title>Jamie on Software</title>
    <link>http://jamieonsoftware.com</link>
    <description>Development, entrepreneurship and rude remarks.</description>
    <dc:language>en-GB</dc:language>
    <dc:creator>jamie@jamierumbelow.net</dc:creator>
    <dc:rights>Copyright 2010</dc:rights>
    <dc:date>2010-06-09T10:26:03+00:00</dc:date>
    <admin:generatorAgent rdf:resource="http://expressionengine.com/" />
    

    <item>
      <title>EECI Wrap&#45;up</title>
      <link>http://jamieonsoftware.com/blog/entry/eeci-wrap-up</link>
      <guid>http://jamieonsoftware.com/blog/entry/eeci-wrap-up#When:11:26:03Z</guid>
      <description>I&#8217;ve been collecting all the photos, videos, slides and more from my recent trip to San Francisco and the ExpressionEngine CodeIgniter Conference. There&#8217;s still plenty more reports, photos, videos et cetera appearing all over the internet, so if you&#8217;re interested keep checking back and I&#8217;ll update this post with other&#8217;s wrap&#45;ups, as I&#8217;m sure there&#8217;ll be many.

If you missed it, the second ExpressionEngine CodeIgniter conference was held from May 31st &#45; June 2nd in the Fort Mason Centre in San Francisco, California, United States of America. Robert, Janneke, Chris and the rest of the Whoooz! team really pulled out the stops, and ran a fantastic conference.

The Venue and San Francisco

I was thrilled to get to visit San Francisco. The city is incredible, the culture fantastic and the vibe, pure electric. There&#8217;s every race, religion, sexuality and gender under the sun, everything&#8217;s so liberal and open. I&#8217;ve rarely had so much energy, so much passion. It was an inspiring location, and a perfect place to hold a technical conference.



The venue itself, the Fort Mason Centre, was pretty interesting. While the rooms weren&#8217;t exactly perfect, it was a gorgeous location, and turned out to be a great venue. There were plenty of facilities on site, and I managed to have my first ever root beer. Let me tell you now, children. Root beer is incredible. It&#8217;s so damn good, I can&#8217;t believe we don&#8217;t have it in the UK. Anyway, I digress. There was a lovely vegetarian restaurant that I got to try out called Green&#8217;s, so thanks a lot to Mitchell Kimbrough at Solspace for taking me there.

Community

I&#8217;ll speak for every CodeIgniter attendee at the conference: being able to interact with and talk to our ExpressionEngine counterparts was an absolute pleasure. Attending EECI is a huge reminder of just how awesome both communities are. While I wasn&#8217;t allowed in either of the after parties for obvious reasons, I was allowed in Kennedy&#8217;s Bar where many social events took place, and mingling with the ExpressionEngine and CodeIgniter folk was just fantastic. Adding to an open bar, I&#8217;m sure it&#8217;d be brilliant.

During the conference itself, there was plenty of interaction. There was no barrier between speakers and attendees: just passionate people geeking out about their favourite framework and CMS. The Solspace CodeShare Corner was a great place to chat to people or show off new projects. Relationships were made, deals were cut, and I&#8217;m sure there&#8217;ll be plenty of interesting projects that spew out from this conference.



Sessions

All the sessions were stellar. Boasting an incredible mix of great speakers, on a variety of topics, EECI really was an inspirational and informative conference. Many conferences nowadays are only good for the social networking, but EECI was definitely an exception. I don&#8217;t think I&#8217;ve ever heard the word &#8216;ExpressionEngine&#8217; more times in a single day than I did on June 1st. While everyone was fantastic, I&#8217;d like to show my appreciation to Ed Finkler, Tom Myer, Simon Collison, Brandon Kelly and Kenny Meyers, who all put on brilliant presentations.

I also hear fantastic things about Jamie Pittock&#8217;s, Leslie Flinger&#8217;s and Greg Wood&#8217;s sessions, so be sure to check them out. You can find the videos from the sessions online if you buy a online pass, and it&#8217;s highly recommended.



MojoMotor and Community Partners

Damn near everyone from EllisLab were present at the event, and Rick Ellis, Leslie Camacho, Derek Jones and Derek Allard gave the keynote. Leslie announced that EllisLab were opening up a new program called Official Community Partners, which provides support, financial backing and official status to community sites. Currently, these are all EE&#45;focused, but I don&#8217;t doubt that CodeIgniter focused community sites will start to pop up.

Derek Allard, EllisLab&#8217;s technology architect announced EllisLab&#8217;s next product, MojoMotor. MojoMotor is a small CMS designed to &#8220;do less&#8221;. MojoMotor is currently in private BETA, but it&#8217;s going to be opened up to the public very soon, and let me tell you, it&#8217;s something special. Keep an eye on this one.



My Presentation

My presentation was titled &#8220;Getting Ignited with EE2&#8221;, and was all about how to get into ExpressionEngine add&#45;on development from a CodeIgniter perspective. My talk went down really well, with loads of people tweeting and congratulating me for it. It was a really fun subject to talk about, and managed to appeal to a wide range of people; loads of people from both the CI side and EE side turned up to my talk. Get the slides at SlideShare and the ending video over at Vimeo.



EECI 2010

EECI 2010 was an absolutely brilliant conference. I loved every minute of it, and I&#8217;ll definitely recommend heading over to Leiden in September for EECI Europe. Mega props to everyone who attended, the guys and girls at Whoooz!, all the speakers and everyone else involved with the ExpressionEngine&#45;CodeIgniter event of the year.</description>
      <dc:date>2010-06-09T11:26:03+00:00</dc:date>
    </item>

    <item>
      <title>Coming up at EECI 2010</title>
      <link>http://jamieonsoftware.com/blog/entry/coming-up-at-eeci-2010</link>
      <guid>http://jamieonsoftware.com/blog/entry/coming-up-at-eeci-2010#When:13:48:26Z</guid>
      <description>There are going to be loads of people at EECI2010 SF, but the majority of them are going to be ExpressionEngine folk. We need to get the CodeIgniter numbers up, people, so I thought I&#8217;d post a sneak preview of my talk and my masterclass. If you want to get tickets already, head straight over to the EECI website and get them ASAP!

Kicking arse with EE2

EE2 is written on CodeIgniter. That gives us, CodeIgniter developers, the perfect chance to get into a market, the perfect chance to merge the communities, and moreover, the perfect chance to kick some serious arse. How do you get started with EE2 development? How do you sell your add&#45;ons? What common pitfalls and problems do EE developers come across? All this and more, in this funny, real, and occasionally controversial talk from the CodeIgniter Community Chieftain, Jamie Rumbelow.

MongoDB and CodeIgniter

Everyone&#8217;s talking about MongoDB. It&#8217;s a brand new, scalable, fast and lightweight document&#45;oriented database that is totally different from any relational databases like MySQL or PostgreSQL. But what makes it so special? And more importantly, how do you use MongoDB in your CodeIgniter applications? Find out what Mongo is, how to install it and why it&#8217;s so awesome in this MasterClass from the CodeIgniter Community Chieftain, Jamie Rumbelow.</description>
      <dc:date>2010-05-13T13:48:26+00:00</dc:date>
    </item>

    <item>
      <title>Terrible wording on an advert</title>
      <link>http://jamieonsoftware.com/blog/entry/terrible-wording-on-an-advert</link>
      <guid>http://jamieonsoftware.com/blog/entry/terrible-wording-on-an-advert#When:16:55:30Z</guid>
      <description>Here&#8217;s some extremely bad wording on an advert I saw in Tweetie:



This is essentially saying &#8216;Our product is really complex and hard to use, why don&#8217;t you give it a go!&#8217; Clearly the copy writer didn&#8217;t read it when they saw it, because this jumps out as an overwhelmingly bad mistake in copy writing. Alternative methods of phrasing might be &#8216;[Brand Name] is the most powerful, feature rich system utility available. Give it a try now!&#8217;, or &#8216;[Brand Name] solves some of your most complex system utility problems for you.&#8217; Make your product work for your users, not against. Additionally, make this apparent to potential customers in your advertising. First impressions count.</description>
      <dc:date>2010-05-08T16:55:30+00:00</dc:date>
    </item>

    <item>
      <title>Forking CodeIgniter on BitBucket</title>
      <link>http://jamieonsoftware.com/blog/entry/forking-codeigniter-on-bitbucket</link>
      <guid>http://jamieonsoftware.com/blog/entry/forking-codeigniter-on-bitbucket#When:18:56:20Z</guid>
      <description>CodeIgniter 2 is available (in development) on BitBucket, and because of that, it&#8217;s ready for you to fork and work on. The EllisLab people are usually pretty good with answering pull requests and feature additions, and the most likely way of them accepting any proposals is for you to dive in and get coding. I thought I&#8217;d put together a quick guide on forking CodeIgniter.

How?

It&#8217;s easy. Visit the CodeIgniter BitBucket Page and hit the &#8220;Fork&#8221; link. It&#8217;ll guide you through forking it, and will eventually redirect you to your forked repo&#8217;s page. Copy the HTTPS/SSH link there (pick your choosing; I prefer SSH but need to use HTTPS for some stuff because my school blocks port 20&#8230; plus, if you&#8217;re running windows then setting up SSH can be tricky). Jump into terminal and navigate to the directory in which you want to store your fork.

Getting to know hgrc

We&#8217;ll start off by cloning the directory from the remote repository, using that URL we got a minute ago.


hg clone ssh://hg@bitbucket.org/jamierumbelow/codeigniter


This will bring all the files from the remote repository and download them locally. cd into that directory. Now, we want to be able to pull in updates from EllisLab and merge them with our updates. Luckily, using Mercurial this is a piece of cake. Mercurial stores all the repository information in one root folder called .hg. It looks for a file called .hgrc in there to set repository&#45;level settings. Open up the .hg/hgrc file in your text editor (in my case, TextMate).


mate .hg/hgrc


You should already see a few lines in here. It should look something like this:


[paths]
default = ssh://hg@bitbucket.org/jamierumbelow/codeigniter


This is setting the default path to be your repository. This means that by default, hg push and hg pull will use that URL to push and pull changesets from. We want to add a new path that links back to EllisLab&#8217;s copy of CodeIgniter, so we can pull changes from them. Underneath the default path declaration, add the following:


ellislab = ssh://hg@bitbucket.org/ellislab/codeigniter


And that&#8217;s it. Now, save that file and jump back into Terminal. We can now pull changesets from EllisLab by running hg pull ellislab. Great! We can make our own changes, commit them and push them to our own repository. Then, all you have to do is hit &#8220;Pull Request&#8221; in BitBucket and your changes will be speeding off to EllisLab instantly. That wasn&#8217;t so hard, was it?</description>
      <dc:date>2010-05-04T18:56:20+00:00</dc:date>
    </item>

    <item>
      <title>Rumbel&#45;oh! the Joker</title>
      <link>http://jamieonsoftware.com/blog/entry/rumbel-oh-the-joker</link>
      <guid>http://jamieonsoftware.com/blog/entry/rumbel-oh-the-joker#When:08:15:52Z</guid>
      <description>I&#8217;m extremely annoyed with myself. Let this be a lesson to everyone who is working on a project and has put anything more than 2 hours work into it: Back up and use some form of version control. If you don&#8217;t, you&#8217;ll seriously regret it. Anyway, let me tell you a story&#8230;

Welcome to Expressionland

A long time ago there existed a country which called itself Expressionland. It was a reasonably happy place; it&#8217;s monarch, the Emperor Ellis was kind to its people, the lords and ladies were generous and there was always an opportunity for anyone to profit within the gates of its capitol city.
The Emperor Ellis held a number of mechanical devices, which we would know as engines. Each time a problem occurred with the engines, or the Emperor needed them to go faster or for longer, the Chief of the Guards, Sir Jones, would call upon his minions and the people of Expressionland to assist him in upgrading the engines.
Sir Jones, who was a kind man, made the upgrade process as simple as possible; merely replacing a few parts of the engine while keeping the main cogs intact. Very rarely did anyone run into any issues, and when they did, Lady Lisa, the kingdom&#8217;s most respected inhabitant, would be there on call to assist anyone.
For years people lived, undisturbed in Expressionland. The residents of this wonderful place were happy.

There&#8217;s always a Joker

Stumbling up to the city gates, a Joker, by the name of Rumbel&#45;oh!, and with a passion for mechanics, asked if he could join the city. He thought he could bring a new spin to the engines, and the people were gracious, so they let him in.
For months he toiled away at working on the engines, with one popular addition to the engines available for the people to purchase. He worked tirelessly, for long days and nights, to make the engine as powerful as he could. He was getting close to releasing the biggest and best of his additions yet. In fact, he may well have released the addition in a few days post to his experience, of which shall now be told.
The brave knight, Sir Jones, had come back from fighting the troops of Wordpressia, and decided that the engines needed an upgrade. He issued the upgrade warrant, and the people got to work at upgrading their engines.
The Joker, however, was a fool. He forgot to take the correct steps in upgrading. He forgot to clone his engine before hand, so none of the precious parts were lost. He didn&#8217;t bother investing in a version control system for his engine. He passed by on Sir Jones&#8217; question to ensure that nothing like this happened.
All his hard work, all his sweat and blood, had been lost. Months of work, months of additions. Lost. Blown into the wind never to be seen again.

The Moral?

So, I lost 2 months work on Taggable. I&#8217;m going to have to pretty much start from scratch &#45; 1.2 was a pretty big rewrite and I&#8217;ve lost everything that I&#8217;ve done. As well as Taggable, I&#8217;ve also lost Judge, EngineRoom and Carousel (more on them later). Luckily, I&#8217;ve still got the Sparkplugs site, which is a relief.
Anyway, I&#8217;m setting up remote backups for my Sites directory ASAP, and will be promptly putting everything into version control. It&#8217;s taught me a big, big lesson.</description>
      <dc:date>2010-05-02T08:15:52+00:00</dc:date>
    </item>

    <item>
      <title>Screen Scraping with PHP</title>
      <link>http://jamieonsoftware.com/blog/entry/screen-scraping-with-php</link>
      <guid>http://jamieonsoftware.com/blog/entry/screen-scraping-with-php#When:08:24:02Z</guid>
      <description>There are quite a few good screen scraping libraries available for PHP apps so that you can pull and parse a page, search for specific elements, enter data into and post forms et cetera, but if you just need to do a bit of screen&#45;scraping work and you don&#8217;t need an entire library (or don&#8217;t want the additional overhead of another file to load), PHP has a few handy tricks up its sleeve to make this really easy.

Getting the source

Getting the source code of a HTML page is really easy. You could go down the route of using cURL if you need a lot of control over your requests, want to make asynchronous requests or need to use any other HTTP method than GET, but for basic stuff, file_get_contents works absolutely fine.


    &amp;lt;?php
    
    $html = file_get_contents(&amp;#x27;http://codeigniter.com&amp;#x27;);


After you&#8217;ve got the source code of the page, we could clean it and get some nice, valid XHTML using PHP&#8217;s Tidy Extension, or we could just hope that it&#8217;s valid enough so our parser can understand it. In this case, as I know the CodeIgniter homepage has got some pretty good markup, we&#8217;ll do the latter.

Parsing the HTML

Parsing the HTML we&#8217;ve downloaded is seriously easy. We want to get it into a form where we can use xPath to scan through the source and find the elements we want. To do this, we&#8217;ll use a method which is without a doubt full of win. We create a DOMDocument object, set $strictErrorChecking to FALSE (HTML isn&#8217;t usually strict enough) and run the loadHTML() method.


    &amp;lt;?php
    
    $dom = new DOMDocument();
    $dom&#45;&amp;gt;strictErrorChecking = FALSE;
    $dom&#45;&amp;gt;loadHTML($html);


With this DOM document, we now have an objectified representation of our remote page. The final step to screen scraping karma is to push this object into a SimpleXMLElement, with which we can fully traverse and manipulate the document.


    &amp;lt;?php
    
    $obj = simplexml_import_dom($dom);


Win. Okay, now we can use this SimpleXML element to run XPath queries on our document. We&#8217;re going to find the two lists on the CodeIgniter homepage under the CodeIgniter is right for you if&#8230; section, then loop through their elements and display them on our own site. Taking a quick peek at the CodeIgniter.com source code shows us that the lists are &amp;lt;ul&amp;gt; tags and they have the IDs of column1 and column2.


    &amp;lt;?php
    
    $lists = $obj&#45;&amp;gt;xpath(&amp;quot;//ul[@id=&amp;#x27;column1&amp;#x27;] | //ul[@id=&amp;#x27;column2&amp;#x27;]&amp;quot;);


Collecting the reasons

Now we&#8217;ve got these elements, let&#8217;s loop through them and collect the reasons.


    &amp;lt;?php
    
    $reasons = array();
    
    foreach ($lists as $list) {
        // obj { li = array() }
        foreach ($list&#45;&amp;gt;li as $reason) {
            $reasons[] = (string)$reason;
        }
    }


We&#8217;re looping through an array of two elements (both lists), and each list has a number of &amp;lt;li&amp;gt; elements. We loop through those and collect their values. We need to remember to cast the $reason object as a string so we can see the string itself, rather than it&#8217;s objectified representation.

Wow, that was pretty easy. Now all we have to do is loop through the reasons and output them, and we&#8217;ve completed our little screen scraper.


    &amp;lt;?php
    
    echo(&amp;quot;&amp;lt;h1&amp;gt;Why is CodeIgniter right for you?&amp;lt;/h1&amp;gt;&amp;lt;p&amp;gt;&amp;quot;);
    echo implode(&amp;#x27;, &amp;#x27;, $reasons);
    echo(&amp;quot;&amp;lt;/p&amp;gt;&amp;lt;h1&amp;gt;CodeIgniter provides all these reasons, and more!&amp;lt;/h1&amp;gt;&amp;quot;);


Great, we&#8217;re done. So there we go, that&#8217;s how you write a simple screen scraper in PHP.</description>
      <dc:date>2010-04-26T08:24:02+00:00</dc:date>
    </item>

    <item>
      <title>The Playa Effect</title>
      <link>http://jamieonsoftware.com/blog/entry/the-playa-effect</link>
      <guid>http://jamieonsoftware.com/blog/entry/the-playa-effect#When:16:33:13Z</guid>
      <description>There are very few times when you get to test out a genuinely exciting product &#45; something that is revered and well known across a community and is hugely anticipated. I&#8217;m lucky enough to be able to test out the latest version of Brandon Kelly&#8217;s infamous Playa, which yesterday hit version 3. This update, among other things, introduces ExpressionEngine 2 support, a snazzy new interface and loads of bug fixes. I&#8217;ve been testing it out for a few days, and here&#8217;s my review.

Installation

Installation was pretty much seamless. I&#8217;ve been working with an alpha/beta copy, so there were one or two bugs that I encountered, but I reported them to Brandon and since then have been fixed. For those of you who are upgrading from Playa 2, there is an upgrade script that makes it easy to pull your data over.

The New Interface

The new user interface in the control panel is absolutely lovely. It&#8217;s fluid, intuitive and extremely easy to use and understand. It feels smooth and polished; and is an utter joy to use. I&#8217;d like a few more filtering options, as well as the ability to be able to sort by various fields dynamically on the publish form, but all in all, the interface is extremely well put together.

Template Tags

&#8230;are great! I can&#8217;t think of anything else I&#8217;d ever need here. Almost mimics the &#123;exp:channel:entries&#125; tag, and that&#8217;s due to the fact it actually implements EE&#8217;s relationship functionality it at a lower level.

Price

Playa is a little pricey, but by all means every penny is worth it, and Brandon&#8217;s support is fantastic. It&#8217;s a fair price to pay for what Brandon has done for the EE community, and it&#8217;s an incredible product that I can only see getting better and better.

So, buy it

All in all, Pixel and Tonic&#8217;s Playa 3 is a fantastic EE2 addon. It&#8217;s powerful, simple, sexy and elegant. I would recommend it to anyone. 5 stars.</description>
      <dc:date>2010-04-13T16:33:13+00:00</dc:date>
    </item>

    <item>
      <title>Wrap me up and put me in a box</title>
      <link>http://jamieonsoftware.com/blog/entry/wrap-me-up-and-put-me-in-a-box</link>
      <guid>http://jamieonsoftware.com/blog/entry/wrap-me-up-and-put-me-in-a-box#When:10:52:39Z</guid>
      <description>One of the additions that I&#8217;m most excited about to the in&#45;development CodeIgniter 2.0 codebase is the addition of code packages, and the power to then load those packages inside your application. This opens so many doors to developers, because, finally, we can bundle repeated functionality inside a package and distribute it as open&#45;source or free code. Even if you don&#8217;t want to expose your own packages, you can re&#45;use them internally, which makes for a veritable mix of both writing application specific code, and abstracting elements of those applications out (such as an authentication engine, for instance) to become re&#45;usable and unspecific. With documentation for 2.0 still patchy, I thought I&#8217;d go through exactly how to use packages and what benefits they provide.

Relative Positioning

Packages count as application&#45;specific code in themselves, and so are generally put in the application/third_party directory. A single package directory can contain its own controllers/, models/, views/, libraries/, config/, helpers/ and language/ directories. Think of them as mini&#45;cities inside a bigger city. Sprawling metropolises inside vast underground caves.
Want to put your packages somewhere else? No problem. Currently, as the loader for 2.0 is still under development, you&#8217;re not tied down to a specific location. At some point, no doubt, the location of packages will be finalised, but even after EllisLab set the recommended location, there will still be the underlying package API, so you won&#8217;t be stuck with using application/third_party.

Lock and loading

In this current stage of early development, loading packages is somewhat fragmented. Currently, you use the loader to add the package&#8217;s path to the list of resource paths. When a file is loaded with the loader, the loader checks in that file&#8217;s respective path(s) for the file, working based on an order of chronology. If the loader can&#8217;t find the file in the application/libraries directory, it will look in the first package path you add, then the second, then the third, then any subsequent to that. That means that you can&#8217;t have conflicting classes or files your application.
Adding package paths is simple:


    &amp;lt;?php
    
    $this&#45;&amp;gt;load&#45;&amp;gt;add_package_path(APPPATH.&amp;#x27;third_party/mango/&amp;#x27;);



Here we add the mango package to the list of searched directories. We can then load any subsequent classes inside the mango package using the loader just like before.


    &amp;lt;?php
    
    // Load mango/libraries/resources.php
    $this&#45;&amp;gt;load&#45;&amp;gt;library(&amp;#x27;resources&amp;#x27;);
    
    // Use the library
    $juice = $this&#45;&amp;gt;resources&#45;&amp;gt;juice();
    $oil   = $this&#45;&amp;gt;resources&#45;&amp;gt;oil();
    
    // Load mango/models/juice.php
    $this&#45;&amp;gt;load&#45;&amp;gt;model(&amp;#x27;juice&amp;#x27;);
    $prepared_juice = $this&#45;&amp;gt;juice&#45;&amp;gt;prepare($juice, $oil);
    
    // We can also load any application&#45;wide files
    // Load application/libraries/drinks.php
    $this&#45;&amp;gt;drink&#45;&amp;gt;create($prepared_juice, &amp;quot;Mango Juice&amp;quot;);



If you are working with multiple package directories, you can remove packages from the paths array after you are finished with them. After you&#8217;ve finished devouring the flesh of your delicious mango, you can suck clean the stone in the middle and put it in the bin, before washing your hands.


    &amp;lt;?php
    
    $this&#45;&amp;gt;load&#45;&amp;gt;remove_package_path(APPPATH.&amp;quot;third_party/mango/&amp;quot;);



Views and mangos

Unfortunately, there is still one loose link in the chain. That odd mango that turns rotten, mushy and spoiled to both the tongue and the eye. View loading is still inherently difficult, for some strange reason. If you wish to load views inside packages, you must manually set the loader&#8217;s load path to the views directory inside your package, and then back to the original load path after you&#8217;re done. The simplest way is to wrap it up inside a helper method:


    &amp;lt;?php
    
    public function view($name, $params = array()) {
        // Keep the original path and set the active path to the mango/views directory
        $orig_path = $this&#45;&amp;gt;load&#45;&amp;gt;_ci_view_path;
        $this&#45;&amp;gt;load&#45;&amp;gt;_ci_view_path = APPPATH.&amp;#x27;third_party/mango/views/&amp;#x27;;
        
        // Load the view
        $this&#45;&amp;gt;load&#45;&amp;gt;view($name, $params);
        
        // Revert back to the original load path
        $this&#45;&amp;gt;load&#45;&amp;gt;_ci_view
    }



That cleans things up a bit, because now all you have to do is call:


    $this&#45;&gt;view(&apos;fruit/details&apos;, array(&apos;fruit&apos; =&gt; &apos;Mango&apos;));



Routing and more

Packages aren&#8217;t really there yet. They&#8217;re cool, and they provide a lot of promise, but as CodeIgniter 2.0 is mercifully under development, you can&#8217;t do a few basic things that really are necessary, such as routing to a package or autoloading package paths.
I&#8217;ll revisit this topic in a few months when packages are more stable and you can do more with them. However, they are still pretty useful for grouping code together, sharing code across multiple applications, and the addition of proper routing, view loading and autoloading will just sweeten the deal.</description>
      <dc:date>2010-04-09T10:52:39+00:00</dc:date>
    </item>

    <item>
      <title>Testing RESTful response types</title>
      <link>http://jamieonsoftware.com/blog/entry/testing-restful-response-types</link>
      <guid>http://jamieonsoftware.com/blog/entry/testing-restful-response-types#When:15:07:32Z</guid>
      <description>I&#8217;ve been doing a lot of Rails development recently as part of my new job (our whole infrastructure is built on Rails, you see), and have been practicing Test&#45;driven Development religiously. As part of this, I&#8217;ve been developing an API that returns more than one response format, and I was looking to find out how to test if the correct response type is being returned.

The way I approached this was using the @response.content_type variable, and running an assert_equal, comparing it with the correct mime type:


test &quot;that the response type is JSON&quot; do
  get :index, :format =&gt; &apos;json&apos;
  assert_equal @response.content_type, &apos;application/json&apos;
end


That worked fine for a while, but I slowly grew tired of repeating myself and having to copy and paste content types. Also, the above solution isn&#8217;t particularly flexible; as far as I&#8217;m aware, there are 6 different accepted content types for JSON alone. What if I were to copy and paste this code into, say, a Sinatra app or some other app where I was writing my tests in Ruby, only to find it returned a different content type and my tests were incorrect?

So, I decided to abstract the method out into my test_helper.rb into it&#8217;s own assertion method. This method would take a symbol to specify what response type to check, check the actual response type against a pre&#45;defined list of response types that are grouped under the response type of the symbol passed in, and assert that it was included in the array. It looked something like this:


def assert_response_is(type, message = &apos;&apos;)
  case type
    when :json
      check = [ 
        &apos;application/json&apos;, 
        &apos;text/json&apos;, 
        &apos;application/x&#45;javascript&apos;, 
        &apos;text/javascript&apos;, 
        &apos;text/x&#45;javascript&apos;, 
        &apos;text/x&#45;json&apos;
      ]
    when :xml
      check = [ &apos;application/xml&apos;, &apos;text/xml&apos; ]
    when :yaml
      check = [ 
        &apos;text/yaml&apos;,
        &apos;text/x&#45;yaml&apos;,
        &apos;application/yaml&apos;,
        &apos;application/x&#45;yaml&apos; 
      ]
    else
      check = []
  end
  
  assert check.include?(@response.content_type), message
end


Again, that worked fine, but there were still a few issues with it. What if I wanted to check another response type that wasn&#8217;t predefined? How could I add that? I decided to use a bit of Ruby&#8217;s metaprogramming to check for a method on the current class. That way, if I wanted to add any more content types I could define that method and it would check against the array returned:


# ...
      else
        if methods.include?(&apos;assert_response_types&apos;)
          check = assert_response_types
        else
          check = []
        end
    end
# ...


Almost there. The penultimate thing I noticed was that the script was still specific to Rails, as it was checking the @response.content_type variable. So, I used the same technique as above:


# ...
    if @response.content_type
      ct = @response.content_type
    elsif methods.include?(&apos;assert_response_response&apos;)
      ct = assert_response_response
    else
      ct = &apos;&apos;
    end
# ...


Great! Finally, I wanted the failure message to be a bit more descriptive than &#8220; is not true&#8221;. I dug around a bit inside the Ruby Standard Library and found that the default Test::Unit assertions raised a Test::Unit::AssertionFailedError when an assertion failed. Also, I discovered the helpful build_message function that builds up an error message. So, all I had to do was rescue assert&#8217;s exception and raise my own with my own custom message:


# ...
    begin
      assert check.include?(ct) 
    rescue Test::Unit::AssertionFailedError
      raise Test::Unit::AssertionFailedError.new(build_message(message, &quot;The response type is not ?&quot;, type.to_s))
    end
  end


Tie all this together and I have a pretty neat assert_response_is assertion, to check that the response type is a certain value! The entire method looks like this:


  def assert_response_is(type, message = &apos;&apos;)
    case type
      when :json
        check = [ 
          &apos;application/json&apos;, 
          &apos;text/json&apos;, 
          &apos;application/x&#45;javascript&apos;, 
          &apos;text/javascript&apos;, 
          &apos;text/x&#45;javascript&apos;, 
          &apos;text/x&#45;json&apos;
        ]
      when :xml
        check = [ &apos;application/xml&apos;, &apos;text/xml&apos; ]
      when :yaml
        check = [ 
          &apos;text/yaml&apos;,
          &apos;text/x&#45;yaml&apos;,
          &apos;application/yaml&apos;,
          &apos;application/x&#45;yaml&apos; 
        ]
      else
        if methods.include?(&apos;assert_response_types&apos;)
          check = assert_response_types
        else
          check = []
        end
    end
    
    if @response.content_type
      ct = @response.content_type
    elsif methods.include?(&apos;assert_response_response&apos;)
      ct = assert_response_response
    else
      ct = &apos;&apos;
    end
    
    begin
      assert check.include?(ct) 
    rescue Test::Unit::AssertionFailedError
      raise Test::Unit::AssertionFailedError.new(build_message(message, &quot;The response type is not ?&quot;, type.to_s))
    end
  end


And my tests look like:


  test &quot;that the index method returns all users in all formats&quot; do
    # json
    get :index, :format =&gt; &apos;json&apos;
    assert_response_is :json
    
    # xml
    get :index, :format =&gt; &apos;xml&apos;
    assert_response_is :xml
    
    # yaml
    get :index, :format =&gt; &apos;yaml&apos;
    assert_response_is :yaml
  end


So there we go, that&#8217;s how to test RESTful response types in Ruby, using Test::Unit. I&#8217;m still pretty new at using Ruby, so any Rubyists feel free to take and make my code nicer!</description>
      <dc:date>2010-04-02T15:07:32+00:00</dc:date>
    </item>

    <item>
      <title>CodeIgniter Repo Naming Conventions</title>
      <link>http://jamieonsoftware.com/blog/entry/codeigniter-repo-naming-conventions</link>
      <guid>http://jamieonsoftware.com/blog/entry/codeigniter-repo-naming-conventions#When:14:28:50Z</guid>
      <description>With the announcement that CodeIgniter 2 is now under public development over at BitBucket, lots of developers have been moving their open source projects over to Mercurial, and thus BitBucket. With such a big change that is starting to be reflected across the community, I propose we create a globally used convention for naming BitBucket Repositories (or GitHub, for that matter) that contain CodeIgniter&#45;based libraries or projects.

I suggest we prefix every CodeIgniter&#45;specific repository with codeigniter&#45;. I&#8217;ve been doing this, as has Phil Sturgeon, but others (I&#8217;m looking at you Haughin) haven&#8217;t, and it&#8217;d be great to have this global convention set up. It would make finding CodeIgniter repositories much easier.

Spread the word, and hopefully we&#8217;ll have a really good consistent way of naming BitBucket repositories.</description>
      <dc:date>2010-03-27T14:28:50+00:00</dc:date>
    </item>

    
    </channel>
</rss>