<?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>Sarah Taraporewalla's Technical Ramblings &#187; Open source projects</title>
	<atom:link href="http://sarahtaraporewalla.com/thoughts/category/open-source-projects/feed/" rel="self" type="application/rss+xml" />
	<link>http://sarahtaraporewalla.com/thoughts</link>
	<description></description>
	<lastBuildDate>Sun, 31 Jan 2010 22:03:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Slippers: How to click your heels</title>
		<link>http://sarahtaraporewalla.com/thoughts/open-source-projects/slippers-how-to-click-your-heels/</link>
		<comments>http://sarahtaraporewalla.com/thoughts/open-source-projects/slippers-how-to-click-your-heels/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 07:13:28 +0000</pubDate>
		<dc:creator>Sarah</dc:creator>
				<category><![CDATA[Open source projects]]></category>

		<guid isPermaLink="false">http://sarahtaraporewalla.com/thoughts/?p=260</guid>
		<description><![CDATA[In my last post about Slippers, I introduced it&#8217;s philosophy and the places that you could find it. In this post, I will introduce some of its constructs.
Rendering template of a string without any holes

template = &#34;This is a string without any holes in it&#34;
engine = Slippers::Engine.new(template)
engine.render #=&#62; &#34;This is a string without any holes [...]]]></description>
			<content:encoded><![CDATA[<p>In my l<a href="http://sarahtaraporewalla.com/thoughts/open-source-projects/slippers-introduction/">ast post</a> about <a href="http://slippersrb.com">Slippers</a>, I introduced it&#8217;s philosophy and the places that you could find it. In this post, I will introduce some of its constructs.</p>
<p>Rendering template of a string without any holes</p>
<pre class="brush: ruby;">
template = &quot;This is a string without any holes in it&quot;
engine = Slippers::Engine.new(template)
engine.render #=&gt; &quot;This is a string without any holes in it&quot;
</pre>
<p>Filling in a hole within a template</p>
<pre class="brush: ruby;">
template = &quot;This is a string with a message of $message$&quot;
engine = Slippers::Engine.new(template)
engine.render(:message =&gt; &quot;hello world&quot;) #=&gt; &quot;This is a string with a message of hello world&quot;
</pre>
<p>Rendering a subtemplate within a template</p>
<pre class="brush: ruby;">
subtemplate = Slippers::Template.new(&quot;this is a subtemplate&quot;)
template_group = Slippers::TemplateGroup.new(:templates =&gt; {:message =&gt; subtemplate})
template = &quot;This is a template and then $message()$&quot;
engine = Slippers::Engine.new(template, :template_group =&gt; template_group)
engine.render #=&gt; &quot;This is a template and then this is a subtemplate&quot;
</pre>
<p>Applying an object to a subtemplate</p>
<pre class="brush: ruby;">
subtemplate = Slippers::Template.new(&quot;this is a subtemplate with a message of $saying$&quot;)
template_group = Slippers::TemplateGroup.new(:templates =&gt; {:message_subtemplate =&gt; subtemplate})
template = &quot;This is a template and then $message:message_subtemplate()$!&quot;
engine = Slippers::Engine.new(template, :template_group =&gt; template_group)
engine.render(:message =&gt; {:saying =&gt; 'hello world'}) #=&gt; &quot;This is a template and then this is a subtemplate with a message of hello world!&quot;
</pre>
<p>Applying an object to an anonymous subtemplate</p>
<pre class="brush: ruby;">
template = &quot;This is a template and then $message:{this is a subtemplate with a message of $saying$}$!&quot;
engine = Slippers::Engine.new(template)
engine.render(:message =&gt; {:saying =&gt; 'hello world'}) #=&gt; &quot;This is a template and then this is a subtemplate with a message of hello world!&quot;
</pre>
<p>Render a subtemplate using a different rendering technology</p>
<pre class="brush: ruby;">
age_renderer = AgeRenderer.new
subtemplate = Slippers::Engine.new('$first$ $last$')
person = OpenStruct.new({:name =&gt; {:first =&gt; 'Fred', :last =&gt; 'Flinstone'}, :dob =&gt; Date.new(DateTime.now.year - 34, 2, 4)})
template_group = Slippers::TemplateGroup.new(:templates =&gt; {:name =&gt; subtemplate, :age =&gt; age_renderer})
engine = Slippers::Engine.new(&quot;Introducing $name:name()$ who is $dob:age()$.&quot;, :template_group =&gt; template_group)
engine.render(person) #=&gt; &quot;Introducing Fred Flinstone who is 34 years old.&quot;
</pre>
<p>Select a renderer based on the type of the object to render</p>
<pre class="brush: ruby;">
person = OpenStruct.new({:name =&gt; {:first =&gt; 'Fred', :last =&gt; 'Flinstone'}, :dob =&gt; Date.new(DateTime.now.year-34, 2, 4)})
template_group = Slippers::TemplateGroup.new(:templates =&gt; {:name =&gt; Slippers::Engine.new('$first$ $last$'), Date =&gt; AgeRenderer.new})
engine = Slippers::Engine.new(&quot;Introducing $name:name()$ who is $dob$.&quot;, :template_group =&gt; template_group)
engine.render(person) #=&gt; &quot;Introducing Fred Flinstone who is 34 years old.&quot;
</pre>
<p>Use the specified expression options to render list items</p>
<pre class="brush: ruby;">
template = 'This is a list of values $values; null=&quot;-1&quot;, seperator=&quot;, &quot;$'
engine = Slippers::Engine.new(template)
engine.render(:values =&gt; [1,2,3,nil]) #=&gt; &quot;This is a list of values 1, 2, 3, -1&quot;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://sarahtaraporewalla.com/thoughts/open-source-projects/slippers-how-to-click-your-heels/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Slippers: Introduction</title>
		<link>http://sarahtaraporewalla.com/thoughts/open-source-projects/slippers-introduction/</link>
		<comments>http://sarahtaraporewalla.com/thoughts/open-source-projects/slippers-introduction/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 07:14:11 +0000</pubDate>
		<dc:creator>Sarah</dc:creator>
				<category><![CDATA[Open source projects]]></category>

		<guid isPermaLink="false">http://sarahtaraporewalla.com/thoughts/?p=246</guid>
		<description><![CDATA[There are many template engines that you can choose for the generation of views in your mvc application. The problem with most of the them, however, is that they are too permissive. These turing-complete engines allow for many complex constructs within the template, which begin at simple if statements and for loops, and expand to [...]]]></description>
			<content:encoded><![CDATA[<p>There are many template engines that you can choose for the generation of views in your mvc application. The problem with most of the them, however, is that they are too permissive. These turing-complete engines allow for many complex constructs within the template, which begin at simple if statements and for loops, and expand to complex object traversal. While these permissive languages are intended to offer great flexibility, in reality they promote bad practices. Allowing logic to permeate your view is bad for many reasons: firstly, the code in views is rarely tested; secondly, the separation between the models and the view blurs and business logic creeps into the view.</p>
<p>All we want our template engine to do is read a string which has holes in it, and replace those holes with the desired string, much like mail merge. Luckily for me, there is already a templating engine which enforces strict separation of model and view by only supporting these strings with holes &#8211; String Template. <a href="http://www.stringtemplate.org">String Template</a> is originally created in Java, however there has been subsequent ports to C# and python. It is <a href="http://www.stringtemplate.org/about.html">opinionated</a>, and I like it&#8217;s opinions. (And if you prefer permissive views, I would recommend you reading about the origins of String Template before completely ruling it out.)</p>
<p>Unfortunately, when I started to try out <a href="http://www.ramaze.net">Ramaze</a> (a great web framework for ruby &#8211; much better than rails imho) I looked around for a port of String Template to ruby, but couldn&#8217;t find out. So, I decided that if no-one else would port it, I would&#8230;and so <a href="http://slippersrb.com">Slippers</a> was born.</p>
<p><a href="http://slippersrb.com">Slippers</a> is  a strict template engine for ruby, supporting the syntax from String Template including anonymous template, named templates and template group directories but also goes beyond this to allow you to use your own renderers. Nearly all the useful constructs from String Template have been ported, and you can see the comparison on the <a href="http://starapor.github.com/slippers/slippers_vs_string_template.html">Slippers vs String Template</a> page.</p>
<p>In creating Slippers, I have been surprised to find how many development tools for ruby can now be found &#8220;in the cloud&#8221; (ie on the web):</p>
<ul>
<li>Slippers code repository is hosted on <a href="http://github.com/starapor/slippers">github</a>.</li>
<li>Slippers has been test-driven, and I have a CI build at <a href="http://runcoderun.com/starapor/slippers">runcoderun.com</a>. As you can see, I have also made it Ruby 1.9 compatible.</li>
<li>The gem can be found on <a href="http://gemcutter.org/">gemcutter</a>. To install:
<pre class="brush: ruby;">
# Run the following if you haven't done so before:
$ gem sources -a http://gemcutter.org
# Install the gem:
$ sudo gem install slippers
</pre>
</li>
</ul>
<p>Ramaze now supports Slippers as a view engine, as of gem <a href="http://gemcutter.org/gems/ramaze">version 2009.10</a> (also on gemcutter).</p>
<p>More information about Slippers can be found at <a href="http://slippersrb.com">http://slippersrb.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://sarahtaraporewalla.com/thoughts/open-source-projects/slippers-introduction/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
