.# -*- coding: utf-8 -*- $ [ANN] Erubis 2.6.4 released - Rails 2.2 and 2.3 support I have released Erubis 2.6.4. http://www.kuwata-lab.com/erubis/ Erubis is another eRuby implementation which is very fast and extensible than ERB and eruby. Enhancement since 2.6.3: * Ruby on Rails 2.2 and 2.3 support. Have fun! -- regards, makoto kuwata .#-------------------------------------------------------------------------------- Erubis 2.6.4 released - Rails 2.2 and 2.3 supported I have released Erubis 2.6.4. Erubis is another eRuby implementation which is very fast and extensible than ERB. This release supports Ruby on Rails 2.2 and 2.3. .#-------------------------------------------------------------------------------- $ [ANN] Erubis 2.6.3 released - a fast and extensible eRuby I have released Erubis 2.6.3. http://www.kuwata-lab.com/erubis/ Erubis is another eRuby implementation which is very fast and extensible than ERB and eruby. This is just bug fix release. Bugfixes from 2.6.2: * Enhancer name was not displayed in Ruby 1.9.1 when it was missing. * Command option argument name was not displayed correctly as a part of error message. * MethoNotFound error was raised when invalid option was specified. I'll support '<% =%>' (used in Merb) in the next release of Erubis. -- regards, makoto kuwata .#-------------------------------------------------------------------------------- $ [ANN] Erubis 2.6.2 released - a fast and extensible eRuby I have released Erubis 2.6.2. http://www.kuwata-lab.com/erubis/ Erubis is another eRuby implementation which is very fast and extensible than ERB and eruby. Enhancements from 2.6.1: * Ruby 1.9 support Bugfixes from 2.6.1: * Fixed installation problem on Windows (Thanks to Tim Morgan and Allen). If you have got any errors or problems, please tell me. -- regards, makoto kuwata .#-------------------------------------------------------------------------------- $ [ANN] Erubis 2.6.1 released - a fast and extensible eRuby I have released Erubis 2.6.1. http://www.kuwata-lab.com/erubis/ http://www.kuwata-lab.com/support/ Erubis is another eRuby implementation which is very fast and extensible than ERB and eruby. Enhancements from 2.6.0: * Rails 2.1 support. (special thanks José Valim) If you have got any errors or problems, please tell me. -- regards, makoto kuwata .#-------------------------------------------------------------------------------- $ [ANN] Erubis 2.6.0 released - a fast and extensible eRuby I have released Erubis 2.6.0. http://www.kuwata-lab.com/erubis/ http://www.kuwata-lab.com/erubis/support/ Erubis is another eRuby implementation which is very fast and extensible than ERB and eruby. Enhancements from 2.5.0: * Improved support of Ruby on Rails 2.0.2. New class ActionView::TemplateHandlers::Erubis is defined and registered as default handler of *.html.erb and *.rhtml. * '<%% %>' and '<%%= %>' are converted into '<% %>' and '<%= %>' respectively. This is for compatibility with ERB. ex1.rhtml: result: $ erubis ex1.rhtml * '<%= -%>' removes tailing spaces and newlines. This is for compatibiliy with ERB when trim mode is '-'. '<%= =%>' also removes tailing spaces and newlines, and this is Erubis-original enhancement (cooler than '<%= -%>', isn't it?). ex2.rhtml:
<%= @var -%> # or <%= @var =%>
result (version 2.6.0): $ erubis -c '{var: "AAA\n"}' ex2.rhtml
AAA
result (version 2.5.0): $ erubis -c '{var: "AAA\n"}' ex2.rhtml
AAA
* Erubis::Eruby.load_file() now allows you to change cache filename. ex. eruby = Erubis::Eruby.load_file("ex3.rhtml", :cachename=>'ex3.rhtml.cache') -- regards, makoto kuwata .#-------------------------------------------------------------------------------- $ [ANN] Erubis 2.5.0 released - a fast and extensible eRuby I have released Erubis 2.5.0. http://www.kuwata-lab.com/erubis/ Erubis is another eRuby implementation which is very fast and extensible than ERB and eruby. Enhancements from 2.4.1: * Ruby on Rails 2.0 support If you are using preprocessing, notice that _?('foo.id') will be NG because it contains period ('.') character. -------------------- [%= link_to 'Edit', edit_user_path(_?('@user.id')) %] [%= link_to 'Show', @user %] [%= link_to 'Delete', @user, :confirm=>'OK?', :method=>:delete %] <%= user_id = @user.id %> [%= link_to 'Edit', edit_user_path(_?('user_id')) %] [%= link_to 'Show', :action=>'show', :id=>_?('user_id') %] [%= link_to 'Delete', {:action=>'destroy', :id=>_?('user_id')}, {:confirm=>'OK?', :method=>:delete} %] -------------------- * (experimental) Rails form helper methods for preprocessing are provided. These helper methos are available with preprocessing. ex. _form.rhtml -------------------- Name: <%= text_field :user, :name %> Name: [%= pp_text_field :user, :name %] -------------------- preprocessed: -------------------- Name: <%= text_field :user, :name %> Name: -------------------- Ruby code: -------------------- _buf << ' Name: '; _buf << ( text_field :stock, :name ).to_s; _buf << ' Name: '; -------------------- This shows that text_filed() is called every time when rendering, but pp_text_filed() is called only once when loading template, so pp_text_field() with prepocessing is much faster than text_field(). See User's guide for details. http://www.kuwata-lab.com/erubis/users-guide.05.html#rails-formhelpers -- regards, makoto kuwata .-------------------------------------------------------------------------------- $ [ANN] Erubis 2.4.1 released - two bugs are fixed I have released Erubis 2.4.1. http://www.kuwata-lab.com/erubis/ Erubis is another eRuby implementation which is very fast and extensible than ERB and eruby. This is a bugfix release. enhancements: - | Add new section 'evaluate(context) v.s. result(binding)' to user's guide. This section describes why Erubis::Eruby#evaluate(context) is recommended rather than Erubis::Eruby#result(binding). User's Guide > Other Topics > evaluate(context) v.s. result(binding) http://www.kuwata-lab.com/erubis/users-guide.06.html#topics-context-vs-binding - | Add new command-line property '--docwrite={true|false}' to Erubis::Ejavascript. If this property is true then 'document.write(_buf.join(""));' is used as postamble and if it is false then '_buf.join("")' is used. Default is true for compatibility reason but it will be false in the future release. (This feature was proposed by D.Dribin. Thank you.) bugfix: - | When using Erubis::Eruby#evaluate(), changing local variables in templates have affected to variables accessible with TOPLEVEL_BINDING. It means that if you change variables in templates, it is possible to change variables in main program. This was a bug and is now fixed not to affect to variables in main program. ex. template.rhtml -------------------- <% for x in @items %> item = <%= x %> <% end %> -------------------- ex. main-program.rb -------------------- require 'erubis' x = 10 items = ['foo', 'bar', 'baz'] eruby = Erubis::Eruby.new(File.read('template.rhtml')) s = eruby.evaluate(:items=>items) print s $stderr.puts "*** debug: x=#{x.inspect}" #=> x="baz" (2.4.0) #=> x=10 (2.4.1) -------------------- - | PercentLineEnhancer was very slow. Now performance problem is solved. -- regards, kwatch $ [ANN] Erubis 2.4.0 released - a fast eRuby implementation 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. Show 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 -------------------------------------------------------------------------------- $ [ANN] Erubis 2.3.1 released - a serious bug is fixed in rails_helper.rb Erubis 2.3.1 released. This is a bug fix release. http://www.kuwata-lab.com/erubis/ Bugfix: * A serious bug in 'helpers/rails_helper.rb' is fixed. You must be update if you are using Erubis with Ruby on Rails. -- regards, kwatch $ [ANN] Erubis 2.3.0 released - a fast and extensible eRuby implementation Hi all, I have just released Erubis 2.3.0. http://www.kuwata-lab.com/erubis http://www.kuwata-lab.com/erubis/CHANGES Erubis is another implementation of eRuby and it gives more speed to Ruby on Rails application. Features: * Very fast, almost three times faster than ERB and even ten percent faster than eruby (implemented in C) * File caching of converted Ruby script support, which makes eRuby about 40-50 percent faster. * 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 or Ruby script * Easy to extend in subclass * Ruby on Rails support * Mod_ruby support Installation is very easy. .* Just type 'gem install -r erubis' if you have installed RubyGems. .* Or download erubis_2.3.0.tar.bz2 and type 'ruby setup.rb'. See users' guide (erubis_2.3.0/doc/users-guide.html) for details. Enhancements: * New class 'Erubis::FastEruby' is added. It is a subclass of Erubis::Eruby and includes InterpolationEnhancer. Erubis::FastEruby is compatible with and faster than Erubis::Eruby. * New enhancer 'InterpolationEnhancer' is added. This enhancer uses expression interpolation to eliminate method call of String#<<. In the result, this enhancer makes Eruby a little faster. -------------------- ## Assume that input is '<%=name%>'. ## Eruby convert input into the following code. String#<< is called 5 times. _buf << ''; _buf << (name).to_s; _buf << ''; ## When InterpolationEnhancer is used, String#<< is called only once. _buf << %Q`#{name}`; -------------------- * New enhancer 'ErboutEnhancer' is added. ErboutEnhancer set '_erbout' as well as '_buf' to be compatible with ERB. ==================== $ cat ex.rhtml

Hello

$ erubis -x ex.rhtml _buf = ''; _buf << '

Hello

'; _buf.to_s $ erubis -xE Erbout ex.rhtml _erbout = _buf = ''; _buf << '

Hello

'; _buf.to_s ==================== * [experimental] New enhancer 'DeleteIndentEnhancer' is added. This enhancer deletes indentation of HTML file. ==================== $ cat ex.rhtml
$ erubis ex.rhtml
$ erubis -E DeleteIndent ex.rhtml
==================== * Mod_ruby is supported (very thanks to Andrew R Jackson!). See users-guide and 'contrib/erubis-run.rb' for details. * New command-line option '-X', '-N', '-U', and '-C' are added. These are intended to be a replacement of 'notext' command. = '-X' shows only ruby statements and expressions. = '-N' adds line numbers. = '-U' compress empty lines into a line. = '-C' removes empty lines. Changes: * 'helpers/rails_helper.rb' is changed to use ErboutEnhancer. The following is an examle to use Erubis with Ruby on Rails. File 'config/environment.rb': ---------------------------------------- require 'erubis/helpers/rails_helper' #Erubis::Helpers::RailsHelper.engine_class = Erubis::Eruby # or Erubis::FastEruby #Erubis::Helpers::RailsHelper.init_properties = {} #Erubis::Helpers::RailsHelper.show_src = false # set true for debugging ---------------------------------------- * Command 'notext' has been removed. Use '-X', '-N', '-U', and '-C' instead. * Tab characters in YAML file are expaneded automatically. If you want not to expand tab characters, add command-line optio '-T'. * Benchmark scripts (benchmark/bench.*) are rewrited. * Users-guide (doc/users-guide.html) is updated. Have fun! -- regards, kwatch .#-------------------------------------------------------------------------------- $ [ANN] Erubis 2.2.0 release - a fast eRuby implementation Hi all, I have just released Erubis 2.2.0. http://www.kuwata-lab.com/erubis http://www.kuwata-lab.com/erubis/CHANGES Erubis is another implementation of eRuby. Features: * Very fast, almost three times faster than ERB and even ten percent faster than 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 or Ruby script * Easy to extend in subclass * Ruby on Rails support See users' guide (erubis_2.2.0/doc/users-guide.html) for details. $$ Enhancements * Performance tuned up. Release 2.2.0 works about 8 percent faster than 2.1.0. As a result, Erubis works more than 10 percent faster than eruby. (eruby is the extension module of eRuby written in C.) * Support of Ruby on Rails improved. If you want to use Erubis with Ruby on Rails, add the following code into your 'config/environment.rb' and restart web server. This will set Erubis as eRuby compiler in Ruby on Rails instead of ERB. -------------------- require 'erubis/helpers/rails_helper' #Erubis::Helpers::RailsHelper.engine_class = Erubis::Eruby #Erubis::Helpers::RailsHelper.init_properties = {} #Erubis::Helpers::RailsHelper.show_src = true -------------------- Methods 'capture()' and 'content_for()' of ActionView::Helpers::CaptureHelper are available. Methd ActionView::Helpers::TextHelper#concat() is also available. If Erubis::Helpers::RailsHelper.show_src is ture, Erubis prints converted Ruby code into log file (such as 'log/development.log'). This is for debug. * Erubis::Engine.load_file(filename) creates cache file (filename + '.cache') automatically if cache file is old or not exist. Caching makes Erubis about 40-50 percent faster. ex. -------------------- require 'erubis' eruby = Erubis::Eruby.load_file('example.rhtml') ## cache file 'example.rhtml.cache' is created automatically -------------------- * Command-line option '-f datafile' can take Ruby script ('*.rb') as well as YAML file ('*.yaml' or '*.yml'). ex. ==================== $ cat context.rb @title = 'Example' @list = %w[AAA BBB CCC] $ cat example.rhtml

<%= @title %>

$ erubis -f context.rb example.rhtml

Example

==================== * New command-line option '-c context' support. It takes context string in YAML inline style or Ruby code style. ex. YAML inline style ==================== $ erubis -c '{title: Example, list: [AAA, BBB, CCC]}' example.rhtml ==================== ex. Ruby style ==================== $ erubis -c '@title="Example"; @list=%w[AAA BBB CCC]' example.rhtml ==================== * New command-line option '-z' (syntax checking) support. It is similar to 'erubis -x file.rhtml | ruby -wc', but it can take several filenames. ex. ==================== $ erubis -z app/views/*/*.rhtml Syntax OK ==================== * New constant Erubis::VERSION added. $$ Changes * Class Erubis::Eruby changed to include Erubis::StringBufferEnhancer instead of Erubis::ArrayBufferEnhancer. This is for Ruby on Rails support. ex. ==================== $ cat example.rhtml $ erubis -x example.rhtml _buf = ''; _buf << ' '; _buf.to_s ==================== * Erubis::StringBufferEnhancer#add_postamble() prints "_buf.to_s" instead of "_buf". This is useful for 'erubis -x file.rhtml | ruby -wc'. * Command-line option '-T' is removed. Use '--trim=false' instead. * License is changed to MIT License. * Embedded pattern '<%- -%>' can be handled. -- regards, kwatch -------------------------------------------------------------------------------- $ [ANN] Erubis 2.1.0 release - a fast eRuby implementation 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) '' as embedded pattern instead of '<% .. %>'. example.rhtml --------------------
@!{item}@
-------------------- compile: ==================== $ erubis -x --pi example.rhtml _buf = []; _buf << ' '; @list.each_with_index do |item, i| klass = i % 2 == 0 ? 'odd' : 'even' _buf << ' '; end _buf << '
'; _buf << (item).to_s; _buf << '
'; _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 -------------------- <% @list.each_with_index do |item, i| %> <% klass = i % 2 == 0 ? 'odd' : 'even' %> <% end %>
<%== item %>
-------------------- 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
==================== 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 $ [ANN] Erubis 2.0.1 release - a fast eRuby implementation I have released Erubis 2.0.0. http://rubyforge.org/projects/erubis/ Erubis is a pure ruby implementation of eRuby. This is a minor bugfix version. $ [ANN] Erubis 2.0.0 release - a fast eRuby implementation I have released Erubis 2.0.0. http://rubyforge.org/projects/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.0.0/doc/users-guide.html) for details. Changes from 1.1: * module 'PrintEnhancer' is renamed to 'PrintEnabledEnahncer' * module 'FastEnhancer' and class 'FastEruby' is obsolete (these are integrated with Eruby class) * Eruby#evaluate() calls instance_eval() instead of eval() * XmlEruby.escape_xml() is moved to XmlHelper.escape_xml() * and so on Enhancements from 1.1: * multi programming language support (Ruby,PHP,C,Java,Scheme,Perl,Javascript) * many enhancer modules are added (see users' guide for details) * class Eruby runs very fast because FastEnhancer module is integrated into Eruby by default * TinyEruby class (tiny.rb) is added * and so on If you are interested in Eruby internal, see the following classes at first. * Erubis::TinyEruby (erubis/tiny.rb) -- the most simple eRuby implementation. * Erubis::Engine (erubis/engine.rb) -- base class of Eruby, Ephp, Ejava, and so on. * Erubis::Eruby (erubis/engine/eruby.rb) -- engine class for eRuby. -- regards, kwatch $ Release 1.1.1 (2006-03-06) I have released Erubis 1.1.0. http://rubyforge.org/projects/erubis/ Erubis is an implementation of eRuby. It has the following features: * Auto sanitizing support * Auto trimming spaces around '<% %>' * Embedded pattern changeable (default '<% %>') * Context object available * Print statement available * Faster mode support * Easy to expand in subclass Erubis is implemented in pure Ruby. It requires Ruby 1.8 or higher. See doc/users-guide.html in archive for details. : Enhancement from 1.1.0 * New command-line option '-x' supported. This option prints Ruby source code of eRuby script coverted and remove the last '_out' line. This is more convenient than '-s' when validating with 'ruby -wc'. example: ==================== $ cat foo.eruby <% (1..3).each do |i| %> i = <%= i %> <% end %> $ eruby -x foo.eruby _out = ''; (1..3).each do |i| _out << " i = "; _out << ( i ).to_s; _out << "\n" end $ eruby -x foo.eruby | ruby -wc Syntax OK $ eruby -s foo.eruby _out = ''; (1..3).each do |i| _out << " i = "; _out << ( i ).to_s; _out << "\n" end _out $ erubis -s foo.rhtml | ruby -wc -:4: warning: useless use of a variable in void context Syntax OK ==================== $ Release 1.1.0 (2006-03-05) I have released Erubis 1.1.0. http://rubyforge.org/projects/erubis/ Erubis is an implementation of eRuby. It has the following features: * Auto sanitizing support * Embedded pattern changeable (default '<% %>') * Auto trimming spaces around '<% %>' * Context object available * Print statement available * Faster mode support * Easy to expand in subclass Erubis is implemented in pure Ruby. It requires Ruby 1.8 or higher. Sample code (example.rb): -------------------- ## eRuby script ## ('<%= %>' is escaped and '<%== %>' is not escaped when using XmlEruby class) input = < <% for item in list %>
  • <%= item %> <%== item %>
  • <% end %> END ## create Eruby object require 'erubis' eruby = Erubis::XmlEruby.new(input) # or Erubis::Eruby.new(input) ## get result list = ['', 'b&b', '"ccc"'] puts eruby.result(binding()) -------------------- result: ==================== $ ruby example.rb ==================== See doc/users-guide.html in archive for details. : Enhancement from 1.0.1 * '<%# .. %>' supported. Erubis ignores '<%# %>'. * New class PrintEruby and PrintXmlEruby available. These class enables you to embed print statement in eRuby (this feature is not supported in ERB). ex. example.eb -------------------- ## data list = ['aaa', 'bbb', 'ccc'] context = { :list => list } ## eRuby script ## (use print statement instead of <%= item %>) input = <<-END END ## create eruby and get result as string require 'erubis' eruby = Erubis::PrintEruby.new(input) str = eruby.evaluate(context) # don't use result()! print str -------------------- result: ==================== $ ruby example.rb ==================== Have fun! -- regards, kwatch