<?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>Underneath the already known &#187; erb</title>
	<atom:link href="http://vaskas.ru/tag/erb/feed/" rel="self" type="application/rss+xml" />
	<link>http://vaskas.ru</link>
	<description>What Vaskas thinks</description>
	<lastBuildDate>Mon, 13 Jul 2009 19:38:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using ERB for massive static pages compilation</title>
		<link>http://vaskas.ru/2008/08/05/using-erb-for-massive-static-pages-compilation/</link>
		<comments>http://vaskas.ru/2008/08/05/using-erb-for-massive-static-pages-compilation/#comments</comments>
		<pubDate>Tue, 05 Aug 2008 10:44:34 +0000</pubDate>
		<dc:creator>vaskas</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[erb]]></category>
		<category><![CDATA[inshaker]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://vaskas.ru/?p=13</guid>
		<description><![CDATA[For Inshaker, we needed a templating mechanism for pages sharing the same design. We also wanted the pages to be static (for performance reasons). We did not need them to be generated on-the-fly.
ERB was an ideal option for such a purpose. It allows us to generate all (75+) static pages when we need to make [...]]]></description>
			<content:encoded><![CDATA[<p>For <a href="http://www.inshaker.ru">Inshaker</a>, we needed a templating mechanism for pages sharing the same design. We also wanted the pages to be static (for performance reasons). We did not need them to be generated on-the-fly.<br />
ERB was an ideal option for such a purpose. It allows us to generate all (75+) static pages when we need to make an update.<br />
It is also very simple in terms of use:</p>
<p>1. You create a template for your page (template.rhtml)</p>
<pre><code class="html">
&lt;html&gt;
&lt;head&gt;
	&lt;title&gt;&lt;%= @title %&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
	This page was generated by &lt;%= @name %&gt; on &lt;%= Time.now.to_s %&gt;.
	&lt;ul&gt;
	&lt;% @tags.each do |tag| %&gt;
	&lt;li&gt;&lt;%= tag %&gt;&lt;/li&gt;
	&lt;% end %&gt;
	&lt;/ul&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
<p>2. You create a ruby class which is bound to the template and run erb (erb_test.rb)</p>
<pre><code class="ruby">
require 'rubygems'
require 'erb'

class MyPage
  def initialize(hash)
    @title = hash[:title] + " - that's what I mean"
    @name = hash[:name]
    @tags = hash[:tags]
  end

  def get_binding
    binding
  end
end

# Instantiate ERB with the instance of that class and flush the output
template = File.open("template.rhtml").read
renderer = ERB.new(template)
page     = MyPage.new({:title => "ERB rules",
                       :name => "Ninja",
                       :tags => ["ruby", "erb", "html", "example"]})

File.open("mypage.html", "w+") { |html|
    html.write renderer.result(page.get_binding)
}
</code></pre>
<p>Of course, this is just a basic usage example. ERB shows its power when there are A LOT of pages to be generated, not a single one <img src='http://vaskas.ru/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /><br />
I should have a closer look at SproutCore since they seem to be using the same principle for views compilation.</p>
]]></content:encoded>
			<wfw:commentRss>http://vaskas.ru/2008/08/05/using-erb-for-massive-static-pages-compilation/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
