<?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>David Lowry &#187; ruby</title>
	<atom:link href="http://www.davidlowry.co.uk/tag/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.davidlowry.co.uk</link>
	<description></description>
	<lastBuildDate>Sat, 05 Nov 2011 14:35:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Blog Move 1: Getting WordPress data to Ruby using XML</title>
		<link>http://www.davidlowry.co.uk/341/export-wordpress-to-ruby-rails/</link>
		<comments>http://www.davidlowry.co.uk/341/export-wordpress-to-ruby-rails/#comments</comments>
		<pubDate>Sat, 05 Jun 2010 22:44:50 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[hpricot]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://davidlowry.co.uk/?p=341</guid>
		<description><![CDATA[Step 1 in the &#8220;Moving my blog&#8221; process is &#8220;Extract the current site’s data into a manageable format&#8221; Frankly, that&#8217;s easy! WordPress has a functionality to export the site&#8217;s content to a single XML file containing all the published Categories, Tags, Posts, Pages and Comments. To do this (WordPress v2.9.2) click Tools &#62; Export and...<a href="http://www.davidlowry.co.uk/341/export-wordpress-to-ruby-rails/">&#187;</a>]]></description>
			<content:encoded><![CDATA[<p>Step 1 in the &#8220;Moving my blog&#8221; process is &#8220;Extract the current site’s data into a manageable format&#8221;</p>
<p>Frankly, that&#8217;s easy! WordPress has a functionality to export the site&#8217;s content to a single XML file containing all the published Categories, Tags, Posts, Pages and Comments. To do this (WordPress v2.9.2) click Tools &gt; Export and save the file. In previous versions of the software I believe it&#8217;s under the Manage menu.</p>
<p><script src="http://gist.github.com/427052.js?file=gistfile4.xml"></script><br />
 <noscript><a href="http://davidlowry.co.uk/wordpress/wp-content/uploads/2010/06/Screen-shot-2010-06-05-at-22.43.57.png"><img class="alignnone size-full wp-image-342" title="Wordpress XML Code" src="http://davidlowry.co.uk/wordpress/wp-content/uploads/2010/06/Screen-shot-2010-06-05-at-22.43.57.png" alt="Wordpress XML Code: viewed in Dashcode, if you care." width="613" height="323" /></a></noscript></p>
<p>I&#8217;m aware I could import the data directly from the WordPress database (to wherever it goes in the end) but let&#8217;s imagine we can&#8217;t. Anyway, database access would be tediously slow and inefficient to test against and implement.</p>
<p>A quick google for <a href="http://www.google.co.uk/search?q=%22import+wordpress+xml+ruby%22">&#8220;import wordpress xml ruby&#8221;</a> threw up nothing helpful so I turned to the Ruby XML libraries. <a href="http://railstips.org/">John Nunemaker</a> &#8220;feverishly posts everything he learns&#8221; at <a href="http://railstips.org/">railstips.org</a> and has two articles of use here:</p>
<ul>
<li><a href="http://railstips.org/blog/archives/2006/12/09/parsing-xml-with-hpricot/">Parsing XML with hpricot</a></li>
<li><a href="http://railstips.org/blog/archives/2008/08/11/parsing-xml-with-ruby/">Parsing XML with Ruby</a></li>
</ul>
<p>The latter deals with three different ruby xml libraries and compares their speed, ease of use and how nice their names are to say. He puts <a href="http://www.germane-software.com/software/rexml/">REXML</a>, <a href="http://hpricot.com/">hpricot</a> and <a href="http://libxml.rubyforge.org/">libxml-ruby</a>. I&#8217;ll save you the pleasure of reading the article (if you like) and ccv John&#8217;s summary:</p>
<blockquote><p>
&#8220;Libxml is blisteringly fast, [but] Hpricot has cooler name, REXML and Hpricot both feel easier to use out of the box&#8221;
</p></blockquote>
<p>And there you go. Hpricot it is!</p>
<p>Now to get the data into Ruby. After a quick glance at the rubytips article and <a href="http://rdoc.info/projects/hpricot/hpricot">The RDocs</a> I put together this code as a starting point:<br />
 <script src="http://gist.github.com/427052.js?file=gistfile2.builder"></script><br />
<noscript></p>
<pre><code>
cats_hierarchy={}
(doc/"wp:category").each do |category|
    cat_name = category.at("wp:category_nicename").innerHTML
    cat_parent = category.at("wp:category_parent").innerHTML

    if cats_hierarchy.include? cat_parent
        cats_hierarchy[cat_parent] = cat_name
    else
        cats_hierarchy[cat_name] = []
    end
end

cats = cats_hierarchy.to_a.flatten
</code></pre>
<p></noscript></p>
<p>That gives me two each to use Ruby objects each containing all of my category data: a hash which preserves the hierarchy of the structure and all the names in a linear array.<br />
<script src="http://gist.github.com/427052.js?file=gistfile3.builder"></script><br />
<noscript></p>
<pre><code>
?> cats = cats_hierarchy.to_a.flatten.uniq
=> ["route66", nil, "rails", "american-2008", "reciprocal-affection", "hope-for-the-future", "code", "blog", "review-blog", "rant", "brands", "projects", "yab_shop", "textpattern", "meaningful-labor", "giants", "accessibility", "root", "charity-project", "apple", "xhtml", "america-2006-route-66", "ruby", "learning", "america-2007", "uncategorized", "iphone", "america-2008"]

?> cats_hierarchy
=> {"route66"=>nil, "rails"=>nil, "american-2008"=>nil, "reciprocal-affection"=>nil, "hope-for-the-future"=>nil, "code"=>nil, "blog"=>"review-blog", "rant"=>nil, "brands"=>nil, "projects"=>nil, "yab_shop"=>nil, "textpattern"=>nil, "meaningful-labor"=>nil, "giants"=>nil, "accessibility"=>nil, "root"=>nil, "charity-project"=>nil, "apple"=>nil, "xhtml"=>nil, "america-2006-route-66"=>nil, "ruby"=>nil, "learning"=>nil, "america-2007"=>nil, "uncategorized"=>nil, "iphone"=>nil, "america-2008"=>nil}
</code></pre>
<p></noscript></p>
<p>And so we have the starting point to getting this WordPress exported XML data into a Ruby application.</p>
<p>More soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidlowry.co.uk/341/export-wordpress-to-ruby-rails/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Rails / LAMP / WordPress Setup Guide</title>
		<link>http://www.davidlowry.co.uk/258/rails-lamp-wordpress-setup-guide/</link>
		<comments>http://www.davidlowry.co.uk/258/rails-lamp-wordpress-setup-guide/#comments</comments>
		<pubDate>Thu, 07 May 2009 19:47:27 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[blog]]></category>
		<category><![CDATA[meaningful labor]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[environment]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[lamp]]></category>
		<category><![CDATA[setup]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://davidlowry.co.uk/rails-lamp-wordpress-setup-guide/</guid>
		<description><![CDATA[I&#8217;ve had huge amounts of pain getting WordPress set up locally over the last few weeks on my old machine and when it struck again with my new development environment it definitely time to write down the required steps to get a great LAMP/Rails setup prepared (for me)! Leopard has PHP and Apache fairly up...<a href="http://www.davidlowry.co.uk/258/rails-lamp-wordpress-setup-guide/">&#187;</a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve had huge amounts of pain getting WordPress set up locally over the last few weeks on my old machine and when it struck again with my new development environment it definitely time to write down the required steps to get a great LAMP/Rails setup prepared (for me)!</p>
<p>Leopard has PHP and Apache fairly up to date, and probably MySQL as well, but I decided to get MySQL up to scratch using the Universal Binary along with a few command line instructions available <a href="http://developer.apple.com/internet/opensource/osdb.html">here (guide and links to downloads)</a>.</p>
<p>I didn&#8217;t use this script myself, and at a year old it may have a few imperfections, but <a href="http://hivelogic.com/articles/view/ruby-rails-leopard">HiveLogic have a fairly well rounded Ruby/Rails install going on.</a></p>
<p>Finally, WordPress to go on your LAMP stack will be a lot less painful using <a href="http://www.tech-recipes.com/rx/2757/leopard_how_to_install_wordpress/">this guide for Tech Recipes</a>.</p>
<p>Any suggestions additions or replacements for this list? Drop a comment!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidlowry.co.uk/258/rails-lamp-wordpress-setup-guide/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ruby Uninitialized Constant Error (Mental Note)</title>
		<link>http://www.davidlowry.co.uk/114/ruby-uninitialized-constant-error-mental-note/</link>
		<comments>http://www.davidlowry.co.uk/114/ruby-uninitialized-constant-error-mental-note/#comments</comments>
		<pubDate>Mon, 14 Apr 2008 15:37:28 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[learning]]></category>
		<category><![CDATA[meaningful labor]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[script generate]]></category>
		<category><![CDATA[uninitialized constants]]></category>

		<guid isPermaLink="false">http://davidlowry.co.uk/?p=114</guid>
		<description><![CDATA[The reason I always get initialized constant errors occurring in Ruby is accidentally naming models the plural form of the database table name and not letting Rails automatically create the pluralisations. script/generate scaffold contact_skill contact_id:integer skill_id:integer description:string not script/generate scaffold contact_skills ... (This reason is one I constantly forget, and Google never helps me. Now...<a href="http://www.davidlowry.co.uk/114/ruby-uninitialized-constant-error-mental-note/">&#187;</a>]]></description>
			<content:encoded><![CDATA[<p>The reason I always get initialized constant errors occurring in Ruby is accidentally naming models the plural form of the database table name and not letting Rails automatically create the pluralisations.</p>
<p><code>script/generate scaffold contact_skill contact_id:integer skill_id:integer description:string </code><br />
not<br />
<code>script/generate scaffold contact_skills ... </code></p>
<p>(This reason is one I constantly forget, and Google never helps me. Now I will not forget)</p>
<p>&#8212;&#8211;</p>
<p>edit: I&#8217;ve had a LOAD of google hits from this search query in the last few days, if this helps you <em>or doesn&#8217;t</em> please leave a comment to make this article more complete.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidlowry.co.uk/114/ruby-uninitialized-constant-error-mental-note/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

