erubis 2.0.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. data/ChangeLog +150 -2
  2. data/LGPL +504 -0
  3. data/README.txt +14 -8
  4. data/benchmark/erubybench.rb +1 -1
  5. data/benchmark/erubybench.rhtml +3 -3
  6. data/bin/erubis +1 -1
  7. data/bin/notext +154 -0
  8. data/contrib/erubis +1036 -374
  9. data/contrib/inline-require +5 -3
  10. data/doc-api/classes/Erubis.html +43 -1
  11. data/doc-api/classes/Erubis/ArrayBufferEnhancer.html +14 -14
  12. data/doc-api/classes/Erubis/ArrayEnhancer.html +14 -14
  13. data/doc-api/classes/Erubis/Basic.html +112 -0
  14. data/doc-api/classes/Erubis/Basic/Converter.html +318 -0
  15. data/doc-api/classes/Erubis/Basic/Engine.html +130 -0
  16. data/doc-api/classes/Erubis/BiPatternEnhancer.html +14 -14
  17. data/doc-api/classes/Erubis/CGenerator.html +386 -0
  18. data/doc-api/classes/Erubis/Context.html +31 -32
  19. data/doc-api/classes/Erubis/Converter.html +231 -0
  20. data/doc-api/classes/Erubis/Ec.html +9 -283
  21. data/doc-api/classes/Erubis/Ejava.html +9 -274
  22. data/doc-api/classes/Erubis/Ejavascript.html +9 -298
  23. data/doc-api/classes/Erubis/Engine.html +68 -508
  24. data/doc-api/classes/Erubis/Eperl.html +9 -259
  25. data/doc-api/classes/Erubis/Ephp.html +9 -239
  26. data/doc-api/classes/Erubis/ErubisError.html +2 -2
  27. data/doc-api/classes/Erubis/Eruby.html +4 -187
  28. data/doc-api/classes/Erubis/EscapeEnhancer.html +9 -11
  29. data/doc-api/classes/Erubis/Escheme.html +9 -272
  30. data/doc-api/classes/Erubis/Evaluator.html +212 -0
  31. data/doc-api/classes/Erubis/Generator.html +410 -0
  32. data/doc-api/classes/Erubis/HeaderFooterEnhancer.html +16 -16
  33. data/doc-api/classes/Erubis/Helper.html +112 -0
  34. data/doc-api/classes/Erubis/Helper/CachedRailsTemplate.html +198 -0
  35. data/doc-api/classes/Erubis/Helper/RailsTemplate.html +366 -0
  36. data/doc-api/classes/Erubis/JavaGenerator.html +359 -0
  37. data/doc-api/classes/Erubis/JavascriptGenerator.html +381 -0
  38. data/doc-api/classes/Erubis/Main.html +27 -25
  39. data/doc-api/classes/Erubis/NoCodeEnhancer.html +249 -0
  40. data/doc-api/classes/Erubis/NoCodeEruby.html +120 -0
  41. data/doc-api/classes/Erubis/NoTextEnhancer.html +8 -8
  42. data/doc-api/classes/Erubis/NotSupportedError.html +119 -0
  43. data/doc-api/classes/Erubis/OptimizedEruby.html +22 -304
  44. data/doc-api/classes/Erubis/OptimizedGenerator.html +439 -0
  45. data/doc-api/classes/Erubis/OptimizedXmlEruby.html +7 -7
  46. data/doc-api/classes/Erubis/PI.html +124 -0
  47. data/doc-api/classes/Erubis/PI/Converter.html +318 -0
  48. data/doc-api/classes/Erubis/PI/Ec.html +166 -0
  49. data/doc-api/classes/Erubis/PI/Ejava.html +166 -0
  50. data/doc-api/classes/Erubis/PI/Ejavascript.html +166 -0
  51. data/doc-api/classes/Erubis/PI/Engine.html +122 -0
  52. data/doc-api/classes/Erubis/PI/Eperl.html +166 -0
  53. data/doc-api/classes/Erubis/PI/Ephp.html +166 -0
  54. data/doc-api/classes/Erubis/PI/Eruby.html +155 -0
  55. data/doc-api/classes/Erubis/PI/Escheme.html +166 -0
  56. data/doc-api/classes/Erubis/PI/TinyEruby.html +305 -0
  57. data/doc-api/classes/Erubis/PercentLineEnhancer.html +7 -7
  58. data/doc-api/classes/Erubis/PerlGenerator.html +344 -0
  59. data/doc-api/classes/Erubis/PhpGenerator.html +350 -0
  60. data/doc-api/classes/Erubis/PrintEnabledEnhancer.html +24 -24
  61. data/doc-api/classes/Erubis/PrintOutEnhancer.html +35 -35
  62. data/doc-api/classes/Erubis/RubyEvaluator.html +190 -0
  63. data/doc-api/classes/Erubis/RubyGenerator.html +327 -0
  64. data/doc-api/classes/Erubis/SchemeGenerator.html +382 -0
  65. data/doc-api/classes/Erubis/SimplifyEnhancer.html +17 -13
  66. data/doc-api/classes/Erubis/StdoutEnhancer.html +14 -14
  67. data/doc-api/classes/Erubis/StringBufferEnhancer.html +14 -14
  68. data/doc-api/classes/Erubis/TinyEruby.html +45 -40
  69. data/doc-api/classes/Erubis/XmlHelper.html +14 -14
  70. data/doc-api/created.rid +1 -1
  71. data/doc-api/files/__/README_txt.html +27 -9
  72. data/doc-api/files/erubis/context_rb.html +107 -0
  73. data/doc-api/files/erubis/converter_rb.html +114 -0
  74. data/doc-api/files/erubis/engine/ec_rb.html +2 -2
  75. data/doc-api/files/erubis/engine/ejava_rb.html +2 -2
  76. data/doc-api/files/erubis/engine/ejavascript_rb.html +2 -2
  77. data/doc-api/files/erubis/engine/enhanced_rb.html +2 -2
  78. data/doc-api/files/erubis/engine/eperl_rb.html +2 -2
  79. data/doc-api/files/erubis/engine/ephp_rb.html +2 -2
  80. data/doc-api/files/erubis/engine/eruby_rb.html +3 -2
  81. data/doc-api/files/erubis/engine/escheme_rb.html +2 -2
  82. data/doc-api/files/erubis/engine/optimized_rb.html +2 -2
  83. data/doc-api/files/erubis/engine_rb.html +6 -3
  84. data/doc-api/files/erubis/enhancer_rb.html +2 -9
  85. data/doc-api/files/erubis/error_rb.html +107 -0
  86. data/doc-api/files/erubis/evaluator_rb.html +115 -0
  87. data/doc-api/files/erubis/generator_rb.html +114 -0
  88. data/doc-api/files/erubis/helper/rails_rb.html +140 -0
  89. data/doc-api/files/erubis/helper_rb.html +1 -1
  90. data/doc-api/files/erubis/local-setting_rb.html +1 -1
  91. data/doc-api/files/erubis/main_rb.html +2 -2
  92. data/doc-api/files/erubis/tiny_rb.html +2 -2
  93. data/doc-api/files/erubis_rb.html +2 -2
  94. data/doc-api/fr_class_index.html +32 -0
  95. data/doc-api/fr_file_index.html +6 -0
  96. data/doc-api/fr_method_index.html +178 -136
  97. data/doc/users-guide.html +538 -199
  98. data/examples/{Makefile → basic/Makefile} +11 -11
  99. data/examples/basic/example.ec +42 -0
  100. data/examples/{example.ejava → basic/example.ejava} +5 -1
  101. data/examples/{example.ejavascript → basic/example.ejs} +0 -0
  102. data/examples/{example.eperl → basic/example.eperl} +2 -2
  103. data/examples/{example.ephp → basic/example.ephp} +0 -0
  104. data/examples/{example.eruby → basic/example.eruby} +0 -0
  105. data/examples/{example.escheme → basic/example.escheme} +0 -0
  106. data/examples/pi/Makefile +54 -0
  107. data/examples/pi/example.ec +42 -0
  108. data/examples/pi/example.ejava +45 -0
  109. data/examples/pi/example.ejs +16 -0
  110. data/examples/pi/example.eperl +16 -0
  111. data/examples/pi/example.ephp +17 -0
  112. data/examples/pi/example.eruby +15 -0
  113. data/examples/pi/example.escheme +26 -0
  114. data/lib/erubis.rb +15 -8
  115. data/lib/erubis/context.rb +54 -0
  116. data/lib/erubis/converter.rb +307 -0
  117. data/lib/erubis/engine.rb +57 -227
  118. data/lib/erubis/engine/ec.rb +31 -20
  119. data/lib/erubis/engine/ejava.rb +33 -21
  120. data/lib/erubis/engine/ejavascript.rb +30 -18
  121. data/lib/erubis/engine/enhanced.rb +7 -2
  122. data/lib/erubis/engine/eperl.rb +33 -19
  123. data/lib/erubis/engine/ephp.rb +32 -14
  124. data/lib/erubis/engine/eruby.rb +34 -7
  125. data/lib/erubis/engine/escheme.rb +34 -15
  126. data/lib/erubis/engine/optimized.rb +25 -11
  127. data/lib/erubis/enhancer.rb +53 -19
  128. data/lib/erubis/error.rb +24 -0
  129. data/lib/erubis/evaluator.rb +71 -0
  130. data/lib/erubis/generator.rb +83 -0
  131. data/lib/erubis/helper.rb +1 -1
  132. data/lib/erubis/helper/rails.rb +159 -0
  133. data/lib/erubis/local-setting.rb +1 -1
  134. data/lib/erubis/main.rb +87 -46
  135. data/lib/erubis/tiny.rb +81 -7
  136. data/test/assert-text-equal.rb +1 -1
  137. data/test/test-engines.rb +8 -9
  138. data/test/test-erubis.rb +196 -18
  139. data/test/{test-bin.rb → test-main.rb} +123 -21
  140. data/test/test-notext.rb +27 -0
  141. data/test/test.rb +5 -3
  142. data/test/testutil.rb +25 -36
  143. metadata +75 -13
  144. data/COPYING +0 -340
  145. data/examples/example.ec +0 -24
@@ -14,7 +14,7 @@
14
14
 
15
15
  <div align="left"><h1>Erubis Users' Guide</h1></div>
16
16
  <div align="left">
17
- last update: $Date: 2006-05-20 08:57:39 +0900 (Sat, 20 May 2006) $<br>
17
+ last update: $Date: 2006-09-24 21:01:00 +0900 (Sun, 24 Sep 2006) $<br>
18
18
  </div>
19
19
 
20
20
  <a name="preface"></a>
@@ -23,7 +23,7 @@
23
23
  It has the following features.
24
24
  </p>
25
25
  <ul type="disc">
26
- <li>Very fast, almost three times faster than ERB and even as fast as eruby (implemented in C)
26
+ <li>Very fast, almost three times faster than ERB and even faster than eruby (implemented in C)
27
27
  </li>
28
28
  <li>Auto escaping support
29
29
  </li>
@@ -31,13 +31,17 @@ It has the following features.
31
31
  </li>
32
32
  <li>Embedded pattern changeable (default '&lt;% %&gt;')
33
33
  </li>
34
- <li>Support multi-language (Ruby/PHP/C/Java/Scheme/Perl/Javascript)
34
+ <li>Enable to handle Processing Instructions (PI) as embedded pattern (ex. '&lt;?rb ... ?&gt;')
35
+ </li>
36
+ <li>Multi-language support (Ruby/PHP/C/Java/Scheme/Perl/Javascript)
35
37
  </li>
36
38
  <li>Context object available and easy to combine eRuby template with YAML datafile
37
39
  </li>
38
40
  <li>Print statement available
39
41
  </li>
40
- <li>Easy to extend in subclass
42
+ <li>Easy to expand and customize in subclass
43
+ </li>
44
+ <li>Ruby on Rails support
41
45
  </li>
42
46
  </ul>
43
47
  <p>Erubis is implemented in pure Ruby. It requires Ruby 1.8 or higher.
@@ -69,6 +73,8 @@ It has the following features.
69
73
  </li>
70
74
  <li><a href="#tut-preamble">Preamble and Postamble</a>
71
75
  </li>
76
+ <li><a href="#tut-pi">Processing Instruction (PI) Converter</a>
77
+ </li>
72
78
  </ul>
73
79
  </li>
74
80
  <li><a href="#enhancer">Enhancer</a>
@@ -89,6 +95,8 @@ It has the following features.
89
95
  </li>
90
96
  <li><a href="#notext-enhancer">NoTextEnhancer</a>
91
97
  </li>
98
+ <li><a href="#nocode-enhancer">NoCodeEnhancer</a>
99
+ </li>
92
100
  <li><a href="#simplify-enhancer">SimplifyEnhancer</a>
93
101
  </li>
94
102
  <li><a href="#bipattern-enhancer">BiPatternEnhancer</a>
@@ -119,7 +127,11 @@ It has the following features.
119
127
  <ul>
120
128
  <li><a href="#topics-tinyeruby">TinyEruby class</a>
121
129
  </li>
122
- <li><a href="#topics-php">NoTextEnhancer in PHP</a>
130
+ <li><a href="#topics-rails">Ruby on Rails Support</a>
131
+ </li>
132
+ <li><a href="#topics-php">NoTextEnhancer and NoCodeEnhancer in PHP</a>
133
+ </li>
134
+ <li><a href="#topics-notext">Command <code>notext</code></a>
123
135
  </li>
124
136
  <li><a href="#topics-benchmark">Benchmark</a>
125
137
  </li>
@@ -185,10 +197,10 @@ $ contrib/inline-require -I lib bin/erubis &gt; contrib/erubis
185
197
  <div class="program_caption">
186
198
  example1.eruby</div>
187
199
  <pre class="program">&lt;ul&gt;
188
- <b>&lt;% for item in list %&gt;</b>
189
- &lt;li&gt;<b>&lt;%= item %&gt;</b>&lt;/li&gt;
190
- <b>&lt;% end %&gt;</b>
191
- <b>&lt;%# here is ignored because starting with '#' %&gt;</b>
200
+ <strong>&lt;% for item in list %&gt;</strong>
201
+ &lt;li&gt;<strong>&lt;%= item %&gt;</strong>&lt;/li&gt;
202
+ <strong>&lt;% end %&gt;</strong>
203
+ <strong>&lt;%# here is ignored because starting with '#' %&gt;</strong>
192
204
  &lt;/ul&gt;
193
205
  </pre>
194
206
  <a name="example1.rb"></a>
@@ -196,14 +208,20 @@ example1.eruby</div>
196
208
  example1.rb</div>
197
209
  <pre class="program">require 'erubis'
198
210
  input = File.read('example1.eruby')
199
- eruby = <b>Erubis::Eruby.new(input)</b> # create Eruby object
211
+ eruby = <strong>Erubis::Eruby.new(input)</strong> # create Eruby object
200
212
 
201
213
  puts "---------- script source ---"
202
- puts <b>eruby.src</b> # print script source
214
+ puts <strong>eruby.src</strong> # print script source
203
215
 
204
216
  puts "---------- result ----------"
205
217
  list = ['aaa', 'bbb', 'ccc']
206
- puts <b>eruby.result(binding())</b> # get result
218
+ puts <strong>eruby.result(binding())</strong> # get result
219
+
220
+ ## # or
221
+ ## eruby = Erubis::Eruby.new
222
+ ## input = File.read('example1.eruby')
223
+ ## src = eruby.convert(input)
224
+ ## eval src
207
225
  </pre>
208
226
  <div class="terminal_caption">
209
227
  output</div>
@@ -228,7 +246,7 @@ _buf.join
228
246
  </p>
229
247
  <div class="terminal_caption">
230
248
  example of command-line option '-x'</div>
231
- <pre class="terminal">$ erubis <b>-x</b> example1.eruby
249
+ <pre class="terminal">$ erubis <strong>-x</strong> example1.eruby
232
250
  _buf = []; _buf &lt;&lt; '&lt;ul&gt;
233
251
  '; for item in list
234
252
  _buf &lt;&lt; ' &lt;li&gt;'; _buf &lt;&lt; ( item ).to_s; _buf &lt;&lt; '&lt;/li&gt;
@@ -273,7 +291,7 @@ _buf.join
273
291
  </p>
274
292
  <div class="terminal_caption">
275
293
  compiled source code with command-line option '-T'</div>
276
- <pre class="terminal">$ erubis -x <b>-T</b> example2.eruby
294
+ <pre class="terminal">$ erubis -x <strong>-T</strong> example2.eruby
277
295
  _buf = []; _buf &lt;&lt; '&lt;ul&gt;
278
296
  '; _buf &lt;&lt; ' '; for item in list ; _buf &lt;&lt; '
279
297
  '; _buf &lt;&lt; ' &lt;li&gt;
@@ -291,7 +309,7 @@ _buf.join
291
309
  example2.rb</div>
292
310
  <pre class="program">require 'erubis'
293
311
  input = File.read('example2.eruby')
294
- eruby = Erubis::Eruby.new(input<b>, :trim=&gt;false</b>)
312
+ eruby = Erubis::Eruby.new(input<strong>, :trim=&gt;false</strong>)
295
313
 
296
314
  puts "---------- script source ---"
297
315
  puts eruby.src # print script source
@@ -339,13 +357,13 @@ _buf.join
339
357
  Erubis::Eruby class act as the following:
340
358
  </p>
341
359
  <ul type="disc">
342
- <li><code>&lt;%= <i>expr</i> %&gt;</code> - not escaped.
360
+ <li><code>&lt;%= <em>expr</em> %&gt;</code> - not escaped.
343
361
  </li>
344
- <li><code>&lt;%== <i>expr</i> %&gt;</code> - escaped.
362
+ <li><code>&lt;%== <em>expr</em> %&gt;</code> - escaped.
345
363
  </li>
346
- <li><code>&lt;%=== <i>expr</i> %&gt;</code> - out to $stderr.
364
+ <li><code>&lt;%=== <em>expr</em> %&gt;</code> - out to $stderr.
347
365
  </li>
348
- <li><code>&lt;%==== <i>expr</i> %&gt;</code> - ignored.
366
+ <li><code>&lt;%==== <em>expr</em> %&gt;</code> - ignored.
349
367
  </li>
350
368
  </ul>
351
369
  <p>Erubis::EscapedEruby<sup>(<a href="#fnref:1" name="fnlink:1">*1</a>)</sup> class handle '&lt;%= %&gt;' as escaped and '&lt;%== %&gt;' as not escaped.
@@ -356,9 +374,9 @@ Also Erubis::XmlEruby class (which is equivalent to Erubis::EscapedEruby) is pro
356
374
  <div class="program_caption">
357
375
  example3.eruby</div>
358
376
  <pre class="program">&lt;% for item in list %&gt;
359
- &lt;p&gt;<b>&lt;%=</b> item <b>%&gt;</b>&lt;/p&gt;
360
- &lt;p&gt;<b>&lt;%==</b> item <b>%&gt;</b>&lt;/p&gt;
361
- &lt;p&gt;<b>&lt;%===</b> item <b>%&gt;</b>&lt;/p&gt;
377
+ &lt;p&gt;<strong>&lt;%=</strong> item <strong>%&gt;</strong>&lt;/p&gt;
378
+ &lt;p&gt;<strong>&lt;%==</strong> item <strong>%&gt;</strong>&lt;/p&gt;
379
+ &lt;p&gt;<strong>&lt;%===</strong> item <strong>%&gt;</strong>&lt;/p&gt;
362
380
 
363
381
  &lt;% end %&gt;
364
382
  </pre>
@@ -367,13 +385,13 @@ example3.eruby</div>
367
385
  example3.rb</div>
368
386
  <pre class="program">require 'erubis'
369
387
  input = File.read('example3.eruby')
370
- eruby = Erubis::<b>EscapedEruby</b>.new(input) # or Erubis::XmlEruby
388
+ eruby = Erubis::<strong>EscapedEruby</strong>.new(input) # or Erubis::XmlEruby
371
389
 
372
390
  puts "---------- script source ---"
373
391
  puts eruby.src # print script source
374
392
 
375
393
  puts "---------- result ----------"
376
- <b>list = ['&lt;aaa&gt;', 'b&amp;b', '"ccc"']</b>
394
+ <strong>list = ['&lt;aaa&gt;', 'b&amp;b', '"ccc"']</strong>
377
395
  puts eruby.result(binding()) # get result
378
396
  </pre>
379
397
  <div class="terminal_caption">
@@ -381,9 +399,9 @@ output</div>
381
399
  <pre class="terminal">$ ruby example3.rb 2&gt; stderr.log
382
400
  ---------- script source ---
383
401
  _buf = []; for item in list
384
- _buf &lt;&lt; ' &lt;p&gt;'; <b>_buf &lt;&lt; Erubis::XmlHelper.escape_xml( item );</b> _buf &lt;&lt; '&lt;/p&gt;
385
- &lt;p&gt;'; <b>_buf &lt;&lt; ( item ).to_s;</b> _buf &lt;&lt; '&lt;/p&gt;
386
- &lt;p&gt;'; <b>$stderr.puts("*** debug: item=#{(item).inspect}");</b> _buf &lt;&lt; '&lt;/p&gt;
402
+ _buf &lt;&lt; ' &lt;p&gt;'; <strong>_buf &lt;&lt; Erubis::XmlHelper.escape_xml( item );</strong> _buf &lt;&lt; '&lt;/p&gt;
403
+ &lt;p&gt;'; <strong>_buf &lt;&lt; ( item ).to_s;</strong> _buf &lt;&lt; '&lt;/p&gt;
404
+ &lt;p&gt;'; <strong>$stderr.puts("*** debug: item=#{(item).inspect}");</strong> _buf &lt;&lt; '&lt;/p&gt;
387
405
 
388
406
  '; end
389
407
  _buf.join
@@ -405,10 +423,10 @@ $ cat stderr.log
405
423
  *** debug: item="b&amp;b"
406
424
  *** debug: item="\"ccc\""
407
425
  </pre>
408
- <p>The command-line option '-e'<sup>(<a href="#fnref:2" name="fnlink:2">*2</a>)</sup> will do the same action as Erubis::EscapedEruby.
426
+ <p>The command-line option '-e' will do the same action as Erubis::EscapedEruby.
409
427
  This option is available for any language.
410
428
  </p>
411
- <pre class="terminal">$ erubis -l ruby <b>-e</b> example3.eruby
429
+ <pre class="terminal">$ erubis -l ruby <strong>-e</strong> example3.eruby
412
430
  _buf = []; for item in list
413
431
  _buf &lt;&lt; ' &lt;p&gt;'; _buf &lt;&lt; Erubis::XmlHelper.escape_xml( item ); _buf &lt;&lt; '&lt;/p&gt;
414
432
  &lt;p&gt;'; _buf &lt;&lt; ( item ).to_s; _buf &lt;&lt; '&lt;/p&gt;
@@ -417,19 +435,19 @@ _buf = []; for item in list
417
435
  '; end
418
436
  _buf.join
419
437
  </pre>
420
- <p>Escaping function (default 'Erubis::XmlHelper.escape_xml()') can be changed by command-line property '--escape=xxx' or by overriding Erubis::Eruby#escaped_expr() in subclass.
438
+ <p>Escaping function (default 'Erubis::XmlHelper.escape_xml()') can be changed by command-line property '--escapefunc=xxx' or by overriding Erubis::Eruby#escaped_expr() in subclass.
421
439
  </p>
422
440
  <div class="program_caption">
423
441
  example to override Erubis::Eruby#escaped_expr()</div>
424
442
  <pre class="program">class CGIEruby &lt; Erubis::Eruby
425
- def <b>escaped_expr(code)</b>
443
+ def <strong>escaped_expr(code)</strong>
426
444
  return "CGI.escapeHTML((#{code.strip}).to_s)"
427
445
  #return "h(#{code.strip})"
428
446
  end
429
447
  end
430
448
 
431
449
  class LatexEruby &lt; Erubi::Eruby
432
- def <b>escaped_expr(code)</b>
450
+ def <strong>escaped_expr(code)</strong>
433
451
  return "(#{code}).gsub(/[%\\]/,'\\\\\&amp;')"
434
452
  end
435
453
  end
@@ -438,8 +456,6 @@ end
438
456
  <dl compact>
439
457
  <dt>(<a name="fnref:1" href="#fnlink:1">*1</a>)</dt>
440
458
  <dd>Erubis::EscapedEruby class includes Erubis::EscapeEnhancer which swtches the action of '&lt;%= %&gt;' and '&lt;%== %&gt;'.</dd>
441
- <dt>(<a name="fnref:2" href="#fnlink:2">*2</a>)</dt>
442
- <dd>Command-line option '-e' is equivarent to '-E Escape'.</dd>
443
459
  </dl>
444
460
  </div>
445
461
  <br>
@@ -447,18 +463,18 @@ end
447
463
 
448
464
  <a name="tut-pattern"></a>
449
465
  <h3 class="section2">Embedded Pattern</h3>
450
- <p>You can change embedded pattern '<code>&lt;% %&gt;</code>' to another with command-line option '-p' or option '<code>:pattern=&gt;...</code>' of Erubis::Eruby.new().
466
+ <p>You can change embedded pattern '<code>&lt;% %&gt;</code>' to another by command-line option '-p' or option '<code>:pattern=&gt;...</code>' of Erubis::Eruby.new().
451
467
  </p>
452
468
  <a name="example4.eruby"></a>
453
469
  <div class="program_caption">
454
470
  example4.eruby</div>
455
- <pre class="program"><b>&lt;!--%</b> for item in list <b>%--&gt;</b>
456
- &lt;p&gt;<b>&lt;!--%=</b> item <b>%--&gt;</b>&lt;/p&gt;
457
- <b>&lt;!--%</b> end <b>%--&gt;</b>
471
+ <pre class="program"><strong>&lt;!--%</strong> for item in list <strong>%--&gt;</strong>
472
+ &lt;p&gt;<strong>&lt;!--%=</strong> item <strong>%--&gt;</strong>&lt;/p&gt;
473
+ <strong>&lt;!--%</strong> end <strong>%--&gt;</strong>
458
474
  </pre>
459
475
  <div class="terminal_caption">
460
476
  compiled source code with command-line option '-p'</div>
461
- <pre class="terminal">$ erubis -x <b>-p '&lt;!--% %--&gt;'</b> example4.eruby
477
+ <pre class="terminal">$ erubis -x <strong>-p '&lt;!--% %--&gt;'</strong> example4.eruby
462
478
  _buf = []; for item in list
463
479
  _buf &lt;&lt; ' &lt;p&gt;'; _buf &lt;&lt; ( item ).to_s; _buf &lt;&lt; '&lt;/p&gt;
464
480
  '; end
@@ -469,7 +485,7 @@ _buf.join
469
485
  example4.rb</div>
470
486
  <pre class="program">require 'erubis'
471
487
  input = File.read('example4.eruby')
472
- eruby = Erubis::Eruby.new(input<b>, :pattern=&gt;'&lt;!--% %--&gt;'</b>)
488
+ eruby = Erubis::Eruby.new(input<strong>, :pattern=&gt;'&lt;!--% %--&gt;'</strong>)
473
489
  # or '&lt;(?:!--)?% %(?:--)?&gt;'
474
490
 
475
491
  puts "---------- script source ---"
@@ -510,9 +526,9 @@ In Erubis, Hash object and Erubis::Context object are available as context objec
510
526
  <a name="example5.eruby"></a>
511
527
  <div class="program_caption">
512
528
  example5.eruby</div>
513
- <pre class="program">&lt;span&gt;&lt;%= <b>@val</b> %&gt;&lt;/span&gt;
529
+ <pre class="program">&lt;span&gt;&lt;%= <strong>@val</strong> %&gt;&lt;/span&gt;
514
530
  &lt;ul&gt;
515
- &lt;% for item in <b>@list</b> %&gt;
531
+ &lt;% for item in <strong>@list</strong> %&gt;
516
532
  &lt;li&gt;&lt;%= item %&gt;&lt;/li&gt;
517
533
  &lt;% end %&gt;
518
534
  &lt;/ul&gt;
@@ -526,16 +542,16 @@ eruby = Erubis::Eruby.new(input) # create Eruby object
526
542
 
527
543
  ## create context object
528
544
  ## (key means var name, which may be string or symbol.)
529
- <b>context = {
545
+ <strong>context = {
530
546
  :val =&gt; 'Erubis Example',
531
547
  'list' =&gt; ['aaa', 'bbb', 'ccc'],
532
- }</b>
548
+ }</strong>
533
549
  # or
534
550
  # context = Erubis::Context.new()
535
551
  # context['val'] = 'Erubis Example'
536
552
  # context[:list] = ['aaa', 'bbb', 'ccc'],
537
553
 
538
- puts <b>eruby.evaluate(context)</b> # get result
554
+ puts <strong>eruby.evaluate(context)</strong> # get result
539
555
  </pre>
540
556
  <div class="terminal_caption">
541
557
  output</div>
@@ -561,7 +577,7 @@ definition of result(binding) and evaluate(context)</div>
561
577
  eval _h.keys.inject("") {|s,k| s &lt;&lt; "#{k} = _h[#{k.inspect}];"}
562
578
  _binding = binding()
563
579
  end
564
- return <b>eval(@src, _binding)</b>
580
+ return <strong>eval(@src, _binding)</strong>
565
581
  end
566
582
 
567
583
  def evaluate(context)
@@ -571,7 +587,7 @@ def evaluate(context)
571
587
  context = Erubis::Context.new
572
588
  hash.each { |key, val| context[key] = val }
573
589
  end
574
- return <b>context.instance_eval(@src)</b>
590
+ return <strong>context.instance_eval(@src)</strong>
575
591
  end
576
592
  </pre>
577
593
  <p>instance_eval() is defined at Object class so it is able to use any object as a context object as well as Hash or Erubis::Context.
@@ -584,13 +600,13 @@ example6.rb</div>
584
600
  end
585
601
 
586
602
  ## any object can be a context object
587
- <b>mydata = MyData.new</b>
588
- <b>mydata.val = 'Erubis Example'</b>
589
- <b>mydata.list = ['aaa', 'bbb', 'ccc']</b>
603
+ <strong>mydata = MyData.new</strong>
604
+ <strong>mydata.val = 'Erubis Example'</strong>
605
+ <strong>mydata.list = ['aaa', 'bbb', 'ccc']</strong>
590
606
 
591
607
  require 'erubis'
592
608
  eruby = Erubis::Eruby.new(File.read('example5.eruby'))
593
- puts eruby.evaluate(<b>mydata</b>)
609
+ puts eruby.evaluate(<strong>mydata</strong>)
594
610
  </pre>
595
611
  <div class="terminal_caption">
596
612
  output</div>
@@ -612,8 +628,8 @@ output</div>
612
628
  <a name="example7.yaml"></a>
613
629
  <div class="program_caption">
614
630
  example7.yaml</div>
615
- <pre class="program"><b>title:</b> Users List
616
- <b>users:</b>
631
+ <pre class="program"><strong>title:</strong> Users List
632
+ <strong>users:</strong>
617
633
  - name: foo
618
634
  mail: foo@mail.com
619
635
  - name: bar
@@ -624,9 +640,9 @@ example7.yaml</div>
624
640
  <a name="example7.eruby"></a>
625
641
  <div class="program_caption">
626
642
  example7.eruby</div>
627
- <pre class="program">&lt;h1&gt;&lt;%= <b>@title</b> %&gt;&lt;/h1&gt;
643
+ <pre class="program">&lt;h1&gt;&lt;%= <strong>@title</strong> %&gt;&lt;/h1&gt;
628
644
  &lt;ul&gt;
629
- &lt;% for user in <b>@users</b> %&gt;
645
+ &lt;% for user in <strong>@users</strong> %&gt;
630
646
  &lt;li&gt;
631
647
  &lt;a href="mailto:&lt;%= user['mail']%&gt;"&gt;&lt;%= user['name'] %&gt;&lt;/a&gt;
632
648
  &lt;/li&gt;
@@ -641,10 +657,10 @@ input = File.read('example7.eruby')
641
657
  eruby = Erubis::Eruby.new(input) # create Eruby object
642
658
 
643
659
  ## load YAML document as context object
644
- <b>require 'yaml'</b>
645
- <b>context = YAML.load_file('example7.yaml')</b>
660
+ <strong>require 'yaml'</strong>
661
+ <strong>context = YAML.load_file('example7.yaml')</strong>
646
662
 
647
- puts <b>eruby.evaluate(context)</b> # get result
663
+ puts <strong>eruby.evaluate(context)</strong> # get result
648
664
  </pre>
649
665
  <div class="terminal_caption">
650
666
  output</div>
@@ -667,7 +683,7 @@ You don't have to write ruby script such as 'example7.rb'.
667
683
  </p>
668
684
  <div class="terminal_caption">
669
685
  example of command-line option '-f'</div>
670
- <pre class="terminal">$ erubis <b>-f example7.yaml</b> example7.eruby
686
+ <pre class="terminal">$ erubis <strong>-f example7.yaml</strong> example7.eruby
671
687
  &lt;h1&gt;Users List&lt;/h1&gt;
672
688
  &lt;ul&gt;
673
689
  &lt;li&gt;
@@ -705,13 +721,13 @@ example8.eruby</div>
705
721
  </p>
706
722
  <pre class="terminal">## without '-b'
707
723
  $ erubis -x example8.eruby
708
- <b>_buf = [];</b> for item in @list
724
+ <strong>_buf = [];</strong> for item in @list
709
725
  _buf &lt;&lt; ' &lt;b&gt;'; _buf &lt;&lt; ( item ).to_s; _buf &lt;&lt; '&lt;/b&gt;
710
726
  '; end
711
- <b>_buf.join</b>
727
+ <strong>_buf.join</strong>
712
728
 
713
729
  ## with '-b'
714
- $ erubis -x <b>-b</b> example8.eruby
730
+ $ erubis -x <strong>-b</strong> example8.eruby
715
731
  for item in @list
716
732
  _buf &lt;&lt; ' &lt;b&gt;'; _buf &lt;&lt; ( item ).to_s; _buf &lt;&lt; '&lt;/b&gt;
717
733
  '; end
@@ -724,7 +740,7 @@ example8.rb</div>
724
740
  <pre class="program">require 'erubis'
725
741
  input = File.read('example8.eruby')
726
742
  eruby1 = Erubis::Eruby.new(input)
727
- eruby2 = Erubis::Eruby.new(input, <b>:preamble=&gt;false, :postamble=&gt;false</b>)
743
+ eruby2 = Erubis::Eruby.new(input, <strong>:preamble=&gt;false, :postamble=&gt;false</strong>)
728
744
 
729
745
  puts eruby1.src # print preamble and postamble
730
746
  puts "--------------"
@@ -745,6 +761,118 @@ _buf.join
745
761
  <br>
746
762
 
747
763
 
764
+ <a name="tut-pi"></a>
765
+ <h3 class="section2">Processing Instruction (PI) Converter</h3>
766
+ <p>Erubis can parse Processing Instructions (PI) as embedded pattern.
767
+ </p>
768
+ <ul type="disc">
769
+ <li>'<code>&lt;?rb <em>...</em> ?&gt;</code>' represents Ruby statement.
770
+ </li>
771
+ <li>'<code>@{<em>...</em>}@</code>' represents escaped expression value.
772
+ </li>
773
+ <li>'<code>@!{<em>...</em>}@</code>' represents normal expression value.
774
+ </li>
775
+ <li>'<code>@!!{<em>...</em>}@</code>' prints expression value to standard output.
776
+ </li>
777
+ <li>(experimental) '<code>&lt;%= <em>...</em> %&gt;</code>' is also available to print expression value.
778
+ </li>
779
+ </ul>
780
+ <p>This is more useful than basic embedded pattern ('<code>&lt;% ... &gt;</code>') because PI doesn't break XML or HTML at all.
781
+ For example the following XHTML file is well-formed and HTML validator got no errors on this example.
782
+ </p>
783
+ <a name="example9.xhtml"></a>
784
+ <div class="program_caption">
785
+ example9.xhtml</div>
786
+ <pre class="program">&lt;?xml version="1.0" ?&gt;
787
+ <strong>&lt;?rb
788
+ lang = 'en'
789
+ list = ['&lt;aaa&gt;', 'b&amp;b', '"ccc"']
790
+ ?&gt;</strong>
791
+ &lt;html lang="<strong>@!{lang}@</strong>"&gt;
792
+ &lt;body&gt;
793
+ &lt;ul&gt;
794
+ <strong>&lt;?rb for item in list ?&gt;</strong>
795
+ &lt;li&gt;<strong>@{item}@</strong>&lt;/li&gt;
796
+ <strong>&lt;?rb end ?&gt;</strong>
797
+ &lt;/ul&gt;
798
+ &lt;/body&gt;
799
+ &lt;/html&gt;
800
+ </pre>
801
+ <p>If the command-line property '--pi=<em>name</em>' is specified, erubis command parses input with PI converter.
802
+ If <em>name</em> is omitted then the following name is used according to '-l <em>lang</em>'.
803
+ </p>
804
+ <div align="center">
805
+ <table class="table1" border="1" cellspacing="0" summary=" mapping of '-l' option and PI name
806
+ ">
807
+ <caption class="caption1">
808
+ mapping of '-l' option and PI name
809
+ </caption>
810
+ <tr class="tr1">
811
+ <th class="th1">'-l' option</th>
812
+ <th class="th1">PI name</th>
813
+ </tr>
814
+ <tr class="tr1">
815
+ <td class="td1">-l ruby</td>
816
+ <td class="td1">&lt;?rb ... ?&gt;</td>
817
+ </tr>
818
+ <tr class="tr1">
819
+ <td class="td1">-l php</td>
820
+ <td class="td1">&lt;?php ... ?&gt;</td>
821
+ </tr>
822
+ <tr class="tr1">
823
+ <td class="td1">-l perl</td>
824
+ <td class="td1">&lt;?perl ... ?&gt;</td>
825
+ </tr>
826
+ <tr class="tr1">
827
+ <td class="td1">-l java</td>
828
+ <td class="td1">&lt;?java ... ?&gt;</td>
829
+ </tr>
830
+ <tr class="tr1">
831
+ <td class="td1">-l javascript</td>
832
+ <td class="td1">&lt;?js ... ?&gt;</td>
833
+ </tr>
834
+ <tr class="tr1">
835
+ <td class="td1">-l scheme</td>
836
+ <td class="td1">&lt;?scheme ... ?&gt;</td>
837
+ </tr>
838
+ </table>
839
+ </div>
840
+ <div class="terminal_caption">
841
+ output</div>
842
+ <pre class="terminal">$ erubis <strong>--pi</strong> example9.xhtml
843
+ &lt;?xml version="1.0" ?&gt;
844
+ &lt;html lang="en"&gt;
845
+ &lt;body&gt;
846
+ &lt;ul&gt;
847
+ &lt;li&gt;&amp;lt;aaa&amp;gt;&lt;/li&gt;
848
+ &lt;li&gt;b&amp;amp;b&lt;/li&gt;
849
+ &lt;li&gt;&amp;quot;ccc&amp;quot;&lt;/li&gt;
850
+ &lt;/ul&gt;
851
+ &lt;/body&gt;
852
+ &lt;/html&gt;
853
+ </pre>
854
+ <p>Expression character can be changeable by command-line property '--embchar=<em>char</em>. Default is '<code>@</code>'.
855
+ </p>
856
+ <p><strong>(experimental)</strong> Erubis supports '&lt;%= ... %&gt;' pattern with PI pattern.
857
+ </p>
858
+ <div class="program_caption">
859
+ example of Rails view template</div>
860
+ <pre class="program">&lt;table&gt;
861
+ &lt;tr&gt;
862
+ &lt;?rb for item in @list ?&gt;
863
+ &lt;td&gt;@{item.id}@&lt;/td&gt;
864
+ &lt;td&gt;@{item.name}@&lt;/td&gt;
865
+ &lt;td&gt;
866
+ <strong>&lt;%=</strong> link_to 'Destroy', {:action=&gt;'destroy', :id=&gt;item.id},
867
+ :confirm=&gt;'Are you OK?' <strong>%&gt;</strong>
868
+ &lt;/td&gt;
869
+ &lt;?rb end ?&gt;
870
+ &lt;/tr&gt;
871
+ &lt;/table&gt;
872
+ </pre>
873
+ <br>
874
+
875
+
748
876
  <br>
749
877
 
750
878
 
@@ -811,6 +939,11 @@ The following is an example to use some enhancers in command-line.
811
939
  Print embedded code only and ignore normal text.
812
940
  </dd>
813
941
  <dt class="dt1">
942
+ <a href="#nocode-enhancer">NoCodeEnhancer</a> (language-independent)</dt>
943
+ <dd class="dd1">
944
+ Print normal text only and ignore code.
945
+ </dd>
946
+ <dt class="dt1">
814
947
  <a href="#simplify-enhancer">SimplifyEnhancer</a> (language-independent)</dt>
815
948
  <dd class="dd1">
816
949
  Make compile faster but don't trim spaces around '&lt;% %&gt;'.
@@ -853,8 +986,8 @@ compiled source code</div>
853
986
  <pre class="terminal">$ erubis -xE Escape example.eruby
854
987
  _buf = []; _buf &lt;&lt; '&lt;div&gt;
855
988
  '; for item in list
856
- _buf &lt;&lt; ' &lt;p&gt;'; <b>_buf &lt;&lt; Erubis::XmlHelper.escape_xml( item );</b> _buf &lt;&lt; '&lt;/p&gt;
857
- &lt;p&gt;'; <b>_buf &lt;&lt; ( item ).to_s;</b> _buf &lt;&lt; '&lt;/p&gt;
989
+ _buf &lt;&lt; ' &lt;p&gt;'; <strong>_buf &lt;&lt; Erubis::XmlHelper.escape_xml( item );</strong> _buf &lt;&lt; '&lt;/p&gt;
990
+ &lt;p&gt;'; <strong>_buf &lt;&lt; ( item ).to_s;</strong> _buf &lt;&lt; '&lt;/p&gt;
858
991
  '; end
859
992
  _buf &lt;&lt; '&lt;/div&gt;
860
993
  ';
@@ -873,7 +1006,7 @@ Therefore, you can use 'print' statement in embedded ruby code.
873
1006
  <div class="terminal_caption">
874
1007
  compiled source code</div>
875
1008
  <pre class="terminal">$ erubis -xE Stdout example.eruby
876
- <b>_buf = $stdout;</b> _buf &lt;&lt; '&lt;div&gt;
1009
+ <strong>_buf = $stdout;</strong> _buf &lt;&lt; '&lt;div&gt;
877
1010
  '; for item in list
878
1011
  _buf &lt;&lt; ' &lt;p&gt;'; _buf &lt;&lt; ( item ).to_s; _buf &lt;&lt; '&lt;/p&gt;
879
1012
  &lt;p&gt;'; _buf &lt;&lt; Erubis::XmlHelper.escape_xml( item ); _buf &lt;&lt; '&lt;/p&gt;
@@ -894,12 +1027,12 @@ compiled source code</div>
894
1027
  <div class="terminal_caption">
895
1028
  compiled source code</div>
896
1029
  <pre class="terminal">$ erubis -xE PrintOut example.eruby
897
- <b>print</b> '&lt;div&gt;
1030
+ <strong>print</strong> '&lt;div&gt;
898
1031
  '; for item in list
899
- <b>print</b> ' &lt;p&gt;'; <b>print</b>(( item ).to_s); <b>print</b> '&lt;/p&gt;
900
- &lt;p&gt;'; <b>print</b> Erubis::XmlHelper.escape_xml( item ); <b>print</b> '&lt;/p&gt;
1032
+ <strong>print</strong> ' &lt;p&gt;'; <strong>print</strong>(( item ).to_s); <strong>print</strong> '&lt;/p&gt;
1033
+ &lt;p&gt;'; <strong>print</strong> Erubis::XmlHelper.escape_xml( item ); <strong>print</strong> '&lt;/p&gt;
901
1034
  '; end
902
- <b>print</b> '&lt;/div&gt;
1035
+ <strong>print</strong> '&lt;/div&gt;
903
1036
  ';
904
1037
  </pre>
905
1038
  <p>PrintOutEnhancer is only for Eruby.
@@ -915,7 +1048,7 @@ compiled source code</div>
915
1048
  <div class="program_caption">
916
1049
  printenabled-example.eruby</div>
917
1050
  <pre class="program">&lt;% for item in @list %&gt;
918
- &lt;b&gt;<b>&lt;% print item %&gt;</b>&lt;/b&gt;
1051
+ &lt;b&gt;<strong>&lt;% print item %&gt;</strong>&lt;/b&gt;
919
1052
  &lt;% end %&gt;
920
1053
  </pre>
921
1054
  <a name="printenabled-example.rb"></a>
@@ -951,14 +1084,14 @@ because print() method in '&lt;% ... %&gt;' invokes not Kernel#print() but Print
951
1084
  </p>
952
1085
  <div class="terminal_caption">
953
1086
  compiled source code</div>
954
- <pre class="terminal"><b>_buf = [];</b> _buf &lt;&lt; '&lt;div&gt;
1087
+ <pre class="terminal"><strong>_buf = [];</strong> _buf &lt;&lt; '&lt;div&gt;
955
1088
  '; for item in list
956
1089
  _buf &lt;&lt; ' &lt;p&gt;'; _buf &lt;&lt; ( item ).to_s; _buf &lt;&lt; '&lt;/p&gt;
957
1090
  &lt;p&gt;'; _buf &lt;&lt; Erubis::XmlHelper.escape_xml( item ); _buf &lt;&lt; '&lt;/p&gt;
958
1091
  '; end
959
1092
  _buf &lt;&lt; '&lt;/div&gt;
960
1093
  ';
961
- <b>_buf</b>
1094
+ <strong>_buf</strong>
962
1095
  </pre>
963
1096
  <p>ArrayEnhancer is only for Eruby.
964
1097
  </p>
@@ -981,14 +1114,14 @@ Erubis::Eruby includes this enhancer by default.
981
1114
  <p>StringBufferEnhancer makes Eruby to use string buffer.
982
1115
  </p>
983
1116
  <pre class="terminal">$ erubis -xE StringBuffer example.eruby
984
- <b>_buf = '';</b> _buf &lt;&lt; '&lt;div&gt;
1117
+ <strong>_buf = '';</strong> _buf &lt;&lt; '&lt;div&gt;
985
1118
  '; for item in list
986
1119
  _buf &lt;&lt; ' &lt;p&gt;'; _buf &lt;&lt; ( item ).to_s; _buf &lt;&lt; '&lt;/p&gt;
987
1120
  &lt;p&gt;'; _buf &lt;&lt; Erubis::XmlHelper.escape_xml( item ); _buf &lt;&lt; '&lt;/p&gt;
988
1121
  '; end
989
1122
  _buf &lt;&lt; '&lt;/div&gt;
990
1123
  ';
991
- <b>_buf</b>
1124
+ <strong>_buf</strong>
992
1125
  </pre>
993
1126
  <p>StringBufferEnhancer is only for Eruby.
994
1127
  </p>
@@ -1042,6 +1175,52 @@ _buf.join
1042
1175
  <br>
1043
1176
 
1044
1177
 
1178
+ <a name="nocode-enhancer"></a>
1179
+ <h3 class="section2">NoCodeEnhancer</h3>
1180
+ <p>NoCodeEnhancer suppress output of embedded code and prints only normal text.
1181
+ This is useful especially when validating HTML tags.
1182
+ </p>
1183
+ <a name="nocode-example.eruby"></a>
1184
+ <div class="program_caption">
1185
+ nocode-example.eruby</div>
1186
+ <pre class="program">&lt;h3&gt;List&lt;/h3&gt;
1187
+ &lt;% if !@list || @list.empty? %&gt;
1188
+ &lt;p&gt;not found.&lt;/p&gt;
1189
+ &lt;% else %&gt;
1190
+ &lt;table&gt;
1191
+ &lt;tbody&gt;
1192
+ &lt;% @list.each_with_index do |item, i| %&gt;
1193
+ &lt;tr bgcolor="&lt;%= i%2 == 0 ? '#FFCCCC' : '#CCCCFF' %&gt;"&gt;
1194
+ &lt;td&gt;&lt;%= item %&gt;&lt;/td&gt;
1195
+ &lt;/tr&gt;
1196
+ &lt;% end %&gt;
1197
+ &lt;/tbody&gt;
1198
+ &lt;/table&gt;
1199
+ &lt;% end %&gt;
1200
+ </pre>
1201
+ <div class="terminal_caption">
1202
+ output example of NoTextEnhancer</div>
1203
+ <pre class="terminal">$ erubis -TxE NoCode notext-example.eruby
1204
+ &lt;h3&gt;List&lt;/h3&gt;
1205
+
1206
+ &lt;p&gt;not found.&lt;/p&gt;
1207
+
1208
+ &lt;table&gt;
1209
+ &lt;tbody&gt;
1210
+
1211
+ &lt;tr bgcolor=""&gt;
1212
+ &lt;td&gt;&lt;/td&gt;
1213
+ &lt;/tr&gt;
1214
+
1215
+ &lt;/tbody&gt;
1216
+ &lt;/table&gt;
1217
+
1218
+ </pre>
1219
+ <p>NoCodeEnhancer is language-independent. It is useful even if you are PHP user, see <a href="#topics-php">this section</a>.
1220
+ </p>
1221
+ <br>
1222
+
1223
+
1045
1224
  <a name="simplify-enhancer"></a>
1046
1225
  <h3 class="section2">SimplifyEnhancer</h3>
1047
1226
  <p>SimplifyEnhancer makes compiling a little faster but don't trim spaces around '&lt;% %&gt;'.
@@ -1073,16 +1252,16 @@ You can specify pattern by :bipattern property.
1073
1252
  <div class="program_caption">
1074
1253
  bipattern-example.rhtml</div>
1075
1254
  <pre class="program">&lt;% for item in list %&gt;
1076
- &lt;b&gt;<b>[= item =]</b>&lt;/b&gt;
1077
- &lt;b&gt;<b>[== item =]</b>&lt;/b&gt;
1255
+ &lt;b&gt;<strong>[= item =]</strong>&lt;/b&gt;
1256
+ &lt;b&gt;<strong>[== item =]</strong>&lt;/b&gt;
1078
1257
  &lt;% end %&gt;
1079
1258
  </pre>
1080
1259
  <div class="terminal_caption">
1081
1260
  compiled source code</div>
1082
1261
  <pre class="terminal">$ erubis -xE BiPattern bipattern-example.rhtml
1083
1262
  _buf = []; for item in list
1084
- _buf &lt;&lt; ' &lt;b&gt;'; <b>_buf &lt;&lt; ( item ).to_s;</b> _buf &lt;&lt; '&lt;/b&gt;
1085
- &lt;b&gt;'; <b>_buf &lt;&lt; Erubis::XmlHelper.escape_xml( item );</b> _buf &lt;&lt; '&lt;/b&gt;
1263
+ _buf &lt;&lt; ' &lt;b&gt;'; <strong>_buf &lt;&lt; ( item ).to_s;</strong> _buf &lt;&lt; '&lt;/b&gt;
1264
+ &lt;b&gt;'; <strong>_buf &lt;&lt; Erubis::XmlHelper.escape_xml( item );</strong> _buf &lt;&lt; '&lt;/b&gt;
1086
1265
  '; end
1087
1266
  _buf.join
1088
1267
  </pre>
@@ -1099,17 +1278,17 @@ This is for compatibility with eruby and ERB.
1099
1278
  <a name="percentline-example.rhtml"></a>
1100
1279
  <div class="program_caption">
1101
1280
  percentline-example.rhtml</div>
1102
- <pre class="program"><b>% for item in list</b>
1281
+ <pre class="program"><strong>% for item in list</strong>
1103
1282
  &lt;b&gt;&lt;%= item %&gt;&lt;/b&gt;
1104
- <b>% end</b>
1283
+ <strong>% end</strong>
1105
1284
  %% lines with '%%'
1106
1285
  </pre>
1107
1286
  <div class="terminal_caption">
1108
1287
  compiled source code</div>
1109
1288
  <pre class="terminal">$ erubis -xE PercentLine percentline-example.rhtml
1110
- _buf = []; <b>for item in list</b>
1289
+ _buf = []; <strong>for item in list</strong>
1111
1290
  _buf &lt;&lt; ' &lt;b&gt;'; _buf &lt;&lt; ( item ).to_s; _buf &lt;&lt; '&lt;/b&gt;
1112
- '; <b>end</b>
1291
+ '; <strong>end</strong>
1113
1292
  _buf &lt;&lt; '% lines with \'%%\'
1114
1293
  ';
1115
1294
  _buf.join
@@ -1128,28 +1307,28 @@ _buf.join
1128
1307
  <a name="headerfooter-example.eruby"></a>
1129
1308
  <div class="program_caption">
1130
1309
  headerfooter-example.eruby</div>
1131
- <pre class="program"><b>&lt;!--#header:</b>
1132
- <b>def list_items(items)</b>
1133
- <b>#--&gt;</b>
1310
+ <pre class="program"><strong>&lt;!--#header:</strong>
1311
+ <strong>def list_items(items)</strong>
1312
+ <strong>#--&gt;</strong>
1134
1313
  &lt;% for item in items %&gt;
1135
1314
  &lt;b&gt;&lt;%= item %&gt;&lt;/b&gt;
1136
1315
  &lt;% end %&gt;
1137
- <b>&lt;!--#footer:</b>
1138
- <b>end</b>
1139
- <b>#--&gt;</b>
1316
+ <strong>&lt;!--#footer:</strong>
1317
+ <strong>end</strong>
1318
+ <strong>#--&gt;</strong>
1140
1319
  </pre>
1141
1320
  <div class="terminal_caption">
1142
1321
  compiled source code</div>
1143
1322
  <pre class="terminal">$ erubis -xE HeaderFooter headerfooter-example.eruby
1144
1323
 
1145
- <b>def list_items(items)</b>
1324
+ <strong>def list_items(items)</strong>
1146
1325
 
1147
1326
  _buf = []; for item in items
1148
1327
  _buf &lt;&lt; ' &lt;b&gt;'; _buf &lt;&lt; ( item ).to_s; _buf &lt;&lt; '&lt;/b&gt;
1149
1328
  '; end
1150
1329
  _buf.join
1151
1330
 
1152
- <b>end</b>
1331
+ <strong>end</strong>
1153
1332
 
1154
1333
  </pre>
1155
1334
  <p>Compare to the following:
@@ -1157,27 +1336,27 @@ _buf.join
1157
1336
  <a name="normal-eruby-test.eruby"></a>
1158
1337
  <div class="program_caption">
1159
1338
  normal-eruby-test.eruby</div>
1160
- <pre class="program"><b>&lt;%</b>
1161
- <b>def list_items(items)</b>
1162
- <b>%&gt;</b>
1339
+ <pre class="program"><strong>&lt;%</strong>
1340
+ <strong>def list_items(items)</strong>
1341
+ <strong>%&gt;</strong>
1163
1342
  &lt;% for item in items %&gt;
1164
1343
  &lt;li&gt;&lt;%= item %&gt;&lt;/li&gt;
1165
1344
  &lt;% end %&gt;
1166
- <b>&lt;%</b>
1167
- <b>end</b>
1168
- <b>%&gt;</b>
1345
+ <strong>&lt;%</strong>
1346
+ <strong>end</strong>
1347
+ <strong>%&gt;</strong>
1169
1348
  </pre>
1170
1349
  <div class="terminal_caption">
1171
1350
  compiled source code</div>
1172
1351
  <pre class="terminal">$ erubis -x normal-eruby-test.eruby
1173
1352
  _buf = [];
1174
- <b>def list_items(items)</b>
1353
+ <strong>def list_items(items)</strong>
1175
1354
 
1176
1355
  for item in items
1177
1356
  _buf &lt;&lt; '&lt;li&gt;'; _buf &lt;&lt; ( item ).to_s; _buf &lt;&lt; '&lt;/li&gt;
1178
1357
  '; end
1179
1358
 
1180
- <b>end</b>
1359
+ <strong>end</strong>
1181
1360
 
1182
1361
  _buf.join
1183
1362
  </pre>
@@ -1189,20 +1368,20 @@ that is, header is no need to be in the head of eRuby script.
1189
1368
  headerfooter-example2.rhtml</div>
1190
1369
  <pre class="program">&lt;?xml version="1.0"?&gt;
1191
1370
  &lt;html&gt;
1192
- <b>&lt;!--#header:</b>
1193
- <b>def page(list)</b>
1194
- <b>#--&gt;</b>
1371
+ <strong>&lt;!--#header:</strong>
1372
+ <strong>def page(list)</strong>
1373
+ <strong>#--&gt;</strong>
1195
1374
  :
1196
- <b>&lt;!--#footer:</b>
1197
- <b>end</b>
1198
- <b>#--&gt;</b>
1375
+ <strong>&lt;!--#footer:</strong>
1376
+ <strong>end</strong>
1377
+ <strong>#--&gt;</strong>
1199
1378
  &lt;/html&gt;
1200
1379
  </pre>
1201
1380
  <div class="terminal_caption">
1202
1381
  compiled source code</div>
1203
1382
  <pre class="terminal">$ erubis -xE HeaderFooter headerfooter-example2.rhtml
1204
1383
 
1205
- <b>def page(list)</b>
1384
+ <strong>def page(list)</strong>
1206
1385
 
1207
1386
  _buf = []; _buf &lt;&lt; '&lt;?xml version="1.0"?&gt;
1208
1387
  &lt;html&gt;
@@ -1211,7 +1390,7 @@ _buf = []; _buf &lt;&lt; '&lt;?xml version="1.0"?&gt;
1211
1390
  ';
1212
1391
  _buf.join
1213
1392
 
1214
- <b>end</b>
1393
+ <strong>end</strong>
1215
1394
 
1216
1395
  </pre>
1217
1396
  <p>HeaderFooterEnhancer is experimental and is language-independent.
@@ -1250,15 +1429,15 @@ example.ephp</div>
1250
1429
  <pre class="program">&lt;?xml version="1.0"?&gt;
1251
1430
  &lt;html&gt;
1252
1431
  &lt;body&gt;
1253
- &lt;p&gt;Hello <b>&lt;%= $user %&gt;</b>!&lt;/p&gt;
1432
+ &lt;p&gt;Hello <strong>&lt;%= $user %&gt;</strong>!&lt;/p&gt;
1254
1433
  &lt;table&gt;
1255
1434
  &lt;tbody&gt;
1256
- <b>&lt;% $i = 0; %&gt;</b>
1257
- <b>&lt;% foreach ($list as $item) { %&gt;</b>
1258
- <b>&lt;% $i++; %&gt;</b>
1259
- &lt;tr bgcolor=<b>"&lt;%= $i % 2 == 0 ? '#FFCCCC' : '#CCCCFF' %&gt;"</b>&gt;
1260
- &lt;td&gt;<b>&lt;%= $i %&gt;</b>&lt;/td&gt;
1261
- &lt;td&gt;<b>&lt;%== $item %&gt;</b>&lt;/td&gt;
1435
+ <strong>&lt;% $i = 0; %&gt;</strong>
1436
+ <strong>&lt;% foreach ($list as $item) { %&gt;</strong>
1437
+ <strong>&lt;% $i++; %&gt;</strong>
1438
+ &lt;tr bgcolor=<strong>"&lt;%= $i % 2 == 0 ? '#FFCCCC' : '#CCCCFF' %&gt;"</strong>&gt;
1439
+ &lt;td&gt;<strong>&lt;%= $i %&gt;</strong>&lt;/td&gt;
1440
+ &lt;td&gt;<strong>&lt;%== $item %&gt;</strong>&lt;/td&gt;
1262
1441
  &lt;/tr&gt;
1263
1442
  &lt;% } %&gt;
1264
1443
  &lt;/tbody&gt;
@@ -1296,33 +1475,33 @@ compiled source code</div>
1296
1475
  <a name="example.ec"></a>
1297
1476
  <div class="program_caption">
1298
1477
  example.ec</div>
1299
- <pre class="program"><b>&lt;%
1478
+ <pre class="program"><strong>&lt;%
1300
1479
  #include &lt;stdio.h&gt;
1301
1480
 
1302
1481
  int main(int argc, char *argv[])
1303
1482
  {
1304
1483
  int i;
1305
1484
 
1306
- %&gt;</b>
1485
+ %&gt;</strong>
1307
1486
  &lt;html&gt;
1308
1487
  &lt;body&gt;
1309
- &lt;p&gt;Hello <b>&lt;%= "%s", argv[0] %&gt;</b>!&lt;/p&gt;
1488
+ &lt;p&gt;Hello <strong>&lt;%= "%s", argv[0] %&gt;</strong>!&lt;/p&gt;
1310
1489
  &lt;table&gt;
1311
1490
  &lt;tbody&gt;
1312
- <b>&lt;% for (i = 1; i &lt; argc; i++) { %&gt;</b>
1313
- &lt;tr bgcolor="<b>&lt;%= i % 2 == 0 ? "#FFCCCC" : "#CCCCFF" %&gt;</b>"&gt;
1314
- &lt;td&gt;<b>&lt;%= "%d", i %&gt;</b>&lt;/td&gt;
1315
- &lt;td&gt;<b>&lt;%= "%s", argv[i] %&gt;</b>&lt;/td&gt;
1491
+ <strong>&lt;% for (i = 1; i &lt; argc; i++) { %&gt;</strong>
1492
+ &lt;tr bgcolor="<strong>&lt;%= i % 2 == 0 ? "#FFCCCC" : "#CCCCFF" %&gt;</strong>"&gt;
1493
+ &lt;td&gt;<strong>&lt;%= "%d", i %&gt;</strong>&lt;/td&gt;
1494
+ &lt;td&gt;<strong>&lt;%= "%s", argv[i] %&gt;</strong>&lt;/td&gt;
1316
1495
  &lt;/tr&gt;
1317
- <b>&lt;% } %&gt;</b>
1496
+ <strong>&lt;% } %&gt;</strong>
1318
1497
  &lt;/tbody&gt;
1319
1498
  &lt;/table&gt;
1320
1499
  &lt;/body&gt;
1321
1500
  &lt;/html&gt;
1322
- <b>&lt;%
1501
+ <strong>&lt;%
1323
1502
  return 0;
1324
1503
  }
1325
- %&gt;</b>
1504
+ %&gt;</strong>
1326
1505
  </pre>
1327
1506
  <div class="terminal_caption">
1328
1507
  compiled source code</div>
@@ -1364,7 +1543,7 @@ fputs(" &lt;/tbody&gt;\n"
1364
1543
  <a name="Example.ejava"></a>
1365
1544
  <div class="program_caption">
1366
1545
  Example.ejava</div>
1367
- <pre class="program"><b>&lt;%
1546
+ <pre class="program"><strong>&lt;%
1368
1547
  import java.util.*;
1369
1548
 
1370
1549
  public class Example {
@@ -1377,23 +1556,23 @@ public class Example {
1377
1556
 
1378
1557
  public String view() {
1379
1558
  StringBuffer _buf = new StringBuffer();
1380
- %&gt;</b>
1559
+ %&gt;</strong>
1381
1560
  &lt;html&gt;
1382
1561
  &lt;body&gt;
1383
- &lt;p&gt;Hello <b>&lt;%= user %&gt;</b>!&lt;/p&gt;
1562
+ &lt;p&gt;Hello <strong>&lt;%= user %&gt;</strong>!&lt;/p&gt;
1384
1563
  &lt;table&gt;
1385
1564
  &lt;tbody&gt;
1386
- <b>&lt;% for (int i = 0; i &lt; list.length; i++) { %&gt;</b>
1387
- &lt;tr bgcolor=<b>"&lt;%= i % 2 == 0 ? "#FFCCCC" : "#CCCCFF" %&gt;"</b>&gt;
1388
- &lt;td&gt;<b>&lt;%= i + 1 %&gt;</b>&lt;/td&gt;
1389
- &lt;td&gt;<b>&lt;%== list[i] %&gt;</b>&lt;/td&gt;
1565
+ <strong>&lt;% for (int i = 0; i &lt; list.length; i++) { %&gt;</strong>
1566
+ &lt;tr bgcolor=<strong>"&lt;%= i % 2 == 0 ? "#FFCCCC" : "#CCCCFF" %&gt;"</strong>&gt;
1567
+ &lt;td&gt;<strong>&lt;%= i + 1 %&gt;</strong>&lt;/td&gt;
1568
+ &lt;td&gt;<strong>&lt;%== list[i] %&gt;</strong>&lt;/td&gt;
1390
1569
  &lt;/tr&gt;
1391
- <b>&lt;% } %&gt;</b>
1570
+ <strong>&lt;% } %&gt;</strong>
1392
1571
  &lt;/tbody&gt;
1393
1572
  &lt;/table&gt;
1394
1573
  &lt;body&gt;
1395
1574
  &lt;/html&gt;
1396
- <b>&lt;%
1575
+ <strong>&lt;%
1397
1576
  return _buf.toString();
1398
1577
  }
1399
1578
 
@@ -1418,7 +1597,7 @@ public class Example {
1418
1597
  return sb.toString();
1419
1598
  }
1420
1599
  }
1421
- %&gt;</b>
1600
+ %&gt;</strong>
1422
1601
  </pre>
1423
1602
  <div class="terminal_caption">
1424
1603
  compiled source code</div>
@@ -1490,30 +1669,30 @@ return _buf.toString();
1490
1669
  example.escheme</div>
1491
1670
  <pre class="program">&lt;html&gt;
1492
1671
  &lt;body&gt;
1493
- <b>&lt;%
1672
+ <strong>&lt;%
1494
1673
  (let ((user "Erubis")
1495
1674
  (items '("&lt;aaa&gt;" "b&amp;b" "\"ccc\""))
1496
1675
  (i 0))
1497
- %&gt;</b>
1498
- &lt;p&gt;Hello <b>&lt;%= user %&gt;</b>!&lt;/p&gt;
1676
+ %&gt;</strong>
1677
+ &lt;p&gt;Hello <strong>&lt;%= user %&gt;</strong>!&lt;/p&gt;
1499
1678
  &lt;table&gt;
1500
- <b>&lt;%
1679
+ <strong>&lt;%
1501
1680
  (for-each
1502
1681
  (lambda (item)
1503
1682
  (set! i (+ i 1))
1504
- %&gt;</b>
1505
- &lt;tr bgcolor="<b>&lt;%= (if (= (modulo i 2) 0) "#FFCCCC" "#CCCCFF") %&gt;</b>"&gt;
1506
- &lt;td&gt;<b>&lt;%= i %&gt;</b>&lt;/td&gt;
1507
- &lt;td&gt;<b>&lt;%= item %&gt;</b>&lt;/td&gt;
1683
+ %&gt;</strong>
1684
+ &lt;tr bgcolor="<strong>&lt;%= (if (= (modulo i 2) 0) "#FFCCCC" "#CCCCFF") %&gt;</strong>"&gt;
1685
+ &lt;td&gt;<strong>&lt;%= i %&gt;</strong>&lt;/td&gt;
1686
+ &lt;td&gt;<strong>&lt;%= item %&gt;</strong>&lt;/td&gt;
1508
1687
  &lt;/tr&gt;
1509
- <b>&lt;%
1688
+ <strong>&lt;%
1510
1689
  ) ; lambda end
1511
1690
  items) ; for-each end
1512
- %&gt;</b>
1691
+ %&gt;</strong>
1513
1692
  &lt;/table&gt;
1514
- <b>&lt;%
1693
+ <strong>&lt;%
1515
1694
  ) ; let end
1516
- %&gt;</b>
1695
+ %&gt;</strong>
1517
1696
  &lt;/body&gt;
1518
1697
  &lt;/html&gt;
1519
1698
  </pre>
@@ -1590,21 +1769,21 @@ compiled source code (with --func=display property)</div>
1590
1769
  <a name="example.eperl"></a>
1591
1770
  <div class="program_caption">
1592
1771
  example.eprl</div>
1593
- <pre class="program"><b>&lt;%
1772
+ <pre class="program"><strong>&lt;%
1594
1773
  my $user = 'Erubis';
1595
1774
  my @list = ('&lt;aaa&gt;', 'b&amp;b', '"ccc"');
1596
- %&gt;</b>
1775
+ %&gt;</strong>
1597
1776
  &lt;html&gt;
1598
1777
  &lt;body&gt;
1599
- &lt;p&gt;Hello <b>&lt;%= $user %&gt;</b>!&lt;/p&gt;
1778
+ &lt;p&gt;Hello <strong>&lt;%= $user %&gt;</strong>!&lt;/p&gt;
1600
1779
  &lt;table&gt;
1601
- <b>&lt;% $i = 0; %&gt;</b>
1602
- <b>&lt;% for $item (@list) { %&gt;</b>
1603
- &lt;tr bgcolor=<b>&lt;%= ++$i % 2 == 0 ? '#FFCCCC' : '#CCCCFF' %&gt;</b>"&gt;
1604
- &lt;td&gt;<b>&lt;%= $i %&gt;</b>&lt;/td&gt;
1605
- &lt;td&gt;<b>&lt;%= $item %&gt;</b>&lt;/td&gt;
1780
+ <strong>&lt;% $i = 0; %&gt;</strong>
1781
+ <strong>&lt;% for $item (@list) { %&gt;</strong>
1782
+ &lt;tr bgcolor=<strong>&lt;%= ++$i % 2 == 0 ? '#FFCCCC' : '#CCCCFF' %&gt;</strong>"&gt;
1783
+ &lt;td&gt;<strong>&lt;%= $i %&gt;</strong>&lt;/td&gt;
1784
+ &lt;td&gt;<strong>&lt;%= $item %&gt;</strong>&lt;/td&gt;
1606
1785
  &lt;/tr&gt;
1607
- <b>&lt;% } %&gt;</b>
1786
+ <strong>&lt;% } %&gt;</strong>
1608
1787
  &lt;/table&gt;
1609
1788
  &lt;/body&gt;
1610
1789
  &lt;/html&gt;
@@ -1612,7 +1791,7 @@ example.eprl</div>
1612
1791
  <div class="terminal_caption">
1613
1792
  compiled source code</div>
1614
1793
  <pre class="terminal">$ erubis -l perl example.eperl
1615
-
1794
+ use HTML::Entities;
1616
1795
  my $user = 'Erubis';
1617
1796
  my @list = ('&lt;aaa&gt;', 'b&amp;b', '"ccc"');
1618
1797
 
@@ -1637,25 +1816,25 @@ print(' &lt;/table&gt;
1637
1816
 
1638
1817
  <a name="lang-javascript"></a>
1639
1818
  <h3 class="section2">JavaScript</h3>
1640
- <p>example.ejs
1641
- </p>
1642
1819
  <a name="example.ejs"></a>
1643
- <pre class="program"><b>&lt;%
1820
+ <div class="program_caption">
1821
+ example.ejs</div>
1822
+ <pre class="program"><strong>&lt;%
1644
1823
  var user = 'Erubis';
1645
1824
  var list = ['&lt;aaa&gt;', 'b&amp;b', '"ccc"'];
1646
- %&gt;</b>
1825
+ %&gt;</strong>
1647
1826
  &lt;html&gt;
1648
1827
  &lt;body&gt;
1649
- &lt;p&gt;Hello <b>&lt;%= user %&gt;</b>!&lt;/p&gt;
1828
+ &lt;p&gt;Hello <strong>&lt;%= user %&gt;</strong>!&lt;/p&gt;
1650
1829
  &lt;table&gt;
1651
1830
  &lt;tbody&gt;
1652
- <b>&lt;% var i; %&gt;</b>
1653
- <b>&lt;% for (i = 0; i &lt; list.length; i++) { %&gt;</b>
1654
- &lt;tr bgcolor="<b>&lt;%= i % 2 == 0 ? '#FFCCCC' : '#CCCCFF' %&gt;</b>"&gt;
1655
- &lt;td&gt;<b>&lt;%= i + 1 %&gt;</b>&lt;/td&gt;
1656
- &lt;td&gt;<b>&lt;%= list[i] %&gt;</b>&lt;/td&gt;
1831
+ <strong>&lt;% var i; %&gt;</strong>
1832
+ <strong>&lt;% for (i = 0; i &lt; list.length; i++) { %&gt;</strong>
1833
+ &lt;tr bgcolor="<strong>&lt;%= i % 2 == 0 ? '#FFCCCC' : '#CCCCFF' %&gt;</strong>"&gt;
1834
+ &lt;td&gt;<strong>&lt;%= i + 1 %&gt;</strong>&lt;/td&gt;
1835
+ &lt;td&gt;<strong>&lt;%= list[i] %&gt;</strong>&lt;/td&gt;
1657
1836
  &lt;/tr&gt;
1658
- <b>&lt;% } %&gt;</b>
1837
+ <strong>&lt;% } %&gt;</strong>
1659
1838
  &lt;/tbody&gt;
1660
1839
  &lt;/table&gt;
1661
1840
  &lt;/body&gt;
@@ -1703,10 +1882,43 @@ try TinyEruby class.
1703
1882
  <br>
1704
1883
 
1705
1884
 
1885
+ <a name="topics-rails"></a>
1886
+ <h3 class="section2">Ruby on Rails Support</h3>
1887
+ <p>Erubis supports Ruby on Rails.
1888
+ Add the following code to your 'app/controllers/application.rb'.
1889
+ </p>
1890
+ <div class="program_caption">
1891
+ app/controllers/application.rb</div>
1892
+ <pre class="program">require 'erubis/helper/rails'
1893
+ suffix = 'erubis'
1894
+ ActionView::Base.register_template_handler(suffix, Erubis::Helper::RailsTemplate)
1895
+ #Erubis::Helper::RailsTemplate.engine_class = Erubis::EscapedEruby ## or Erubis::PI::Eruby
1896
+ #Erubis::Helper::RailsTemplate.default_properties = { :escape=&gt;true, :escapefunc=&gt;'h' }
1897
+ </pre>
1898
+ <p>If you specify Erubis::Helper::CachedRailsTemplate class instead of Erubis::Helper::RailsTemplate class, template string is cached in memory (but template is not reloaded when it is modified).
1899
+ </p>
1900
+ <p>You may got the followign error:
1901
+ </p>
1902
+ <pre class="program">(eval):10:in `render': no block given
1903
+ </pre>
1904
+ <p>It is because layout file scaffold created contains 'yield' method.
1905
+ Use '@content_for_layout' instead 'yield'.
1906
+ </p>
1907
+ <div class="program_caption">
1908
+ app/views/layouts/xxx.erubis</div>
1909
+ <pre class="program"> ...
1910
+ &lt;%<strong>#</strong>= yield %&gt;
1911
+ <strong>&lt;%= @content_for_layout %&gt;</strong>
1912
+ ...
1913
+ </pre>
1914
+ <br>
1915
+
1916
+
1706
1917
  <a name="topics-php"></a>
1707
- <h3 class="section2">NoTextEnhancer in PHP</h3>
1708
- <p>NoTextEnhancer is quite useful not only for eRuby but also for PHP.
1709
- It can "drop" HTML text and show up embedded Ruby/PHP code.
1918
+ <h3 class="section2">NoTextEnhancer and NoCodeEnhancer in PHP</h3>
1919
+ <p>NoTextEnhancer and NoCodEnahncer are quite useful not only for eRuby but also for PHP.
1920
+ The former "drops" HTML text and show up embedded Ruby/PHP code
1921
+ and the latter drops embedded Ruby/PHP code and leave HTML text.
1710
1922
  </p>
1711
1923
  <p>For example, see the following PHP script.
1712
1924
  </p>
@@ -1738,22 +1950,150 @@ NoTextEnhancer can separate PHP code from HTML document.
1738
1950
  </p>
1739
1951
  <div class="terminal_caption">
1740
1952
  example of using NoTextEnhancer with PHP file</div>
1741
- <pre class="terminal">$ erubis -T -l php -E NoText -p '&lt;\?php \?&gt;' notext-example.php | uniq
1953
+ <pre class="terminal">$ erubis -T -l php -E NoText -p '&lt;\?php \?&gt;' notext-example.php | cat -n
1954
+ 1
1955
+ 2
1956
+ 3
1957
+ 4 &lt;?php if (!$list || count($list) == 0) { ?&gt;
1958
+ 5
1959
+ 6 &lt;?php } else { ?&gt;
1960
+ 7
1961
+ 8
1962
+ 9 &lt;?php $i = 0; ?&gt;
1963
+ 10 &lt;?php foreach ($list as $item) { ?&gt;
1964
+ 11 &lt;?php echo ++$i % 2 == 1 ? '#FFCCCC' : '#CCCCFF'; ?&gt;
1965
+ 12 &lt;?php echo $item; ?&gt;
1966
+ 13
1967
+ 14 &lt;?php } ?&gt;
1968
+ 15
1969
+ 16
1970
+ 17 &lt;?php } ?&gt;
1971
+ 18
1972
+ 19
1973
+ </pre>
1974
+ <p>In the same way, NoCodeEnhancer can extract HTML tags.
1975
+ </p>
1976
+ <div class="terminal_caption">
1977
+ example of using NoCodeEnhancer with PHP file</div>
1978
+ <pre class="terminal">$ erubis -T -l php -E NoCode -p '&lt;\?php \?&gt;' notext-example.php | cat -n
1979
+ 1 &lt;html&gt;
1980
+ 2 &lt;body&gt;
1981
+ 3 &lt;h3&gt;List&lt;/h3&gt;
1982
+ 4
1983
+ 5 &lt;p&gt;not found.&lt;/p&gt;
1984
+ 6
1985
+ 7 &lt;table&gt;
1986
+ 8 &lt;tbody&gt;
1987
+ 9
1988
+ 10
1989
+ 11 &lt;tr bgcolor=""&gt;
1990
+ 12 &lt;td&gt;&lt;/td&gt;
1991
+ 13 &lt;/tr&gt;
1992
+ 14
1993
+ 15 &lt;/tbody&gt;
1994
+ 16 &lt;/table&gt;
1995
+ 17
1996
+ 18 &lt;/body&gt;
1997
+ 19 &lt;/html&gt;
1998
+ </pre>
1999
+ <br>
1742
2000
 
1743
- &lt;?php if (!$list || count($list) == 0) { ?&gt;
1744
2001
 
1745
- &lt;?php } else { ?&gt;
2002
+ <a name="topics-notext"></a>
2003
+ <h3 class="section2">Command <code>notext</code></h3>
2004
+ <p>Command 'notext' removes text part from eRuby script and leaves only embedded Ruby code.
2005
+ This is very useful when debugging eRuby script.
2006
+ </p>
2007
+ <div class="program_caption">
2008
+ notext-ex.rhtml</div>
2009
+ <pre class="program">&lt;html&gt;
2010
+ &lt;head&gt;
2011
+ &lt;title&gt;notext example&lt;/title&gt;
2012
+ &lt;/head&gt;
2013
+ &lt;body&gt;
2014
+ &lt;table&gt;
2015
+ &lt;% @list.each_with_index do |item, i| %&gt;
2016
+ &lt;% klass = i % 2 == 0 ? 'odd' : 'even' %&gt;
2017
+ &lt;tr class="&lt;%= klass %&gt;"&gt;
2018
+ &lt;td&gt;&lt;%== item %&gt;&lt;/td&gt;
2019
+ &lt;/tr&gt;
2020
+ &lt;% end %&gt;
2021
+ &lt;/table&gt;
2022
+ &lt;/body&gt;
2023
+ &lt;/html&gt;
2024
+ </pre>
2025
+ <div class="terminal_caption">
2026
+ command line example</div>
2027
+ <pre class="terminal">$ notext notext-ex.rhtml
2028
+ _buf = [];
1746
2029
 
1747
- &lt;?php $i = 0; ?&gt;
1748
- &lt;?php foreach ($list as $item) { ?&gt;
1749
- &lt;?php echo ++$i % 2 == 1 ? '#FFCCCC' : '#CCCCFF'; ?&gt;
1750
- &lt;?php echo $item; ?&gt;
1751
2030
 
1752
- &lt;?php } ?&gt;
1753
2031
 
1754
- &lt;?php } ?&gt;
1755
2032
 
2033
+
2034
+ @list.each_with_index do |item, i| ;
2035
+ klass = i % 2 == 0 ? 'odd' : 'even' ;
2036
+ _buf &lt;&lt; ( klass ).to_s;
2037
+ _buf &lt;&lt; Erubis::XmlHelper.escape_xml( item );
2038
+
2039
+ end ;
2040
+
2041
+
2042
+ _buf.join
1756
2043
  </pre>
2044
+ <p>Command-line option '-u' deletes continuous empty lines to one empty line.
2045
+ </p>
2046
+ <div class="terminal_caption">
2047
+ command-line example</div>
2048
+ <pre class="terminal">$ notext <strong>-u</strong> notext-ex.rhtml
2049
+ _buf = [];
2050
+
2051
+ @list.each_with_index do |item, i| ;
2052
+ klass = i % 2 == 0 ? 'odd' : 'even' ;
2053
+ _buf &lt;&lt; ( klass ).to_s;
2054
+ _buf &lt;&lt; Erubis::XmlHelper.escape_xml( item );
2055
+
2056
+ end ;
2057
+
2058
+ _buf.join
2059
+ </pre>
2060
+ <p>Command-line option '-c' deletes all empty lines.
2061
+ </p>
2062
+ <div class="terminal_caption">
2063
+ command-line example</div>
2064
+ <pre class="terminal">$ notext <strong>-c</strong> notext-ex.rhtml
2065
+ _buf = [];
2066
+ @list.each_with_index do |item, i| ;
2067
+ klass = i % 2 == 0 ? 'odd' : 'even' ;
2068
+ _buf &lt;&lt; ( klass ).to_s;
2069
+ _buf &lt;&lt; Erubis::XmlHelper.escape_xml( item );
2070
+ end ;
2071
+ _buf.join
2072
+ </pre>
2073
+ <p>Command-line option '-n' shows line numbers. It can work with '-c' or '-u'.
2074
+ </p>
2075
+ <pre class="terminal">$ notext <strong>-nu</strong> example2.rhtml
2076
+ 1: _buf = [];
2077
+
2078
+ 7: @list.each_with_index do |item, i| ;
2079
+ 8: klass = i % 2 == 0 ? 'odd' : 'even' ;
2080
+ 9: _buf &lt;&lt; ( klass ).to_s;
2081
+ 10: _buf &lt;&lt; Erubis::XmlHelper.escape_xml( item );
2082
+
2083
+ 12: end ;
2084
+
2085
+ 16: _buf.join
2086
+ $ notext <strong>-nc</strong> example2.rhtml
2087
+ 1: _buf = [];
2088
+ 7: @list.each_with_index do |item, i| ;
2089
+ 8: klass = i % 2 == 0 ? 'odd' : 'even' ;
2090
+ 9: _buf &lt;&lt; ( klass ).to_s;
2091
+ 10: _buf &lt;&lt; Erubis::XmlHelper.escape_xml( item );
2092
+ 12: end ;
2093
+ 16: _buf.join
2094
+ </pre>
2095
+ <p>Command 'notext' supports '-l <em>lang</em>' options. For example, command-line option '-l php' retrieves embedded PHP code from PHP file.
2096
+ </p>
1757
2097
  <br>
1758
2098
 
1759
2099
 
@@ -1763,43 +2103,37 @@ example of using NoTextEnhancer with PHP file</div>
1763
2103
  Here is an example result of benchmark.
1764
2104
  </p>
1765
2105
  <div class="output_caption">
1766
- Env: Linux FedoraCore4, Celeron 667MHz, Mem512MB, Ruby1.8.4</div>
2106
+ Env: Linux FedoraCore4, Celeron 667MHz, Mem512MB, Ruby1.8.4, eruby1.0.5</div>
1767
2107
  <pre class="output"> user system total real
1768
- ERuby 138.280000 1.900000 140.180000 (141.470426)
1769
- ERB 402.220000 3.190000 405.410000 (408.886894)
1770
- Erubis::Eruby 147.080000 2.400000 149.480000 (150.752255)
1771
- Erubis::StringBufferEruby 186.130000 2.600000 188.730000 (190.374098)
1772
- Erubis::SimplifiedEruby 130.100000 2.210000 132.310000 (133.426010)
1773
- Erubis::StdoutEruby 106.010000 2.130000 108.140000 (108.999193)
1774
- Erubis::StdoutSimplifiedEruby 97.130000 2.180000 99.310000 (100.104433)
1775
- Erubis::TinyEruby 118.740000 2.360000 121.100000 (122.141380)
1776
- Erubis::TinyStdoutEruby 86.140000 1.840000 87.980000 ( 88.679196)
2108
+ ERuby 131.990000 1.900000 133.890000 (135.061456)
2109
+ ERB 385.040000 3.180000 388.220000 (391.570653)
2110
+ Erubis::Eruby 127.750000 2.520000 130.270000 (131.385922)
2111
+ Erubis::StringBufferEruby 167.610000 2.600000 170.210000 (171.712798)
2112
+ Erubis::StdoutEruby 92.790000 2.000000 94.790000 ( 95.532633)
2113
+ Erubis::TinyEruby 118.720000 2.250000 120.970000 (122.022996)
2114
+ Erubis::TinyStdoutEruby 87.130000 2.030000 89.160000 ( 89.879538)
1777
2115
  </pre>
1778
2116
  <div class="output_caption">
1779
- Env: MacOS X 10.4, PowerPC 1.42GHz, Mem1.5GB, Ruby1.8.4</div>
2117
+ Env: MacOS X 10.4, PowerPC 1.42GHz, Mem1.5GB, Ruby1.8.4, eruby1.0.5</div>
1780
2118
  <pre class="output"> user system total real
1781
2119
  ERuby 55.040000 2.120000 57.160000 ( 89.311397)
1782
2120
  ERB 103.960000 3.480000 107.440000 (159.231792)
1783
2121
  Erubis::Eruby 36.130000 1.570000 37.700000 ( 52.188574)
1784
2122
  Erubis::StringBufferEruby 47.270000 1.980000 49.250000 ( 73.867537)
1785
- Erubis::SimplifiedEruby 34.310000 1.600000 35.910000 ( 51.762841)
1786
2123
  Erubis::StdoutEruby 26.240000 1.490000 27.730000 ( 41.840430)
1787
- Erubis::StdoutSimplifiedEruby 25.380000 1.340000 26.720000 ( 37.231918)
1788
2124
  Erubis::TinyEruby 31.690000 1.590000 33.280000 ( 49.862091)
1789
2125
  Erubis::TinyStdoutEruby 22.550000 1.230000 23.780000 ( 33.316978)
1790
2126
  </pre>
1791
2127
  <p>This shows that:
1792
2128
  </p>
1793
2129
  <ul type="disc">
1794
- <li>Erubis::Eruby is about 2.7 or 2.9 times faster than ERB.
2130
+ <li>Erubis::Eruby is about 3 times faster than ERB.
1795
2131
  </li>
1796
- <li>Erubis::Eruby is about 6% slower in linux or 1.5 times faster than ERuby in Mac.
1797
- </li>
1798
- <li>Erubis::SimplifiedEruby (which incudes SimplifiedEnhander) is faster than ERuby.
2132
+ <li>Erubis::Eruby is about 3% faster than ERuby in linux or 1.5 times faster in Mac.
1799
2133
  </li>
1800
2134
  <li>String buffer (StringBufferEnhancer) is slower than array buffer (ArrayBufferEnhancer which Erubis::Eruby includes)
1801
2135
  </li>
1802
- <li>Using print statement or $stdout is faster than array buffer and string buffer.
2136
+ <li>Using $stdout is faster than array buffer and string buffer.
1803
2137
  </li>
1804
2138
  <li>Erubis::TinyEruby (at 'erubis/tiny.rb') and it's subclasses are the fastest in all eRuby implementation.
1805
2139
  </li>
@@ -1814,7 +2148,7 @@ Erubis::TinyStdoutEruby 22.550000 1.230000 23.780000 ( 33.316978)
1814
2148
  <h2 class="section1">Command Reference</h2>
1815
2149
  <a name="command-usage"></a>
1816
2150
  <h3 class="section2">Usage</h3>
1817
- <p>erubis [..options..] [<i>file</i> ...]
2151
+ <p>erubis [..options..] [<em>file</em> ...]
1818
2152
  </p>
1819
2153
  <br>
1820
2154
 
@@ -1858,7 +2192,7 @@ Erubis::TinyStdoutEruby 22.550000 1.230000 23.780000 ( 33.316978)
1858
2192
  -p pattern </b></dt>
1859
2193
  <dd class="dd3">
1860
2194
  Embedded pattern (default '&lt;% %&gt;').
1861
- This is equivarent to '--pattern=<i>pattern</i>'.
2195
+ This is equivarent to '--pattern=<em>pattern</em>'.
1862
2196
  </dd>
1863
2197
  <dt class="dt3"><b>
1864
2198
  -l lang </b></dt>
@@ -1907,6 +2241,11 @@ Erubis::TinyStdoutEruby 22.550000 1.230000 23.780000 ( 33.316978)
1907
2241
  <dd class="dd3">
1908
2242
  invoke Eruby#result() instead of Eruby#evaluate()
1909
2243
  </dd>
2244
+ <dt class="dt3"><b>
2245
+ --pi[=name] </b></dt>
2246
+ <dd class="dd3">
2247
+ parse '&lt;?name ... ?&gt;' instead of '&lt;% ... %&gt;'
2248
+ </dd>
1910
2249
  </dl>
1911
2250
  <br>
1912
2251