summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
author(no author) <(no author)@c9e70521-770b-0410-b9ac-ce6205b42a9f>2007-03-05 02:13:12 +0000
committer(no author) <(no author)@c9e70521-770b-0410-b9ac-ce6205b42a9f>2007-03-05 02:13:12 +0000
commitacdd8b2b37dee6a5a42d8ffd74c7d31e61191563 (patch)
treedf1995ef60b5563b25b8c31d698580ec5d8f6931 /doc
parentb33d57b596fbbc1082ec3ea3d2b2b3d158241534 (diff)
downloaderubis-acdd8b2b37dee6a5a42d8ffd74c7d31e61191563.tar.gz
- [enhance] add ErboutEnhancer
- [enhance] add ExpressionInterpolationEnhancer
Diffstat (limited to 'doc')
-rw-r--r--doc/users-guide.html77
-rw-r--r--doc/users-guide.txt91
2 files changed, 160 insertions, 8 deletions
diff --git a/doc/users-guide.html b/doc/users-guide.html
index 36a93ba..b9355b3 100644
--- a/doc/users-guide.html
+++ b/doc/users-guide.html
@@ -99,6 +99,8 @@ It has the following features.
</li>
<li><a href="#stringbuffer-enhancer">StringBufferEnhancer</a>
</li>
+ <li><a href="#erbout-enhancer">ErboutEnhancer</a>
+ </li>
<li><a href="#notext-enhancer">NoTextEnhancer</a>
</li>
<li><a href="#nocode-enhancer">NoCodeEnhancer</a>
@@ -111,6 +113,8 @@ It has the following features.
</li>
<li><a href="#headerfooter-enhancer">HeaderFooterEnhancer</a>
</li>
+ <li><a href="#expressioninterpolation-enhancer">ExpressionInterpolationEnhancer</a>
+ </li>
</ul>
</li>
<li><a href="#lang">Multi-Language</a>
@@ -998,12 +1002,17 @@ The following is an example to use some enhancers in command-line.
<dt class="dt1">
<a href="#arraybuffer-enhancer">ArrayBufferEnhancer</a> (only for Eruby)</dt>
<dd class="dd1">
- Use array buffer. This is included in Erubis::Eruby by default.
+ Use array buffer. It is a little slower than StringBufferEnhancer.
</dd>
<dt class="dt1">
<a href="#stringbuffer-enhancer">StringBufferEnhancer</a> (only for Eruby)</dt>
<dd class="dd1">
- Use string buffer. It is a little slower than ArrayBufferEnhancer.
+ Use string buffer. This is included in Erubis::Eruby by default.
+</dd>
+<dt class="dt1">
+<a href="#erbout-enhancer">ErboutEnhancer</a> (only for Eruby)</dt>
+<dd class="dd1">
+ Set '_erbout = _buf = "";' to be compatible with ERB.
</dd>
<dt class="dt1">
<a href="#notext-enhancer">NoTextEnhancer</a> (language-independent)</dt>
@@ -1035,6 +1044,11 @@ The following is an example to use some enhancers in command-line.
<dd class="dd1">
[experimental] Enable you to add header and footer in eRuby script.
</dd>
+<dt class="dt1">
+<a href="#expressioninterpolation-enhancer">ExpressionInterpolationEnhancer</a> (only for Eruby)</dt>
+<dd class="dd1">
+ [experimental] convert '&lt;p&gt;&lt;%= text %&gt;&lt;/p&gt;' into '_buf &lt;&lt; %Q`&lt;p&gt;#{text}&lt;/p&gt;`'.
+</dd>
</dl>
<p>If you required 'erubis/engine/enhanced', Eruby subclasses which include each enhancers are defined.
For example, class BiPatternEruby includes BiPatternEnhancer.
@@ -1156,7 +1170,8 @@ because print() method in '&lt;% ... %&gt;' invokes not Kernel#print() but Print
</p>
<div class="terminal_caption">
compiled source code</div>
-<pre class="terminal"><strong>_buf = [];</strong> _buf &lt;&lt; '&lt;div&gt;
+<pre class="terminal">$ erubis -xE Array example.eruby
+<strong>_buf = [];</strong> _buf &lt;&lt; '&lt;div&gt;
'; for item in list
_buf &lt;&lt; ' &lt;p&gt;'; _buf &lt;&lt; ( item ).to_s; _buf &lt;&lt; '&lt;/p&gt;
&lt;p&gt;'; _buf &lt;&lt; Erubis::XmlHelper.escape_xml( item ); _buf &lt;&lt; '&lt;/p&gt;
@@ -1185,7 +1200,7 @@ Array buffer is a litte slower than String buffer.
'; end
_buf &lt;&lt; '&lt;/div&gt;
';
-<strong>_buf</strong>.join
+<strong>_buf.join</strong>
</pre>
<br>
@@ -1201,6 +1216,26 @@ Erubis::Eruby includes this enhancer by default.
<br>
+<a name="erbout-enhancer"></a>
+<h3 class="section2">ErboutEnhancer</h3>
+<p>ErboutEnhancer makes Eruby to be compatible with ERB.
+This is useful especially for Ruby on Rails.
+</p>
+<pre class="terminal">$ erubis -xE Erbout example.eruby
+<strong>_erbout = _buf = '';</strong> _buf &lt;&lt; '&lt;div&gt;
+'; for item in list
+ _buf &lt;&lt; ' &lt;p&gt;'; _buf &lt;&lt; ( item ).to_s; _buf &lt;&lt; '&lt;/p&gt;
+ &lt;p&gt;'; _buf &lt;&lt; Erubis::XmlHelper.escape_xml( item ); _buf &lt;&lt; '&lt;/p&gt;
+'; end
+ _buf &lt;&lt; '&lt;/div&gt;
+';
+_buf.to_s
+</pre>
+<p>ErboutEnhancer is only for Eruby.
+</p>
+<br>
+
+
<a name="notext-enhancer"></a>
<h3 class="section2">NoTextEnhancer</h3>
<p>NoTextEnhancer suppress output of text and prints only embedded code.
@@ -1471,6 +1506,40 @@ _buf.to_s
<br>
+<a name="expressioninterpolation-enhancer"></a>
+<h3 class="section2">ExpressionInterpolationEnhancer</h3>
+<p>[experimental]
+</p>
+<p>ExpressionInterpolationEnhancer converts "&lt;h1&gt;&lt;%= title %&gt;&lt;/h1&gt;" into
+"_buf &lt;&lt; %Q`&lt;h1&gt;#{ title }&lt;/h1&gt;`".
+This makes Eruby a litter faster because method call of String#&lt;&lt; are eliminated
+by expression interpolations.
+</p>
+<div class="program_caption">
+ExpressionInterpolationEnhancer elmininates method call of String#&lt;&lt;.</div>
+<pre class="program">## Assume that input is '&lt;a href="&lt;%=url%&gt;"&gt;&lt;%=name%&gt;&lt;/a&gt;'.
+## Eruby convert input into the following code. String#&lt;&lt; is called 5 times.
+_buf &lt;&lt; '&lt;a href="'; _buf &lt;&lt; (url).to_s; _buf &lt;&lt; '"&gt;'; _buf &lt;&lt; (name).to_s; _buf &lt;&lt; '&lt;/a&gt;';
+
+## If ExpressionInterpolationEnhancer is used, String#&lt;&lt; is called only once.
+_buf &lt;&lt; %Q`&lt;a href="#{url}"&gt;#{name}&lt;/a&gt;`;
+</pre>
+<div class="terminal_caption">
+compiled source code</div>
+<pre class="terminal">$ erubis -xE ExpressionInterpolation example.eruby
+_buf = ''; _buf &lt;&lt; <strong>%Q`</strong>&lt;div&gt;\n<strong>`</strong>
+ for item in list
+ _buf &lt;&lt; <strong>%Q`</strong> &lt;p&gt;<strong>#{ item }</strong>&lt;/p&gt;
+ &lt;p&gt;<strong>#{Erubis::XmlHelper.escape_xml( item )}</strong>&lt;/p&gt;\n<strong>`</strong>
+ end
+ _buf &lt;&lt; <strong>%Q`</strong>&lt;/div&gt;\n<strong>`</strong>
+_buf.to_s
+</pre>
+<p>ExpressionInterpolationEnhancer is only for Eruby.
+</p>
+<br>
+
+
<br>
diff --git a/doc/users-guide.txt b/doc/users-guide.txt
index fd766d0..e129044 100644
--- a/doc/users-guide.txt
+++ b/doc/users-guide.txt
@@ -735,9 +735,11 @@ The following is the list of enhancers.
.: {{<ArrayEnhancer|#array-enhancer>}} (only for Eruby)
Return array of string instead of returning string.
.: {{<ArrayBufferEnhancer|#arraybuffer-enhancer>}} (only for Eruby)
- Use array buffer. This is included in Erubis::Eruby by default.
+ Use array buffer. It is a little slower than StringBufferEnhancer.
.: {{<StringBufferEnhancer|#stringbuffer-enhancer>}} (only for Eruby)
- Use string buffer. It is a little slower than ArrayBufferEnhancer.
+ Use string buffer. This is included in Erubis::Eruby by default.
+.: {{<ErboutEnhancer|#erbout-enhancer>}} (only for Eruby)
+ Set '_erbout = _buf = "";' to be compatible with ERB.
.: {{<NoTextEnhancer|#notext-enhancer>}} (language-independent)
Print embedded code only and ignore normal text.
.: {{<NoCodeEnhancer|#nocode-enhancer>}} (language-independent)
@@ -750,6 +752,8 @@ The following is the list of enhancers.
Regard lines starting with '%' as Ruby code. This is for compatibility with eruby and ERB.
.: {{<HeaderFooterEnhancer|#headerfooter-enhancer>}} (language-independent)
[experimental] Enable you to add header and footer in eRuby script.
+.: {{<ExpressionInterpolationEnhancer|#expressioninterpolation-enhancer>}} (only for Eruby)
+ [experimental] convert '<p><%= text %></p>' into '_buf << %Q`<p>#{text}</p>`'.
If you required 'erubis/engine/enhanced', Eruby subclasses which include each enhancers are defined.
@@ -926,6 +930,7 @@ ArrayEnhancer makes Eruby to return an array of strings.
.? compiled source code
.====================
+$ erubis -xE Array example.eruby
.<<<:! erubis -xE Array guide.d/example.eruby | ruby -pe 'sub! /^_buf( = \[\];)?/, "{{*\\&*}}"'
.====================
@@ -942,7 +947,7 @@ ArrayBufferEnhancer is only for Eruby.
.====================
$ erubis -xE ArrayBuffer example.eruby
-.<<<:! erubis -xE ArrayBuffer guide.d/example.eruby | ruby -pe 'sub!(/^_buf( = ..;|\.to_s)?/,"{{*\\&*}}")'
+.<<<:! erubis -xE ArrayBuffer guide.d/example.eruby | ruby -pe 'sub!(/^_buf( = .*?;|\.join)?/,"{{*\\&*}}")'
.====================
@@ -972,7 +977,7 @@ Erubis::Eruby includes this enhancer by default.
.#.====================
.#$ erubis -xE StringBuffer example.eruby
-.#.<<<:! erubis -xE StringBuffer guide.d/example.eruby | ruby -pe 'sub!(/^_buf( = ..;)?/,"{{*\\&*}}")'
+.#.<<<:! erubis -xE StringBuffer guide.d/example.eruby | ruby -pe 'sub!(/^_buf( = .*?;)?/,"{{*\\&*}}")'
.#.====================
@@ -980,6 +985,37 @@ StringBufferEnhancer is only for Eruby.
+.$$ ErboutEnhancer | erbout-enhancer
+
+ErboutEnhancer makes Eruby to be compatible with ERB.
+This is useful especially for Ruby on Rails.
+
+.#.? erbout-example.rb
+.#.-------------------- erbout-example.rb
+.#require 'erubis'
+.#class ErboutEruby < Erubis::Eruby
+.# include Erubis::ErboutEnhancer
+.#end
+.#eruby = ErboutEruby.new(File.read('example.eruby'))
+.#print eruby.src
+.#.--------------------
+.#
+.#.? compiled source code
+.#.====================
+.#$ ruby erbout-example.rb
+.#.<<<:! (cd guide.d; ruby erbout-example.rb)
+.#.====================
+
+.====================
+$ erubis -xE Erbout example.eruby
+.<<<:! erubis -xE Erbout guide.d/example.eruby | ruby -pe 'sub! /^_erbout = _buf = .*?;/,"{{*\\&*}}"'
+.====================
+
+
+ErboutEnhancer is only for Eruby.
+
+
+
.$$ NoTextEnhancer | notext-enhancer
NoTextEnhancer suppress output of text and prints only embedded code.
@@ -1269,6 +1305,53 @@ HeaderFooterEnhancer is experimental and is language-independent.
+.$$ ExpressionInterpolationEnhancer | expressioninterpolation-enhancer
+
+[experimental]
+
+ExpressionInterpolationEnhancer converts "<h1><%= title %></h1>" into
+"_buf << %Q`<h1>#{ title }</h1>`".
+This makes Eruby a litter faster because method call of String#<< are eliminated
+by expression interpolations.
+
+.? ExpressionInterpolationEnhancer elmininates method call of String#<<.
+.--------------------
+## Assume that input is '<a href="<%=url%>"><%=name%></a>'.
+## Eruby convert input into the following code. String#<< is called 5 times.
+_buf << '<a href="'; _buf << (url).to_s; _buf << '">'; _buf << (name).to_s; _buf << '</a>';
+
+## If ExpressionInterpolationEnhancer is used, String#<< is called only once.
+_buf << %Q`<a href="#{url}">#{name}</a>`;
+.--------------------
+
+.#.? expressioninterpolation-example.rb
+.#.-------------------- expressioninterpolation-example.rb
+.#require 'erubis'
+.#class ExpressionInterpolationEruby < Erubis::Eruby
+.# include Erubis::ExpressionInterpolationEnhancer
+.#end
+.#eruby = ExpressionInterpolationEruby.new(File.read('example.eruby'))
+.### or
+.##eruby = Erubis::FastEruby.new(File.read('example.eruby'))
+.#print eruby.src
+.#.--------------------
+.#
+.#.? compiled source code
+.#.====================
+.#$ ruby expressioninterpolation-example.rb
+.#.<<<:! (cd guide.d; ruby expressioninterpolation-example.rb)
+.#.====================
+
+.? compiled source code
+.====================
+$ erubis -xE ExpressionInterpolation example.eruby
+.<<<:! erubis -xE ExpressionInterpolation guide.d/example.eruby | ruby -pe 'gsub! /(%Q`|`|\#\{.*?\})/, "{{*\\&*}}"'
+.====================
+
+ExpressionInterpolationEnhancer is only for Eruby.
+
+
+
.$ Multi-Language | lang
Erubis supports the following language currently: