Posted By: Makoto Kuwata
Date: 2007-07-19 04:05
Summary: [ANN] Erubis 2.4.0 released - a fast eRuby implementation
Project: Erubis

Erubis 2.4.0 released.
http://www.kuwata-lab.com/erubis/
In this release, Erubis provides an important feature for
Ruby on Rails application.

Enhancements:

- |
Preprocessing is supported by Ruby on Rails helper.
Preprocessing makes Ruby on Rails application about 20-40 percent faster.

For example,

[%= link_to 'Show', :action=>'show', :id=>_?('@user.id') %]

is evaluate by preprocessor and expanded into the following
when template file is loaded.

<a href="/users/show/<%=@user.id%>">Show</a>

It means that link_to() is never called when template is rendered
and rendering speed will be much faster in the result.

See User's Guide for details.
http://www.kuwata-lab.com/erubis/users-guide.05.html#rails-preprocessing

- |
Erubis::Eruby#evaluate() (or Erubis::RubyEvaluator#evaluate())
creates Proc object from @src and eval it.

def evaluate(context=Context.new)
context = Context.new(context) if context.is_a?(Hash)
@_proc ||= eval("proc { #{@src} }", TOPLEVEL_BINDING, @filename || '(erubis)')
return context.instance_eval(&@_proc)
end

This makes evaluate() much faster when eruby object is reused.

- |
Erubis::Eruby#def_method() is supported.
This method defines ruby code as instance method or singleton metod.

require 'erubis'
s = "hello <%= name %>"
eruby = Erubis::Eruby.new(s)
filename = 'hello.rhtml'

## define instance method to Dummy class (or module)
class Dummy; end
eruby.def_method(Dummy, 'render(name)', filename) # filename is optional
p Dummy.new.render('world') #=> "hello world"

## define singleton method to an object
obj = Object.new
eruby.def_method(obj, 'render(name)', filename) # filename is optional
p obj.render('world') #=> "hello world"

This is equivarent to ERB#def_method().

- |
Erubis::XmlHelper.url_escape() and u() which is alias of url_escape()
are added.
This is equivarent to ERB#Util.url_escape().


Bugfix:

- Help message was not shown when '-h' is specified. Fixed.

- 'def method()' was not availabe in template file. Fixed.


--
regards,
kwatch

Latest News
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
diff-lcs 1.2.4 Released
    Austin Ziegler - 2013-04-21 00:08

 

Forums | Admin

Discussion Forums: -ann--erubis-2.4.0-released---a-fast-eruby-implementation

Start New Thread Start New Thread

 

Topic Topic Starter Replies Last Post