erubis 2.6.6 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. data/CHANGES.txt +79 -3
  2. data/MIT-LICENSE +1 -1
  3. data/README.txt +2 -2
  4. data/benchmark/bench.rb +2 -2
  5. data/bin/erubis +2 -2
  6. data/contrib/erubis +293 -155
  7. data/contrib/inline-require +2 -2
  8. data/doc-api/classes/Erubis.html +10 -1
  9. data/doc-api/classes/Erubis/ArrayBufferEnhancer.html +12 -12
  10. data/doc-api/classes/Erubis/ArrayEnhancer.html +14 -14
  11. data/doc-api/classes/Erubis/Basic/Converter.html +24 -24
  12. data/doc-api/classes/Erubis/BiPatternEnhancer.html +12 -12
  13. data/doc-api/classes/Erubis/CGenerator.html +60 -60
  14. data/doc-api/classes/Erubis/Context.html +42 -42
  15. data/doc-api/classes/Erubis/Converter.html +27 -27
  16. data/doc-api/classes/Erubis/CppGenerator.html +382 -0
  17. data/doc-api/classes/Erubis/DeleteIndentEnhancer.html +7 -7
  18. data/doc-api/classes/Erubis/Ecpp.html +126 -0
  19. data/doc-api/classes/Erubis/Engine.html +36 -36
  20. data/doc-api/classes/Erubis/ErboutEnhancer.html +14 -14
  21. data/doc-api/classes/Erubis/EscapeEnhancer.html +6 -6
  22. data/doc-api/classes/Erubis/EscapedEcpp.html +120 -0
  23. data/doc-api/classes/Erubis/Evaluator.html +19 -19
  24. data/doc-api/classes/Erubis/Generator.html +60 -60
  25. data/doc-api/classes/Erubis/HeaderFooterEnhancer.html +14 -14
  26. data/doc-api/classes/Erubis/Helpers/RailsFormHelper.html +150 -150
  27. data/doc-api/classes/Erubis/Helpers/RailsHelper.html +49 -49
  28. data/doc-api/classes/Erubis/Helpers/RailsHelper/TemplateConverter.html +24 -24
  29. data/doc-api/classes/Erubis/InterpolationEnhancer.html +38 -39
  30. data/doc-api/classes/Erubis/JavaGenerator.html +60 -60
  31. data/doc-api/classes/Erubis/JavascriptGenerator.html +66 -66
  32. data/doc-api/classes/Erubis/Main.html +22 -22
  33. data/doc-api/classes/Erubis/NoCodeEnhancer.html +30 -30
  34. data/doc-api/classes/Erubis/NoTextEnhancer.html +6 -6
  35. data/doc-api/classes/Erubis/OptimizedEruby.html +6 -6
  36. data/doc-api/classes/Erubis/OptimizedGenerator.html +72 -72
  37. data/doc-api/classes/Erubis/OptimizedXmlEruby.html +6 -6
  38. data/doc-api/classes/Erubis/PI.html +1 -0
  39. data/doc-api/classes/Erubis/PI/Converter.html +18 -18
  40. data/doc-api/classes/Erubis/PI/Ec.html +6 -6
  41. data/doc-api/classes/Erubis/PI/Ecpp.html +166 -0
  42. data/doc-api/classes/Erubis/PI/Ejava.html +6 -6
  43. data/doc-api/classes/Erubis/PI/Ejavascript.html +6 -6
  44. data/doc-api/classes/Erubis/PI/Eperl.html +6 -6
  45. data/doc-api/classes/Erubis/PI/Ephp.html +6 -6
  46. data/doc-api/classes/Erubis/PI/Eruby.html +7 -7
  47. data/doc-api/classes/Erubis/PI/Escheme.html +6 -6
  48. data/doc-api/classes/Erubis/PI/TinyEruby.html +24 -24
  49. data/doc-api/classes/Erubis/PercentLineEnhancer.html +18 -34
  50. data/doc-api/classes/Erubis/PerlGenerator.html +54 -54
  51. data/doc-api/classes/Erubis/PhpGenerator.html +54 -54
  52. data/doc-api/classes/Erubis/PrefixedLineEnhancer.html +210 -0
  53. data/doc-api/classes/Erubis/PrefixedLineEruby.html +120 -0
  54. data/doc-api/classes/Erubis/PreprocessingEruby.html +12 -12
  55. data/doc-api/classes/Erubis/PreprocessingHelper.html +22 -22
  56. data/doc-api/classes/Erubis/PrintEnabledEnhancer.html +20 -20
  57. data/doc-api/classes/Erubis/PrintOutEnhancer.html +33 -33
  58. data/doc-api/classes/Erubis/RubyEvaluator.html +18 -18
  59. data/doc-api/classes/Erubis/RubyGenerator.html +59 -58
  60. data/doc-api/classes/Erubis/SchemeGenerator.html +60 -60
  61. data/doc-api/classes/Erubis/SimplifyEnhancer.html +7 -7
  62. data/doc-api/classes/Erubis/StdoutEnhancer.html +13 -13
  63. data/doc-api/classes/Erubis/StringBufferEnhancer.html +14 -14
  64. data/doc-api/classes/Erubis/TinyEruby.html +24 -24
  65. data/doc-api/classes/Erubis/XmlHelper.html +30 -30
  66. data/doc-api/classes/Kernel.html +155 -0
  67. data/doc-api/created.rid +1 -1
  68. data/doc-api/files/README_txt.html +3 -3
  69. data/doc-api/files/erubis/context_rb.html +1 -1
  70. data/doc-api/files/erubis/converter_rb.html +3 -3
  71. data/doc-api/files/erubis/engine/ec_rb.html +1 -1
  72. data/doc-api/files/erubis/engine/ecpp_rb.html +115 -0
  73. data/doc-api/files/erubis/engine/ejava_rb.html +2 -2
  74. data/doc-api/files/erubis/engine/ejavascript_rb.html +2 -2
  75. data/doc-api/files/erubis/engine/enhanced_rb.html +2 -2
  76. data/doc-api/files/erubis/engine/eperl_rb.html +1 -1
  77. data/doc-api/files/erubis/engine/ephp_rb.html +1 -1
  78. data/doc-api/files/erubis/engine/eruby_rb.html +2 -2
  79. data/doc-api/files/erubis/engine/escheme_rb.html +1 -1
  80. data/doc-api/files/erubis/engine/optimized_rb.html +1 -1
  81. data/doc-api/files/erubis/engine_rb.html +2 -2
  82. data/doc-api/files/erubis/enhancer_rb.html +2 -2
  83. data/doc-api/files/erubis/error_rb.html +1 -1
  84. data/doc-api/files/erubis/evaluator_rb.html +1 -1
  85. data/doc-api/files/erubis/generator_rb.html +3 -3
  86. data/doc-api/files/erubis/helper_rb.html +1 -1
  87. data/doc-api/files/erubis/helpers/rails_form_helper_rb.html +1 -1
  88. data/doc-api/files/erubis/helpers/rails_helper_rb.html +1 -1
  89. data/doc-api/files/erubis/local-setting_rb.html +1 -1
  90. data/doc-api/files/erubis/main_rb.html +4 -2
  91. data/doc-api/files/erubis/preprocessing_rb.html +1 -1
  92. data/doc-api/files/erubis/tiny_rb.html +1 -1
  93. data/doc-api/files/erubis/util_rb.html +107 -0
  94. data/doc-api/files/erubis_rb.html +2 -2
  95. data/doc-api/fr_class_index.html +7 -0
  96. data/doc-api/fr_file_index.html +2 -0
  97. data/doc-api/fr_method_index.html +237 -223
  98. data/doc/docstyle.css +25 -4
  99. data/doc/users-guide.html +286 -21
  100. data/examples/basic/Makefile +7 -2
  101. data/examples/basic/example.ecpp +33 -0
  102. data/lib/erubis.rb +4 -3
  103. data/lib/erubis/context.rb +2 -2
  104. data/lib/erubis/converter.rb +3 -3
  105. data/lib/erubis/engine.rb +8 -8
  106. data/lib/erubis/engine/ec.rb +2 -2
  107. data/lib/erubis/engine/ecpp.rb +113 -0
  108. data/lib/erubis/engine/ejava.rb +9 -9
  109. data/lib/erubis/engine/ejavascript.rb +9 -9
  110. data/lib/erubis/engine/enhanced.rb +7 -2
  111. data/lib/erubis/engine/eperl.rb +2 -2
  112. data/lib/erubis/engine/ephp.rb +2 -2
  113. data/lib/erubis/engine/eruby.rb +8 -7
  114. data/lib/erubis/engine/escheme.rb +2 -2
  115. data/lib/erubis/engine/optimized.rb +2 -2
  116. data/lib/erubis/enhancer.rb +70 -27
  117. data/lib/erubis/error.rb +2 -2
  118. data/lib/erubis/evaluator.rb +2 -2
  119. data/lib/erubis/generator.rb +3 -3
  120. data/lib/erubis/helper.rb +2 -2
  121. data/lib/erubis/helpers/rails_form_helper.rb +2 -2
  122. data/lib/erubis/helpers/rails_helper.rb +2 -2
  123. data/lib/erubis/local-setting.rb +2 -2
  124. data/lib/erubis/main.rb +31 -4
  125. data/lib/erubis/preprocessing.rb +2 -2
  126. data/lib/erubis/tiny.rb +2 -2
  127. data/lib/erubis/util.rb +22 -0
  128. data/test/assert-text-equal.rb +2 -2
  129. data/test/data/users-guide/bufvar-example.rb +10 -0
  130. data/test/data/users-guide/bufvar-example.result +17 -0
  131. data/test/data/users-guide/example.ecpp +30 -0
  132. data/test/data/users-guide/example_c.result +22 -19
  133. data/test/data/users-guide/fasteruby-example.rb +8 -0
  134. data/test/data/users-guide/fasteruby-example.result +18 -0
  135. data/test/data/users-guide/percentline-example.rhtml +3 -1
  136. data/test/data/users-guide/percentline_example.result +5 -3
  137. data/test/data/users-guide/prefixedline-example.rb +9 -0
  138. data/test/data/users-guide/prefixedline-example.rhtml +6 -0
  139. data/test/data/users-guide/prefixedline_example.result +9 -0
  140. data/test/test-engines.rb +58 -2
  141. data/test/test-enhancers.rb +51 -2
  142. data/test/test-erubis.rb +14 -10
  143. data/test/test-index-cgi.rb +191 -0
  144. data/test/test-main.rb +35 -4
  145. data/test/test-users-guide.rb +18 -2
  146. data/test/test.rb +18 -2
  147. data/test/testutil.rb +22 -7
  148. metadata +30 -24
@@ -27,7 +27,7 @@ pre {
27
27
  white-space:pre;
28
28
  }
29
29
 
30
- .program {
30
+ pre.program {
31
31
  border-style:solid;
32
32
  border-width:1px;
33
33
  border-color:#6699FF;
@@ -38,7 +38,7 @@ pre {
38
38
  word-break:break-all;
39
39
  }
40
40
 
41
- .terminal {
41
+ pre.terminal {
42
42
  border-style:solid;
43
43
  border-width:1;
44
44
  border-color:#999999;
@@ -49,7 +49,7 @@ pre {
49
49
  word-break:break-all;
50
50
  }
51
51
 
52
- .output {
52
+ pre.output {
53
53
  border-style:solid;
54
54
  border-width:1px;
55
55
  border-color:#CCCCCC;
@@ -61,6 +61,12 @@ pre {
61
61
  }
62
62
 
63
63
 
64
+ pre strong {
65
+ color: #990000;
66
+ font-weight: bold;
67
+ }
68
+
69
+
64
70
  .program_caption {
65
71
  margin-top: 20px;
66
72
  }
@@ -168,7 +174,7 @@ h3, .subsection {
168
174
  font-size:small;
169
175
  }
170
176
 
171
- .note {
177
+ div.note, div.tips {
172
178
  background-color:#FFFFDD;
173
179
  border-style:solid;
174
180
  border-width:0px 1px 0px 1px;
@@ -176,9 +182,14 @@ h3, .subsection {
176
182
  color:#333300;
177
183
  /* font-size:small; */
178
184
  line-height:120%;
185
+ margin-top: 10px;
179
186
  padding: 5px 20px 5px 20px;
180
187
  }
181
188
 
189
+ div.note span.caption, div.tips span.caption {
190
+ color: #C60;
191
+ }
192
+
182
193
  .figure {
183
194
  /*
184
195
  border-width:1px;
@@ -186,3 +197,13 @@ h3, .subsection {
186
197
  white-space:pre;
187
198
  */
188
199
  }
200
+
201
+ strong {
202
+ color: #630;
203
+ font-weight; bold;
204
+ }
205
+
206
+
207
+ em {
208
+ font-style: italic;
209
+ }
@@ -13,12 +13,7 @@
13
13
  <div class="mainbody">
14
14
 
15
15
  <div align="left"><h1>Erubis Users' Guide</h1></div>
16
- <div align="left">
17
- release: 2.6.6<br>
18
- last update: $Date$<br>
19
- </div>
20
-
21
- <p>release: 2.6.6
16
+ <p>release: 2.7.0
22
17
  </p>
23
18
  <a name="preface"></a>
24
19
  <h2 class="section1">Preface</h2>
@@ -117,6 +112,8 @@ Erubis now supports Ruby 1.9.
117
112
  </li>
118
113
  <li><a href="#percentline-enhancer">PercentLineEnhancer</a>
119
114
  </li>
115
+ <li><a href="#prefixedline-enhancer">PrefixedLineEnhancer</a>
116
+ </li>
120
117
  <li><a href="#headerfooter-enhancer">HeaderFooterEnhancer</a>
121
118
  </li>
122
119
  <li><a href="#interpolation-enhancer">InterpolationEnhancer</a>
@@ -131,6 +128,8 @@ Erubis now supports Ruby 1.9.
131
128
  </li>
132
129
  <li><a href="#lang-c">C</a>
133
130
  </li>
131
+ <li><a href="#lang-cpp">C++</a>
132
+ </li>
134
133
  <li><a href="#lang-java">Java</a>
135
134
  </li>
136
135
  <li><a href="#lang-scheme">Scheme</a>
@@ -155,9 +154,13 @@ Erubis now supports Ruby 1.9.
155
154
  </li>
156
155
  <li><a href="#topics">Other Topics</a>
157
156
  <ul>
158
- <li><a href="#'&lt;%= =%&gt;' and '&lt;%= -%&gt;'">'&lt;%= =%&gt;' and '&lt;%= -%&gt;'</a>
157
+ <li><a href="#topics-fasteruby"><code>Erubis::FastEruby</code> Class</a>
158
+ </li>
159
+ <li><a href="#topics-bufvar"><code>:bufvar</code> Option</a>
160
+ </li>
161
+ <li><a href="#topics-trimspaces">'&lt;%= =%&gt;' and '&lt;%= -%&gt;'</a>
159
162
  </li>
160
- <li><a href="#'&lt;%% %&gt;' and '&lt;%%= %&gt;'">'&lt;%% %&gt;' and '&lt;%%= %&gt;'</a>
163
+ <li><a href="#topics-doublepercent">'&lt;%% %&gt;' and '&lt;%%= %&gt;'</a>
161
164
  </li>
162
165
  <li><a href="#topics-context-vs-binding">evaluate(context) v.s. result(binding)</a>
163
166
  </li>
@@ -173,6 +176,8 @@ Erubis now supports Ruby 1.9.
173
176
  </li>
174
177
  <li><a href="#topcs-modruby">Helper Class for mod_ruby</a>
175
178
  </li>
179
+ <li><a href="#topics-index-cgi">Helper CGI Script for Apache</a>
180
+ </li>
176
181
  <li><a href="#topics-defmethod">Define method</a>
177
182
  </li>
178
183
  <li><a href="#topics-benchmark">Benchmark</a>
@@ -1638,19 +1643,23 @@ This is for compatibility with eruby and ERB.
1638
1643
  <a name="percentline-example.rhtml"></a>
1639
1644
  <div class="program_caption">
1640
1645
  percentline-example.rhtml</div>
1641
- <pre class="program"><strong>% for item in list</strong>
1642
- &lt;b&gt;&lt;%= item %&gt;&lt;/b&gt;
1646
+ <pre class="program">&lt;ul&gt;
1647
+ <strong>% for item in list</strong>
1648
+ &lt;li&gt;&lt;%= item %&gt;&lt;/li&gt;
1643
1649
  <strong>% end</strong>
1644
- %% lines with '%%'
1650
+ &lt;/ul&gt;
1651
+ <strong>%% lines with '%%'</strong>
1645
1652
  </pre>
1646
1653
  <a name="percentline_example.result"></a>
1647
1654
  <div class="terminal_caption">
1648
1655
  compiled source code</div>
1649
1656
  <pre class="terminal">$ erubis -xE PercentLine percentline-example.rhtml
1650
- _buf = ''; <strong>for item in list</strong>
1651
- _buf &lt;&lt; ' &lt;b&gt;'; _buf &lt;&lt; ( item ).to_s; _buf &lt;&lt; '&lt;/b&gt;
1657
+ _buf = ''; _buf &lt;&lt; '&lt;ul&gt;
1658
+ '; <strong>for item in list</strong>
1659
+ _buf &lt;&lt; ' &lt;li&gt;'; _buf &lt;&lt; ( item ).to_s; _buf &lt;&lt; '&lt;/li&gt;
1652
1660
  '; <strong>end</strong>
1653
- _buf &lt;&lt; '% lines with \'%%\'
1661
+ _buf &lt;&lt; '&lt;/ul&gt;
1662
+ <strong>% lines with \'%%\'</strong>
1654
1663
  ';
1655
1664
  _buf.to_s
1656
1665
  </pre>
@@ -1659,6 +1668,58 @@ _buf.to_s
1659
1668
  <br>
1660
1669
 
1661
1670
 
1671
+ <a name="prefixedline-enhancer"></a>
1672
+ <h3 class="section2">PrefixedLineEnhancer</h3>
1673
+ <p>PrefixedlineEnhancer regards lines starting with '%' as Ruby code.
1674
+ It is similar to <a href="#percentline-enhancer">PercentLineEnhancer</a>, but there are some differences.
1675
+ </p>
1676
+ <ul type="disc">
1677
+ <li>PrefixedlineEnhancer allows to indent lines starting with '%', but PercentLineEnhancer doesn't.
1678
+ </li>
1679
+ <li>PrefixedlineEnhancer allows to change prefixed character (default '%'), but PercentLineEnhancer doesn't.
1680
+ </li>
1681
+ </ul>
1682
+ <a name="prefixedline-example.rhtml"></a>
1683
+ <div class="program_caption">
1684
+ prefixedline-example.rhtml</div>
1685
+ <pre class="program">&lt;ul&gt;
1686
+ <strong>! for item in list</strong>
1687
+ &lt;li&gt;&lt;%= item %&gt;&lt;/li&gt;
1688
+ <strong>! end</strong>
1689
+ &lt;/ul&gt;
1690
+ <strong>!! lines with '!!'</strong>
1691
+ </pre>
1692
+ <a name="prefixedline-example.rb"></a>
1693
+ <div class="program_caption">
1694
+ prefixedline-example.rb</div>
1695
+ <pre class="program">require 'erubis'
1696
+
1697
+ class PrefixedLineEruby &lt; Erubis::Eruby
1698
+ include Erubis::PrefixedLineEnhancer
1699
+ end
1700
+
1701
+ input = File.read('prefixedline-example.rhtml')
1702
+ eruby = PrefixedLineEruby.new(input, :prefixchar=&gt;'!') # default '%'
1703
+ print eruby.src
1704
+ </pre>
1705
+ <a name="prefixedline_example.result"></a>
1706
+ <div class="terminal_caption">
1707
+ compiled source code</div>
1708
+ <pre class="terminal">$ ruby prefixedline-example.rb
1709
+ _buf = ''; _buf &lt;&lt; '&lt;ul&gt;
1710
+ '; <strong>for item in list</strong>
1711
+ _buf &lt;&lt; ' &lt;li&gt;'; _buf &lt;&lt; ( item ).to_s; _buf &lt;&lt; '&lt;/li&gt;
1712
+ '; <strong>end</strong>
1713
+ _buf &lt;&lt; '&lt;/ul&gt;
1714
+ <strong>! lines with \'!!\'</strong>
1715
+ ';
1716
+ _buf.to_s
1717
+ </pre>
1718
+ <p>PrefixedLineEnhancer is language-independent.
1719
+ </p>
1720
+ <br>
1721
+
1722
+
1662
1723
  <a name="headerfooter-enhancer"></a>
1663
1724
  <h3 class="section2">HeaderFooterEnhancer</h3>
1664
1725
  <p>[experimental]
@@ -1974,6 +2035,81 @@ fputs(" &lt;/tbody&gt;\n"
1974
2035
  <br>
1975
2036
 
1976
2037
 
2038
+ <a name="lang-cpp"></a>
2039
+ <h3 class="section2">C++</h3>
2040
+ <a name="example.ecpp"></a>
2041
+ <div class="program_caption">
2042
+ example.ecpp</div>
2043
+ <pre class="program"><strong>&lt;%
2044
+ #include &lt;string&gt;
2045
+ #include &lt;iostream&gt;
2046
+ #include &lt;sstream&gt;
2047
+
2048
+ int main(int argc, char *argv[])
2049
+ {
2050
+ std::stringstream _buf;
2051
+ %&gt;</strong>
2052
+ &lt;html&gt;
2053
+ &lt;body&gt;
2054
+ &lt;p&gt;Hello <strong>&lt;%= argv[0] %&gt;</strong>!&lt;/p&gt;
2055
+ &lt;table&gt;
2056
+ &lt;tbody&gt;
2057
+ <strong>&lt;% for (int i = 1; i &lt; argc; i++) { %&gt;</strong>
2058
+ &lt;tr bgcolor="<strong>&lt;%= i % 2 == 0 ? "#FFCCCC" : "#CCCCFF" %&gt;</strong>"&gt;
2059
+ &lt;td&gt;<strong>&lt;%= i %&gt;</strong>&lt;/td&gt;
2060
+ &lt;td&gt;<strong>&lt;%= argv[i] %&gt;</strong>&lt;/td&gt;
2061
+ &lt;/tr&gt;
2062
+ <strong>&lt;% } %&gt;</strong>
2063
+ &lt;/tbody&gt;
2064
+ &lt;/table&gt;
2065
+ &lt;/body&gt;
2066
+ &lt;/html&gt;
2067
+ <strong>&lt;%
2068
+ std::string output = _buf.str();
2069
+ std::cout &lt;&lt; output;
2070
+ return 0;
2071
+ }
2072
+ %&gt;</strong>
2073
+ </pre>
2074
+ <a name="example_c.result"></a>
2075
+ <div class="terminal_caption">
2076
+ compiled source code</div>
2077
+ <pre class="terminal">$ erubis -l cpp example.ecpp
2078
+ #line 1 "example.ecpp"
2079
+
2080
+ #include &lt;string&gt;
2081
+ #include &lt;iostream&gt;
2082
+ #include &lt;sstream&gt;
2083
+
2084
+ int main(int argc, char *argv[])
2085
+ {
2086
+ std::stringstream _buf;
2087
+
2088
+ _buf &lt;&lt; "&lt;html&gt;\n"
2089
+ " &lt;body&gt;\n"
2090
+ " &lt;p&gt;Hello "; _buf &lt;&lt; (argv[0]); _buf &lt;&lt; "!&lt;/p&gt;\n"
2091
+ " &lt;table&gt;\n"
2092
+ " &lt;tbody&gt;\n";
2093
+ for (int i = 1; i &lt; argc; i++) {
2094
+ _buf &lt;&lt; " &lt;tr bgcolor=\""; _buf &lt;&lt; (i % 2 == 0 ? "#FFCCCC" : "#CCCCFF"); _buf &lt;&lt; "\"&gt;\n"
2095
+ " &lt;td&gt;"; _buf &lt;&lt; (i); _buf &lt;&lt; "&lt;/td&gt;\n"
2096
+ " &lt;td&gt;"; _buf &lt;&lt; (argv[i]); _buf &lt;&lt; "&lt;/td&gt;\n"
2097
+ " &lt;/tr&gt;\n";
2098
+ }
2099
+ _buf &lt;&lt; " &lt;/tbody&gt;\n"
2100
+ " &lt;/table&gt;\n"
2101
+ " &lt;/body&gt;\n"
2102
+ "&lt;/html&gt;\n";
2103
+
2104
+ std::string output = _buf.str();
2105
+ std::cout &lt;&lt; output;
2106
+ return 0;
2107
+ }
2108
+
2109
+ </pre>
2110
+ <br>
2111
+
2112
+
1977
2113
  <a name="lang-java"></a>
1978
2114
  <h3 class="section2">Java</h3>
1979
2115
  <a name="Example.ejava"></a>
@@ -2206,7 +2342,7 @@ compiled source code (with <code>--func=display</code> property)</div>
2206
2342
  <h3 class="section2">Perl</h3>
2207
2343
  <a name="example.eperl"></a>
2208
2344
  <div class="program_caption">
2209
- example.eprl</div>
2345
+ example.eperl</div>
2210
2346
  <pre class="program"><strong>&lt;%
2211
2347
  my $user = 'Erubis';
2212
2348
  my @list = ('&lt;aaa&gt;', 'b&amp;b', '"ccc"');
@@ -2326,6 +2462,8 @@ engine = Erubis::Ejavascript.new(s, <code>:docwrite=&gt;false</code>)
2326
2462
 
2327
2463
  <a name="rails"></a>
2328
2464
  <h2 class="section1">Ruby on Rails Support</h2>
2465
+ <p><span style="color:#FF0000">NOTICE: Rails 3 adopts Erubis as default default engine. You don't need to do anything at all when using Rails 3. This section is for Rails 2.</span>
2466
+ </p>
2329
2467
  <p>Erubis supports Ruby on Rails.
2330
2468
  This section describes how to use Erubis with Ruby on Rails.
2331
2469
  </p>
@@ -2613,7 +2751,92 @@ This means that pp_text_field() with preprocessing makes view layer very fast.
2613
2751
 
2614
2752
  <a name="topics"></a>
2615
2753
  <h2 class="section1">Other Topics</h2>
2616
- <a name="'&lt;%= =%&gt;' and '&lt;%= -%&gt;'"></a>
2754
+ <a name="topics-fasteruby"></a>
2755
+ <h3 class="section2"><code>Erubis::FastEruby</code> Class</h3>
2756
+ <p><code>Erubis::FastEruby</code> class generates more effective code than <code>Erubis::Eruby</code>.
2757
+ </p>
2758
+ <a name="fasteruby-example.rb"></a>
2759
+ <div class="program_caption">
2760
+ fasteruby-example.rb</div>
2761
+ <pre class="program">require 'erubis'
2762
+ input = File.read('example.eruby')
2763
+
2764
+ puts "----- Erubis::Eruby -----"
2765
+ print Erubis::Eruby.new(input).src
2766
+
2767
+ puts "----- Erubis::FastEruby -----"
2768
+ print <strong>Erubis::FastEruby</strong>.new(input).src
2769
+ </pre>
2770
+ <a name="fasteruby-example.result"></a>
2771
+ <div class="terminal_caption">
2772
+ result</div>
2773
+ <pre class="terminal">$ ruby fasteruby-example.rb
2774
+ ----- Erubis::Eruby -----
2775
+ _buf = ''; _buf &lt;&lt; '&lt;div&gt;
2776
+ '; for item in list
2777
+ _buf &lt;&lt; ' &lt;p&gt;'; <strong>_buf &lt;&lt; ( item ).to_s;</strong> _buf &lt;&lt; '&lt;/p&gt;
2778
+ &lt;p&gt;'; <strong>_buf &lt;&lt; Erubis::XmlHelper.escape_xml( item );</strong> _buf &lt;&lt; '&lt;/p&gt;
2779
+ '; end
2780
+ _buf &lt;&lt; '&lt;/div&gt;
2781
+ ';
2782
+ _buf.to_s
2783
+ ----- Erubis::FastEruby -----
2784
+ _buf = ''; _buf &lt;&lt; %Q`&lt;div&gt;\n`
2785
+ for item in list
2786
+ _buf &lt;&lt; %Q` &lt;p&gt;<strong>#{ item }</strong>&lt;/p&gt;
2787
+ &lt;p&gt;<strong>#{Erubis::XmlHelper.escape_xml( item )}</strong>&lt;/p&gt;\n`
2788
+ end
2789
+ _buf &lt;&lt; %Q`&lt;/div&gt;\n`
2790
+ _buf.to_s
2791
+ </pre>
2792
+ <p>Technically, <code>Erubis::FastEruby</code> is just a subclass of <code>Erubis::Eruby</code> and includes <code><a href="#interpolation-enhancer">InterpolationEnhancer</a></code>. <code>Erubis::FastEruby</code> is faster than <code>Erubis::Eruby</code> but is not extensible compared to <code>Erubis::Eruby</code>. This is the reason why <code>Erubis::FastEruby</code> is not the default class of Erubis.
2793
+ </p>
2794
+ <br>
2795
+
2796
+
2797
+ <a name="topics-bufvar"></a>
2798
+ <h3 class="section2"><code>:bufvar</code> Option</h3>
2799
+ <p>Since 2.7.0, Erubis supports <code>:bufvar</code> option which allows you to change buffer variable name (default '<code>_buf</code>').
2800
+ </p>
2801
+ <a name="bufvar-example.rb"></a>
2802
+ <div class="program_caption">
2803
+ bufvar-example.rb</div>
2804
+ <pre class="program">require 'erubis'
2805
+ input = File.read('example.eruby')
2806
+
2807
+ puts "----- default -----"
2808
+ eruby = Erubis::FastEruby.new(input)
2809
+ puts eruby.src
2810
+
2811
+ puts "----- with :bufvar option -----"
2812
+ eruby = Erubis::FastEruby.new(input, <strong>:bufvar=&gt;'@_out_buf'</strong>)
2813
+ print eruby.src
2814
+ </pre>
2815
+ <a name="bufvar-example.result"></a>
2816
+ <div class="terminal_caption">
2817
+ result</div>
2818
+ <pre class="terminal">$ ruby bufvar-example.rb
2819
+ ----- default -----
2820
+ _buf = ''; _buf &lt;&lt; %Q`&lt;div&gt;\n`
2821
+ for item in list
2822
+ _buf &lt;&lt; %Q` &lt;p&gt;#{ item }&lt;/p&gt;
2823
+ &lt;p&gt;#{Erubis::XmlHelper.escape_xml( item )}&lt;/p&gt;\n`
2824
+ end
2825
+ _buf &lt;&lt; %Q`&lt;/div&gt;\n`
2826
+ _buf.to_s
2827
+ ----- with :bufvar option -----
2828
+ <strong>@_out_buf</strong> = ''; <strong>@_out_buf</strong> &lt;&lt; %Q`&lt;div&gt;\n`
2829
+ for item in list
2830
+ <strong>@_out_buf</strong> &lt;&lt; %Q` &lt;p&gt;#{ item }&lt;/p&gt;
2831
+ &lt;p&gt;#{Erubis::XmlHelper.escape_xml( item )}&lt;/p&gt;\n`
2832
+ end
2833
+ <strong>@_out_buf</strong> &lt;&lt; %Q`&lt;/div&gt;\n`
2834
+ <strong>@_out_buf</strong>.to_s
2835
+ </pre>
2836
+ <br>
2837
+
2838
+
2839
+ <a name="topics-trimspaces"></a>
2617
2840
  <h3 class="section2">'&lt;%= =%&gt;' and '&lt;%= -%&gt;'</h3>
2618
2841
  <p>Since 2.6.0, '&lt;%= -%&gt;' remove tail spaces and newline.
2619
2842
  This is for compatibiliy with ERB when trim mode is '-'.
@@ -2646,7 +2869,7 @@ AAA
2646
2869
  <br>
2647
2870
 
2648
2871
 
2649
- <a name="'&lt;%% %&gt;' and '&lt;%%= %&gt;'"></a>
2872
+ <a name="topics-doublepercent"></a>
2650
2873
  <h3 class="section2">'&lt;%% %&gt;' and '&lt;%%= %&gt;'</h3>
2651
2874
  <p>Since 2.6.0, '&lt;%% %&gt;' and '&lt;%%= %&gt;' are converted into '&lt;% %&gt;' and '&lt;%= %&gt;' respectively.
2652
2875
  This is for compatibility with ERB.
@@ -2987,8 +3210,8 @@ example of using NoCodeEnhancer with PHP file</div>
2987
3210
  <p>Thanks Andrew R Jackson, he developed 'erubis-run.rb' which enables you to use Erubis with mod_ruby.
2988
3211
  </p>
2989
3212
  <ol type="1">
2990
- <li>Copy 'erubis-2.6.6/contrib/erubis-run.rb' to the 'RUBYLIBDIR/apache' directory (for example '/usr/local/lib/ruby/1.8/apache') which contains 'ruby-run.rb', 'eruby-run.rb', and so on.
2991
- <pre class="terminal">$ cd erubis-2.6.6/
3213
+ <li>Copy 'erubis-2.7.0/contrib/erubis-run.rb' to the 'RUBYLIBDIR/apache' directory (for example '/usr/local/lib/ruby/1.8/apache') which contains 'ruby-run.rb', 'eruby-run.rb', and so on.
3214
+ <pre class="terminal">$ cd erubis-2.7.0/
2992
3215
  $ sudo copy contrib/erubis-run.rb /usr/local/lib/ruby/1.8/apache/
2993
3216
  </pre>
2994
3217
  </li>
@@ -3039,6 +3262,48 @@ in the same directory in which '*.rhtml' file exists.
3039
3262
  <br>
3040
3263
 
3041
3264
 
3265
+ <a name="topics-index-cgi"></a>
3266
+ <h3 class="section2">Helper CGI Script for Apache</h3>
3267
+ <p>Erubis provides helper CGI script for Apache.
3268
+ Using this script, it is very easy to publish *.rhtml files as *.html.
3269
+ </p>
3270
+ <pre class="terminal">### install Erubis
3271
+ $ tar xzf erubis-X.X.X.tar.gz
3272
+ $ cd erubis-X.X.X/
3273
+ $ ruby setup.py install
3274
+ ### copy files to ~/public_html
3275
+ $ mkdir -p ~/public_html
3276
+ $ cp public_html/_htaccess ~/public_html/.htaccess
3277
+ $ cp public_html/index.cgi ~/public_html/
3278
+ $ cp public_html/index.rhtml ~/public_html/
3279
+ ### add executable permission to index.cgi
3280
+ $ chmod a+x ~/public_html/index.cgi
3281
+ ### edit .htaccess
3282
+ $ vi ~/public_html/.htaccess
3283
+ ### (optional) edit index.cgi to configure
3284
+ $ vi ~/public_html/index.cgi
3285
+ </pre>
3286
+ <p>Edit ~/public_html/.htaccess and modify user name.
3287
+ </p>
3288
+ <div class="program_caption">
3289
+ ~/public_html/.htaccess</div>
3290
+ <pre class="program">## enable mod_rewrie
3291
+ RewriteEngine on
3292
+ ## deny access to *.rhtml and *.cache
3293
+ #RewriteRule \.(rhtml|cache)$ - [R=404,L]
3294
+ RewriteRule \.(rhtml|cache)$ - [F,L]
3295
+ ## rewrite only if requested file is not found
3296
+ RewriteCond %{SCRIPT_FILENAME} !-f
3297
+ ## handle request to *.html and directories by index.cgi
3298
+ RewriteRule (\.html|/|^)$ /~<strong>username</strong>/index.cgi
3299
+ #RewriteRule (\.html|/|^)$ index.cgi
3300
+ </pre>
3301
+ <p>After these steps, *.rhtml will be published as *.html.
3302
+ For example, if you access to <code>http://<em>host</em>.<em>domain</em>/~<em>username</em>/index.html</code> (or <code>http://<em>host</em>.<em>domain</em>/~<em>username</em>/</code>), file <code>~/public_html/index.rhtml</code> will be displayed.
3303
+ </p>
3304
+ <br>
3305
+
3306
+
3042
3307
  <a name="topics-defmethod"></a>
3043
3308
  <h3 class="section2">Define method</h3>
3044
3309
  <p>Erubis::Eruby#def_method() defines instance method or singleton method.
@@ -3064,12 +3329,12 @@ p obj.render('world') #=&gt; "hello world"
3064
3329
 
3065
3330
  <a name="topics-benchmark"></a>
3066
3331
  <h3 class="section2">Benchmark</h3>
3067
- <p>A benchmark script is included in Erubis package at 'erubis-2.6.6/benchark/' directory.
3332
+ <p>A benchmark script is included in Erubis package at 'erubis-2.7.0/benchark/' directory.
3068
3333
  Here is an example result of benchmark.
3069
3334
  </p>
3070
3335
  <div class="terminal_caption">
3071
3336
  MacOS X 10.4 Tiger, Intel CoreDuo 1.83GHz, Ruby1.8.6, eruby1.0.5, gcc4.0.1</div>
3072
- <pre class="terminal">$ cd erubis-2.6.6/benchmark/
3337
+ <pre class="terminal">$ cd erubis-2.7.0/benchmark/
3073
3338
  $ ruby bench.rb -n 10000 -m execute
3074
3339
  *** ntimes=10000, testmode=execute
3075
3340
  user system total real