erbse 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES.txt +828 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.md +51 -0
  5. data/benchmark/Makefile +6 -0
  6. data/benchmark/bench.rb +313 -0
  7. data/benchmark/bench_context.yaml +141 -0
  8. data/benchmark/templates/_footer.html +4 -0
  9. data/benchmark/templates/_header.html +52 -0
  10. data/benchmark/templates/bench_erb.rhtml +29 -0
  11. data/benchmark/templates/bench_erubis.rhtml +29 -0
  12. data/benchmark/templates/bench_eruby.rhtml +29 -0
  13. data/bin/erubis +10 -0
  14. data/erbse.gemspec +24 -0
  15. data/lib/erbse.rb +52 -0
  16. data/lib/erbse/context.rb +83 -0
  17. data/lib/erbse/converter.rb +357 -0
  18. data/lib/erbse/engine.rb +114 -0
  19. data/lib/erbse/engine/ec.rb +117 -0
  20. data/lib/erbse/engine/ecpp.rb +113 -0
  21. data/lib/erbse/engine/ejava.rb +110 -0
  22. data/lib/erbse/engine/ejavascript.rb +119 -0
  23. data/lib/erbse/engine/enhanced.rb +126 -0
  24. data/lib/erbse/engine/eperl.rb +95 -0
  25. data/lib/erbse/engine/ephp.rb +99 -0
  26. data/lib/erbse/engine/eruby.rb +119 -0
  27. data/lib/erbse/engine/escheme.rb +114 -0
  28. data/lib/erbse/engine/optimized.rb +127 -0
  29. data/lib/erbse/enhancer.rb +723 -0
  30. data/lib/erbse/error.rb +23 -0
  31. data/lib/erbse/evaluator.rb +88 -0
  32. data/lib/erbse/generator.rb +85 -0
  33. data/lib/erbse/helper.rb +47 -0
  34. data/lib/erbse/helpers/rails_form_helper.rb +197 -0
  35. data/lib/erbse/helpers/rails_helper.rb +353 -0
  36. data/lib/erbse/main.rb +516 -0
  37. data/lib/erbse/preprocessing.rb +58 -0
  38. data/lib/erbse/tiny.rb +144 -0
  39. data/lib/erbse/util.rb +22 -0
  40. data/lib/erbse/version.rb +3 -0
  41. data/test/assert-text-equal.rb +44 -0
  42. data/test/data/users-guide/Example.ejava +55 -0
  43. data/test/data/users-guide/array_example.result +9 -0
  44. data/test/data/users-guide/arraybuffer_example.result +9 -0
  45. data/test/data/users-guide/bipattern-example.rhtml +4 -0
  46. data/test/data/users-guide/bipattern_example.result +6 -0
  47. data/test/data/users-guide/bufvar-example.rb +10 -0
  48. data/test/data/users-guide/bufvar-example.result +17 -0
  49. data/test/data/users-guide/context.rb +6 -0
  50. data/test/data/users-guide/context.yaml +8 -0
  51. data/test/data/users-guide/def_method.rb +14 -0
  52. data/test/data/users-guide/def_method.result +3 -0
  53. data/test/data/users-guide/escape_example.result +9 -0
  54. data/test/data/users-guide/example.ec +27 -0
  55. data/test/data/users-guide/example.ecpp +30 -0
  56. data/test/data/users-guide/example.ejs +20 -0
  57. data/test/data/users-guide/example.eperl +18 -0
  58. data/test/data/users-guide/example.ephp +18 -0
  59. data/test/data/users-guide/example.eruby +6 -0
  60. data/test/data/users-guide/example.escheme +28 -0
  61. data/test/data/users-guide/example1.eruby +6 -0
  62. data/test/data/users-guide/example1.rb +17 -0
  63. data/test/data/users-guide/example1.result +16 -0
  64. data/test/data/users-guide/example10.rb +4 -0
  65. data/test/data/users-guide/example10.result +17 -0
  66. data/test/data/users-guide/example10.xhtml +14 -0
  67. data/test/data/users-guide/example10_x.result +17 -0
  68. data/test/data/users-guide/example11.php +20 -0
  69. data/test/data/users-guide/example11.result +23 -0
  70. data/test/data/users-guide/example11.rhtml +21 -0
  71. data/test/data/users-guide/example11_C.result +10 -0
  72. data/test/data/users-guide/example11_N.result +16 -0
  73. data/test/data/users-guide/example11_U.result +16 -0
  74. data/test/data/users-guide/example11_php.result +15 -0
  75. data/test/data/users-guide/example1_x.result +9 -0
  76. data/test/data/users-guide/example2.eruby +7 -0
  77. data/test/data/users-guide/example2.rb +10 -0
  78. data/test/data/users-guide/example2.result +27 -0
  79. data/test/data/users-guide/example2_trim.result +10 -0
  80. data/test/data/users-guide/example2_x.result +10 -0
  81. data/test/data/users-guide/example3.eruby +6 -0
  82. data/test/data/users-guide/example3.rb +10 -0
  83. data/test/data/users-guide/example31.result +22 -0
  84. data/test/data/users-guide/example32.result +4 -0
  85. data/test/data/users-guide/example3_e.result +8 -0
  86. data/test/data/users-guide/example4.eruby +3 -0
  87. data/test/data/users-guide/example4.rb +11 -0
  88. data/test/data/users-guide/example4.result +10 -0
  89. data/test/data/users-guide/example4_x.result +5 -0
  90. data/test/data/users-guide/example5.eruby +6 -0
  91. data/test/data/users-guide/example5.rb +16 -0
  92. data/test/data/users-guide/example5.result +7 -0
  93. data/test/data/users-guide/example6.rb +12 -0
  94. data/test/data/users-guide/example6.result +7 -0
  95. data/test/data/users-guide/example7.eruby +8 -0
  96. data/test/data/users-guide/example71.result +13 -0
  97. data/test/data/users-guide/example72.result +13 -0
  98. data/test/data/users-guide/example8.eruby +6 -0
  99. data/test/data/users-guide/example8_ruby.result +7 -0
  100. data/test/data/users-guide/example8_yaml.result +7 -0
  101. data/test/data/users-guide/example9.eruby +3 -0
  102. data/test/data/users-guide/example9.rb +8 -0
  103. data/test/data/users-guide/example9.result +9 -0
  104. data/test/data/users-guide/example91.result +5 -0
  105. data/test/data/users-guide/example92.result +4 -0
  106. data/test/data/users-guide/example_c.result +32 -0
  107. data/test/data/users-guide/example_java.result +56 -0
  108. data/test/data/users-guide/example_js.result +22 -0
  109. data/test/data/users-guide/example_perl.result +20 -0
  110. data/test/data/users-guide/example_php.result +19 -0
  111. data/test/data/users-guide/example_scheme.result +30 -0
  112. data/test/data/users-guide/example_scheme_display.result +29 -0
  113. data/test/data/users-guide/fasteruby-example.rb +8 -0
  114. data/test/data/users-guide/fasteruby-example.result +18 -0
  115. data/test/data/users-guide/fasteruby.rb +11 -0
  116. data/test/data/users-guide/fasteruby.result +38 -0
  117. data/test/data/users-guide/fasteruby.rhtml +15 -0
  118. data/test/data/users-guide/headerfooter-example.eruby +9 -0
  119. data/test/data/users-guide/headerfooter-example2.rb +8 -0
  120. data/test/data/users-guide/headerfooter-example2.rhtml +10 -0
  121. data/test/data/users-guide/headerfooter_example.result +11 -0
  122. data/test/data/users-guide/headerfooter_example2.result +13 -0
  123. data/test/data/users-guide/interpolation_example.result +9 -0
  124. data/test/data/users-guide/main_program1.rb +8 -0
  125. data/test/data/users-guide/main_program1.result +6 -0
  126. data/test/data/users-guide/main_program2.rb +8 -0
  127. data/test/data/users-guide/main_program2.result +6 -0
  128. data/test/data/users-guide/nocode-example.eruby +14 -0
  129. data/test/data/users-guide/nocode-php.result +20 -0
  130. data/test/data/users-guide/nocode_example.result +15 -0
  131. data/test/data/users-guide/normal-eruby-test.eruby +9 -0
  132. data/test/data/users-guide/normal_eruby_test.result +11 -0
  133. data/test/data/users-guide/notext-example.eruby +14 -0
  134. data/test/data/users-guide/notext-example.php +19 -0
  135. data/test/data/users-guide/notext-php.result +20 -0
  136. data/test/data/users-guide/notext_example.result +16 -0
  137. data/test/data/users-guide/percentline-example.rhtml +6 -0
  138. data/test/data/users-guide/percentline_example.result +9 -0
  139. data/test/data/users-guide/prefixedline-example.rb +9 -0
  140. data/test/data/users-guide/prefixedline-example.rhtml +6 -0
  141. data/test/data/users-guide/prefixedline_example.result +9 -0
  142. data/test/data/users-guide/printenable_example.result +4 -0
  143. data/test/data/users-guide/printenabled-example.eruby +3 -0
  144. data/test/data/users-guide/printenabled-example.rb +8 -0
  145. data/test/data/users-guide/printstatement_example.result +8 -0
  146. data/test/data/users-guide/simplify_example.result +9 -0
  147. data/test/data/users-guide/stderr.log +3 -0
  148. data/test/data/users-guide/stdout_exmple.result +9 -0
  149. data/test/data/users-guide/stringbuffer_example.result +9 -0
  150. data/test/data/users-guide/tail_260.result +4 -0
  151. data/test/data/users-guide/tailnewline.rhtml +3 -0
  152. data/test/data/users-guide/template1.rhtml +4 -0
  153. data/test/data/users-guide/template2.rhtml +4 -0
  154. data/test/test-engines.rb +425 -0
  155. data/test/test-enhancers.rb +646 -0
  156. data/test/test-erubis.rb +887 -0
  157. data/test/test-index-cgi.rb +191 -0
  158. data/test/test-main.rb +752 -0
  159. data/test/test-users-guide.rb +73 -0
  160. data/test/test.rb +45 -0
  161. data/test/testutil.rb +111 -0
  162. metadata +233 -0
@@ -0,0 +1,8 @@
1
+ require 'erubis'
2
+ class PrintEnabledEruby < Erubis::Eruby
3
+ include Erubis::PrintEnabledEnhancer
4
+ end
5
+ input = File.read('printenabled-example.eruby')
6
+ eruby = PrintEnabledEruby.new(input)
7
+ list = ['aaa', 'bbb', 'ccc']
8
+ print eruby.evaluate(:list=>list)
@@ -0,0 +1,8 @@
1
+ $ erubis -xE PrintOut example.eruby
2
+ print '<div>
3
+ '; for item in list
4
+ print ' <p>'; print(( item ).to_s); print '</p>
5
+ <p>'; print Erubis::XmlHelper.escape_xml( item ); print '</p>
6
+ '; end
7
+ print '</div>
8
+ ';
@@ -0,0 +1,9 @@
1
+ $ erubis -xE Simplify example.eruby
2
+ _buf = ''; _buf << '<div>
3
+ '; for item in list ; _buf << '
4
+ <p>'; _buf << ( item ).to_s; _buf << '</p>
5
+ <p>'; _buf << Erubis::XmlHelper.escape_xml( item ); _buf << '</p>
6
+ '; end ; _buf << '
7
+ </div>
8
+ ';
9
+ _buf.to_s
@@ -0,0 +1,3 @@
1
+ *** debug: item="<aaa>"
2
+ *** debug: item="b&b"
3
+ *** debug: item="\"ccc\""
@@ -0,0 +1,9 @@
1
+ $ erubis -xE Stdout example.eruby
2
+ _buf = $stdout; _buf << '<div>
3
+ '; for item in list
4
+ _buf << ' <p>'; _buf << ( item ).to_s; _buf << '</p>
5
+ <p>'; _buf << Erubis::XmlHelper.escape_xml( item ); _buf << '</p>
6
+ '; end
7
+ _buf << '</div>
8
+ ';
9
+ ''
@@ -0,0 +1,9 @@
1
+ $ erubis -xE StringBuffer example.eruby
2
+ _buf = ''; _buf << '<div>
3
+ '; for item in list
4
+ _buf << ' <p>'; _buf << ( item ).to_s; _buf << '</p>
5
+ <p>'; _buf << Erubis::XmlHelper.escape_xml( item ); _buf << '</p>
6
+ '; end
7
+ _buf << '</div>
8
+ ';
9
+ _buf.to_s
@@ -0,0 +1,4 @@
1
+ $ erubis -c '{var: "AAA\n"}' tailnewline.rhtml
2
+ <div>
3
+ AAA
4
+ </div>
@@ -0,0 +1,3 @@
1
+ <div>
2
+ <%= @var -%>
3
+ </div>
@@ -0,0 +1,4 @@
1
+ <% for x in items %>
2
+ item = <%= x %>
3
+ <% end %>
4
+ ** debug: local variables=<%= local_variables().inspect() %>
@@ -0,0 +1,4 @@
1
+ <% for x in @items %>
2
+ item = <%= x %>
3
+ <% end %>
4
+ ** debug: local variables=<%= local_variables().inspect() %>
@@ -0,0 +1,425 @@
1
+ ##
2
+ ## $Release: 2.7.0 $
3
+ ## copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
4
+ ##
5
+
6
+ require "#{File.dirname(__FILE__)}/test.rb"
7
+
8
+ require 'erubis'
9
+ require 'erubis/engine/eruby'
10
+ require 'erubis/engine/ephp'
11
+ require 'erubis/engine/ec'
12
+ require 'erubis/engine/ecpp'
13
+ require 'erubis/engine/ejava'
14
+ require 'erubis/engine/escheme'
15
+ require 'erubis/engine/eperl'
16
+ require 'erubis/engine/ejavascript'
17
+
18
+
19
+ class EnginesTest < Test::Unit::TestCase
20
+
21
+ #load_yaml_documents(__FILE__)
22
+ testdata_list = load_yaml_datafile(__FILE__)
23
+ define_testmethods(testdata_list)
24
+
25
+ def _test()
26
+ klass = Erubis.const_get(@class)
27
+ engine = klass.new(@input, @options || {})
28
+ actual = engine.src
29
+ assert_text_equal(@expected, actual)
30
+ end
31
+
32
+
33
+ self.post_definition()
34
+
35
+ end
36
+
37
+ __END__
38
+ - name: ruby1
39
+ lang: ruby
40
+ class: Eruby
41
+ options:
42
+ input: |
43
+ <table>
44
+ <tbody>
45
+ <% i = 0
46
+ list.each_with_index do |item, i| %>
47
+ <tr>
48
+ <td><%= i+1 %></td>
49
+ <td><%== list %></td>
50
+ </tr>
51
+ <% end %>
52
+ </tbody>
53
+ </table>
54
+ <%=== i+1 %>
55
+ expected: |
56
+ _buf = ''; _buf << '<table>
57
+ <tbody>
58
+ '; i = 0
59
+ list.each_with_index do |item, i|
60
+ _buf << ' <tr>
61
+ <td>'; _buf << ( i+1 ).to_s; _buf << '</td>
62
+ <td>'; _buf << Erubis::XmlHelper.escape_xml( list ); _buf << '</td>
63
+ </tr>
64
+ '; end
65
+ _buf << ' </tbody>
66
+ </table>
67
+ '; $stderr.puts("*** debug: i+1=#{(i+1).inspect}"); _buf << '
68
+ ';
69
+ _buf.to_s
70
+ ##
71
+ - name: ruby2_options
72
+ lang: ruby
73
+ class: Eruby
74
+ options: { :bufvar: '@_out_buf' }
75
+ input: |
76
+ <table>
77
+ <% for item in @items %>
78
+ <tr>
79
+ <td><%= i+1 %></td>
80
+ <td><%== list %></td>
81
+ </tr>
82
+ <% end %>
83
+ </table>
84
+ expected: |
85
+ @_out_buf = ''; @_out_buf << '<table>
86
+ '; for item in @items
87
+ @_out_buf << ' <tr>
88
+ <td>'; @_out_buf << ( i+1 ).to_s; @_out_buf << '</td>
89
+ <td>'; @_out_buf << Erubis::XmlHelper.escape_xml( list ); @_out_buf << '</td>
90
+ </tr>
91
+ '; end
92
+ @_out_buf << '</table>
93
+ ';
94
+ @_out_buf.to_s
95
+ ##
96
+ - name: php1
97
+ lang: php
98
+ class: Ephp
99
+ options:
100
+ input: |
101
+ <table>
102
+ <tbody>
103
+ <%
104
+ $i = 0;
105
+ foreach ($list as $item) {
106
+ $i++;
107
+ %>
108
+ <tr>
109
+ <td><%= $i %></td>
110
+ <td><%== $item %></td>
111
+ </tr>
112
+ <%
113
+ }
114
+ %>
115
+ </tbody>
116
+ </table>
117
+ <%=== $i %>
118
+ expected: |
119
+ <table>
120
+ <tbody>
121
+ <?php
122
+ $i = 0;
123
+ foreach ($list as $item) {
124
+ $i++;
125
+ ?>
126
+ <tr>
127
+ <td><?php echo $i; ?></td>
128
+ <td><?php echo htmlspecialchars($item); ?></td>
129
+ </tr>
130
+ <?php
131
+ }
132
+ ?>
133
+ </tbody>
134
+ </table>
135
+ <?php error_log('*** debug: $i='.($i), 0); ?>
136
+ ##
137
+ - name: c1
138
+ lang: c
139
+ class: Ec
140
+ options: { :filename: foo.html, :indent: ' ' }
141
+ input: |4
142
+ <table>
143
+ <tbody>
144
+ <% for (i = 0; i < list; i++) { %>
145
+ <tr>
146
+ <td><%= "%d", i %></td>
147
+ <td><%== list[i] %></td>
148
+ </tr>
149
+ <% } %>
150
+ </tbody>
151
+ </table>
152
+ <%=== "%d", i %>
153
+ expected: |
154
+ #line 1 "foo.html"
155
+ fputs("<table>\n"
156
+ " <tbody>\n", stdout);
157
+ for (i = 0; i < list; i++) {
158
+ fputs(" <tr>\n"
159
+ " <td>", stdout); fprintf(stdout, "%d", i); fputs("</td>\n"
160
+ " <td>", stdout); escape(list[i], stdout); fputs("</td>\n"
161
+ " </tr>\n", stdout);
162
+ }
163
+ fputs(" </tbody>\n"
164
+ "</table>\n", stdout);
165
+ fprintf(stderr, "*** debug: i=" "%d", i); fputs("\n", stdout);
166
+ ##
167
+ - name: cpp1
168
+ lang: cpp
169
+ class: Ecpp
170
+ options: { :filename: foo.html, :indent: ' ' }
171
+ input: |4
172
+ <table>
173
+ <tbody>
174
+ <% for (i = 0; i < n; i++) { %>
175
+ <tr>
176
+ <td><%= i %></td>
177
+ <td><%== list[i] %></td>
178
+ </tr>
179
+ <% } %>
180
+ </tbody>
181
+ </table>
182
+ <%=== i %>
183
+ expected: |
184
+ #line 1 "foo.html"
185
+ _buf << "<table>\n"
186
+ " <tbody>\n";
187
+ for (i = 0; i < n; i++) {
188
+ _buf << " <tr>\n"
189
+ " <td>"; _buf << (i); _buf << "</td>\n"
190
+ " <td>"; escape(list[i]); _buf << "</td>\n"
191
+ " </tr>\n";
192
+ }
193
+ _buf << " </tbody>\n"
194
+ "</table>\n";
195
+ std::cerr << "*** debug: i=" << (i); _buf << "\n";
196
+ ##
197
+ - name: java1
198
+ lang: java
199
+ class: Ejava
200
+ options: { :buf: _buf, :bufclass: StringBuilder, :indent: ' ' }
201
+ input: |
202
+ <table>
203
+ <tbody>
204
+ <%
205
+ int i = 0;
206
+ for (Iterator it = list.iterator(); it.hasNext(); ) {
207
+ String s = (String)it.next();
208
+ i++;
209
+ %>
210
+ <tr class="<%= i%2==0 ? "even" : "odd" %>">
211
+ <td><%= i %></td>
212
+ <td><%== s %></td>
213
+ </tr>
214
+ <%
215
+ }
216
+ %>
217
+ <tbody>
218
+ </table>
219
+ <%=== i %>
220
+ expected: |4
221
+ StringBuilder _buf = new StringBuilder(); _buf.append("<table>\n"
222
+ + " <tbody>\n");
223
+
224
+ int i = 0;
225
+ for (Iterator it = list.iterator(); it.hasNext(); ) {
226
+ String s = (String)it.next();
227
+ i++;
228
+
229
+ _buf.append(" <tr class=\""); _buf.append(i%2==0 ? "even" : "odd"); _buf.append("\">\n"
230
+ + " <td>"); _buf.append(i); _buf.append("</td>\n"
231
+ + " <td>"); _buf.append(escape(s)); _buf.append("</td>\n"
232
+ + " </tr>\n");
233
+
234
+ }
235
+
236
+ _buf.append(" <tbody>\n"
237
+ + "</table>\n");
238
+ System.err.println("*** debug: i="+(i)); _buf.append("\n");
239
+ return _buf.toString();
240
+ ##
241
+ - name: scheme1
242
+ lang: scheme
243
+ class: Escheme
244
+ options:
245
+ input: &scheme1_input|
246
+ <% (let ((i 0)) %>
247
+ <table>
248
+ <tbody>
249
+ <%
250
+ (for-each
251
+ (lambda (item)
252
+ (set! i (+ i 1))
253
+ %>
254
+ <tr>
255
+ <td><%= i %></td>
256
+ <td><%== item %></td>
257
+ </tr>
258
+ <%
259
+ ); lambda end
260
+ list); for-each end
261
+ %>
262
+ </tbody>
263
+ </table>
264
+ <%=== i %>
265
+ <% ); let end %>
266
+ expected: |4
267
+ (let ((_buf '())) (define (_add x) (set! _buf (cons x _buf))) (let ((i 0))
268
+ (_add "<table>
269
+ <tbody>\n")
270
+
271
+ (for-each
272
+ (lambda (item)
273
+ (set! i (+ i 1))
274
+
275
+ (_add " <tr>
276
+ <td>")(_add i)(_add "</td>
277
+ <td>")(_add (escape item))(_add "</td>
278
+ </tr>\n")
279
+
280
+ ); lambda end
281
+ list); for-each end
282
+
283
+ (_add " </tbody>
284
+ </table>\n")
285
+ (display "*** debug: i=")(display i)(display "\n")(_add "\n")
286
+ ); let end
287
+ (reverse _buf))
288
+
289
+ ##
290
+ - name: scheme2
291
+ lang: scheme
292
+ class: Escheme
293
+ options: { :func: 'display' }
294
+ input: *scheme1_input
295
+ expected: |4
296
+ (let ((i 0))
297
+ (display "<table>
298
+ <tbody>\n")
299
+
300
+ (for-each
301
+ (lambda (item)
302
+ (set! i (+ i 1))
303
+
304
+ (display " <tr>
305
+ <td>")(display i)(display "</td>
306
+ <td>")(display (escape item))(display "</td>
307
+ </tr>\n")
308
+
309
+ ); lambda end
310
+ list); for-each end
311
+
312
+ (display " </tbody>
313
+ </table>\n")
314
+ (display "*** debug: i=")(display i)(display "\n")(display "\n")
315
+ ); let end
316
+ ##
317
+ - name: perl1
318
+ lang: perl
319
+ class: Eperl
320
+ options:
321
+ input: |
322
+ <%
323
+ my $user = 'Erubis';
324
+ my @list = ('<aaa>', 'b&b', '"ccc"');
325
+ %>
326
+ <p>Hello <%= $user %>!</p>
327
+ <table>
328
+ <tbody>
329
+ <% $i = 0; %>
330
+ <% for $item (@list) { %>
331
+ <tr bgcolor=<%= ++$i % 2 == 0 ? '#FFCCCC' : '#CCCCFF' %>">
332
+ <td><%= $i %></td>
333
+ <td><%== $item %></td>
334
+ </tr>
335
+ <% } %>
336
+ </tbody>
337
+ </table>
338
+ <%=== $i %>
339
+ expected: |4
340
+ use HTML::Entities;
341
+ my $user = 'Erubis';
342
+ my @list = ('<aaa>', 'b&b', '"ccc"');
343
+
344
+ print('<p>Hello '); print($user); print('!</p>
345
+ <table>
346
+ <tbody>
347
+ '); $i = 0;
348
+ for $item (@list) {
349
+ print(' <tr bgcolor='); print(++$i % 2 == 0 ? '#FFCCCC' : '#CCCCFF'); print('">
350
+ <td>'); print($i); print('</td>
351
+ <td>'); print(encode_entities($item)); print('</td>
352
+ </tr>
353
+ '); }
354
+ print(' </tbody>
355
+ </table>
356
+ '); print('*** debug: $i=', $i, "\n");print('
357
+ ');
358
+ ##
359
+ - name: javascript1
360
+ lang: javascript
361
+ class: Ejavascript
362
+ options:
363
+ input: &javascript_input |
364
+ <%
365
+ var user = 'Erubis';
366
+ var list = ['<aaa>', 'b&b', '"ccc"'];
367
+ %>
368
+ <p>Hello <%= user %>!</p>
369
+ <table>
370
+ <tbody>
371
+ <% var i; %>
372
+ <% for (i = 0; i < list.length; i++) { %>
373
+ <tr bgcolor=<%= ++i % 2 == 0 ? '#FFCCCC' : '#CCCCFF' %>">
374
+ <td><%= i %></td>
375
+ <td><%= list[i] %></td>
376
+ </tr>
377
+ <% } %>
378
+ </tbody>
379
+ </table>
380
+ <%=== i %>
381
+ expected: |4
382
+ var _buf = [];
383
+ var user = 'Erubis';
384
+ var list = ['<aaa>', 'b&b', '"ccc"'];
385
+
386
+ _buf.push("<p>Hello "); _buf.push(user); _buf.push("!</p>\n\
387
+ <table>\n\
388
+ <tbody>\n");
389
+ var i;
390
+ for (i = 0; i < list.length; i++) {
391
+ _buf.push(" <tr bgcolor="); _buf.push(++i % 2 == 0 ? '#FFCCCC' : '#CCCCFF'); _buf.push("\">\n\
392
+ <td>"); _buf.push(i); _buf.push("</td>\n\
393
+ <td>"); _buf.push(list[i]); _buf.push("</td>\n\
394
+ </tr>\n");
395
+ }
396
+ _buf.push(" </tbody>\n\
397
+ </table>\n");
398
+ alert("*** debug: i="+(i)); _buf.push("\n");
399
+ document.write(_buf.join(""));
400
+ ##
401
+ - name: javascript2
402
+ lang: javascript
403
+ class: Ejavascript
404
+ options: { :docwrite: false }
405
+ input: *javascript_input
406
+ expected: |4
407
+ var _buf = [];
408
+ var user = 'Erubis';
409
+ var list = ['<aaa>', 'b&b', '"ccc"'];
410
+
411
+ _buf.push("<p>Hello "); _buf.push(user); _buf.push("!</p>\n\
412
+ <table>\n\
413
+ <tbody>\n");
414
+ var i;
415
+ for (i = 0; i < list.length; i++) {
416
+ _buf.push(" <tr bgcolor="); _buf.push(++i % 2 == 0 ? '#FFCCCC' : '#CCCCFF'); _buf.push("\">\n\
417
+ <td>"); _buf.push(i); _buf.push("</td>\n\
418
+ <td>"); _buf.push(list[i]); _buf.push("</td>\n\
419
+ </tr>\n");
420
+ }
421
+ _buf.push(" </tbody>\n\
422
+ </table>\n");
423
+ alert("*** debug: i="+(i)); _buf.push("\n");
424
+ _buf.join("");
425
+ ##