erubis 2.6.6 → 2.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.txt +79 -3
- data/MIT-LICENSE +1 -1
- data/README.txt +2 -2
- data/benchmark/bench.rb +2 -2
- data/bin/erubis +2 -2
- data/contrib/erubis +293 -155
- data/contrib/inline-require +2 -2
- data/doc-api/classes/Erubis.html +10 -1
- data/doc-api/classes/Erubis/ArrayBufferEnhancer.html +12 -12
- data/doc-api/classes/Erubis/ArrayEnhancer.html +14 -14
- data/doc-api/classes/Erubis/Basic/Converter.html +24 -24
- data/doc-api/classes/Erubis/BiPatternEnhancer.html +12 -12
- data/doc-api/classes/Erubis/CGenerator.html +60 -60
- data/doc-api/classes/Erubis/Context.html +42 -42
- data/doc-api/classes/Erubis/Converter.html +27 -27
- data/doc-api/classes/Erubis/CppGenerator.html +382 -0
- data/doc-api/classes/Erubis/DeleteIndentEnhancer.html +7 -7
- data/doc-api/classes/Erubis/Ecpp.html +126 -0
- data/doc-api/classes/Erubis/Engine.html +36 -36
- data/doc-api/classes/Erubis/ErboutEnhancer.html +14 -14
- data/doc-api/classes/Erubis/EscapeEnhancer.html +6 -6
- data/doc-api/classes/Erubis/EscapedEcpp.html +120 -0
- data/doc-api/classes/Erubis/Evaluator.html +19 -19
- data/doc-api/classes/Erubis/Generator.html +60 -60
- data/doc-api/classes/Erubis/HeaderFooterEnhancer.html +14 -14
- data/doc-api/classes/Erubis/Helpers/RailsFormHelper.html +150 -150
- data/doc-api/classes/Erubis/Helpers/RailsHelper.html +49 -49
- data/doc-api/classes/Erubis/Helpers/RailsHelper/TemplateConverter.html +24 -24
- data/doc-api/classes/Erubis/InterpolationEnhancer.html +38 -39
- data/doc-api/classes/Erubis/JavaGenerator.html +60 -60
- data/doc-api/classes/Erubis/JavascriptGenerator.html +66 -66
- data/doc-api/classes/Erubis/Main.html +22 -22
- data/doc-api/classes/Erubis/NoCodeEnhancer.html +30 -30
- data/doc-api/classes/Erubis/NoTextEnhancer.html +6 -6
- data/doc-api/classes/Erubis/OptimizedEruby.html +6 -6
- data/doc-api/classes/Erubis/OptimizedGenerator.html +72 -72
- data/doc-api/classes/Erubis/OptimizedXmlEruby.html +6 -6
- data/doc-api/classes/Erubis/PI.html +1 -0
- data/doc-api/classes/Erubis/PI/Converter.html +18 -18
- data/doc-api/classes/Erubis/PI/Ec.html +6 -6
- data/doc-api/classes/Erubis/PI/Ecpp.html +166 -0
- data/doc-api/classes/Erubis/PI/Ejava.html +6 -6
- data/doc-api/classes/Erubis/PI/Ejavascript.html +6 -6
- data/doc-api/classes/Erubis/PI/Eperl.html +6 -6
- data/doc-api/classes/Erubis/PI/Ephp.html +6 -6
- data/doc-api/classes/Erubis/PI/Eruby.html +7 -7
- data/doc-api/classes/Erubis/PI/Escheme.html +6 -6
- data/doc-api/classes/Erubis/PI/TinyEruby.html +24 -24
- data/doc-api/classes/Erubis/PercentLineEnhancer.html +18 -34
- data/doc-api/classes/Erubis/PerlGenerator.html +54 -54
- data/doc-api/classes/Erubis/PhpGenerator.html +54 -54
- data/doc-api/classes/Erubis/PrefixedLineEnhancer.html +210 -0
- data/doc-api/classes/Erubis/PrefixedLineEruby.html +120 -0
- data/doc-api/classes/Erubis/PreprocessingEruby.html +12 -12
- data/doc-api/classes/Erubis/PreprocessingHelper.html +22 -22
- data/doc-api/classes/Erubis/PrintEnabledEnhancer.html +20 -20
- data/doc-api/classes/Erubis/PrintOutEnhancer.html +33 -33
- data/doc-api/classes/Erubis/RubyEvaluator.html +18 -18
- data/doc-api/classes/Erubis/RubyGenerator.html +59 -58
- data/doc-api/classes/Erubis/SchemeGenerator.html +60 -60
- data/doc-api/classes/Erubis/SimplifyEnhancer.html +7 -7
- data/doc-api/classes/Erubis/StdoutEnhancer.html +13 -13
- data/doc-api/classes/Erubis/StringBufferEnhancer.html +14 -14
- data/doc-api/classes/Erubis/TinyEruby.html +24 -24
- data/doc-api/classes/Erubis/XmlHelper.html +30 -30
- data/doc-api/classes/Kernel.html +155 -0
- data/doc-api/created.rid +1 -1
- data/doc-api/files/README_txt.html +3 -3
- data/doc-api/files/erubis/context_rb.html +1 -1
- data/doc-api/files/erubis/converter_rb.html +3 -3
- data/doc-api/files/erubis/engine/ec_rb.html +1 -1
- data/doc-api/files/erubis/engine/ecpp_rb.html +115 -0
- data/doc-api/files/erubis/engine/ejava_rb.html +2 -2
- data/doc-api/files/erubis/engine/ejavascript_rb.html +2 -2
- data/doc-api/files/erubis/engine/enhanced_rb.html +2 -2
- data/doc-api/files/erubis/engine/eperl_rb.html +1 -1
- data/doc-api/files/erubis/engine/ephp_rb.html +1 -1
- data/doc-api/files/erubis/engine/eruby_rb.html +2 -2
- data/doc-api/files/erubis/engine/escheme_rb.html +1 -1
- data/doc-api/files/erubis/engine/optimized_rb.html +1 -1
- data/doc-api/files/erubis/engine_rb.html +2 -2
- data/doc-api/files/erubis/enhancer_rb.html +2 -2
- data/doc-api/files/erubis/error_rb.html +1 -1
- data/doc-api/files/erubis/evaluator_rb.html +1 -1
- data/doc-api/files/erubis/generator_rb.html +3 -3
- data/doc-api/files/erubis/helper_rb.html +1 -1
- data/doc-api/files/erubis/helpers/rails_form_helper_rb.html +1 -1
- data/doc-api/files/erubis/helpers/rails_helper_rb.html +1 -1
- data/doc-api/files/erubis/local-setting_rb.html +1 -1
- data/doc-api/files/erubis/main_rb.html +4 -2
- data/doc-api/files/erubis/preprocessing_rb.html +1 -1
- data/doc-api/files/erubis/tiny_rb.html +1 -1
- data/doc-api/files/erubis/util_rb.html +107 -0
- data/doc-api/files/erubis_rb.html +2 -2
- data/doc-api/fr_class_index.html +7 -0
- data/doc-api/fr_file_index.html +2 -0
- data/doc-api/fr_method_index.html +237 -223
- data/doc/docstyle.css +25 -4
- data/doc/users-guide.html +286 -21
- data/examples/basic/Makefile +7 -2
- data/examples/basic/example.ecpp +33 -0
- data/lib/erubis.rb +4 -3
- data/lib/erubis/context.rb +2 -2
- data/lib/erubis/converter.rb +3 -3
- data/lib/erubis/engine.rb +8 -8
- data/lib/erubis/engine/ec.rb +2 -2
- data/lib/erubis/engine/ecpp.rb +113 -0
- data/lib/erubis/engine/ejava.rb +9 -9
- data/lib/erubis/engine/ejavascript.rb +9 -9
- data/lib/erubis/engine/enhanced.rb +7 -2
- data/lib/erubis/engine/eperl.rb +2 -2
- data/lib/erubis/engine/ephp.rb +2 -2
- data/lib/erubis/engine/eruby.rb +8 -7
- data/lib/erubis/engine/escheme.rb +2 -2
- data/lib/erubis/engine/optimized.rb +2 -2
- data/lib/erubis/enhancer.rb +70 -27
- data/lib/erubis/error.rb +2 -2
- data/lib/erubis/evaluator.rb +2 -2
- data/lib/erubis/generator.rb +3 -3
- data/lib/erubis/helper.rb +2 -2
- data/lib/erubis/helpers/rails_form_helper.rb +2 -2
- data/lib/erubis/helpers/rails_helper.rb +2 -2
- data/lib/erubis/local-setting.rb +2 -2
- data/lib/erubis/main.rb +31 -4
- data/lib/erubis/preprocessing.rb +2 -2
- data/lib/erubis/tiny.rb +2 -2
- data/lib/erubis/util.rb +22 -0
- data/test/assert-text-equal.rb +2 -2
- data/test/data/users-guide/bufvar-example.rb +10 -0
- data/test/data/users-guide/bufvar-example.result +17 -0
- data/test/data/users-guide/example.ecpp +30 -0
- data/test/data/users-guide/example_c.result +22 -19
- data/test/data/users-guide/fasteruby-example.rb +8 -0
- data/test/data/users-guide/fasteruby-example.result +18 -0
- data/test/data/users-guide/percentline-example.rhtml +3 -1
- data/test/data/users-guide/percentline_example.result +5 -3
- data/test/data/users-guide/prefixedline-example.rb +9 -0
- data/test/data/users-guide/prefixedline-example.rhtml +6 -0
- data/test/data/users-guide/prefixedline_example.result +9 -0
- data/test/test-engines.rb +58 -2
- data/test/test-enhancers.rb +51 -2
- data/test/test-erubis.rb +14 -10
- data/test/test-index-cgi.rb +191 -0
- data/test/test-main.rb +35 -4
- data/test/test-users-guide.rb +18 -2
- data/test/test.rb +18 -2
- data/test/testutil.rb +22 -7
- metadata +30 -24
data/doc/docstyle.css
CHANGED
@@ -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
|
+
}
|
data/doc/users-guide.html
CHANGED
@@ -13,12 +13,7 @@
|
|
13
13
|
<div class="mainbody">
|
14
14
|
|
15
15
|
<div align="left"><h1>Erubis Users' Guide</h1></div>
|
16
|
-
|
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="#
|
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">'<%= =%>' and '<%= -%>'</a>
|
159
162
|
</li>
|
160
|
-
<li><a href="#
|
163
|
+
<li><a href="#topics-doublepercent">'<%% %>' and '<%%= %>'</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"
|
1642
|
-
|
1646
|
+
<pre class="program"><ul>
|
1647
|
+
<strong>% for item in list</strong>
|
1648
|
+
<li><%= item %></li>
|
1643
1649
|
<strong>% end</strong>
|
1644
|
-
|
1650
|
+
</ul>
|
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 = '';
|
1651
|
-
|
1657
|
+
_buf = ''; _buf << '<ul>
|
1658
|
+
'; <strong>for item in list</strong>
|
1659
|
+
_buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li>
|
1652
1660
|
'; <strong>end</strong>
|
1653
|
-
_buf << '
|
1661
|
+
_buf << '</ul>
|
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"><ul>
|
1686
|
+
<strong>! for item in list</strong>
|
1687
|
+
<li><%= item %></li>
|
1688
|
+
<strong>! end</strong>
|
1689
|
+
</ul>
|
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 < Erubis::Eruby
|
1698
|
+
include Erubis::PrefixedLineEnhancer
|
1699
|
+
end
|
1700
|
+
|
1701
|
+
input = File.read('prefixedline-example.rhtml')
|
1702
|
+
eruby = PrefixedLineEruby.new(input, :prefixchar=>'!') # 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 << '<ul>
|
1710
|
+
'; <strong>for item in list</strong>
|
1711
|
+
_buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li>
|
1712
|
+
'; <strong>end</strong>
|
1713
|
+
_buf << '</ul>
|
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(" </tbody>\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><%
|
2044
|
+
#include <string>
|
2045
|
+
#include <iostream>
|
2046
|
+
#include <sstream>
|
2047
|
+
|
2048
|
+
int main(int argc, char *argv[])
|
2049
|
+
{
|
2050
|
+
std::stringstream _buf;
|
2051
|
+
%></strong>
|
2052
|
+
<html>
|
2053
|
+
<body>
|
2054
|
+
<p>Hello <strong><%= argv[0] %></strong>!</p>
|
2055
|
+
<table>
|
2056
|
+
<tbody>
|
2057
|
+
<strong><% for (int i = 1; i < argc; i++) { %></strong>
|
2058
|
+
<tr bgcolor="<strong><%= i % 2 == 0 ? "#FFCCCC" : "#CCCCFF" %></strong>">
|
2059
|
+
<td><strong><%= i %></strong></td>
|
2060
|
+
<td><strong><%= argv[i] %></strong></td>
|
2061
|
+
</tr>
|
2062
|
+
<strong><% } %></strong>
|
2063
|
+
</tbody>
|
2064
|
+
</table>
|
2065
|
+
</body>
|
2066
|
+
</html>
|
2067
|
+
<strong><%
|
2068
|
+
std::string output = _buf.str();
|
2069
|
+
std::cout << output;
|
2070
|
+
return 0;
|
2071
|
+
}
|
2072
|
+
%></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 <string>
|
2081
|
+
#include <iostream>
|
2082
|
+
#include <sstream>
|
2083
|
+
|
2084
|
+
int main(int argc, char *argv[])
|
2085
|
+
{
|
2086
|
+
std::stringstream _buf;
|
2087
|
+
|
2088
|
+
_buf << "<html>\n"
|
2089
|
+
" <body>\n"
|
2090
|
+
" <p>Hello "; _buf << (argv[0]); _buf << "!</p>\n"
|
2091
|
+
" <table>\n"
|
2092
|
+
" <tbody>\n";
|
2093
|
+
for (int i = 1; i < argc; i++) {
|
2094
|
+
_buf << " <tr bgcolor=\""; _buf << (i % 2 == 0 ? "#FFCCCC" : "#CCCCFF"); _buf << "\">\n"
|
2095
|
+
" <td>"; _buf << (i); _buf << "</td>\n"
|
2096
|
+
" <td>"; _buf << (argv[i]); _buf << "</td>\n"
|
2097
|
+
" </tr>\n";
|
2098
|
+
}
|
2099
|
+
_buf << " </tbody>\n"
|
2100
|
+
" </table>\n"
|
2101
|
+
" </body>\n"
|
2102
|
+
"</html>\n";
|
2103
|
+
|
2104
|
+
std::string output = _buf.str();
|
2105
|
+
std::cout << 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.
|
2345
|
+
example.eperl</div>
|
2210
2346
|
<pre class="program"><strong><%
|
2211
2347
|
my $user = 'Erubis';
|
2212
2348
|
my @list = ('<aaa>', 'b&b', '"ccc"');
|
@@ -2326,6 +2462,8 @@ engine = Erubis::Ejavascript.new(s, <code>:docwrite=>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="
|
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 << '<div>
|
2776
|
+
'; for item in list
|
2777
|
+
_buf << ' <p>'; <strong>_buf << ( item ).to_s;</strong> _buf << '</p>
|
2778
|
+
<p>'; <strong>_buf << Erubis::XmlHelper.escape_xml( item );</strong> _buf << '</p>
|
2779
|
+
'; end
|
2780
|
+
_buf << '</div>
|
2781
|
+
';
|
2782
|
+
_buf.to_s
|
2783
|
+
----- Erubis::FastEruby -----
|
2784
|
+
_buf = ''; _buf << %Q`<div>\n`
|
2785
|
+
for item in list
|
2786
|
+
_buf << %Q` <p><strong>#{ item }</strong></p>
|
2787
|
+
<p><strong>#{Erubis::XmlHelper.escape_xml( item )}</strong></p>\n`
|
2788
|
+
end
|
2789
|
+
_buf << %Q`</div>\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=>'@_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 << %Q`<div>\n`
|
2821
|
+
for item in list
|
2822
|
+
_buf << %Q` <p>#{ item }</p>
|
2823
|
+
<p>#{Erubis::XmlHelper.escape_xml( item )}</p>\n`
|
2824
|
+
end
|
2825
|
+
_buf << %Q`</div>\n`
|
2826
|
+
_buf.to_s
|
2827
|
+
----- with :bufvar option -----
|
2828
|
+
<strong>@_out_buf</strong> = ''; <strong>@_out_buf</strong> << %Q`<div>\n`
|
2829
|
+
for item in list
|
2830
|
+
<strong>@_out_buf</strong> << %Q` <p>#{ item }</p>
|
2831
|
+
<p>#{Erubis::XmlHelper.escape_xml( item )}</p>\n`
|
2832
|
+
end
|
2833
|
+
<strong>@_out_buf</strong> << %Q`</div>\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">'<%= =%>' and '<%= -%>'</h3>
|
2618
2841
|
<p>Since 2.6.0, '<%= -%>' 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="
|
2872
|
+
<a name="topics-doublepercent"></a>
|
2650
2873
|
<h3 class="section2">'<%% %>' and '<%%= %>'</h3>
|
2651
2874
|
<p>Since 2.6.0, '<%% %>' and '<%%= %>' are converted into '<% %>' and '<%= %>' 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.
|
2991
|
-
<pre class="terminal">$ cd erubis-2.
|
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') #=> "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.
|
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.
|
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
|