leah blogs

September 2004

13sep2004 · Tangerine

Since there are more Ruby packages for templating than there are real users of them (:-P), I’ve decided it can’t hurt to make one myself.

It’s called Tangerine, and is the first library I’ve developed using TDD. (Thanks, dragonkh :-)).

Of course it’s hard to design (and not only implement) something new, therefore I did two spikes before, dubbed AllOfMyLove which was a 20 lines gsub for experimentation, and DeepBlueTea, a lot longer code that used a “real” parser (as needed for nested parentheses). (I guess I’m a grand-master in inventing silly project names :-P).

Tangerine finally implements a compiler which creates a Proc out of the template for good performance. In benchmarks I did myself (never trust a benchmark…), Tangerine turned out to be 2 times faster than a comparable ERB template. (ERB evals all the time.)

Finally, I’ll show a short sample to show how it feels like:

<h1>,,title</h1>
<h2>,,tagline</h2>
<p>,,(Time.now)</p>

,,# overview
<ul id="toc">
,,entries{
  [<li>,,(title.upcase)</li>]
}
</ul>

,,entries{
<h3>,,title</h3>
  ,,recent?{<em>[New]</em>}
  <p>,,body</p>
<hr />

}

<p>,,title -- ,,tagline. ,,(Time.now.strftime("%d%b%Y").downcase)</p>

This is a very primitive template for a simple weblog, and will result in something like this:

<h1>chris blogs</h1>
<h2>a blog by christian neukirchen</h2>
<p>Mon Sep 13 19:29:04 CEST 2004</p>

<ul id="toc">
  [<li>HEAD</li>]
  [<li>ANOTHER</li>]
</ul>

<h3>head</h3>
  <em>[New]</em>
  <p>some &lt;content&gt;</p>
<hr />
<h3>another</h3>

  <p>again</p>
<hr />

<p>chris blogs -- a blog by christian neukirchen. 13sep2004</p>

A few issues still need to be handled better, I’ll do a release soon.

Name für eine jüdische Kneipe: Bar Mitzwah.

Zustand des Religionsbuches bei Erhalt: lächerlich. :-)

NP: Led Zeppelin—Tangerine

Copyright © 2004–2022