summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormakoto kuwata <kwa@kuwata-lab.com>2007-07-19 01:06:05 +0000
committermakoto kuwata <kwa@kuwata-lab.com>2007-07-19 01:06:05 +0000
commit21a11d1c629e9696425334edf42edee3b30083c2 (patch)
tree94d0ecf7cbf569372c4dbebeb2ad186e93c1b92a
parent8f64eea63dfa6b60ada039526f762bde70ca7e3c (diff)
downloaderubis-21a11d1c629e9696425334edf42edee3b30083c2.tar.gz
- [update] document updated
-rw-r--r--CHANGES56
-rw-r--r--ChangeLog.txt3
-rw-r--r--ReleaseNote.txt67
-rw-r--r--doc/users-guide.html275
-rw-r--r--doc/users-guide.txt278
-rw-r--r--lib/erubis/helpers/rails_helper.rb15
-rw-r--r--website/Rookbook.rb8
-rw-r--r--website/index.txt11
-rw-r--r--website/index.xhtml12
9 files changed, 539 insertions, 186 deletions
diff --git a/CHANGES b/CHANGES
index 64f2f42..b32b345 100644
--- a/CHANGES
+++ b/CHANGES
@@ -4,6 +4,62 @@
#
+- release: 2.4.0
+ date: 2007-07-19
+ 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 not called when template is rendered
+ and rendering speed will be much faster in the result.
+
+ See User's Guide for details.
+
+ - |
+ 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 module's instance method.
+
+ def def_method(module_object, method_name, filename=nil)
+ module_object.module_eval("def #{method_name}; #{@src}; end", filename || @filename)
+ end
+
+ 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.
+
+
+#
- release: 2.3.1
date: 2007-05-26
bugfix:
diff --git a/ChangeLog.txt b/ChangeLog.txt
index 0ea74e8..89f1be8 100644
--- a/ChangeLog.txt
+++ b/ChangeLog.txt
@@ -2,6 +2,9 @@
.?lastupdate: $Date$
.?version: $Rev$
+: Rev.90 (2007-07-19)
+ .- [update] document updated
+
: Rev.89 (2007-07-19)
.- [enhance] add Erubis::XmlHelper::url_encode() (and u() which is alias of url_encode())
.- [enhance] Erubis::RubyEvaluator#evaluate() now convert @src into @_proc object and do instance_eval(&@_proc)
diff --git a/ReleaseNote.txt b/ReleaseNote.txt
index c086f88..d0549ae 100644
--- a/ReleaseNote.txt
+++ b/ReleaseNote.txt
@@ -1,3 +1,70 @@
+$ [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 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 module's instance method.
+
+ def def_method(module_object, method_name, filename=nil)
+ module_object.module_eval("def #{method_name}; #{@src}; end", filename || @filename)
+ end
+
+ 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.
+
+
+
+
+--------------------------------------------------------------------------------
+
$ [ANN] Erubis 2.3.1 released - a serious bug is fixed in rails_helper.rb
Erubis 2.3.1 released.
diff --git a/doc/users-guide.html b/doc/users-guide.html
index f2c99f0..dcb80ae 100644
--- a/doc/users-guide.html
+++ b/doc/users-guide.html
@@ -25,29 +25,29 @@
It has the following features.
</p>
<ul type="disc">
-<li><a href="#topics-benchmark">Very fast</a>, almost three times faster than ERB and about ten percent faster than eruby (implemented in C)
+<li>Very fast, almost three times faster than ERB and about ten percent faster than eruby (implemented in C)
</li>
-<li><a href="#topics-caching">File caching of converted Ruby script support</a>
+<li>File caching of converted Ruby script support
</li>
-<li><a href="#tut-escape">Auto escaping support</a>
+<li>Auto escaping support
</li>
-<li><a href="#tut-trim">Auto trimming spaces around '&lt;% %&gt;'</a>
+<li>Auto trimming spaces around '&lt;% %&gt;'
</li>
-<li><a href="#tut-pattern">Embedded pattern changeable</a> (default '&lt;% %&gt;')
+<li>Embedded pattern changeable (default '&lt;% %&gt;')
</li>
-<li><a href="#tut-pi">Enable to handle Processing Instructions (PI) as embedded pattern</a> (ex. '&lt;?rb ... ?&gt;')
+<li>Enable to handle Processing Instructions (PI) as embedded pattern (ex. '&lt;?rb ... ?&gt;')
</li>
-<li><a href="#lang">Multi-language support</a> (Ruby/PHP/C/Java/Scheme/Perl/Javascript)
+<li>Multi-language support (Ruby/PHP/C/Java/Scheme/Perl/Javascript)
</li>
-<li><a href="#tut-context">Context object available</a> and <a href="#tut-datafile">easy to combine eRuby template with YAML datafile</a>
+<li>Context object available and easy to combine eRuby template with YAML datafile
</li>
-<li><a href="#printenabled-enhancer">Print statement available</a>
+<li>Print statement available
</li>
-<li><a href="#enhancer">Easy to expand and customize in subclass</a>
+<li>Easy to expand and customize in subclass
</li>
-<li><a href="#topics-rails">Ruby on Rails support</a>
+<li><a href="#rails">Ruby on Rails support</a>
</li>
-<li><a href="#topcs-modruby">mod_ruby support</a>
+<li>mod_ruby support|#topcs-modruby
</li>
</ul>
<p>Erubis is implemented in pure Ruby. It requires Ruby 1.8 or higher.
@@ -139,6 +139,16 @@ It has the following features.
</li>
</ul>
</li>
+ <li><a href="#rails">Ruby on Rails Support</a>
+ <ul>
+ <li><a href="#rails-settings">Settings</a>
+ </li>
+ <li><a href="#rails-preprocessing">Preprosessing</a>
+ </li>
+ <li><a href="#rails-others">Others</a>
+ </li>
+ </ul>
+ </li>
<li><a href="#topics">Other Topics</a>
<ul>
<li><a href="#topics-fasteruby">Class Erubis::FastEruby</a>
@@ -149,8 +159,6 @@ It has the following features.
</li>
<li><a href="#topics-tinyeruby">Erubis::TinyEruby class</a>
</li>
- <li><a href="#topics-rails">Ruby on Rails Support</a>
- </li>
<li><a href="#topics-php">NoTextEnhancer and NoCodeEnhancer in PHP</a>
</li>
<li><a href="#topcs-modruby">Helper Class for mod_ruby</a>
@@ -2281,6 +2289,176 @@ document.write(_buf.join(""));
<br>
+<a name="rails"></a>
+<h2 class="section1">Ruby on Rails Support</h2>
+<p>Erubis supports Ruby on Rails.
+This section describes how to use Erubis with Ruby on Rails.
+</p>
+<a name="rails-settings"></a>
+<h3 class="section2">Settings</h3>
+<ol type="1">
+<li>Add the following code to your 'config/environment.rb'.
+<div class="program_caption">
+config/environment.rb</div>
+<pre class="program">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
+#Erubis::Helpers::RailsHelper.preprocessing = true
+</pre>
+<p> This will replace ERB in Rails by Erubis entirely.
+</p>
+</li>
+<li>(Optional) apply the following patch to 'action_pack/lib/action_view/base.rb'.
+<div class="program_caption">
+action_view_base_rb.patch</div>
+<pre class="program">--- lib/action_view/base.rb (original)
++++ lib/action_view/base.rb (working copy)
+@@ -445,6 +445,11 @@
+ end
+ end
+
++ # convert template into ruby code
++ def convert_template_into_ruby_code(template)
++ ERB.new(template, nil, @@erb_trim_mode).src
++ end
++
+ # Create source code for given template
+ def create_template_source(extension, template, render_symbol, locals)
+ if template_requires_setup?(extension)
+@@ -458,7 +463,7 @@
+ "update_page do |page|\n#{template}\nend"
+ end
+ else
+- body = ERB.new(template, nil, @@erb_trim_mode).src
++ body = convert_template_into_ruby_code(template)
+ end
+
+ @@template_args[render_symbol] ||= {}
+</pre>
+<p> This patch is included in erubis_2.X.X/contrib directory and the following is an
+ example to apply this patch.
+</p>
+<div class="terminal_caption">
+how to apply patch:</div>
+<pre class="terminal">$ cd /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_view/
+$ sudo patch -p1 &lt; /tmp/erubis_2.X.X/contrib/action_view_base_rb.patch
+</pre>
+<p> Notice that this patch is not necessary if you are using Ruby on Rails ver 1.1 or 1.2, but it is recommended.
+</p>
+</li>
+<li>Restart web server.
+<pre class="terminal">$ ruby script/server
+</pre>
+</li>
+</ol>
+<p>The setting is above all.
+</p>
+<br>
+
+
+<a name="rails-preprocessing"></a>
+<h3 class="section2">Preprosessing</h3>
+<p><strong>(Experimental)</strong>
+Erubis supports preprocessing of template files.
+Preprocessing make your Ruby on Rails application about 20-40 percent faster.
+To enable preprocessing, set Erubis::Helpers::RailsHelper.preprocessing to true in your 'environment.rb' file.
+</p>
+<p>For example, assume the following template.
+This is slow because link_to() method is called every time when template is rendered.
+</p>
+<pre class="program">&lt;%= link_to 'Create', :action=&gt;'create' %&gt;
+</pre>
+<p>The following is faster than the above, but not flexible because url is fixed.
+</p>
+<pre class="program">&lt;a href="/users/create"&gt;Create&lt;/a&gt;
+</pre>
+<p>Preprocessing solves this problem.
+If you use '[%= %]' instead of '&lt;%= %&gt;', preprocessor evaluate it only once when template is loaded.
+</p>
+<pre class="program"><strong>[%= link_to 'Create', :action=&gt;'create'%]</strong>
+</pre>
+<p>The above is evaluated by preprocessor and replaced to the following code automatically.
+</p>
+<pre class="program">&lt;a href="/users/create"&gt;Create&lt;/a&gt;
+</pre>
+<p>Notice that this is done only once when template file is loaded.
+It means that link_to() method is not called when template is rendered.
+</p>
+<p>If link_to() method have variable arguments, use <code>_?()</code> helper method.
+</p>
+<pre class="program">&lt;% for use in @users %&gt;
+[%= link_to <strong>_?('user.name')</strong>, :action=&gt;'show', :id=&gt;<strong>_?('user.id')</strong> %]
+&lt;% end %&gt;
+</pre>
+<p>The above is evaluated by preprocessor when template is loaded and expanded into the following code.
+This will be much faster because link_to() method is not called when rendering.
+</p>
+<pre class="program">&lt;% for user in @users %&gt;
+&lt;a href="/users/show/<strong>&lt;%=user.id%&gt;</strong>"&gt;<strong>&lt;%=user.name%&gt;</strong>&lt;/a&gt;
+&lt;% end %&gt;
+</pre>
+<p>Preprocessing statement (<code>[% %]</code>) is also available as well as preprocessing expression (<code>[%= %]</code>).
+</p>
+<pre class="program">&lt;select name="state"&gt;
+ &lt;option value=""&gt;-&lt;/option&gt;
+<strong>[% for code in states.keys.sort %]</strong>
+ &lt;option value="<strong>[%= code %]</strong>"&gt;<strong>[%= states[code] %]</strong>&lt;/option&gt;
+<strong>[% end %]</strong>
+&lt;/select&gt;
+</pre>
+<p>The above will be evaluated by preprocessor and expanded into the following when template is loaded.
+In the result, rendering speed will be much faster because for-loop is not executed when rendering.
+</p>
+<pre class="program">&lt;select name="state"&gt;
+ &lt;option value=""&gt;-&lt;/option&gt;
+ &lt;option value="AK"&gt;Alaska&lt;/option&gt;
+ &lt;option value="AL"&gt;Alabama&lt;/option&gt;
+ &lt;option value="AR"&gt;Arkansas&lt;/option&gt;
+ &lt;option value="AS"&gt;American Samoa&lt;/option&gt;
+ &lt;option value="AZ"&gt;Arizona&lt;/option&gt;
+ &lt;option value="CA"&gt;California&lt;/option&gt;
+ &lt;option value="CO"&gt;Colorado&lt;/option&gt;
+ ....
+&lt;/select&gt;
+</pre>
+<p>Notice that it is not recommended to use preprocessing with tag helpers,
+because tag helpers generate different html code when form parameter has errors or not.
+</p>
+<p>Helper methods of Ruby on Rails are divided into two groups.
+</p>
+<ul type="disc">
+<li>link_to() or _() (method of gettext package) are not need to call for every time
+ as template is rendered because it returns same value when same arguments are passed.
+ These methods can be got faster by preprocessing.
+</li>
+<li>Tag helper methods should be called for every time as template is rendered
+ because it may return differrent value even if the same arguments are passed.
+ Preprocessing is not available with these methods.
+</li>
+</ul>
+<br>
+
+
+<a name="rails-others"></a>
+<h3 class="section2">Others</h3>
+<ul type="disc">
+<li>ActionView::Helpers::CaptureHelper#capture() and ActionView::Helpers::Texthelper#concat() are available.
+</li>
+</ul>
+<ul type="disc">
+<li>If Erubis::Helper::Rails.show_src is ture, Erubis prints converted Ruby code into log file (ex. 'log/development.log').
+</li>
+</ul>
+<p>If it is nil (default), Erubis prints converted Ruby code into log file only when development mode.
+ It is useful for debugging.
+</p>
+<br>
+
+
+<br>
+
+
<a name="topics"></a>
<h2 class="section1">Other Topics</h2>
<a name="topics-fasteruby"></a>
@@ -2412,73 +2590,6 @@ try Erubis::TinyEruby class.
<br>
-<a name="topics-rails"></a>
-<h3 class="section2">Ruby on Rails Support</h3>
-<p>Erubis supports Ruby on Rails.
-</p>
-<ol type="1">
-<li>Add the following code to your 'config/environment.rb'.
-<div class="program_caption">
-config/environment.rb</div>
-<pre class="program">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
-</pre>
-<p> This will replace ERB in Rails by Erubis entirely.
-</p>
-</li>
-<li>(Optional) apply the following patch to 'action_pack/lib/action_view/base.rb'.
-<div class="program_caption">
-action_view_base_rb.patch</div>
-<pre class="program">--- lib/action_view/base.rb (original)
-+++ lib/action_view/base.rb (working copy)
-@@ -445,6 +445,11 @@
- end
- end
-
-+ # convert template into ruby code
-+ def convert_template_into_ruby_code(template)
-+ ERB.new(template, nil, @@erb_trim_mode).src
-+ end
-+
- # Create source code for given template
- def create_template_source(extension, template, render_symbol, locals)
- if template_requires_setup?(extension)
-@@ -458,7 +463,7 @@
- "update_page do |page|\n#{template}\nend"
- end
- else
-- body = ERB.new(template, nil, @@erb_trim_mode).src
-+ body = convert_template_into_ruby_code(template)
- end
-
- @@template_args[render_symbol] ||= {}
-</pre>
-<p> This patch is included in erubis_2.X.X/contrib directory and the following is an
- example to apply this patch.
-</p>
-<div class="terminal_caption">
-how to apply patch:</div>
-<pre class="terminal">$ cd /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_view/
-$ sudo patch -p1 &lt; /tmp/erubis_2.X.X/contrib/action_view_base_rb.patch
-</pre>
-<p> Notice that this patch is not necessary if you are using Ruby on Rails ver 1.1 or 1.2, but it is recommended.
-</p>
-</li>
-<li>Restart web server.
-<pre class="terminal">$ ruby script/server
-</pre>
-</li>
-</ol>
-<p>ActionView::Helpers::CaptureHelper#capture() and ActionView::Helpers::Texthelper#concat() are available.
-</p>
-<p>If Erubis::Helper::Rails.show_src is ture, Erubis prints converted Ruby code into log file (ex. 'log/development.log').
-It is useful for debugging.
-</p>
-<br>
-
-
<a name="topics-php"></a>
<h3 class="section2">NoTextEnhancer and NoCodeEnhancer in PHP</h3>
<p>NoTextEnhancer and NoCodEnahncer are quite useful not only for eRuby but also for PHP.
@@ -2618,7 +2729,7 @@ $ sudo chmod 775 .
</ol>
<p>You must set your directories to be writable by web server process, because
Apache::ErubisRun calls Erubis::Eruby.load_file() internally which creates cache files
-in the same directory as '*.rhtml' file.
+in the same directory in which '*.rhtml' file exists.
</p>
<br>
diff --git a/doc/users-guide.txt b/doc/users-guide.txt
index 4a2d248..291fb99 100644
--- a/doc/users-guide.txt
+++ b/doc/users-guide.txt
@@ -12,18 +12,30 @@ release: $Release$
Erubis is an implementation of eRuby.
It has the following features.
-.* {{<Very fast|#topics-benchmark>}}, almost three times faster than ERB and about ten percent faster than eruby (implemented in C)
-.* {{<File caching of converted Ruby script support|#topics-caching>}}
-.* {{<Auto escaping support|#tut-escape>}}
-.* {{<Auto trimming spaces around '<% %>'|#tut-trim>}}
-.* {{<Embedded pattern changeable|#tut-pattern>}} (default '<% %>')
-.* {{<Enable to handle Processing Instructions (PI) as embedded pattern|#tut-pi>}} (ex. '<?rb ... ?>')
-.* {{<Multi-language support|#lang>}} (Ruby/PHP/C/Java/Scheme/Perl/Javascript)
-.* {{<Context object available|#tut-context>}} and {{<easy to combine eRuby template with YAML datafile|#tut-datafile>}}
-.* {{<Print statement available|#printenabled-enhancer>}}
-.* {{<Easy to expand and customize in subclass|#enhancer>}}
-.* {{<Ruby on Rails support|#topics-rails>}}
-.* {{<mod_ruby support|#topcs-modruby>}}
+.* Very fast, almost three times faster than ERB and about ten percent faster than eruby (implemented in C)
+.* File caching of converted Ruby script support
+.* Auto escaping support
+.* Auto trimming spaces around '<% %>'
+.* Embedded pattern changeable (default '<% %>')
+.* Enable to handle Processing Instructions (PI) as embedded pattern (ex. '<?rb ... ?>')
+.* Multi-language support (Ruby/PHP/C/Java/Scheme/Perl/Javascript)
+.* Context object available and easy to combine eRuby template with YAML datafile
+.* Print statement available
+.* Easy to expand and customize in subclass
+.* {{<Ruby on Rails support|#rails>}}
+.* mod_ruby support|#topcs-modruby
+.#.* {{<Very fast|#topics-benchmark>}}, almost three times faster than ERB and about ten percent faster than eruby (implemented in C)
+.#.* {{<File caching of converted Ruby script support|#topics-caching>}}
+.#.* {{<Auto escaping support|#tut-escape>}}
+.#.* {{<Auto trimming spaces around '<% %>'|#tut-trim>}}
+.#.* {{<Embedded pattern changeable|#tut-pattern>}} (default '<% %>')
+.#.* {{<Enable to handle Processing Instructions (PI) as embedded pattern|#tut-pi>}} (ex. '<?rb ... ?>')
+.#.* {{<Multi-language support|#lang>}} (Ruby/PHP/C/Java/Scheme/Perl/Javascript)
+.#.* {{<Context object available|#tut-context>}} and {{<easy to combine eRuby template with YAML datafile|#tut-datafile>}}
+.#.* {{<Print statement available|#printenabled-enhancer>}}
+.#.* {{<Easy to expand and customize in subclass|#enhancer>}}
+.#.* {{<Ruby on Rails support|#topics-rails>}}
+.#.* {{<mod_ruby support|#topcs-modruby>}}
Erubis is implemented in pure Ruby. It requires Ruby 1.8 or higher.
@@ -2376,6 +2388,178 @@ document.write(_buf.join(""));
+.$ Ruby on Rails Support | rails
+
+Erubis supports Ruby on Rails.
+This section describes how to use Erubis with Ruby on Rails.
+
+
+.$$ Settings | rails-settings
+
+
+.1) Add the following code to your 'config/environment.rb'.
+
+ .? 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
+ #Erubis::Helpers::RailsHelper.preprocessing = true
+ .--------------------
+
+ This will replace ERB in Rails by Erubis entirely.
+
+.2) (Optional) apply the following patch to 'action_pack/lib/action_view/base.rb'.
+
+ .? action_view_base_rb.patch
+ .--------------------
+ --- lib/action_view/base.rb (original)
+ +++ lib/action_view/base.rb (working copy)
+ @@ -445,6 +445,11 @@
+ end
+ end
+
+ + # convert template into ruby code
+ + def convert_template_into_ruby_code(template)
+ + ERB.new(template, nil, @@erb_trim_mode).src
+ + end
+ +
+ # Create source code for given template
+ def create_template_source(extension, template, render_symbol, locals)
+ if template_requires_setup?(extension)
+ @@ -458,7 +463,7 @@
+ "update_page do |page|\n#{template}\nend"
+ end
+ else
+ - body = ERB.new(template, nil, @@erb_trim_mode).src
+ + body = convert_template_into_ruby_code(template)
+ end
+
+ @@template_args[render_symbol] ||= {}
+ .--------------------
+
+ This patch is included in erubis_2.X.X/contrib directory and the following is an
+ example to apply this patch.
+
+ .? how to apply patch:
+ .====================
+ $ cd /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_view/
+ $ sudo patch -p1 < /tmp/erubis_2.X.X/contrib/action_view_base_rb.patch
+ .====================
+
+ Notice that this patch is not necessary if you are using Ruby on Rails ver 1.1 or 1.2, but it is recommended.
+
+.3) Restart web server.
+ .====================
+ $ ruby script/server
+ .====================
+
+The setting is above all.
+
+
+
+.$$ Preprosessing | rails-preprocessing
+
+{{*(Experimental)*}}
+Erubis supports preprocessing of template files.
+Preprocessing make your Ruby on Rails application about 20-40 percent faster.
+To enable preprocessing, set Erubis::Helpers::RailsHelper.preprocessing to true in your 'environment.rb' file.
+
+For example, assume the following template.
+This is slow because link_to() method is called every time when template is rendered.
+
+.--------------------
+<%= link_to 'Create', :action=>'create' %>
+.--------------------
+
+The following is faster than the above, but not flexible because url is fixed.
+
+.--------------------
+<a href="/users/create">Create</a>
+.--------------------
+
+Preprocessing solves this problem.
+If you use '[%= %]' instead of '<%= %>', preprocessor evaluate it only once when template is loaded.
+
+.--------------------
+{{*[%= link_to 'Create', :action=>'create'%]*}}
+.--------------------
+
+The above is evaluated by preprocessor and replaced to the following code automatically.
+
+.--------------------
+<a href="/users/create">Create</a>
+.--------------------
+
+Notice that this is done only once when template file is loaded.
+It means that link_to() method is not called when template is rendered.
+
+If link_to() method have variable arguments, use {{,_?(),}} helper method.
+
+.--------------------
+<% for use in @users %>
+[%= link_to {{*_?('user.name')*}}, :action=>'show', :id=>{{*_?('user.id')*}} %]
+<% end %>
+.--------------------
+
+The above is evaluated by preprocessor when template is loaded and expanded into the following code.
+This will be much faster because link_to() method is not called when rendering.
+
+.--------------------
+<% for user in @users %>
+<a href="/users/show/{{*<%=user.id%>*}}">{{*<%=user.name%>*}}</a>
+<% end %>
+.--------------------
+
+Preprocessing statement ({{,[% %],}}) is also available as well as preprocessing expression ({{,[%= %],}}).
+.--------------------
+<select name="state">
+ <option value="">-</option>
+{{*[% for code in states.keys.sort %]*}}
+ <option value="{{*[%= code %]*}}">{{*[%= states[code] %]*}}</option>
+{{*[% end %]*}}
+</select>
+.--------------------
+
+The above will be evaluated by preprocessor and expanded into the following when template is loaded.
+In the result, rendering speed will be much faster because for-loop is not executed when rendering.
+.--------------------
+<select name="state">
+ <option value="">-</option>
+ <option value="AK">Alaska</option>
+ <option value="AL">Alabama</option>
+ <option value="AR">Arkansas</option>
+ <option value="AS">American Samoa</option>
+ <option value="AZ">Arizona</option>
+ <option value="CA">California</option>
+ <option value="CO">Colorado</option>
+ ....
+</select>
+.--------------------
+
+Notice that it is not recommended to use preprocessing with tag helpers,
+because tag helpers generate different html code when form parameter has errors or not.
+
+Helper methods of Ruby on Rails are divided into two groups.
+.* link_to() or _() (method of gettext package) are not need to call for every time
+ as template is rendered because it returns same value when same arguments are passed.
+ These methods can be got faster by preprocessing.
+.* Tag helper methods should be called for every time as template is rendered
+ because it may return differrent value even if the same arguments are passed.
+ Preprocessing is not available with these methods.
+
+
+.$$ Others | rails-others
+
+.* ActionView::Helpers::CaptureHelper#capture() and ActionView::Helpers::Texthelper#concat() are available.
+
+.* If Erubis::Helper::Rails.show_src is ture, Erubis prints converted Ruby code into log file (ex. 'log/development.log').
+If it is nil (default), Erubis prints converted Ruby code into log file only when development mode.
+ It is useful for debugging.
+
+
+
.$ Other Topics | topics
@@ -2505,74 +2689,6 @@ try Erubis::TinyEruby class.
-.$$ Ruby on Rails Support | topics-rails
-
-Erubis supports Ruby on Rails.
-
-.1) Add the following code to your 'config/environment.rb'.
-
- .? 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
- .--------------------
-
- This will replace ERB in Rails by Erubis entirely.
-
-.2) (Optional) apply the following patch to 'action_pack/lib/action_view/base.rb'.
-
- .? action_view_base_rb.patch
- .--------------------
- --- lib/action_view/base.rb (original)
- +++ lib/action_view/base.rb (working copy)
- @@ -445,6 +445,11 @@
- end
- end
-
- + # convert template into ruby code
- + def convert_template_into_ruby_code(template)
- + ERB.new(template, nil, @@erb_trim_mode).src
- + end
- +
- # Create source code for given template
- def create_template_source(extension, template, render_symbol, locals)
- if template_requires_setup?(extension)
- @@ -458,7 +463,7 @@
- "update_page do |page|\n#{template}\nend"
- end
- else
- - body = ERB.new(template, nil, @@erb_trim_mode).src
- + body = convert_template_into_ruby_code(template)
- end
-
- @@template_args[render_symbol] ||= {}
- .--------------------
-
- This patch is included in erubis_2.X.X/contrib directory and the following is an
- example to apply this patch.
-
- .? how to apply patch:
- .====================
- $ cd /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_view/
- $ sudo patch -p1 < /tmp/erubis_2.X.X/contrib/action_view_base_rb.patch
- .====================
-
- Notice that this patch is not necessary if you are using Ruby on Rails ver 1.1 or 1.2, but it is recommended.
-
-.3) Restart web server.
- .====================
- $ ruby script/server
- .====================
-
-ActionView::Helpers::CaptureHelper#capture() and ActionView::Helpers::Texthelper#concat() are available.
-
-If Erubis::Helper::Rails.show_src is ture, Erubis prints converted Ruby code into log file (ex. 'log/development.log').
-It is useful for debugging.
-
-
-
.$$ NoTextEnhancer and NoCodeEnhancer in PHP | topics-php
NoTextEnhancer and NoCodEnahncer are quite useful not only for eRuby but also for PHP.
@@ -2709,7 +2825,7 @@ Thanks Andrew R Jackson, he developed 'erubis-run.rb' which enables you to use E
You must set your directories to be writable by web server process, because
Apache::ErubisRun calls Erubis::Eruby.load_file() internally which creates cache files
-in the same directory as '*.rhtml' file.
+in the same directory in which '*.rhtml' file exists.
diff --git a/lib/erubis/helpers/rails_helper.rb b/lib/erubis/helpers/rails_helper.rb
index 914ef01..79d28bd 100644
--- a/lib/erubis/helpers/rails_helper.rb
+++ b/lib/erubis/helpers/rails_helper.rb
@@ -31,7 +31,8 @@ module Erubis
## 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
+ ## #Erubis::Helpers::RailsHelper.show_src = false # set true for debugging
+ ## #Erubis::Helpers::RailsHelper.preprocessing = true # set true to enable preprocessing
##
## 2. (optional) apply the patch for 'action_view/base.rb'
##
@@ -79,7 +80,7 @@ module Erubis
@@show_src = flag
end
- ##--- preprocessor: experimental ---
+ ##----- preprocessor: experimental -----
@@preprocessing = false
def self.preprocessing
@@preprocessing
@@ -98,7 +99,7 @@ module Erubis
add_expr_literal(src, "_decode((#{code}))")
end
end
- ##--------------------
+ ##----------------------------------------
end
@@ -209,20 +210,20 @@ class ActionView::Base # :nodoc:
klass = Erubis::Helpers::RailsHelper.engine_class
properties = Erubis::Helpers::RailsHelper.init_properties
show_src = Erubis::Helpers::RailsHelper.show_src
- ## --- preprocessing: experimental ---
+ ##----- preprocessing: experimental -----
if Erubis::Helpers::RailsHelper.preprocessing
preprocessor = Erubis::Helpers::RailsHelper::PreprocessingEruby.new(template)
template = self.instance_eval(preprocessor.src)
logger.debug "** Erubis: preprocessed==<<'END'\n#{template}END\n" if show_src
end
- ## ---------------------
+ ##----------------------------------------
src = klass.new(template, properties).src
#src.insert(0, '_erbout = ')
logger.debug "** Erubis: src==<<'END'\n#{src}END\n" if show_src
src
end
- ## --- preprocessing: experimental ---
+ ##----- preprocessing: experimental -----
def _expr(arg)
return "<%=#{arg}%>"
end
@@ -234,7 +235,7 @@ class ActionView::Base # :nodoc:
arg.gsub!(/&lt;%=(.*?)%&gt;/) { "<%=#{CGI.unescapeHTML($1)}%>" }
return arg
end
- ## ---------------------
+ ##----------------------------------------
end
diff --git a/website/Rookbook.rb b/website/Rookbook.rb
index d187d15..06e9778 100644
--- a/website/Rookbook.rb
+++ b/website/Rookbook.rb
@@ -16,7 +16,7 @@ copyright = parameters['copyright']
## recipes for kuwata-lab.com
##
#all = %W[index.xhtml README.xhtml #{U}.01.xhtml ChangeLog.txt]
-all = %W[index.xhtml #{U}.01.xhtml CHANGES ReleaseNote.txt]
+all = %W[index.xhtml #{U}.01.xhtml CHANGES.txt ReleaseNote.txt]
recipe :default , :all
@@ -25,7 +25,7 @@ recipe :all , all
recipe :clean do
files = []
files.concat Dir.glob("README.*")
- files.concat Dir.glob("CHANGES")
+ files.concat Dir.glob("CHANGES*")
files.concat Dir.glob("#{U}.*")
files.concat(%w[m18n.rb guide.d index.xhtml])
rm_rf [files]
@@ -78,9 +78,9 @@ recipe "index.xhtml" , "index.txt",
# sys "kwaser -t #{tagfile} -b #{@ingred} > #{@product}"
# end
-recipe "CHANGES" , "../CHANGES" do
+recipe "CHANGES.txt" , "../CHANGES" do
#copy r.ingreds[0], r.product
- cp @ingred, "."
+ cp @ingred, @product
end
recipe "ReleaseNote.txt" , "../ReleaseNote.txt" do
diff --git a/website/index.txt b/website/index.txt
index 17ba0c2..c4c5c0b 100644
--- a/website/index.txt
+++ b/website/index.txt
@@ -6,14 +6,15 @@
.$ News
+.* [2007-07-19] {{<erubis_2.4.0|download.cgi>}} released.
.* [2007-05-26] {{<erubis_2.3.1|download.cgi>}} released.
This is a bugfix release. You should update immediately.
.* [2007-05-23] {{<erubis_2.3.0|download.cgi>}} released.
.* [2007-02-12] {{<erubis_2.2.0|download.cgi>}} released.
.* [2006-09-28] {{<erubis-j_1.0.0|download.cgi>}} (porting to Java) released.
.* [2006-09-24] {{<erubis_2.1.0|download.cgi>}} released.
-.* [2006-05-20] {{<erubis_2.0.0|download.cgi>}} released.
-.* [2006-03-05] {{<erubis_1.1.0|download.cgi>}} released.
+.#.* [2006-05-20] {{<erubis_2.0.0|download.cgi>}} released.
+.#.* [2006-03-05] {{<erubis_1.1.0|download.cgi>}} released.
.#.* [2006-05-20] {{<erubis_2.0.0|http://rubyforge.org/projects/erubis/>}} released.
.#.* [2006-03-05] {{<erubis_1.1.0|http://rubyforge.org/projects/erubis/>}} released.
@@ -109,7 +110,7 @@ You can use Erubis in Java with Rhino.
.$ Download
- .* Erubis 2.3.0 (implemented in Ruby)
+ .* Erubis 2.4.0 (implemented in Ruby)
.- if you have installed RubyGems, just type `{{,gem install -r erubis,}}' to install Erubis
.- Or {{<download|download.cgi>}}.^
(Erubis requires {{<abstract|http://rubyforge.org/projects/abstract>}} library.
@@ -119,9 +120,9 @@ You can use Erubis in Java with Rhino.
.$ Documents
.#.* {{<README|README.en.html>}}
- .* Erubis 2.3.0 (implemented in Ruby)
+ .* Erubis 2.4.0 (implemented in Ruby)
.- {{<User's guide|users-guide.html>}}
- .- {{<CHANGES|CHANGES>}}
+ .- {{<CHANGES|CHANGES.txt>}}
.#.- {{<ReleaseNote|ReleaseNote.txt>}}
.* Erubis-J 1.0.0 (implemented in Java)
.- {{<User's guide|erubisj-users-guide.html>}}
diff --git a/website/index.xhtml b/website/index.xhtml
index 5546f2c..92990e8 100644
--- a/website/index.xhtml
+++ b/website/index.xhtml
@@ -24,6 +24,8 @@
<a name="News"></a>
<h2 class="section">News</h2>
<ul class="ul1">
+<li>[2007-07-19] <a href="download.cgi">erubis_2.4.0</a> released.
+</li>
<li>[2007-05-26] <a href="download.cgi">erubis_2.3.1</a> released.
This is a bugfix release. You should update immediately.
</li>
@@ -35,10 +37,6 @@
</li>
<li>[2006-09-24] <a href="download.cgi">erubis_2.1.0</a> released.
</li>
-<li>[2006-05-20] <a href="download.cgi">erubis_2.0.0</a> released.
-</li>
-<li>[2006-03-05] <a href="download.cgi">erubis_1.1.0</a> released.
-</li>
</ul>
@@ -151,7 +149,7 @@ You can use Erubis in Java with Rhino.
<a name="Download"></a>
<h2 class="section">Download</h2>
<ul class="ul1">
- <li>Erubis 2.3.0 (implemented in Ruby)
+ <li>Erubis 2.4.0 (implemented in Ruby)
<ul class="ul2">
<li>if you have installed RubyGems, just type `<code>gem install -r erubis</code>' to install Erubis
</li>
@@ -174,11 +172,11 @@ You can use Erubis in Java with Rhino.
<a name="Documents"></a>
<h2 class="section">Documents</h2>
<ul class="ul1">
- <li>Erubis 2.3.0 (implemented in Ruby)
+ <li>Erubis 2.4.0 (implemented in Ruby)
<ul class="ul2">
<li><a href="users-guide.html">User's guide</a>
</li>
- <li><a href="CHANGES">CHANGES</a>
+ <li><a href="CHANGES.txt">CHANGES</a>
</li>
</ul>
</li>