diff options
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 |
commit | acdd8b2b37dee6a5a42d8ffd74c7d31e61191563 (patch) | |
tree | df1995ef60b5563b25b8c31d698580ec5d8f6931 /doc | |
parent | b33d57b596fbbc1082ec3ea3d2b2b3d158241534 (diff) | |
download | erubis-acdd8b2b37dee6a5a42d8ffd74c7d31e61191563.tar.gz |
- [enhance] add ErboutEnhancer
- [enhance] add ExpressionInterpolationEnhancer
Diffstat (limited to 'doc')
-rw-r--r-- | doc/users-guide.html | 77 | ||||
-rw-r--r-- | doc/users-guide.txt | 91 |
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 '<p><%= text %></p>' into '_buf << %Q`<p>#{text}</p>`'. +</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 '<% ... %>' invokes not Kernel#print() but Print </p> <div class="terminal_caption"> compiled source code</div> -<pre class="terminal"><strong>_buf = [];</strong> _buf << '<div> +<pre class="terminal">$ erubis -xE Array example.eruby +<strong>_buf = [];</strong> _buf << '<div> '; for item in list _buf << ' <p>'; _buf << ( item ).to_s; _buf << '</p> <p>'; _buf << Erubis::XmlHelper.escape_xml( item ); _buf << '</p> @@ -1185,7 +1200,7 @@ Array buffer is a litte slower than String buffer. '; end _buf << '</div> '; -<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 << '<div> +'; for item in list + _buf << ' <p>'; _buf << ( item ).to_s; _buf << '</p> + <p>'; _buf << Erubis::XmlHelper.escape_xml( item ); _buf << '</p> +'; end + _buf << '</div> +'; +_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 "<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. +</p> +<div class="program_caption"> +ExpressionInterpolationEnhancer elmininates method call of String#<<.</div> +<pre class="program">## 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>`; +</pre> +<div class="terminal_caption"> +compiled source code</div> +<pre class="terminal">$ erubis -xE ExpressionInterpolation example.eruby +_buf = ''; _buf << <strong>%Q`</strong><div>\n<strong>`</strong> + for item in list + _buf << <strong>%Q`</strong> <p><strong>#{ item }</strong></p> + <p><strong>#{Erubis::XmlHelper.escape_xml( item )}</strong></p>\n<strong>`</strong> + end + _buf << <strong>%Q`</strong></div>\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: |