<?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>metaduck</title>
	<atom:link href="http://www.metaduck.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.metaduck.com</link>
	<description></description>
	<lastBuildDate>Wed, 05 May 2010 12:04:43 +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>Zero width ExtJS HTMLEditor on IE7</title>
		<link>http://www.metaduck.com/2010/05/zero-width-extjs-htmleditor-on-ie7/</link>
		<comments>http://www.metaduck.com/2010/05/zero-width-extjs-htmleditor-on-ie7/#comments</comments>
		<pubDate>Wed, 05 May 2010 12:04:43 +0000</pubDate>
		<dc:creator>Pedro Teixeira</dc:creator>
				<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.metaduck.com/?p=252</guid>
		<description><![CDATA[Do you have a zero width HTMLEditor on IE7 only?
Don't waste hours like I did trying to figure it out.
Pass in a 'width' argument to the HTMLEditor constructor. That did it for me.
Using ExtJS 3.2.1.
]]></description>
			<content:encoded><![CDATA[<p>Do you have a zero width HTMLEditor on IE7 only?</p>
<p>Don't waste hours like I did trying to figure it out.</p>
<p>Pass in a 'width' argument to the HTMLEditor constructor. That did it for me.</p>
<p>Using ExtJS 3.2.1.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.metaduck.com/2010/05/zero-width-extjs-htmleditor-on-ie7/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Will_paginate and AJAX</title>
		<link>http://www.metaduck.com/2010/04/will_paginate-and-ajax/</link>
		<comments>http://www.metaduck.com/2010/04/will_paginate-and-ajax/#comments</comments>
		<pubDate>Mon, 12 Apr 2010 15:07:59 +0000</pubDate>
		<dc:creator>Pedro Teixeira</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.metaduck.com/?p=247</guid>
		<description><![CDATA[I have been using will_paginate ever since I started on Rails.
It's a great plugin for classic page rendering, but what if you want to use it with AJAX, so it updates a document element (a floating window layer, for instance) with the results instead of reloading the page?
Well, inspired on Redline's blog post (which almost [...]]]></description>
			<content:encoded><![CDATA[<p>I have been using will_paginate ever since I started on Rails.</p>
<p>It's a great plugin for classic page rendering, but what if you want to use it with AJAX, so it updates a document element (a floating window layer, for instance) with the results instead of reloading the page?</p>
<p>Well, inspired on <a href="http://weblog.redlinesoftware.com/2008/1/30/willpaginate-and-remote-links">Redline's blog post</a> (which almost worked for the latest version of the will_paginate plugin), I have the solution.</p>
<p>Create a link renderer. I put in under lib/remote_link_renderer.rb so Rails always loads it on startup.</p>
<pre style="font-size: 1.1em; background-color: #dddddd; overflow-x: auto; overflow-y: auto; padding: 0.4em; border: 1px solid #aaaaaa;"><code style="font-size: 1.1em; font-family: Monaco, 'Courier New', monospace; color: #000000;"><span style="font-family: monospace; color: #8b0000;">class</span> <span>RemoteLinkRenderer</span> &lt; <span>WillPaginate</span>:<span style="font-family: monospace; color: #884400;">:LinkRenderer</span>

  <span style="font-family: monospace; color: #8b0000;">def</span> page_link_or_span<span>(</span>page, span_class = <span style="font-family: monospace; color: #00008b;">'current'</span>, text = nil<span>)</span>
    text ||= page<span style="font-family: monospace; color: #006400;">.to_s</span>
    <span style="font-family: monospace; color: #8b0000;">if</span> page and page != current_page
      <span>@template</span><span style="font-family: monospace; color: #006400;">.link_to_remote</span><span>(</span>text, <span>{</span><span style="font-family: monospace; color: #884400;">:url</span> =&gt; url_for<span>(</span>page<span>)</span>, <span style="font-family: monospace; color: #884400;">:method</span> =&gt; <span style="font-family: monospace; color: #884400;">:get</span><span>}</span><span style="font-family: monospace; color: #006400;">.merge</span><span>(</span><span>@remote</span><span>)</span><span>)</span>
    <span style="font-family: monospace; color: #8b0000;">else</span>
      <span>@template</span><span style="font-family: monospace; color: #006400;">.content_tag</span> <span style="font-family: monospace; color: #884400;">:span</span>, text, <span style="font-family: monospace; color: #884400;">:class</span> =&gt; span_class
    <span style="font-family: monospace; color: #8b0000;">end</span>
  <span style="font-family: monospace; color: #8b0000;">end</span>
<span style="font-family: monospace; color: #8b0000;">end</span></code></pre>
<p>On the view, when you are rendering the pager, do it like this:</p>
<pre style="font-size: 1.1em; background-color: #dddddd; overflow-x: auto; overflow-y: auto; padding: 0.4em; border: 1px solid #aaaaaa;"><code style="font-size: 1.1em; font-family: Monaco, 'Courier New', monospace; color: #000000;">&lt;%= will_paginate <span>@collection</span>, <span style="font-family: monospace; color: #884400;">:renderer</span> =&gt; <span style="font-family: monospace; color: #00008b;">'RemoteLinkRenderer'</span> , <span style="font-family: monospace; color: #884400;">:remote</span> =&gt; <span>{</span><span style="font-family: monospace; color: #884400;">:with</span> =&gt; ’value’, <span style="font-family: monospace; color: #884400;">:update</span> =&gt; ‘some_div’<span>}</span> %&gt;</code></pre>
<p>That's it!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.metaduck.com/2010/04/will_paginate-and-ajax/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to paginate outside of the database with will_paginate</title>
		<link>http://www.metaduck.com/2010/03/how-to-paginate-outside-of-the-database-with-will_paginate/</link>
		<comments>http://www.metaduck.com/2010/03/how-to-paginate-outside-of-the-database-with-will_paginate/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 11:09:33 +0000</pubDate>
		<dc:creator>Pedro Teixeira</dc:creator>
				<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://www.metaduck.com/?p=240</guid>
		<description><![CDATA[will_paginate is a great plugin. I have been using it since I started on Rails.
If you want to paginate records that are inside your database it works great.
But what if you want to paginate records that come from, say an external webservice?
Well, you can use the WillPaginate::Collection class.
This class will let you mimic the collection [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://wiki.github.com/mislav/will_paginate/">will_paginate</a> is a great plugin. I have been using it since I started on Rails.</p>
<p>If you want to paginate records that are inside your database it works great.</p>
<p>But what if you want to paginate records that come from, say an external webservice?</p>
<p>Well, you can use the WillPaginate::Collection class.</p>
<p>This class will let you mimic the collection that will work on a pager, so you can use the view helper pager seamlessly throughout your app.</p>
<p>Just use it like this:</p>
<pre style="font: normal normal normal 14px/normal Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace; color: black; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; padding-top: 0.5em; padding-right: 0.8em; padding-bottom: 0.5em; padding-left: 0.8em; overflow-x: auto; overflow-y: auto; background-position: initial initial; background-repeat: initial initial; border: 1px solid silver;">@entries = WillPaginate::Collection.create(1, 10) do |pager|
  result = Webservice.get(...) # get your results
  # inject the result array into the paginated collection:
  pager.replace(result)

  unless pager.total_entries
    # the pager didn't manage to guess the total count, do it manually
    pager.total_entries = result.count
  end
end</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.metaduck.com/2010/03/how-to-paginate-outside-of-the-database-with-will_paginate/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>New year resolutions</title>
		<link>http://www.metaduck.com/2009/12/new-year-resolutions/</link>
		<comments>http://www.metaduck.com/2009/12/new-year-resolutions/#comments</comments>
		<pubDate>Wed, 30 Dec 2009 16:35:03 +0000</pubDate>
		<dc:creator>Pedro Teixeira</dc:creator>
				<category><![CDATA[No category]]></category>

		<guid isPermaLink="false">http://www.metaduck.com/?p=234</guid>
		<description><![CDATA[Happy new year to everyone!
I haven't posted for a while - had a busy end-of-year...
Things I want to look into early 2010:

Haml
Rails 3
Node.js
Erlang
Hadoop
Scala
EJB 3
Ruby alteranative VMs (JRuby, MacRuby, LevMag)
...and more cool blog posts!

]]></description>
			<content:encoded><![CDATA[<p>Happy new year to everyone!</p>
<p>I haven't posted for a while - had a busy end-of-year...</p>
<p>Things I want to look into early 2010:</p>
<ul>
<li>Haml</li>
<li>Rails 3</li>
<li>Node.js</li>
<li>Erlang</li>
<li>Hadoop</li>
<li>Scala</li>
<li>EJB 3</li>
<li>Ruby alteranative VMs (JRuby, MacRuby, LevMag)</li>
<li>...and more cool blog posts!</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.metaduck.com/2009/12/new-year-resolutions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tools for the job</title>
		<link>http://www.metaduck.com/2009/11/tools-for-the-job/</link>
		<comments>http://www.metaduck.com/2009/11/tools-for-the-job/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 15:28:24 +0000</pubDate>
		<dc:creator>Pedro Teixeira</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://www.metaduck.com/?p=208</guid>
		<description><![CDATA[See the tools / gems / plugins I can't live without.]]></description>
			<content:encoded><![CDATA[<p><img class="size-full wp-image-226 alignleft" title="tools" src="http://www.metaduck.com/wp-content/uploads/2009/11/tools.jpeg" alt="tools" width="123" height="123" />Here are some tools / gems / plugins I can't live without:</p>
<h2>IDEs:</h2>
<ul>
<li><a href="http://www.radrails.org/">Aptana Rad Rails</a> - very good at Rails and Ruby. It's based on Eclipse - Java - so it tends to bloat</li>
<li><a href="http://projects.gnome.org/gedit/">gedit</a>- Tiny footprint, simple. Great for web and PHP with the right plugins and conf tweaks</li>
</ul>
<h2>Ruby / Rails plugins:</h2>
<p><span id="more-208"></span></p>
<ul>
<li><a href="http://wiki.github.com/mislav/will_paginate">will_paginate</a> - ActiveRecord pagination made easy</li>
<li><a href="http://github.com/Squeegy/fleximage">fleximage</a> - online image processing Rails plug-in based on rmagick. Very easy to manipulate</li>
<li><a href="http://github.com/whymirror/hpricot">hpricot gem</a> - for parsing HTML and XML. Very resilient to formatting errors. Use it to parse XML feeds with wrong encoding and screen scraping.</li>
<li><a href="http://github.com/binarylogic/authlogic">authlogic</a> - for easy and extensible authentication. With care you can make it easily authenticate with anything.</li>
<li><a href="http://deveiate.org/projects/BlueCloth">BlueCloth</a> gem - for markdown markup</li>
<li><a href="http://rubyeventmachine.com/">eventmachine</a> - scalable asynchronous Ruby servers made easy.</li>
<li><a href="http://wiki.github.com/pgte/styled_objects">styled_objects</a> - simplify stylesheet development and maintenance. By yours truly.</li>
<li><a href="http://github.com/collectiveidea/delayed_job">delayed_job</a> - job queuing for Rails made easy.</li>
<li><a href="http://github.com/cjbottaro/app_config">app_config</a> gem - easy application configuration. Easily differentiate for each environment.</li>
<li><a href="http://wiki.github.com/frabcus/acts_as_xapian">acts_as_xapian</a> - easy ruby and Rails bindings for Xapian - full text search engine. Xapian uses offline index update and does not use a daemon.</li>
<li><a href="http://stonean.com/page/lockdown">lockdown</a> -  authorization system for Rails</li>
<li><a href="http://wiki.github.com/pgte/acts_as_pingable">acts_as_pingable</a> - to expose you Rails stack to external pings. Use it for pingdom.com integration.</li>
<li><a href="http://github.com/giraffesoft/resource_controller">resource_controller</a> - simplifies code for resource controllers (almost no code at all for most cases !)</li>
<li><a href="http://github.com/rubyist/aasm">aasm (acts as state machine)</a> - easily turn your objects into state machines.</li>
</ul>
<h2>Testing</h2>
<ul>
<li><a href="http://cukes.info/">cucumber</a> - BDD at it's best</li>
<li><a href="http://mocha.rubyforge.org/">mocha</a> - intuitive mocking and stubbing</li>
<li><a href="http://rspec.info/">rspec and rspec-rails</a> - Rails testing</li>
<li><a href="http://github.com/thoughtbot/factory_girl">factory_girl</a> - Get rid of fixtures</li>
</ul>
<h2>Database</h2>
<ul>
<li><a href="http://www.mysql.com/">MySQL</a> - I love it, I hate it, I have to live with it...</li>
<li><a href="http://1978th.net/tokyocabinet/">Tokyo Cabinet</a> - fast single table database for key-value store (it already has multiple columns format) with a simple Ruby API. Useful for a lot of things. You can also use <a href="http://1978th.net/tokyotyrant/">Tokyo Tyrant</a> for service.</li>
</ul>
<h2>Deployment</h2>
<ul>
<li><a href="http://www.capify.org">Capistrano</a> - although there are some simpler alternatives around, I simply love Capistrano and use it for almost everything deployment-related.</li>
<li><a href="http://github.com/jamis/capistrano-ext">capistrano-ext</a> - with multistaging deployment, among other goodies.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.metaduck.com/2009/11/tools-for-the-job/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>sweepy &#8211; Distributed and scalable file caching expiration in Rails</title>
		<link>http://www.metaduck.com/2009/10/sweepy-distributed-and-scalable-file-caching-expiration-in-rails/</link>
		<comments>http://www.metaduck.com/2009/10/sweepy-distributed-and-scalable-file-caching-expiration-in-rails/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 23:13:00 +0000</pubDate>
		<dc:creator>Pedro Teixeira</dc:creator>
				<category><![CDATA[No category]]></category>

		<guid isPermaLink="false">http://www.metaduck.com/?p=196</guid>
		<description><![CDATA[Followin up on my post about Rails cache on a distributed environment, I recently published a Rails plugin called sweepy.
Sweepy allows you to expire file-based cache (page cache and fragment cache) on Rails on multiple boxes.
If you don’t want or don’t need to setup memcached, and just want to simply use Rails page and / [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-224" title="sweepy" src="http://www.metaduck.com/wp-content/uploads/2009/10/sweepy.jpeg" alt="sweepy" width="116" height="142" />Followin up on my post about Rails <a href="http://www.metaduck.com/2009/10/rails-cache-in-distributed-environment/">cache on a distributed environment</a>, I recently published a Rails plugin called <em>sweepy</em>.</p>
<p>Sweepy allows you to expire file-based cache (page cache and fragment cache) on Rails on multiple boxes.</p>
<p>If you don’t want or don’t need to setup memcached, and just want to simply use Rails page and / or fragment caching, sweepy automatically handles page expiration.</p>
<p>You can use the Rails expire_page and expire_cache <span>API</span>, no need to change existing code.</p>
<p><span id="more-196"></span>…with the bonus of sweepy supporting a regexp as a expire_page argument.</p>
<h2>Really, what is <em>sweepy</em>?</h2>
<p><em>sweepy</em> is two things:</p>
<ol>
<li>A daemon running on each box</li>
<li>A Rails plugin to expire cache</li>
</ol>
<h2><em>sweepy</em> is scalable</h2>
<p><em>sweepy</em> uses <span>UDP</span> broadcasts for cache cleaning. This way you can add as many machines as you want, and cache expiration times will remain the same.</p>
<p>Check out <a href="http://github.com/pgte/sweepy">sweepy at github</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.metaduck.com/2009/10/sweepy-distributed-and-scalable-file-caching-expiration-in-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to alias_method_chain a class method on Rails</title>
		<link>http://www.metaduck.com/2009/10/how-to-alias_method_chain-a-class-method-on-rails/</link>
		<comments>http://www.metaduck.com/2009/10/how-to-alias_method_chain-a-class-method-on-rails/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 11:53:04 +0000</pubDate>
		<dc:creator>Pedro Teixeira</dc:creator>
				<category><![CDATA[No category]]></category>

		<guid isPermaLink="false">http://www.metaduck.com/?p=182</guid>
		<description><![CDATA[Sometimes, when building a plugin, you have to extend Rails behaviour using alias_method_chain.
So you do, on the included module:

...
    def self.included(base)
      base.send :include  InstanceMethods
      base.class_eval do
        alias_method_chain :method_i_want_to_extend, :my_feature
      [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes, when building a plugin, you have to extend Rails behaviour using <a href="http://weblog.rubyonrails.org/2006/4/26/new-in-rails-module-alias_method_chain">alias_method_chain</a>.</p>
<p>So you do, on the included module:</p>
<pre class="brush: ruby;">
...
    def self.included(base)
      base.send :include  InstanceMethods
      base.class_eval do
        alias_method_chain :method_i_want_to_extend, :my_feature
      end
    end

    module InstanceMethods
     def method_i_want_to_extend_with_my_feature(args)
       (do something or not...)
       method_i_want_to_extend_without_my_feature(args)
       (do something or not...)
     end
    end
...
</pre>
<p>What if the method you are extending is a class method?</p>
<p><span id="more-182"></span>Simple, just use the singleton class:</p>
<pre class="brush: ruby;">
...
    def self.included(base)
      base.extend ClassMethods
      base.class_eval do
        class &lt;&lt; self
          alias_method_chain :method_i_want_to_extend, :my_feature
        end
      end
    end

    module ClassMethods
     def method_i_want_to_extend_with_my_feature(args)
       (do something or not...)
       method_i_want_to_extend_without_my_feature(args)
       (do something or not...)
     end
    end
...
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.metaduck.com/2009/10/how-to-alias_method_chain-a-class-method-on-rails/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Tutorial &#8211; advanced styled_objects on Rails</title>
		<link>http://www.metaduck.com/2009/10/tutorial-advanced-styled-objects-on-rails/</link>
		<comments>http://www.metaduck.com/2009/10/tutorial-advanced-styled-objects-on-rails/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 11:19:04 +0000</pubDate>
		<dc:creator>Pedro Teixeira</dc:creator>
				<category><![CDATA[No category]]></category>

		<guid isPermaLink="false">http://www.metaduck.com/?p=158</guid>
		<description><![CDATA[Following the building and styling a Rails app with styled_objects tutorial, we will learn how to use some advanced features of styled_objects and also some best practices to keep your CSS code maintainable while using styled_objects.
Use CSS variables
On styled_objects you can define global variables to be used throughout your CSS.
Declare variables on one place: app/views/globals.css
Example [...]]]></description>
			<content:encoded><![CDATA[<p>Following the <em><a href="http://www.metaduck.com/2009/10/tutorial-building-and-styling-a-rails-app-with-styled-objects/">building and styling a Rails app with styled_objects tutorial</a></em>, we will learn how to use some advanced features of styled_objects and also some best practices to keep your CSS code maintainable while using styled_objects.</p>
<h2><span id="more-158"></span>Use CSS variables</h2>
<p>On styled_objects you can define global variables to be used throughout your CSS.</p>
<p>Declare variables on one place: app/views/globals.css</p>
<p>Example of a piece of <em>global.css</em> that defines three variables:</p>
<pre class="brush: css;">@brand_color: #4D926F;
@base_color: #111;
@border-thickness: 1px;
</pre>
<p>Now, on any template or partial CSS file you can use these variables like this:</p>
<pre class="brush: css;">color: @brand_color;
border: @border-thickness solid @base_color;
</pre>
<p>styled_objects uses <a href="http://lesscss.org/">LESS</a> on the background, so you can use <a href="http://lesscss.org/docs.html">LESS syntax</a>, which is very similar to CSS. Be careful to only define global variables on a global file like application.css, so you can be sure the variable is present on all the included CSSs.</p>
<h2>Code generic classes</h2>
<p>OO-CSS says we should separate container styling from content styling. How can we do it using styled_objects?</p>
<p>Let's say you have a container for a box block that can be used throughout many partials. How to reuse this container?</p>
<p>What you need is a layout partial.</p>
<p>Create a app/views/containers/_box.html.erb with the container markup:</p>
<pre class="brush: php;">&lt;%= yield %&gt;</pre>
<p>And create the respective CSS under app/views/containers/_box.css:</p>
<pre class="brush: css;">border: 2px solid #333;</pre>
<p>That's it! No need for additional markup, (although you may need to if you have to decorate the box partial with images, for instance).</p>
<p>Now you only have to call your partials with a box layout like this:</p>
<pre class="brush: php;">
&lt;%= include :partial =&gt; 'article_summary', :layout =&gt; 'containers/box' %&gt;
&lt;%= include :partial =&gt; 'top_headlines', :layout =&gt; 'containers/box' %&gt;
</pre>
<h2>Debug your stylesheets</h2>
<p>Introducing variables can lead to syntax errors that, because the final stylesheet is generated on the server, cannot be debug on a browser.</p>
<p>How to debug the result?</p>
<p>In development mode, when a change you made broke your stylesheet generation, you can:</p>
<p>Open the generated page source on your browser and look for something like <em>&lt;style src="&lt;link href="/styledobjects/...</em></p>
<p>Copy this URL into the browser (by prefixing it with "http://localhost:3000" or the port your are developing on) and:</p>
<p>1. Check the <em>log/development.log</em> for syntax errors</p>
<p>2. Check the screen for errors. You will probably get a LESS error, indicating which sentence went wrong</p>
<p>Most errors are unknown declared variables, and LESS will tell you something like:</p>
<h1>Less::VariableNameError</h1>
<pre>@myvarname
</pre>
<p>This will tell that you are using a variable named <em>myvarname</em> thatis not declared.</p>
<h2>More resources</h2>
<ul>
<li><a href="http://lesscss.org/docs.html">More on LESS syntax</a></li>
<li><a href="http://www.stubbornella.org/content/2009/03/23/object-oriented-css-video-on-ydn/">Stubbornella's presentation about OO-CSS</a> (video)</li>
<li><a href="http://net.tutsplus.com/tutorials/html-css-techniques/object-oriented-css-what-how-and-why/">OO-CSS Tutorial @ Nettuts</a></li>
</ul>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 133px; width: 1px; height: 1px;">
<pre class="less_example">#4D926F;</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.metaduck.com/2009/10/tutorial-advanced-styled-objects-on-rails/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Tutorial: building and styling a Rails app with styled_objects</title>
		<link>http://www.metaduck.com/2009/10/tutorial-building-and-styling-a-rails-app-with-styled-objects/</link>
		<comments>http://www.metaduck.com/2009/10/tutorial-building-and-styling-a-rails-app-with-styled-objects/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 22:53:23 +0000</pubDate>
		<dc:creator>Pedro Teixeira</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.metaduck.com/?p=88</guid>
		<description><![CDATA[How to keep your stylesheets clean and organized using Rails
This tutorial covers building a web application from scratch using Rails with the styled_objects plugin.
As an example we will be building a very static front-end website, mainly to focus on stylesheets.
Everything you get from can be applied to more complex applications.
Because this is such a simple [...]]]></description>
			<content:encoded><![CDATA[<p><strong><em>How to keep your stylesheets clean and organized using Rails</em></strong></p>
<p>This tutorial covers building a web application from scratch using Rails with the styled_objects plugin.</p>
<p><span id="more-88"></span>As an example we will be building a very static front-end website, mainly to focus on stylesheets.</p>
<p>Everything you get from can be applied to more complex applications.</p>
<p>Because this is such a simple application, we won't be using scaffolding generators.</p>
<h2>About styled_obejcts</h2>
<p><a href="http://wiki.github.com/pgte/styled_objects">styled_objects</a> <strong> </strong>is a Rails plugin for simplifying stylesheet management on your application.</p>
<p>Instead of having one or more large stylesheets on your public folder, have many. Keep your <span>CSS</span> close to their respective templates. <strong>styled_objects</strong> will compile them into one file per page.</p>
<h2>Getting started</h2>
<p>1. Bootstrap your Rails app</p>
<pre>$ rails testapp</pre>
<p>2. Install the LESS gem:</p>
<p>Edit your config/environment.rb and place, anywhere before the "end":</p>
<pre class="brush: ruby;">config.gem 'less'</pre>
<p>Run on the shell:</p>
<pre>$ sudo rake gems:install</pre>
<p>2. install the styled_objects plugin</p>
<pre>script/plugin install git://github.com/pgte/styled_objects.git</pre>
<h2>The application</h2>
<p>Here we will be building a simple example application for an e-commerce website.<br />
First we will be focusing on building the controllers and the views, and finally we will learn how to style them with styled_objects.</p>
<p>To start we will be having products and product categories. One product can be in many categories and one category can contain many products. So, it is a many-to-many relationship.</p>
<p>For the sake of simplicity, let's say a product has a name and a description.</p>
<p>Each category have a name.</p>
<p>(I won't go through the building of the models, it's beyond the scope of this tutorial).</p>
<h3>Product page</h3>
<p>After you have your migrations and models setup, we need to configure the routes for our products controller.</p>
<p>Edit your config/routes.rb and add:</p>
<pre class="brush: ruby;">map.resources :products</pre>
<p>Now build the controller under app/controllers/products_controller.rb. For now we will only have a "show" action:</p>
<pre class="brush: ruby;">
class ProductsController &lt; ApplicationController

  def show
    @product = Product.find(params[:id])
  end

end
</pre>
<p>Do the show template  under app/views/products/show.html.erb:</p>
<pre class="brush: ruby;">
&lt;h1&gt;&lt;%= h @product.name %&gt;&lt;/h1&gt;
&lt;p&gt;&lt;%= h @product.description %&gt;&lt;/p&gt;
</pre>
<h3>Category page</h3>
<p>On this page we will be presenting all products on the current category.</p>
<p>Build the product category routes ou config/routes.rb:</p>
<pre class="brush: ruby;">
config.resources :categories
</pre>
<p>Next, build the controller under app/controllers/categories_controller.rb:</p>
<pre class="brush: ruby;">
class CategoriesController &lt; ApplicationController

  def show
    @category = Product.find(params[:id], :include =&gt; :products)
  end

end
</pre>
<p>And the view under app/views/categories/show.html.erb:</p>
<pre class="brush: ruby;">
&lt;h1&gt;&lt;%= h @category.name%&gt;&lt;/h1&gt;

&lt;p&gt;products in this category:&lt;/p&gt;

&lt;%= render :partial =&gt; 'products/product', :collection =&gt; @category.products %&gt;
</pre>
<p>This template is a bit more complex than the product show one because it presents all the products inside the current category by calling the <em>products/_product.html.erb</em> partial for each product.</p>
<p>Let's do this partial (under app/views/products/_product.html.erb):</p>
<pre class="brush: ruby;">
&lt;h2&gt;&lt;%= link_to h(product.name), product_path(product) %&gt;&lt;/h2&gt;
&lt;p&gt;&lt;%= h truncate(product.description) %&gt;&lt;/p&gt;
</pre>
<p>Here, instead of presenting the full product description, we truncate it using the ActionView truncate helper, presenting only the first 30 characters of the product description.</p>
<h2>Styling up</h2>
<p>So, now that we have the category and product pages in place, we need to style them.</p>
<p>But first we need to style the whole website.</p>
<h3>Global styling</h3>
<p>Personally, I feel comfortable with using this folloing setup when starting a website, but it is not a requirement for styled_objects. (We haven't got there yet).</p>
<h4>Reset stylesheet</h4>
<p>There are numerous reset stylesheets out there. I particulary like the one bundled inside blueprint CSS.</p>
<p>So, <a href="http://www.blueprintcss.org/">grab a copy of blueprint</a> and extract the <em>blueprint/src/reset.css</em> file and copy it into <em>public/stylesheets/</em> directory.</p>
<p>Next, edit your <em>app/views/layouts/application.html.erb</em> and add the following line before the &lt;/head&gt; tag:</p>
<pre class="brush: xml;">

&lt;%= stylesheet_link_tag 'reset' %&gt;
</pre>
<h4>Typography sytlesheet</h4>
<p>This is where we add a special stylesheet only for defining your typography. This is where you will be styling your p, a, ul, li, table, etc. tags.</p>
<p>This is your job, but I like to start from the blueprint/src/typography.css bundled on blueprint.</p>
<p>Save this file into public/stylesheets and add the respective the stylesheet link tag right after the reset one:</p>
<pre class="brush: xml;">
&lt;%= stylesheet_link_tag 'reset' %&gt;
&lt;%= stylesheet_link_tag 'typography' %&gt;
</pre>
<p>This stylesheet you will be formatting according to the desired look of your website.</p>
<h4>Layout stylesheet</h4>
<p>Before building a layout stylesheet, you need to build your layout markup. This will be done inside <em>app/layouts/application.html.erb</em> :</p>
<pre class="brush: php;">
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot; &quot;http://www.w3.org/TR/html4/strict.dtd&quot;&gt;
&lt;html&gt;
	&lt;head&gt;
		&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot; /&gt;
		&lt;title&gt;Untitled Document&lt;/title&gt;
		&lt;%= javascript_include_tag 'jquery-1.3.2.min' %&gt;
		&lt;%= stylesheet_link_tag 'reset' %&gt;

	&lt;/head&gt;
	&lt;body&gt;
      &lt;div class=&quot;container&quot;&gt;
        &lt;div id=&quot;header&quot;&gt;&lt;h1&gt;Welcome to ACME&lt;/h1&gt;&lt;/div&gt;
        &lt;div id=&quot;main&quot;&gt;
          &lt;%= yield %&gt;
        &lt;/div&gt;
      &lt;/div&gt;
	&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>So, on inside our HTML body tag we have a div tag with a "container" class. This "container" class will be used to center and fix the width of our content.</p>
<p>This is what goes inside the layout stylesheet, under public/stylesheets/layout.css:</p>
<pre class="brush: css;">
.container {
  width: 950px;
  margin: 0 auto;
}
</pre>
<p>So, we are setting the width of content area of our website and centering it.</p>
<p>A lot more could be done here, like styling the <em>header</em> div. This also should be done on the layout stylesheet.</p>
<p>The main idea here is: <strong>use the layout stylesheet to only style markup on the layout template. Don't style more than that here</strong>.</p>
<h3>Local styling</h3>
<p>Now we want to style our templates and partials individually. That's where styled_objects comes in.</p>
<p>This plugin allows you to define the styles per template or partial wiathout adding any code.</p>
<p>First we need to call this helper on the <em>app/views/layouts/application.html.erb</em> file:</p>
<pre class="brush: ruby;">&lt;%= so_stylesheet_link_tag %&gt;</pre>
<p>Place it right before the &lt;/head&gt; tag. This helper creates the link tag to the URL for the "glued" stylesheet of each page.</p>
<p>We now begin with the product show page.</p>
<p>Create app/views/products/show.css and edit it.</p>
<p>We want to style the title and the description:</p>
<pre class="brush: css;">background-color: #e0e0e0;
h1 {color: #f576d8; border-bottom: 1px solid #822321};
p {padding: 1em 0; background-color: #fff;, border-top: 1px solid #d6d6d6}
</pre>
<p>On the first line we see something that isn't pure CSS: the background color style declared on the root of the CSS document. That's there because we are styling the <em>show.html.erb</em> template, not any sub node.</p>
<p>Now we want to style the product category page.</p>
<p>Create <em>app/views/categories/show.css</em>:</p>
<pre class="brush: css;">
border-top: 5px solid black;
background-color: #f7f7f7;
h1 {letter-spacing: -2px; color: #3e3e3e}
</pre>
<p>Here we're giving the category show template a top border (line 1), a background-color (line 2) and we're also styling the title on line 3.</p>
<p>This category show template also shows the products and for that it uses the <em>products/_product.html.erb</em> partial.</p>
<p>We also wish to style this partial. Create the file <em>app/views/products/_product.css</em>:</p>
<pre class="brush: css;">background-color: #999;
border: 1px solid #333;
float: left;
h2 {text-transform: uppercase}
</pre>
<h3>AJAX loading</h3>
<p>So, styled_objects collects the needed CSS fragments on each page and constructs one URL that references all the "glued" CSSes.</p>
<p>What if I want to have a shopping basket partial that is called by AJAX instead of normal partial rendering inside a template?</p>
<p>Simple: just add &lt;%= so_include_partial(partial_path) %&gt; (or &lt;%= so_include_template(template_path) %&gt; if it's a template) to anywhere on the calling template. The partial CSS will be included.</p>
<p>Next: <a href="http://www.metaduck.com/2009/10/tutorial-advanced-styled-objects-on-rails/">See the Advanced styled_objects on Rails Tutorial</a></p>
<h2>More</h2>
<p>Read more about object-oriented CSS here:</p>
<ul>
<li><a href="http://wiki.github.com/stubbornella/oocss">Object-oriented CSS by stubbornella</a></li>
</ul>
<p>See the presentation video:</p>
<ul>
<li><a href="http://www.stubbornella.org/content/2009/03/23/object-oriented-css-video-on-ydn/">Object-oriented CSS by stubbornella</a></li>
</ul>
<h2>Other resources</h2>
<ul>
<li><a href="http://lesscss.org/docs.html">LESS syntax</a></li>
<li><a href="http://wiki.github.com/pgte/styled_objects">styled_objects Rails plugin</a></li>
<li><a href="http://www.blueprintcss.org/">blueprint CSS framework</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.metaduck.com/2009/10/tutorial-building-and-styling-a-rails-app-with-styled-objects/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>styled_objects Rails plugin</title>
		<link>http://www.metaduck.com/2009/10/styled_objects-rails-plugin/</link>
		<comments>http://www.metaduck.com/2009/10/styled_objects-rails-plugin/#comments</comments>
		<pubDate>Sat, 10 Oct 2009 13:38:13 +0000</pubDate>
		<dc:creator>Pedro Teixeira</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.metaduck.com/?p=84</guid>
		<description><![CDATA[Yesterday I released the styled_objects Rails plugin.
styled_objects is a Rails plugin for simplifying stylesheet management on your application.
Instead of having one or more large stylesheets on your public folder, have many. Keep your CSS close to their respective templates. styled_objects will compile them into one file per page.
Why do I need styled_objects?
Because It’s hard to [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I released the styled_objects Rails plugin.</p>
<p><strong>styled_objects</strong> is a Rails plugin for simplifying stylesheet management on your application.</p>
<p><span id="more-84"></span>Instead of having one or more large stylesheets on your public folder, have many. Keep your <span>CSS</span> close to their respective templates. <strong>styled_objects</strong> will compile them into one file per page.</p>
<h2>Why do I need <strong>styled_objects</strong>?</h2>
<p>Because It’s hard to keep order on your application. Having one or many big stylesheet files is not easy. It’s hard do build, maintain and debug.</p>
<p>Do object-oriented stylesheets. Each presentation object has its own style definitions. With styled_objects everything is where expected.</p>
<p>You also make your stylesheets independent from each other, making it easier to find problems extend your app.</p>
<p><a href="http://www.slideshare.net/stubbornella/object-oriented-css">» Check out this presentation for a full pitch on <span>OOCSS</span> (Object-Oriented <span>CSS</span>).</a></p>
<p><a href="Check out http://wiki.github.com/pgte/styled_objects">Check out http://wiki.github.com/pgte/styled_objects</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.metaduck.com/2009/10/styled_objects-rails-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
