# Non-invasive templating solutions in ruby?

**URL:** <https://www.ruby-forum.com/t/non-invasive-templating-solutions-in-ruby/158677>\
**Category:** Ruby\
**Created:** [January 26, 2009, 7:05pm UTC](https://www.ruby-forum.com/t/non-invasive-templating-solutions-in-ruby/158677 "2009-01-26T19:05:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Terrence\_Brannon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ecc23a/32.png) [@Terrence\_Brannon](https://www.ruby-forum.com/u/Terrence_Brannon)\
**Post date:** [January 26, 2009, 7:05pm UTC](https://www.ruby-forum.com/t/non-invasive-templating-solutions-in-ruby/158677/1 "2009-01-26T19:05:24Z")

</div>

hello, I am a perl and python programmer, but for completeness, I  
would like to know which dynamic html generation systems exist in Ruby  
which focus on driving HTML generation outside of the HTML itself.

In an ‘invasive’ system, you would see presentation logic directly in  
the HTML, for example:

[% IF age \< 10 %]  
Hello [% name %], does your mother know you’re  
using her AOL account?  
[% ELSIF age \< 18 %]  
Sorry, you’re not old enough to enter  
(and too dumb to lie about your age)  
[% ELSE %]  
Welcome [% name %].  
[% END %]

whereas in a ‘non-invasive’ system there would only be HTML with id or  
class tags

  Hello, does your mother know you're using her AOL account? Sorry, you're not old enough to enter (and too dumb to lie about your age) Welcome  

and then you would simply remove the parts of the HTML based on age:

$age-\>retain(‘under10’) if $age \< 10;

My list of non-invasive (aka push-style) templating systems is  
maintained here  
[http://perlmonks.org/?node\_id=674225](http://perlmonks.org/?node_id=674225)

Thanks for your feedback,  
terrence

---

<div class="post-metadata">

**Author:** ![Terrence\_Brannon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ecc23a/32.png) [@Terrence\_Brannon](https://www.ruby-forum.com/u/Terrence_Brannon)\
**Post date:** [January 26, 2009, 9:10pm UTC](https://www.ruby-forum.com/t/non-invasive-templating-solutions-in-ruby/158677/2 "2009-01-26T21:10:34Z")

</div>

Terrence Brannon wrote:

> hello, I am a perl and python programmer,

Hello, I’m a programmer!

> but for completeness, I  
> would like to know which dynamic html generation systems exist in Ruby  
> which focus on driving HTML generation outside of the HTML itself.

> [% ELSE %]  
> Welcome [% name %].  
> [% END %]

Everyone uses eRB there. Except those who use HAML, or certain other  
systems,  
such as Builder::XmlMarkup.

> whereas in a ‘non-invasive’ system there would only be HTML with id or  
> class tags

Look up ‘lilu templates’. They hook into your Rails views, and use  
Hpricot’s CSS  
selectors to search and replace HTML details before they go out.

> $age-\>retain(‘under10’) if $age \< 10;

Exactly - some similar detail in an ‘instruction’ file.

---

<div class="post-metadata">

**Author:** ![Terrence\_Brannon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ecc23a/32.png) [@Terrence\_Brannon](https://www.ruby-forum.com/u/Terrence_Brannon)\
**Post date:** [January 26, 2009, 9:30pm UTC](https://www.ruby-forum.com/t/non-invasive-templating-solutions-in-ruby/158677/3 "2009-01-26T21:30:32Z")

</div>

On Jan 26, 3:06 pm, Phlip [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Look up ‘lilu templates’. They hook into your Rails views, and use Hpricot’s CSS  
> selectors to search and replace HTML details before they go out.
> 
> > $age-\>retain(‘under10’) if $age \< 10;

yes their mailing list seems dead -  
[http://groups.google.com/group/lilu-templates](http://groups.google.com/group/lilu-templates)

but I found kwartz and amrita, so I added those.

Thanks.

---

<div class="post-metadata">

**Author:** ![Terrence\_Brannon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ecc23a/32.png) [@Terrence\_Brannon](https://www.ruby-forum.com/u/Terrence_Brannon)\
**Post date:** [January 26, 2009, 10:00pm UTC](https://www.ruby-forum.com/t/non-invasive-templating-solutions-in-ruby/158677/4 "2009-01-26T22:00:23Z")

</div>

Terrence Brannon wrote:

> whereas in a ‘non-invasive’ system there would only be HTML with id or  
> class tags
> 
> Hello, does your mother know you're using her AOL account? Sorry, you're not old enough to enter (and too dumb to lie about your age) Welcome  
> 
> and then you would simply remove the parts of the HTML based on age:
> 
> $age-\>retain(‘under10’) if $age \< 10;

Amrita works like that. I haven’t used it for a long time, and it  
doesn’t appear to have been updated since 2003, but it worked fine then  
🙂

Another option is to do the template insertion client-side in  
Javascript. For example, Rails Javascript helpers can write the  
Javascript for you dynamically and send it straight to the client:

render :update do |page|  
page.remove\_html ‘under18’  
page.remove\_html ‘welcome’  
end

(It uses Prototype by default, but by installing jRails then the same  
Ruby code will generate jQuery javascript instead)

The attraction of this approach is that Ajax updates work the same way,  
and it’s a stepping-stone towards making a richer Javascript interface  
if you want to go that way.

---

<div class="post-metadata">

**Author:** ![Terrence\_Brannon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ecc23a/32.png) [@Terrence\_Brannon](https://www.ruby-forum.com/u/Terrence_Brannon)\
**Post date:** [January 26, 2009, 9:31pm UTC](https://www.ruby-forum.com/t/non-invasive-templating-solutions-in-ruby/158677/5 "2009-01-26T21:31:44Z")

</div>

On Jan 26, 3:06 pm, Phlip [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Look up ‘lilu templates’.

This was a good review of ruby templates -  
[http://www.hokstad.com/mini-reviews-of-19-ruby-template-engines.html](http://www.hokstad.com/mini-reviews-of-19-ruby-template-engines.html)
