erubis 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (220) hide show
  1. data/CHANGES +120 -3
  2. data/README.txt +1 -1
  3. data/benchmark/Makefile +6 -0
  4. data/benchmark/bench.rb +306 -0
  5. data/benchmark/{erubybench.yaml → bench_context.yaml} +20 -20
  6. data/benchmark/templates/_footer.html +4 -0
  7. data/benchmark/{erubybench.rhtml → templates/_header.html} +1 -34
  8. data/benchmark/templates/bench_erb.rhtml +29 -0
  9. data/benchmark/templates/bench_erubis.rhtml +29 -0
  10. data/benchmark/templates/bench_eruby.rhtml +29 -0
  11. data/bin/erubis +2 -2
  12. data/contrib/erubis +3 -3114
  13. data/contrib/erubis-run.rb +132 -0
  14. data/contrib/inline-require +1 -1
  15. data/doc-api/classes/{ERB.html → ActionView/Base/ERB.html} +3 -3
  16. data/doc-api/classes/Erubis.html +8 -1
  17. data/doc-api/classes/Erubis/ArrayEnhancer.html +12 -12
  18. data/doc-api/classes/Erubis/Basic/Converter.html +24 -24
  19. data/doc-api/classes/Erubis/BiPatternEnhancer.html +14 -14
  20. data/doc-api/classes/Erubis/CGenerator.html +60 -60
  21. data/doc-api/classes/Erubis/Context.html +42 -42
  22. data/doc-api/classes/Erubis/Converter.html +27 -27
  23. data/doc-api/classes/Erubis/DeleteIndentEnhancer.html +150 -0
  24. data/doc-api/classes/Erubis/DeleteIndentEruby.html +120 -0
  25. data/doc-api/classes/Erubis/Engine.html +31 -31
  26. data/doc-api/classes/Erubis/ErboutEnhancer.html +175 -0
  27. data/doc-api/classes/Erubis/ErboutEruby.html +120 -0
  28. data/doc-api/classes/Erubis/Eruby.html +5 -0
  29. data/doc-api/classes/Erubis/EscapeEnhancer.html +6 -6
  30. data/doc-api/classes/Erubis/Evaluator.html +19 -19
  31. data/doc-api/classes/Erubis/FastEruby.html +131 -0
  32. data/doc-api/classes/Erubis/HeaderFooterEnhancer.html +14 -14
  33. data/doc-api/classes/Erubis/Helpers/RailsHelper.html +49 -45
  34. data/doc-api/classes/Erubis/InterpolationEnhancer.html +304 -0
  35. data/doc-api/classes/Erubis/InterpolationEruby.html +120 -0
  36. data/doc-api/classes/Erubis/JavaGenerator.html +54 -54
  37. data/doc-api/classes/Erubis/JavascriptGenerator.html +60 -60
  38. data/doc-api/classes/Erubis/Main.html +35 -27
  39. data/doc-api/classes/Erubis/NoCodeEnhancer.html +5 -5
  40. data/doc-api/classes/Erubis/NoTextEnhancer.html +7 -7
  41. data/doc-api/classes/Erubis/OptimizedEruby.html +6 -6
  42. data/doc-api/classes/Erubis/OptimizedGenerator.html +72 -72
  43. data/doc-api/classes/Erubis/OptimizedXmlEruby.html +6 -6
  44. data/doc-api/classes/Erubis/PI/Converter.html +18 -18
  45. data/doc-api/classes/Erubis/PI/Ec.html +6 -6
  46. data/doc-api/classes/Erubis/PI/Ejava.html +6 -6
  47. data/doc-api/classes/Erubis/PI/Ejavascript.html +6 -6
  48. data/doc-api/classes/Erubis/PI/Eperl.html +6 -6
  49. data/doc-api/classes/Erubis/PI/Ephp.html +6 -6
  50. data/doc-api/classes/Erubis/PI/Eruby.html +7 -7
  51. data/doc-api/classes/Erubis/PI/Escheme.html +6 -6
  52. data/doc-api/classes/Erubis/PI/TinyEruby.html +24 -24
  53. data/doc-api/classes/Erubis/PercentLineEnhancer.html +8 -8
  54. data/doc-api/classes/Erubis/PerlGenerator.html +54 -54
  55. data/doc-api/classes/Erubis/PhpGenerator.html +54 -54
  56. data/doc-api/classes/Erubis/PrintEnabledEnhancer.html +20 -20
  57. data/doc-api/classes/Erubis/PrintOutEnhancer.html +30 -30
  58. data/doc-api/classes/Erubis/RubyEvaluator.html +12 -12
  59. data/doc-api/classes/Erubis/RubyGenerator.html +48 -48
  60. data/doc-api/classes/Erubis/SchemeGenerator.html +60 -60
  61. data/doc-api/classes/Erubis/SimplifyEnhancer.html +8 -8
  62. data/doc-api/classes/Erubis/StdoutEnhancer.html +12 -12
  63. data/doc-api/classes/Erubis/StringBufferEnhancer.html +12 -12
  64. data/doc-api/classes/Erubis/TinyEruby.html +24 -24
  65. data/doc-api/classes/Erubis/XmlHelper.html +14 -14
  66. data/doc-api/created.rid +1 -1
  67. data/doc-api/files/README_txt.html +4 -4
  68. data/doc-api/files/erubis/context_rb.html +2 -2
  69. data/doc-api/files/erubis/converter_rb.html +2 -2
  70. data/doc-api/files/erubis/engine/ec_rb.html +2 -2
  71. data/doc-api/files/erubis/engine/ejava_rb.html +2 -2
  72. data/doc-api/files/erubis/engine/ejavascript_rb.html +2 -2
  73. data/doc-api/files/erubis/engine/enhanced_rb.html +2 -2
  74. data/doc-api/files/erubis/engine/eperl_rb.html +2 -2
  75. data/doc-api/files/erubis/engine/ephp_rb.html +2 -2
  76. data/doc-api/files/erubis/engine/eruby_rb.html +2 -2
  77. data/doc-api/files/erubis/engine/escheme_rb.html +2 -2
  78. data/doc-api/files/erubis/engine/optimized_rb.html +2 -2
  79. data/doc-api/files/erubis/engine_rb.html +2 -2
  80. data/doc-api/files/erubis/enhancer_rb.html +2 -2
  81. data/doc-api/files/erubis/error_rb.html +2 -2
  82. data/doc-api/files/erubis/evaluator_rb.html +2 -2
  83. data/doc-api/files/erubis/generator_rb.html +2 -2
  84. data/doc-api/files/erubis/helper_rb.html +2 -2
  85. data/doc-api/files/erubis/helpers/rails_helper_rb.html +2 -2
  86. data/doc-api/files/erubis/local-setting_rb.html +2 -2
  87. data/doc-api/files/erubis/main_rb.html +2 -2
  88. data/doc-api/files/erubis/tiny_rb.html +2 -2
  89. data/doc-api/files/erubis_rb.html +1 -1
  90. data/doc-api/fr_class_index.html +8 -1
  91. data/doc-api/fr_method_index.html +166 -158
  92. data/doc/users-guide.html +623 -215
  93. data/lib/erubis.rb +2 -2
  94. data/lib/erubis/context.rb +2 -2
  95. data/lib/erubis/converter.rb +2 -2
  96. data/lib/erubis/engine.rb +3 -3
  97. data/lib/erubis/engine/ec.rb +2 -2
  98. data/lib/erubis/engine/ejava.rb +2 -2
  99. data/lib/erubis/engine/ejavascript.rb +2 -2
  100. data/lib/erubis/engine/enhanced.rb +17 -2
  101. data/lib/erubis/engine/eperl.rb +2 -2
  102. data/lib/erubis/engine/ephp.rb +2 -2
  103. data/lib/erubis/engine/eruby.rb +10 -2
  104. data/lib/erubis/engine/escheme.rb +2 -2
  105. data/lib/erubis/engine/optimized.rb +2 -2
  106. data/lib/erubis/enhancer.rb +134 -25
  107. data/lib/erubis/error.rb +2 -2
  108. data/lib/erubis/evaluator.rb +2 -2
  109. data/lib/erubis/generator.rb +2 -2
  110. data/lib/erubis/helper.rb +2 -2
  111. data/lib/erubis/helpers/rails_helper.rb +19 -75
  112. data/lib/erubis/local-setting.rb +2 -2
  113. data/lib/erubis/main.rb +63 -36
  114. data/lib/erubis/tiny.rb +2 -2
  115. data/test/assert-text-equal.rb +2 -2
  116. data/test/data/users-guide/Example.ejava +55 -0
  117. data/test/data/users-guide/array_example.result +9 -0
  118. data/test/data/users-guide/arraybuffer_example.result +9 -0
  119. data/test/data/users-guide/bipattern-example.rhtml +4 -0
  120. data/test/data/users-guide/bipattern_example.result +6 -0
  121. data/test/data/users-guide/context.rb +6 -0
  122. data/test/data/users-guide/context.yaml +8 -0
  123. data/test/data/users-guide/escape_example.result +9 -0
  124. data/test/data/users-guide/example.ec +27 -0
  125. data/test/data/users-guide/example.ejs +20 -0
  126. data/test/data/users-guide/example.eperl +18 -0
  127. data/test/data/users-guide/example.ephp +18 -0
  128. data/test/data/users-guide/example.eruby +6 -0
  129. data/test/data/users-guide/example.escheme +28 -0
  130. data/test/data/users-guide/example1.eruby +6 -0
  131. data/test/data/users-guide/example1.rb +16 -0
  132. data/test/data/users-guide/example1.result +16 -0
  133. data/test/data/users-guide/example10.rb +4 -0
  134. data/test/data/users-guide/example10.result +17 -0
  135. data/test/data/users-guide/example10.xhtml +14 -0
  136. data/test/data/users-guide/example10_x.result +17 -0
  137. data/test/data/users-guide/example11.php +20 -0
  138. data/test/data/users-guide/example11.result +23 -0
  139. data/test/data/users-guide/example11.rhtml +21 -0
  140. data/test/data/users-guide/example11_C.result +10 -0
  141. data/test/data/users-guide/example11_N.result +16 -0
  142. data/test/data/users-guide/example11_U.result +16 -0
  143. data/test/data/users-guide/example11_php.result +15 -0
  144. data/test/data/users-guide/example1_x.result +9 -0
  145. data/test/data/users-guide/example2.eruby +7 -0
  146. data/test/data/users-guide/example2.rb +10 -0
  147. data/test/data/users-guide/example2.result +27 -0
  148. data/test/data/users-guide/example2_trim.result +10 -0
  149. data/test/data/users-guide/example2_x.result +10 -0
  150. data/test/data/users-guide/example3.eruby +6 -0
  151. data/test/data/users-guide/example3.rb +10 -0
  152. data/test/data/users-guide/example31.result +22 -0
  153. data/test/data/users-guide/example32.result +4 -0
  154. data/test/data/users-guide/example3_e.result +8 -0
  155. data/test/data/users-guide/example4.eruby +3 -0
  156. data/test/data/users-guide/example4.rb +11 -0
  157. data/test/data/users-guide/example4.result +10 -0
  158. data/test/data/users-guide/example4_x.result +5 -0
  159. data/test/data/users-guide/example5.eruby +6 -0
  160. data/test/data/users-guide/example5.rb +16 -0
  161. data/test/data/users-guide/example5.result +7 -0
  162. data/test/data/users-guide/example6.rb +12 -0
  163. data/test/data/users-guide/example6.result +7 -0
  164. data/test/data/users-guide/example7.eruby +8 -0
  165. data/test/data/users-guide/example71.result +13 -0
  166. data/test/data/users-guide/example72.result +13 -0
  167. data/test/data/users-guide/example8.eruby +6 -0
  168. data/test/data/users-guide/example8_ruby.result +7 -0
  169. data/test/data/users-guide/example8_yaml.result +7 -0
  170. data/test/data/users-guide/example9.eruby +3 -0
  171. data/test/data/users-guide/example9.rb +8 -0
  172. data/test/data/users-guide/example9.result +9 -0
  173. data/test/data/users-guide/example91.result +5 -0
  174. data/test/data/users-guide/example92.result +4 -0
  175. data/test/data/users-guide/example_c.result +29 -0
  176. data/test/data/users-guide/example_java.result +56 -0
  177. data/test/data/users-guide/example_js.result +22 -0
  178. data/test/data/users-guide/example_perl.result +20 -0
  179. data/test/data/users-guide/example_php.result +19 -0
  180. data/test/data/users-guide/example_scheme.result +30 -0
  181. data/test/data/users-guide/example_scheme_display.result +29 -0
  182. data/test/data/users-guide/fasteruby.rb +11 -0
  183. data/test/data/users-guide/fasteruby.result +38 -0
  184. data/test/data/users-guide/fasteruby.rhtml +15 -0
  185. data/test/data/users-guide/headerfooter-example.eruby +9 -0
  186. data/test/data/users-guide/headerfooter-example2.rb +8 -0
  187. data/test/data/users-guide/headerfooter-example2.rhtml +10 -0
  188. data/test/data/users-guide/headerfooter_example.result +11 -0
  189. data/test/data/users-guide/headerfooter_example2.result +13 -0
  190. data/test/data/users-guide/interpolation_example.result +9 -0
  191. data/test/data/users-guide/nocode-example.eruby +14 -0
  192. data/test/data/users-guide/nocode-php.result +20 -0
  193. data/test/data/users-guide/nocode_example.result +15 -0
  194. data/test/data/users-guide/normal-eruby-test.eruby +9 -0
  195. data/test/data/users-guide/normal_eruby_test.result +11 -0
  196. data/test/data/users-guide/notext-example.eruby +14 -0
  197. data/test/data/users-guide/notext-example.php +19 -0
  198. data/test/data/users-guide/notext-php.result +20 -0
  199. data/test/data/users-guide/notext_example.result +16 -0
  200. data/test/data/users-guide/percentline-example.rhtml +4 -0
  201. data/test/data/users-guide/percentline_example.result +7 -0
  202. data/test/data/users-guide/printenable_example.result +4 -0
  203. data/test/data/users-guide/printenabled-example.eruby +3 -0
  204. data/test/data/users-guide/printenabled-example.rb +8 -0
  205. data/test/data/users-guide/printstatement_example.result +8 -0
  206. data/test/data/users-guide/simplify_example.result +9 -0
  207. data/test/data/users-guide/stdout_exmple.result +9 -0
  208. data/test/data/users-guide/stringbuffer_example.result +9 -0
  209. data/test/test-engines.rb +2 -2
  210. data/test/test-enhancers.rb +569 -0
  211. data/test/test-erubis.rb +3 -380
  212. data/test/test-main.rb +39 -15
  213. data/test/test-users-guide.rb +56 -0
  214. data/test/test.rb +4 -3
  215. data/test/testutil.rb +2 -2
  216. metadata +166 -57
  217. data/benchmark/erubybench-lib.rb +0 -189
  218. data/benchmark/erubybench.rb +0 -600
  219. data/bin/notext +0 -154
  220. data/test/test-notext.rb +0 -27
@@ -0,0 +1,12 @@
1
+ class MyData
2
+ attr_accessor :val, :list
3
+ end
4
+
5
+ ## any object can be a context object
6
+ mydata = MyData.new
7
+ mydata.val = 'Erubis Example'
8
+ mydata.list = ['aaa', 'bbb', 'ccc']
9
+
10
+ require 'erubis'
11
+ eruby = Erubis::Eruby.new(File.read('example5.eruby'))
12
+ puts eruby.evaluate(mydata)
@@ -0,0 +1,7 @@
1
+ $ ruby example6.rb
2
+ <span>Erubis Example</span>
3
+ <ul>
4
+ <li>aaa</li>
5
+ <li>bbb</li>
6
+ <li>ccc</li>
7
+ </ul>
@@ -0,0 +1,8 @@
1
+ <h1><%= @title %></h1>
2
+ <ul>
3
+ <% for user in @users %>
4
+ <li>
5
+ <a href="mailto:<%= user['mail']%>"><%= user['name'] %></a>
6
+ </li>
7
+ <% end %>
8
+ </ul>
@@ -0,0 +1,13 @@
1
+ $ erubis -f context.yaml example7.eruby
2
+ <h1>Users List</h1>
3
+ <ul>
4
+ <li>
5
+ <a href="mailto:foo@mail.com">foo</a>
6
+ </li>
7
+ <li>
8
+ <a href="mailto:bar@mail.net">bar</a>
9
+ </li>
10
+ <li>
11
+ <a href="mailto:baz@mail.org">baz</a>
12
+ </li>
13
+ </ul>
@@ -0,0 +1,13 @@
1
+ $ erubis -f context.rb example7.eruby
2
+ <h1>Users List</h1>
3
+ <ul>
4
+ <li>
5
+ <a href="mailto:foo@mail.com">foo</a>
6
+ </li>
7
+ <li>
8
+ <a href="mailto:bar@mail.net">bar</a>
9
+ </li>
10
+ <li>
11
+ <a href="mailto:baz@mail.org">baz</a>
12
+ </li>
13
+ </ul>
@@ -0,0 +1,6 @@
1
+ <h1><%= @title %></h1>
2
+ <ul>
3
+ <% for item in @list %>
4
+ <li><%= item %></li>
5
+ <% end %>
6
+ </ul>
@@ -0,0 +1,7 @@
1
+ $ erubis -c '@title="Example"; @list=%w[AAA BBB CCC]' example8.eruby
2
+ <h1>Example</h1>
3
+ <ul>
4
+ <li>AAA</li>
5
+ <li>BBB</li>
6
+ <li>CCC</li>
7
+ </ul>
@@ -0,0 +1,7 @@
1
+ $ erubis -c '{title: Example, list: [AAA, BBB, CCC]}' example8.eruby
2
+ <h1>Example</h1>
3
+ <ul>
4
+ <li>AAA</li>
5
+ <li>BBB</li>
6
+ <li>CCC</li>
7
+ </ul>
@@ -0,0 +1,3 @@
1
+ <% for item in @list %>
2
+ <b><%= item %></b>
3
+ <% end %>
@@ -0,0 +1,8 @@
1
+ require 'erubis'
2
+ input = File.read('example9.eruby')
3
+ eruby1 = Erubis::Eruby.new(input)
4
+ eruby2 = Erubis::Eruby.new(input, :preamble=>false, :postamble=>false)
5
+
6
+ puts eruby1.src # print preamble and postamble
7
+ puts "--------------"
8
+ puts eruby2.src # don't print preamble and postamble
@@ -0,0 +1,9 @@
1
+ $ ruby example9.rb
2
+ _buf = ''; for item in @list
3
+ _buf << ' <b>'; _buf << ( item ).to_s; _buf << '</b>
4
+ '; end
5
+ _buf.to_s
6
+ --------------
7
+ for item in @list
8
+ _buf << ' <b>'; _buf << ( item ).to_s; _buf << '</b>
9
+ '; end
@@ -0,0 +1,5 @@
1
+ $ erubis -x example9.eruby
2
+ _buf = ''; for item in @list
3
+ _buf << ' <b>'; _buf << ( item ).to_s; _buf << '</b>
4
+ '; end
5
+ _buf.to_s
@@ -0,0 +1,4 @@
1
+ $ erubis -x -b example9.eruby
2
+ for item in @list
3
+ _buf << ' <b>'; _buf << ( item ).to_s; _buf << '</b>
4
+ '; end
@@ -0,0 +1,29 @@
1
+ $ erubis -l c example.ec
2
+ #line 1 "example.ec"
3
+
4
+ #include <stdio.h>
5
+
6
+ int main(int argc, char *argv[])
7
+ {
8
+ int i;
9
+
10
+
11
+ fputs("<html>\n"
12
+ " <body>\n"
13
+ " <p>Hello ", stdout); fprintf(stdout, "%s", argv[0]); fputs("!</p>\n"
14
+ " <table>\n"
15
+ " <tbody>\n", stdout);
16
+ for (i = 1; i < argc; i++) {
17
+ fputs(" <tr bgcolor=\"", stdout); fprintf(stdout, i % 2 == 0 ? "#FFCCCC" : "#CCCCFF"); fputs("\">\n"
18
+ " <td>", stdout); fprintf(stdout, "%d", i); fputs("</td>\n"
19
+ " <td>", stdout); fprintf(stdout, "%s", argv[i]); fputs("</td>\n"
20
+ " </tr>\n", stdout);
21
+ }
22
+ fputs(" </tbody>\n"
23
+ " </table>\n"
24
+ " </body>\n"
25
+ "</html>\n", stdout);
26
+
27
+ return 0;
28
+ }
29
+
@@ -0,0 +1,56 @@
1
+ $ erubis -b -l java example.ejava
2
+
3
+ import java.util.*;
4
+
5
+ public class Example {
6
+ private String user;
7
+ private String[] list;
8
+ public example(String user, String[] list) {
9
+ this.user = user;
10
+ this.list = list;
11
+ }
12
+
13
+ public String view() {
14
+ StringBuffer _buf = new StringBuffer();
15
+
16
+ _buf.append("<html>\n"
17
+ + " <body>\n"
18
+ + " <p>Hello "); _buf.append(user); _buf.append("!</p>\n"
19
+ + " <table>\n"
20
+ + " <tbody>\n");
21
+ for (int i = 0; i < list.length; i++) {
22
+ _buf.append(" <tr bgcolor=\""); _buf.append(i % 2 == 0 ? "#FFCCCC" : "#CCCCFF"); _buf.append("\">\n"
23
+ + " <td>"); _buf.append(i + 1); _buf.append("</td>\n"
24
+ + " <td>"); _buf.append(escape(list[i])); _buf.append("</td>\n"
25
+ + " </tr>\n");
26
+ }
27
+ _buf.append(" </tbody>\n"
28
+ + " </table>\n"
29
+ + " <body>\n"
30
+ + "</html>\n");
31
+
32
+ return _buf.toString();
33
+ }
34
+
35
+ public static void main(String[] args) {
36
+ String[] list = { "<aaa>", "b&b", "\"ccc\"" };
37
+ Example ex = Example.new("Erubis", list);
38
+ System.out.print(ex.view());
39
+ }
40
+
41
+ public static String escape(String s) {
42
+ StringBuffer sb = new StringBuffer();
43
+ for (int i = 0; i < s.length(); i++) {
44
+ char ch = s.charAt(i);
45
+ switch (ch) {
46
+ case '<': sb.append("&lt;"); break;
47
+ case '>': sb.append("&gt;"); break;
48
+ case '&': sb.append("&amp;"); break;
49
+ case '"': sb.append("&quot;"); break;
50
+ default: sb.append(ch);
51
+ }
52
+ }
53
+ return sb.toString();
54
+ }
55
+ }
56
+
@@ -0,0 +1,22 @@
1
+ $ erubis -l js example.ejs
2
+ var _buf = [];
3
+ var user = 'Erubis';
4
+ var list = ['<aaa>', 'b&b', '"ccc"'];
5
+
6
+ _buf.push("<html>\n\
7
+ <body>\n\
8
+ <p>Hello "); _buf.push(user); _buf.push("!</p>\n\
9
+ <table>\n\
10
+ <tbody>\n");
11
+ var i;
12
+ for (i = 0; i < list.length; i++) {
13
+ _buf.push(" <tr bgcolor=\""); _buf.push(i % 2 == 0 ? '#FFCCCC' : '#CCCCFF'); _buf.push("\">\n\
14
+ <td>"); _buf.push(i + 1); _buf.push("</td>\n\
15
+ <td>"); _buf.push(list[i]); _buf.push("</td>\n\
16
+ </tr>\n");
17
+ }
18
+ _buf.push(" </tbody>\n\
19
+ </table>\n\
20
+ </body>\n\
21
+ </html>\n");
22
+ document.write(_buf.join(""));
@@ -0,0 +1,20 @@
1
+ $ erubis -l perl example.eperl
2
+ use HTML::Entities;
3
+ my $user = 'Erubis';
4
+ my @list = ('<aaa>', 'b&b', '"ccc"');
5
+
6
+ print('<html>
7
+ <body>
8
+ <p>Hello '); print($user); print('!</p>
9
+ <table>
10
+ '); $i = 0;
11
+ for $item (@list) {
12
+ print(' <tr bgcolor='); print(++$i % 2 == 0 ? '#FFCCCC' : '#CCCCFF'); print('">
13
+ <td>'); print($i); print('</td>
14
+ <td>'); print($item); print('</td>
15
+ </tr>
16
+ '); }
17
+ print(' </table>
18
+ </body>
19
+ </html>
20
+ ');
@@ -0,0 +1,19 @@
1
+ $ erubis -l php example.ephp
2
+ <<?php ?>?xml version="1.0"?>
3
+ <html>
4
+ <body>
5
+ <p>Hello <?php echo $user; ?>!</p>
6
+ <table>
7
+ <tbody>
8
+ <?php $i = 0; ?>
9
+ <?php foreach ($list as $item) { ?>
10
+ <?php $i++; ?>
11
+ <tr bgcolor="<?php echo $i % 2 == 0 ? '#FFCCCC' : '#CCCCFF'; ?>">
12
+ <td><?php echo $i; ?></td>
13
+ <td><?php echo htmlspecialchars($item); ?></td>
14
+ </tr>
15
+ <?php } ?>
16
+ </tbody>
17
+ </table>
18
+ </body>
19
+ </html>
@@ -0,0 +1,30 @@
1
+ $ erubis -l scheme example.escheme
2
+ (let ((_buf '())) (define (_add x) (set! _buf (cons x _buf))) (_add "<html>
3
+ <body>\n")
4
+
5
+ (let ((user "Erubis")
6
+ (items '("<aaa>" "b&b" "\"ccc\""))
7
+ (i 0))
8
+
9
+ (_add " <p>Hello ")(_add user)(_add "!</p>
10
+ <table>\n")
11
+
12
+ (for-each
13
+ (lambda (item)
14
+ (set! i (+ i 1))
15
+
16
+ (_add " <tr bgcolor=\"")(_add (if (= (modulo i 2) 0) "#FFCCCC" "#CCCCFF"))(_add "\">
17
+ <td>")(_add i)(_add "</td>
18
+ <td>")(_add item)(_add "</td>
19
+ </tr>\n")
20
+
21
+ ) ; lambda end
22
+ items) ; for-each end
23
+
24
+ (_add " </table>\n")
25
+
26
+ ) ; let end
27
+
28
+ (_add " </body>
29
+ </html>\n")
30
+ (reverse _buf))
@@ -0,0 +1,29 @@
1
+ $ erubis -l scheme --func=display example.escheme
2
+ (display "<html>
3
+ <body>\n")
4
+
5
+ (let ((user "Erubis")
6
+ (items '("<aaa>" "b&b" "\"ccc\""))
7
+ (i 0))
8
+
9
+ (display " <p>Hello ")(display user)(display "!</p>
10
+ <table>\n")
11
+
12
+ (for-each
13
+ (lambda (item)
14
+ (set! i (+ i 1))
15
+
16
+ (display " <tr bgcolor=\"")(display (if (= (modulo i 2) 0) "#FFCCCC" "#CCCCFF"))(display "\">
17
+ <td>")(display i)(display "</td>
18
+ <td>")(display item)(display "</td>
19
+ </tr>\n")
20
+
21
+ ) ; lambda end
22
+ items) ; for-each end
23
+
24
+ (display " </table>\n")
25
+
26
+ ) ; let end
27
+
28
+ (display " </body>
29
+ </html>\n")
@@ -0,0 +1,11 @@
1
+ require 'erubis'
2
+ input = File.read('fasteruby.rhtml')
3
+ eruby = Erubis::FastEruby.new(input) # create Eruby object
4
+
5
+ puts "---------- script source ---"
6
+ puts eruby.src
7
+
8
+ puts "---------- result ----------"
9
+ context = { :title=>'Example', :list=>['aaa', 'bbb', 'ccc'] }
10
+ output = eruby.evaluate(context)
11
+ print output
@@ -0,0 +1,38 @@
1
+ $ ruby fasteruby.rb
2
+ ---------- script source ---
3
+ _buf = ''; _buf << %Q`<html>
4
+ <body>
5
+ <h1>#{Erubis::XmlHelper.escape_xml( @title )}</h1>
6
+ <table>\n`
7
+ i = 0
8
+ for item in @list
9
+ i += 1
10
+ _buf << %Q` <tr>
11
+ <td>#{ i }</td>
12
+ <td>#{Erubis::XmlHelper.escape_xml( item )}</td>
13
+ </tr>\n`
14
+ end
15
+ _buf << %Q` </table>
16
+ </body>
17
+ </html>\n`
18
+ _buf.to_s
19
+ ---------- result ----------
20
+ <html>
21
+ <body>
22
+ <h1>Example</h1>
23
+ <table>
24
+ <tr>
25
+ <td>1</td>
26
+ <td>aaa</td>
27
+ </tr>
28
+ <tr>
29
+ <td>2</td>
30
+ <td>bbb</td>
31
+ </tr>
32
+ <tr>
33
+ <td>3</td>
34
+ <td>ccc</td>
35
+ </tr>
36
+ </table>
37
+ </body>
38
+ </html>
@@ -0,0 +1,15 @@
1
+ <html>
2
+ <body>
3
+ <h1><%== @title %></h1>
4
+ <table>
5
+ <% i = 0 %>
6
+ <% for item in @list %>
7
+ <% i += 1 %>
8
+ <tr>
9
+ <td><%= i %></td>
10
+ <td><%== item %></td>
11
+ </tr>
12
+ <% end %>
13
+ </table>
14
+ </body>
15
+ </html>
@@ -0,0 +1,9 @@
1
+ <!--#header:
2
+ def list_items(items)
3
+ #-->
4
+ <% for item in items %>
5
+ <b><%= item %></b>
6
+ <% end %>
7
+ <!--#footer:
8
+ end
9
+ #-->
@@ -0,0 +1,8 @@
1
+ require 'erubis'
2
+ class HeaderFooterEruby < Erubis::Eruby
3
+ include Erubis::HeaderFooterEnhancer
4
+ end
5
+
6
+ input = File.read('headerfooter-example2.rhtml')
7
+ eruby = HeaderFooterEruby.new(input)
8
+ print eruby.src
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0"?>
2
+ <html>
3
+ <!--#header:
4
+ def page(list)
5
+ #-->
6
+ :
7
+ <!--#footer:
8
+ end
9
+ #-->
10
+ </html>
@@ -0,0 +1,11 @@
1
+ $ erubis -xE HeaderFooter headerfooter-example.eruby
2
+
3
+ def list_items(items)
4
+
5
+ _buf = ''; for item in items
6
+ _buf << ' <b>'; _buf << ( item ).to_s; _buf << '</b>
7
+ '; end
8
+ _buf.to_s
9
+
10
+ end
11
+