I released Tenjin 0.7.0 for Ruby.
http://www.kuwata-lab.com/tenjin/
Users guide:
http://www.kuwata-lab.com/tenjin/rbtenin-users-guide.html
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.
In this release, a lot of features are added.
* Ruby 1.9 support
* Fragment cache
* Safe Template
* New html tag helpers
* M17N support
* and so on...
See http://www.kuwata-lab.com/tenjin/rbtenjin-CHANGES.txt for details.
* [enhance] Support Ruby 1.9.
* [enhance] Add 'HtmlHelper#escape_html()' which escapes '\'' into
'''.
* [change] Change 'HtmlHelper#escape()' to be alias of
'#escape_html()', not '#escape_xml()'
* [change] '${}' is changed to escape "'" into '''.
* [enhance] Fragment cache support
## fragment cache with key ('items/1') and lifetime (60sec)
<?rb cache_with('items/1', 60) do ?>
<ul>
<?rb for item in @get_items.call() ?>
<li>${item}</li>
<?rb end ?>
</ul>
<?rb end ?>
## use file-base cache store
Dir.mkdir('cache.d') unless File.exist?('cache.d')
kv_store = Tenjin::FileBaseStore.new('cache.d')
Tenjin::Engine.data_cache = kv_store
See: http://www.kuwata-lab.com/tenjin/rbtenjin-users-guide.html#fragment-cache
* [enhance] (EXPERIMENTAL) Add 'SafeTemplate' and 'SafeEngine' classes
which escapes HTML characters automatically.
* SafeTemplate and SafeEngine escapes context data except SafeString
object.
* Using these classes, only '${...}' is available. '#{...}' is
inhibited.
##
include Tenjin::HtmlHelper
include Tenjin::SafeHelper
context = {
:text1=>"<AAA>", # will be escaped
:text2=>safe_str("<AAA>"), # not escaped because marked as
'already escaped'
}
engine = Template::SafeEngine.new()
html = engine.render('example.rbhtml', context)
## example.rbhtml:
#<p>text1 = ${@text1}<p>
#<p>text2 = ${@text2}<p>
## Output:
#<p>text1 = <AAA></p>
#<p>text2 = <AAA></p>
See: http://www.kuwata-lab.com/tenjin/rbtenjin-users-guide.html#auto-escaping
* [enhance] Add new option ':lang' to 'Template.new()'
which will be helpful to create M17N page.
This feature should be used with preprocessing.
## creates 'example.rbhtml.en.cache' file
lang = "en"
engine = Tenjin::Engine.new(:preprocess=>true, :lang=>lang)
engine.render("example.rbhtml", {})
## creates 'example.rbhtml.fr.cache' file
lang = "fr"
engine = Tenjin::Engine.new(:preprocess=>true, :lang=>lang)
engine.render("example.rbhtml", {})
See: http://www.kuwata-lab.com/tenjin/rbtenjin-users-guide.html#m17n
* [enhance] 'Template' class now supports ':trace' option which prints
template filename as HTML comment when importing other template file.
## print '<!-- **** begin: partial.rhtml **** -->'
## and '<!-- **** end: partial.rhtml **** -->'
## when importing other template.
engine = Tenjin::Engine.new(:trace=>true)
See: http://www.kuwata-lab.com/tenjin/rbtenjin-users-guide.html#trace
* [enhance] 'Tenjin::Template' class now accepts ':input' option which
represents template file content.
input = <<END
<p>Hello ${@name}!
END
t = Tenjin::Template.new(:input=>input)
puts t.render({:name=>"Guest"})
* [enhance] Support logger.
require 'logger'
Tenjin.logger = Logger.new($stderr)
See: http://www.kuwata-lab.com/tenjin/rbtenjin-users-guide.html#logging
* [enhance] Add new module 'Tenjin::SafeHelper' which includes
'safe_str()', 'safe_escape()', and 'safe_str?()'.
include Tenjin::HtmlHelper
include Tenjin::SafeHelper
#
s = "<AAA>"
puts safe_str?(s) #=> false
s = safe_escape(s) # same as SafeString.new(escape(s))
puts safe_str?(s) #=> true
puts s #=> <AAA>
puts safe_escape(s) #=> <AAA>
#
s = "<AAA>"
s = safe_str(s) # same as SafeString.new(s)
puts safe_str?(s) #=> true
puts s #=> <AAA>
puts safe_escape(s) #=> <AAA>
See: http://www.kuwata-lab.com/tenjin/rbtenjin-users-guide.html#auto-escaping
* [change] Html tag helpers (such as 'checked()') now returns
'SafeString' object to support both 'Tenjin::Template' and
'Tenjin::SafeTemplate'.
* [change] Html tag helpers (such as 'checked()') are moved from
'Tenjin::HtmlHelper' into new module 'Tenjin::HtmlTagHelper'.
* [enhance] Add 'new_cycle()' helper which returns values cyclic.
## template
<?rb cycle = new_cycle('odd', 'even') ?>
<?rb 5.times do ?>
class="${cycle}"
<?rb end ?>
## output
class="odd"
class="even"
class="odd"
class="even"
class="odd"
* [enhance] Add new html tag 'js_link()'.
js_link('Show', '$().show()')
#=> '<a href="javascript:undefined" onclick="$().show();return
false">Show</a>
* [enhance] Add new html tag 'nv()' which generates 'name' and 'value'
attributes.
nv('gender', 'F') #=> ' name="gender" value="F"
nv('gender', 'F', '-') #=> ' name="gender" value="F" id="gender-F"
* [enhance] Add 'public_html/rbtenjin.cgi' which is a sample script to
use tenjin in CGI script.
See: http://www.kuwata-lab.com/tenjin/rbtenjin-users-guide.html#cgi-script
* [bugfix] import() now works well with preprocessing enabled.
* [change][internal] change test scripts to use 'oktset.rb' instead of
test::unit.
* [change][internal] add 'FileFinder' class
* [change][internal] rewrite 'Engine' class to use 'FileFinder' class
* [change][internal] change 'TemplateCache#load()' to make 'timestamp'
arg as optional
* [change][internal] change a lot of methods of 'Engine' class to be
private
* [change][internal] rename 'Engine.datastore()' to
'Engine.data_store()'
* [change][internal] eliminate timestamp checking of template files
* [change][internal] Changed to use File.rename() instead of
File.open() + File#flock()
when creating template cache file.
--
regards,
makoto kuwata
== Release 0.7.1 (2011-11-27)
* [bugfix] Tenjin::Template class now considers magic comment in
template file. For example:
<?rb # -*- coding: utf-8 -*- ?> <p>This template file is
treated as utf-8 string</p>
* [bugfix] Add 'FollowSymLinks' option to 'public_html/.htaccess'.
That option is necessary to enable mod_rewrite.
* [bugfix] Fix 'public_html/hello.rbhtml' to set empty string when
request parameter is not set.
--regards,makoto