# Tenjin 0.6.1 - a fast and full-featured template engine

**URL:** <https://www.ruby-forum.com/t/tenjin-0-6-1-a-fast-and-full-featured-template-engine/128411>\
**Category:** Ruby\
**Created:** [February 7, 2008, 2:00pm UTC](https://www.ruby-forum.com/t/tenjin-0-6-1-a-fast-and-full-featured-template-engine/128411 "2008-02-07T14:00:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![makoto\_kuwata](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a4c791/32.png) [@makoto\_kuwata](https://www.ruby-forum.com/u/makoto_kuwata)\
**Post date:** [February 7, 2008, 2:00pm UTC](https://www.ruby-forum.com/t/tenjin-0-6-1-a-fast-and-full-featured-template-engine/128411/1 "2008-02-07T14:00:31Z")

</div>

Hi all,

I have released Tenjin 0.6.1.  
[http://www.kuwata-lab.com/tenjin/](http://www.kuwata-lab.com/tenjin/)  
changes:  
[http://www.kuwata-lab.com/tenjin/rbtenjin-CHANGES.txt](http://www.kuwata-lab.com/tenjin/rbtenjin-CHANGES.txt)

Tenjin is a fast and full-featured template engine similar to eRuby  
but it has the following advantages against to eRuby and ERB.

- Very fast (twice faster than eruby and three times faster than  
ERB)
- Lightweight (only one file which contains about 1000 lines)
- Not break HTML design because it uses XML Processing  
Instructions (PI) as embedded notation for Python statements.
- Secure because it supports escaping expression value by default.
- Auto caching of converted Python code.
- Nestable layout template
- Inlucde other templates
- Capture part of template
- Load YAML file as context data
- Preprocessing support

Notation of Tenjin is different from eRuby.

- ‘\<?rb ... ?\>’ represents Ruby statements.
- ‘#{…}’ represents Ruby expression.
- ‘${…}’ represents Ruby expression with escaping (sanitizing).

## ex. example.rbhtml
 \<?rb for item in @items ?\> \<?rb end ?\> 

| #{item} | ${item} |

 ----------
# ex. convert into Ruby script

$ rbtenjin -s example.rbhtml  
\_buf = ‘’; \_buf \<\< %Q`

 \n` for item in @items _buf \<\< %Q` \n` end _buf \<\< %Q` 

| #{item} | #{escape((item).to\_s)} |

 \n` \_buf.to\_s ==========
# ex. execute converted Ruby script

$ rbtenjin -c ‘@items=%w[B&B “CCC”]’ example.rbhtml

| | \<AAA\> |
| B&B | B&B |
| "CCC" | "CCC" |

 ==========

Tenjin is more suitable for web applications than eRuby,  
because it doesn’t break HTML desing of template and  
supports partial template and layout temlate.  
See Tenjin User’s Guide for details.  
[http://www.kuwata-lab.com/tenjin/rbtenjin-users-guide.html](http://www.kuwata-lab.com/tenjin/rbtenjin-users-guide.html)

Enhancements from 0.6.0:

- It is able to make any class which includes  
Tenjin::ContextHelper module as context object class.  
This is useful if you want to define helper functions  
as instance method of that class.  
See section ‘Add Your Helper Functions’ for details.  
[http://www.kuwata-lab.com/tenjin/rbtenjin-users-guide.html#dev-helpers](http://www.kuwata-lab.com/tenjin/rbtenjin-users-guide.html#dev-helpers)

---

<div class="post-metadata">

**Author:** ![makoto\_kuwata](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a4c791/32.png) [@makoto\_kuwata](https://www.ruby-forum.com/u/makoto_kuwata)\
**Post date:** [February 9, 2008, 12:04am UTC](https://www.ruby-forum.com/t/tenjin-0-6-1-a-fast-and-full-featured-template-engine/128411/2 "2008-02-09T00:04:34Z")

</div>

makoto kuwata wrote:

> Hi all,
> 
> I have released Tenjin 0.6.1.  
> [http://www.kuwata-lab.com/tenjin/](http://www.kuwata-lab.com/tenjin/)  
> changes:  
> [http://www.kuwata-lab.com/tenjin/rbtenjin-CHANGES.txt](http://www.kuwata-lab.com/tenjin/rbtenjin-CHANGES.txt)
> 
> Tenjin is a fast and full-featured template engine similar to eRuby  
> but it has the following advantages against to eRuby and ERB.

Thanks for your great work on template engines!

> - Very fast (twice faster than eruby and three times faster than  
> ERB)
> - Lightweight (only one file which contains about 1000 lines)
> - Not break HTML design because it uses XML Processing  
> Instructions (PI) as embedded notation for Python statements.
> - Secure because it supports escaping expression value by default.
> - Auto caching of converted Python code.  
> ^^^^^^  
> Python? 😉

Regards,

Michael

---

<div class="post-metadata">

**Author:** ![makoto\_kuwata](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a4c791/32.png) [@makoto\_kuwata](https://www.ruby-forum.com/u/makoto_kuwata)\
**Post date:** [February 9, 2008, 1:38am UTC](https://www.ruby-forum.com/t/tenjin-0-6-1-a-fast-and-full-featured-template-engine/128411/3 "2008-02-09T01:38:24Z")

</div>

- Michael N., 2008-02-09, 08:03:

> > - Auto caching of converted Python code.  
> > ^^^^^^  
> > Python? 😉

Tenjin comes in different flavours including a Python one.

Josef ‘Jupp’ Schugt

---

<div class="post-metadata">

**Author:** ![makoto\_kuwata](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a4c791/32.png) [@makoto\_kuwata](https://www.ruby-forum.com/u/makoto_kuwata)\
**Post date:** [February 9, 2008, 11:50am UTC](https://www.ruby-forum.com/t/tenjin-0-6-1-a-fast-and-full-featured-template-engine/128411/4 "2008-02-09T11:50:30Z")

</div>

This looks really great !

I have written a pre-processor language for the templates in zena (a  
CMS) called zafu. It would be really easy to generate tenjin code  
instead of erb.

By looking at the code, I don’t understand where the performance boost  
comes from. At the end, we have a ruby method, just like with erb, no  
?

Could explain why tenjin is faster ?

Is it during compilation ?

Or during execution (which means a compilation that generates faster  
ruby code) ?

Thanks for your answer.

Gaspard

2008/2/9, Michael N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![makoto\_kuwata](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a4c791/32.png) [@makoto\_kuwata](https://www.ruby-forum.com/u/makoto_kuwata)\
**Post date:** [February 9, 2008, 1:07pm UTC](https://www.ruby-forum.com/t/tenjin-0-6-1-a-fast-and-full-featured-template-engine/128411/5 "2008-02-09T13:07:58Z")

</div>

Josef ‘Jupp’ Schugt wrote:

> - Michael N., 2008-02-09, 08:03:
> 
> > > - Auto caching of converted Python code.  
> > > ^^^^^^  
> > > Python? 😉
> 
> Tenjin comes in different flavours including a Python one.

Cool! So I guess auto caching for Ruby was already implemented since the  
beginning…

Regards,

Michael
