Posted By: Makoto Kuwata
Date: 2006-09-25 07:36
Summary: Erubis 2.1.0 - a fast eRuby implementation
Project: Erubis

I have released Erubis 2.1.0.
http://www.kuwata-lab.com/erubis/

Erubis is a pure ruby implementation of eRuby.

Features:
* Very fast, almost three times faster than ERB and
even as fast as eruby (implemented in C)
* Support multi-language
(Ruby,PHP,C,Java,Scheme,Perl,Javascript)
* Auto escaping support
* Auto trimming spaces around '<% %>'
* Embedded pattern changeable (default '<% %>')
* Context object available and easy to combine eRuby
template with YAML datafile
* Print statement available
* Easy to extend in subclass

See users' guide (erubis_2.1.0/doc/users-guide.html)
for details.


Enhancements from 2.0:

* Ruby on Rails support. Add the following code to
your 'app/controllers/application.rb' and restart web server.

--------------------
require 'erubis/helper/rails'
suffix = 'erubis'
ActionView::Base.register_template_handler(suffix, Erubis::Helper::RailsTemplate)
#Erubis::Helper::RailsTemplate.engine_class = Erubis::EscapedEruby ## or Erubis::PI::Eruby
#Erubis::Helper::RailsTemplate.default_properties = { :escape=>true, :escapefunc=>'h' }
--------------------

And rename your view template as 'xxx.erubis'.
If you got the "(eval):10:in `render': no block given" error,
use '@content_for_layout' instead 'yield' in your layout template.

* Another eRuby engine (PIEngine) support. This engine doesn't
break HTML design because it uses Processing Instructions (PI)
'<?rb .. ?>' as embedded pattern instead of '<% .. %>'.

example.rhtml
--------------------
<table>
<?rb @list.each_with_index do |item, i| ?>
<?rb klass = i % 2 == 0 ? 'odd' : 'even' ?>
<tr class="@{klass}@">
<td>@!{item}@</td>
</tr>
<?rb end ?>
</table>
--------------------

compile:
====================
$ erubis -x --pi example.rhtml
_buf = []; _buf << '<table>
'; @list.each_with_index do |item, i|
klass = i % 2 == 0 ? 'odd' : 'even'
_buf << ' <tr class="'; _buf << Erubis::XmlHelper.escape_xml(klass); _buf << '">
<td>'; _buf << (item).to_s; _buf << '</td>
</tr>
'; end
_buf << '</table>
';
_buf.join
====================

* Add new command 'notext' which remove text part from eRuby
script and leaves only Ruby code.
This is very useful when debugging eRuby script.

example2.rhtml
--------------------
<html>
<body>
<table>
<% @list.each_with_index do |item, i| %>
<% klass = i % 2 == 0 ? 'odd' : 'even' %>
<tr class="<%= klass %>">
<td><%== item %></td>
</tr>
<% end %>
</table>
</body>
</html>
--------------------

command line example:
====================
$ notext example2.rhtml
_buf = [];


@list.each_with_index do |item, i| ;
klass = i % 2 == 0 ? 'odd' : 'even' ;
_buf << ( klass ).to_s;
_buf << Erubis::XmlHelper.escape_xml( item );

end ;



_buf.join
$ notext -nc example2.rhtml
1: _buf = [];
4: @list.each_with_index do |item, i| ;
5: klass = i % 2 == 0 ? 'odd' : 'even' ;
6: _buf << ( klass ).to_s;
7: _buf << Erubis::XmlHelper.escape_xml( item );
9: end ;
13: _buf.join
====================

* Add new enhance 'NoCode' which removes ruby code from
eRuby script and leaves only HTML text part.
It is very useful to validate HTML of eRuby script.

command-line example:
====================
$ erubis -x -E NoCode example2.rhtml
<html>
<body>
<table>


<tr class="">
<td></td>
</tr>

</table>
</body>
</html>
====================


Changes from 2.0:

* License is changed to LGPL.

* Command-line property '--escape=name' is renamed to
'--escapefunc=name'.

* When command-line option '-l perl' is specified, function
'encode_entities()' is used ad escaping function which is
available wth HTML::Entities module.


Bugfix:
* There is a certain pattern which makes Engine#convert()
too slow. Now Engne#convert() is fixed not to be slown.
* Command name is now displayed when '-h' is specified.


Have fun!

--
kwatch

Latest News
BinData 1.5.0 - source moved to github
    Dion Mendel - 2013-05-21 11:10
v13.5.0 Released !!
    id 774 - 2013-05-18 12:28
Runt v0.9.0 Released
    Matthew Lipper - 2013-05-17 00:11
kramdown 1.0.2 released
    Thomas Leitner - 2013-05-09 06:58
mime-types 1.23 Released
    Austin Ziegler - 2013-04-21 01:41

 

Forums | Admin

Discussion Forums: -ann--erubis-2.1.0-release---a-fast-eruby-implementation

Start New Thread Start New Thread

 

Topic Topic Starter Replies Last Post