M
makoto kuwata
Hi all,
I have released Tenjin 0.6.1.
http://www.kuwata-lab.com/tenjin/
changes:
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
----------
<html>
<body>
<table>
<?rb for item in @items ?>
<tr>
<td>#{item}</td>
<td>${item}</td>
</tr>
<?rb end ?>
</table>
</body>
</html>
----------
ex. convert into Ruby script
==========
$ rbtenjin -s example.rbhtml
_buf = ''; _buf << %Q`<html>
<body>
<table>\n`
for item in @items
_buf << %Q` <tr>
<td>#{item}</td>
<td>#{escape((item).to_s)}</td>
</tr>\n`
end
_buf << %Q` </table>
</body>
</html>\n`
_buf.to_s
==========
ex. execute converted Ruby script
==========
$ rbtenjin -c '@items=%w[<AAA> B&B "CCC"]' example.rbhtml
<html>
<body>
<table>
<tr>
<td><AAA></td>
<td><AAA></td>
</tr>
<tr>
<td>B&B</td>
<td>B&B</td>
</tr>
<tr>
<td>"CCC"</td>
<td>"CCC"</td>
</tr>
</table>
</body>
</html>
==========
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
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
ex.
require 'tenjin'
class MyClass
include Tenjin::ContextHelper
#include Tenjin::HtmlHelper # optional
## define helper functions in current class
def link_to(label, url)
return "<a href=\"#{escape(url)}\">#{escape(label)}</a>"
end
def render_template(template_name)
engine = Tenjin::Engine.new()
## pass self as context object
output = engine.render(template_name, self)
return output
end
def main
## set context data as instance variables
@label = 'Top'
@url = '/'
output = render_template('example.rbhtml')
print output
end
end
MyClass.new.main()
I have released Tenjin 0.6.1.
http://www.kuwata-lab.com/tenjin/
changes:
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
----------
<html>
<body>
<table>
<?rb for item in @items ?>
<tr>
<td>#{item}</td>
<td>${item}</td>
</tr>
<?rb end ?>
</table>
</body>
</html>
----------
ex. convert into Ruby script
==========
$ rbtenjin -s example.rbhtml
_buf = ''; _buf << %Q`<html>
<body>
<table>\n`
for item in @items
_buf << %Q` <tr>
<td>#{item}</td>
<td>#{escape((item).to_s)}</td>
</tr>\n`
end
_buf << %Q` </table>
</body>
</html>\n`
_buf.to_s
==========
ex. execute converted Ruby script
==========
$ rbtenjin -c '@items=%w[<AAA> B&B "CCC"]' example.rbhtml
<html>
<body>
<table>
<tr>
<td><AAA></td>
<td><AAA></td>
</tr>
<tr>
<td>B&B</td>
<td>B&B</td>
</tr>
<tr>
<td>"CCC"</td>
<td>"CCC"</td>
</tr>
</table>
</body>
</html>
==========
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
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
ex.
require 'tenjin'
class MyClass
include Tenjin::ContextHelper
#include Tenjin::HtmlHelper # optional
## define helper functions in current class
def link_to(label, url)
return "<a href=\"#{escape(url)}\">#{escape(label)}</a>"
end
def render_template(template_name)
engine = Tenjin::Engine.new()
## pass self as context object
output = engine.render(template_name, self)
return output
end
def main
## set context data as instance variables
@label = 'Top'
@url = '/'
output = render_template('example.rbhtml')
print output
end
end
MyClass.new.main()