erubis 1.1.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. data/ChangeLog +45 -18
  2. data/README.txt +80 -0
  3. data/benchmark/erubybench-lib.rb +189 -0
  4. data/benchmark/erubybench.rb +364 -0
  5. data/benchmark/erubybench.rhtml +61 -0
  6. data/benchmark/erubybench.yaml +61 -0
  7. data/bin/erubis +4 -180
  8. data/contrib/erubis +2297 -0
  9. data/contrib/inline-require +151 -0
  10. data/doc-api/classes/Erubis.html +236 -0
  11. data/doc-api/classes/Erubis/ArrayBufferEnhancer.html +175 -0
  12. data/doc-api/classes/Erubis/ArrayBufferEruby.html +120 -0
  13. data/doc-api/classes/Erubis/ArrayEnhancer.html +174 -0
  14. data/doc-api/classes/Erubis/ArrayEruby.html +120 -0
  15. data/doc-api/classes/Erubis/BiPatternEnhancer.html +212 -0
  16. data/doc-api/classes/Erubis/BiPatternEruby.html +120 -0
  17. data/doc-api/classes/Erubis/CommandOptionError.html +113 -0
  18. data/doc-api/classes/Erubis/Context.html +249 -0
  19. data/doc-api/classes/Erubis/Ec.html +399 -0
  20. data/doc-api/classes/Erubis/Ejava.html +366 -0
  21. data/doc-api/classes/Erubis/Ejavascript.html +390 -0
  22. data/doc-api/classes/Erubis/Engine.html +711 -0
  23. data/doc-api/classes/Erubis/Eperl.html +350 -0
  24. data/doc-api/classes/Erubis/Ephp.html +308 -0
  25. data/doc-api/classes/Erubis/ErubisError.html +117 -0
  26. data/doc-api/classes/Erubis/Eruby.html +310 -0
  27. data/doc-api/classes/Erubis/EscapeEnhancer.html +167 -0
  28. data/doc-api/classes/Erubis/EscapedEc.html +120 -0
  29. data/doc-api/classes/Erubis/EscapedEjava.html +120 -0
  30. data/doc-api/classes/Erubis/EscapedEjavascript.html +120 -0
  31. data/doc-api/classes/Erubis/EscapedEperl.html +120 -0
  32. data/doc-api/classes/Erubis/EscapedEphp.html +120 -0
  33. data/doc-api/classes/Erubis/EscapedEruby.html +127 -0
  34. data/doc-api/classes/Erubis/EscapedEscheme.html +120 -0
  35. data/doc-api/classes/Erubis/Escheme.html +389 -0
  36. data/doc-api/classes/Erubis/HeaderFooterEnhancer.html +264 -0
  37. data/doc-api/classes/Erubis/HeaderFooterEruby.html +120 -0
  38. data/doc-api/classes/Erubis/Main.html +318 -0
  39. data/doc-api/classes/Erubis/NoTextEnhancer.html +159 -0
  40. data/doc-api/classes/Erubis/NoTextEruby.html +120 -0
  41. data/doc-api/classes/Erubis/OptimizedEruby.html +445 -0
  42. data/doc-api/classes/Erubis/OptimizedXmlEruby.html +163 -0
  43. data/doc-api/classes/Erubis/PercentLineEnhancer.html +174 -0
  44. data/doc-api/classes/Erubis/PercentLineEruby.html +120 -0
  45. data/doc-api/classes/Erubis/PrintEnabledEnhancer.html +212 -0
  46. data/doc-api/classes/Erubis/PrintEnabledEruby.html +120 -0
  47. data/doc-api/classes/Erubis/PrintOutEnhancer.html +244 -0
  48. data/doc-api/classes/Erubis/PrintOutEruby.html +120 -0
  49. data/doc-api/classes/Erubis/PrintOutSimplifiedEruby.html +121 -0
  50. data/doc-api/classes/Erubis/SimplifiedEruby.html +120 -0
  51. data/doc-api/classes/Erubis/SimplifyEnhancer.html +185 -0
  52. data/doc-api/classes/Erubis/StdoutEnhancer.html +173 -0
  53. data/doc-api/classes/Erubis/StdoutEruby.html +120 -0
  54. data/doc-api/classes/Erubis/StdoutSimplifiedEruby.html +121 -0
  55. data/doc-api/classes/Erubis/StringBufferEnhancer.html +174 -0
  56. data/doc-api/classes/Erubis/StringBufferEruby.html +120 -0
  57. data/doc-api/classes/Erubis/StringIOEruby.html +120 -0
  58. data/doc-api/classes/Erubis/TinyEruby.html +305 -0
  59. data/doc-api/classes/Erubis/XmlEruby.html +130 -0
  60. data/doc-api/classes/Erubis/XmlHelper.html +193 -0
  61. data/doc-api/created.rid +1 -0
  62. data/doc-api/files/__/README_txt.html +214 -0
  63. data/doc-api/files/erubis/engine/ec_rb.html +115 -0
  64. data/doc-api/files/erubis/engine/ejava_rb.html +115 -0
  65. data/doc-api/files/erubis/engine/ejavascript_rb.html +115 -0
  66. data/doc-api/files/erubis/engine/enhanced_rb.html +115 -0
  67. data/doc-api/files/erubis/engine/eperl_rb.html +115 -0
  68. data/doc-api/files/erubis/engine/ephp_rb.html +115 -0
  69. data/doc-api/files/erubis/engine/eruby_rb.html +115 -0
  70. data/doc-api/files/erubis/engine/escheme_rb.html +115 -0
  71. data/doc-api/files/erubis/engine/optimized_rb.html +114 -0
  72. data/doc-api/files/erubis/engine_rb.html +114 -0
  73. data/doc-api/files/erubis/enhancer_rb.html +114 -0
  74. data/doc-api/files/erubis/helper_rb.html +107 -0
  75. data/doc-api/files/erubis/local-setting_rb.html +107 -0
  76. data/doc-api/files/erubis/main_rb.html +125 -0
  77. data/doc-api/files/erubis/tiny_rb.html +107 -0
  78. data/doc-api/files/erubis_rb.html +118 -0
  79. data/doc-api/fr_class_index.html +77 -0
  80. data/doc-api/fr_file_index.html +43 -0
  81. data/doc-api/fr_method_index.html +157 -0
  82. data/doc-api/index.html +24 -0
  83. data/doc-api/rdoc-style.css +208 -0
  84. data/doc/users-guide.html +1507 -375
  85. data/examples/Makefile +53 -0
  86. data/examples/example.ec +24 -0
  87. data/examples/example.ejava +41 -0
  88. data/examples/example.ejavascript +16 -0
  89. data/examples/example.eperl +16 -0
  90. data/examples/example.ephp +17 -0
  91. data/examples/example.eruby +15 -0
  92. data/examples/example.escheme +26 -0
  93. data/lib/erubis.rb +37 -269
  94. data/lib/erubis/engine.rb +260 -0
  95. data/lib/erubis/engine/ec.rb +106 -0
  96. data/lib/erubis/engine/ejava.rb +101 -0
  97. data/lib/erubis/engine/ejavascript.rb +104 -0
  98. data/lib/erubis/engine/enhanced.rb +102 -0
  99. data/lib/erubis/engine/eperl.rb +83 -0
  100. data/lib/erubis/engine/ephp.rb +84 -0
  101. data/lib/erubis/engine/eruby.rb +91 -0
  102. data/lib/erubis/engine/escheme.rb +96 -0
  103. data/lib/erubis/engine/optimized.rb +114 -0
  104. data/lib/erubis/enhancer.rb +487 -0
  105. data/lib/erubis/helper.rb +53 -0
  106. data/lib/erubis/local-setting.rb +10 -0
  107. data/lib/erubis/main.rb +368 -0
  108. data/lib/erubis/tiny.rb +65 -0
  109. data/test/assert-text-equal.rb +45 -0
  110. data/test/test-bin.rb +222 -45
  111. data/test/test-engines.rb +343 -0
  112. data/test/test-erubis.rb +836 -501
  113. data/test/test.rb +27 -0
  114. data/test/testutil.rb +86 -0
  115. metadata +131 -8
  116. data/README +0 -50
@@ -0,0 +1,45 @@
1
+ ###
2
+ ### $Rev: 6 $
3
+ ### $Release: 2.0.0 $
4
+ ### copyright(c) 2006 kuwata-lab all rights reserved.
5
+ ###
6
+
7
+ require 'test/unit'
8
+ require 'tempfile'
9
+
10
+
11
+ module Test
12
+ module Unit
13
+ class TestCase
14
+
15
+ def assert_text_equal(expected, actual, message=nil, diffopt='-u', flag_cut=true)
16
+ if expected == actual
17
+ assert(true)
18
+ return
19
+ end
20
+ if expected[-1] != ?\n || actual[-1] != ?\n
21
+ expected += "\n"
22
+ actual += "\n"
23
+ end
24
+ begin
25
+ expfile = Tempfile.new(".expected.")
26
+ expfile.write(expected); expfile.flush()
27
+ actfile = Tempfile.new(".actual.")
28
+ actfile.write(actual); actfile.flush()
29
+ diff = `diff #{diffopt} #{expfile.path} #{actfile.path}`
30
+ ensure
31
+ expfile.close(true) if expfile
32
+ actfile.close(true) if actfile
33
+ end
34
+ # cut 1st & 2nd lines
35
+ message = (flag_cut ? diff.gsub(/\A.*\n.*\n/, '') : diff) unless message
36
+ #raise Test::Unit::AssertionFailedError.new(message)
37
+ assert_block(message) { false } # or assert(false, message)
38
+ end
39
+
40
+ alias assert_equal_with_diff assert_text_equal # for compatibility
41
+ alias assert_text_equals assert_text_equal # for typo
42
+
43
+ end
44
+ end
45
+ end
@@ -1,15 +1,12 @@
1
1
  ##
2
- ## $Rev: 3 $
3
- ## $Release: 1.1.0 $
4
- ## $Date: 2006-01-31 12:54:23 +0900 (Tue, 31 Jan 2006) $
2
+ ## $Rev: 21 $
3
+ ## $Release: 2.0.0 $
4
+ ## $Date: 2006-05-20 08:57:39 +0900 (Sat, 20 May 2006) $
5
5
  ##
6
6
 
7
- testdir = File.dirname(File.expand_path(__FILE__))
8
- libdir = File.dirname(testdir) + '/lib'
9
- $: << testdir
10
- $: << libdir
7
+ require "#{File.dirname(__FILE__)}/test.rb"
11
8
 
12
- bindir = File.dirname(testdir) + '/bin'
9
+ bindir = File.dirname(TESTDIR) + '/bin'
13
10
  $script = bindir + '/erubis'
14
11
  if test(?f, 'bin/erubis')
15
12
  $script = 'bin/erubis'
@@ -19,12 +16,19 @@ end
19
16
 
20
17
 
21
18
  require 'test/unit'
22
- #require 'test/unit/ui/console/testrunner'
23
19
  require 'assert-text-equal'
24
20
  require 'yaml'
25
21
  require 'tempfile'
26
22
 
27
23
  require 'erubis'
24
+ require 'erubis/main'
25
+
26
+
27
+ class StringWriter < String
28
+ def write(arg)
29
+ self << arg
30
+ end
31
+ end
28
32
 
29
33
 
30
34
  class BinTest < Test::Unit::TestCase
@@ -37,16 +41,28 @@ list:
37
41
  <% end %>
38
42
  user: <%= defined?(user) ? user : "(none)" %>
39
43
  END
40
-
44
+ INPUT2 = INPUT.gsub(/\blist([^:])/, '@list\1').gsub(/\buser([^:])/, '@user\1')
45
+
46
+ # SRC = <<'END'
47
+ #_buf = ''; _buf << "list:\n"
48
+ # list = ['<aaa>', 'b&b', '"ccc"']
49
+ # for item in list
50
+ #_buf << " - "; _buf << ( item ).to_s; _buf << "\n"
51
+ # end
52
+ #_buf << "user: "; _buf << ( defined?(user) ? user : "(none)" ).to_s; _buf << "\n"
53
+ #_buf
54
+ #END
41
55
  SRC = <<'END'
42
- _out = ''; _out << "list:\n"
43
- list = ['<aaa>', 'b&b', '"ccc"']
56
+ _buf = []; _buf << 'list:
57
+ '; list = ['<aaa>', 'b&b', '"ccc"']
44
58
  for item in list
45
- _out << " - "; _out << ( item ).to_s; _out << "\n"
46
- end
47
- _out << "user: "; _out << ( defined?(user) ? user : "(none)" ).to_s; _out << "\n"
48
- _out
59
+ _buf << ' - '; _buf << ( item ).to_s; _buf << '
60
+ '; end
61
+ _buf << 'user: '; _buf << ( defined?(user) ? user : "(none)" ).to_s; _buf << '
62
+ ';
63
+ _buf.join
49
64
  END
65
+ # SRC2 = SRC.gsub(/\blist /, '@list ').gsub(/\buser /, '@user ')
50
66
 
51
67
  OUTPUT = <<'END'
52
68
  list:
@@ -56,26 +72,50 @@ list:
56
72
  user: (none)
57
73
  END
58
74
 
75
+ ESCAPED_OUTPUT = <<'END'
76
+ list:
77
+ - &lt;aaa&gt;
78
+ - b&amp;b
79
+ - &quot;ccc&quot;
80
+ user: (none)
81
+ END
82
+
59
83
 
60
84
  def _test()
85
+ if $target
86
+ name = (caller()[0] =~ /in `test_(.*?)'/) && $1
87
+ return unless name == $target
88
+ end
61
89
  if @filename == nil
62
90
  method = (caller[0] =~ /in `(.*)'/) && $1 #'
63
91
  @filename = "tmp.#{method}"
64
92
  end
65
93
  File.open(@filename, 'w') { |f| f.write(@input) } if @filename
66
94
  begin
67
- command = "ruby #{$script} #{@options} #{@filename}"
68
- output = `#{command}`
95
+ #if @options.is_a?(Array)
96
+ # command = "ruby #{$script} #{@options.join(' ')} #{@filename}"
97
+ #else
98
+ # command = "ruby #{$script} #{@options} #{@filename}"
99
+ #end
100
+ #output = `#{command}`
101
+ if @options.is_a?(Array)
102
+ argv = @options + [ @filename ]
103
+ else
104
+ argv = "#{@options} #{@filename}".split
105
+ end
106
+ $stdout = output = StringWriter.new
107
+ Erubis::Main.new.execute(argv)
69
108
  ensure
109
+ $stdout = STDOUT
70
110
  File.unlink(@filename) if @filename && test(?f, @filename)
71
111
  end
72
112
  assert_text_equal(@expected, output)
73
113
  end
74
114
 
75
115
 
76
- def test_version
116
+ def test_version # -v
77
117
  @options = '-v'
78
- @expected = (("$Release: 1.1.0 $" =~ /[.\d]+/) && $&) + "\n"
118
+ @expected = (("$Release: 2.0.0 $" =~ /[.\d]+/) && $&) + "\n"
79
119
  @filename = false
80
120
  _test()
81
121
  end
@@ -89,23 +129,24 @@ END
89
129
  end
90
130
 
91
131
 
92
- def test_source1
132
+ def test_source1 # -x
93
133
  @input = INPUT
94
134
  @expected = SRC
95
- @options = '-s'
135
+ @options = '-x'
96
136
  _test()
97
137
  end
98
138
 
99
139
 
100
- def test_pattern1
140
+ def test_pattern1 # -p
101
141
  @input = INPUT.gsub(/<%/, '<!--%').gsub(/%>/, '%-->')
102
142
  @expected = OUTPUT
103
- @options = "-p '<!--% %-->'"
143
+ #@options = "-p '<!--% %-->'"
144
+ @options = ["-p", "<!--% %-->"]
104
145
  _test()
105
146
  end
106
147
 
107
148
 
108
- def test_class1
149
+ def test_class1 # -c
109
150
  @input = INPUT
110
151
  @expected = OUTPUT.gsub(/<aaa>/, '&lt;aaa&gt;').gsub(/b&b/, 'b&amp;b').gsub(/"ccc"/, '&quot;ccc&quot;')
111
152
  @options = "-c XmlEruby"
@@ -113,7 +154,7 @@ END
113
154
  end
114
155
 
115
156
 
116
- def test_notrim1
157
+ def test_notrim1 # -T
117
158
  @input = INPUT
118
159
  @expected = <<'END'
119
160
  list:
@@ -131,33 +172,45 @@ END
131
172
  end
132
173
 
133
174
 
134
- def test_notrim2
175
+ def test_notrim2 # -T
135
176
  @input = INPUT
177
+ # @expected = <<'END'
178
+ #_buf = ''; _buf << "list:\n"
179
+ # list = ['<aaa>', 'b&b', '"ccc"']
180
+ # for item in list ; _buf << "\n"
181
+ #_buf << " - "; _buf << ( item ).to_s; _buf << "\n"
182
+ # end ; _buf << "\n"
183
+ #_buf << "user: "; _buf << ( defined?(user) ? user : "(none)" ).to_s; _buf << "\n"
184
+ #_buf
185
+ #END
136
186
  @expected = <<'END'
137
- _out = ''; _out << "list:\n"
138
- list = ['<aaa>', 'b&b', '"ccc"']
139
- for item in list ; _out << "\n"
140
- _out << " - "; _out << ( item ).to_s; _out << "\n"
141
- end ; _out << "\n"
142
- _out << "user: "; _out << ( defined?(user) ? user : "(none)" ).to_s; _out << "\n"
143
- _out
187
+ _buf = []; _buf << 'list:
188
+ '; list = ['<aaa>', 'b&b', '"ccc"']
189
+ for item in list ; _buf << '
190
+ '; _buf << ' - '; _buf << ( item ).to_s; _buf << '
191
+ '; end ; _buf << '
192
+ '; _buf << 'user: '; _buf << ( defined?(user) ? user : "(none)" ).to_s; _buf << '
193
+ ';
194
+ _buf.join
144
195
  END
145
- @options = "-sT"
196
+ @options = "-xT"
146
197
  _test()
147
198
  end
148
199
 
149
200
 
150
- def test_context1
151
- @input = INPUT
152
- @expected = OUTPUT.gsub(/\(none\)/, 'Hello')
153
- @options = '--user=Hello'
154
- _test()
155
- end
201
+ #--
202
+ #def test_context1
203
+ # @input = INPUT
204
+ # @expected = OUTPUT.gsub(/\(none\)/, 'Hello')
205
+ # @options = '--user=Hello'
206
+ # _test()
207
+ #end
208
+ #++
156
209
 
157
210
 
158
- def test_yaml1
211
+ def test_yaml1 # -f
159
212
  yamlfile = "test.context1.yaml"
160
- @input = INPUT
213
+ @input = INPUT2
161
214
  @expected = OUTPUT.gsub(/\(none\)/, 'Hello')
162
215
  @options = "-f #{yamlfile}"
163
216
  #
@@ -174,7 +227,94 @@ END
174
227
  end
175
228
 
176
229
 
177
- def test_include1
230
+ def test_untabify1 # -t
231
+ yamlfile = "test.context2.yaml"
232
+ @input = INPUT2
233
+ @expected = OUTPUT.gsub(/\(none\)/, 'Hello')
234
+ @options = "-tf #{yamlfile}"
235
+ #
236
+ yaml = <<-END
237
+ user: Hello
238
+ password: world
239
+ END
240
+ File.open(yamlfile, 'w') { |f| f.write(yaml) }
241
+ begin
242
+ _test()
243
+ ensure
244
+ File.unlink(yamlfile) if test(?f, yamlfile)
245
+ end
246
+ end
247
+
248
+
249
+ def test_symbolify1 # -S
250
+ yamlfile = "test.context3.yaml"
251
+ @input = <<END
252
+ <% for h in @list %>
253
+ <tr>
254
+ <td><%= h[:name] %></td><td><%= h[:mail] %></td>
255
+ </tr>
256
+ <% end %>
257
+ END
258
+ @expected = <<END
259
+ <tr>
260
+ <td>foo</td><td>foo@mail.com</td>
261
+ </tr>
262
+ <tr>
263
+ <td>bar</td><td>bar@mail.org</td>
264
+ </tr>
265
+ END
266
+ @options = "-f #{yamlfile} -S"
267
+ #
268
+ yaml = <<-END
269
+ list:
270
+ - name: foo
271
+ mail: foo@mail.com
272
+ - name: bar
273
+ mail: bar@mail.org
274
+ END
275
+ File.open(yamlfile, 'w') { |f| f.write(yaml) }
276
+ begin
277
+ _test()
278
+ ensure
279
+ File.unlink(yamlfile) if test(?f, yamlfile)
280
+ end
281
+ end
282
+
283
+
284
+ def test_context1 # -B
285
+ yamlfile = "test.context4.yaml"
286
+ #
287
+ @input = <<'END'
288
+ user = <%= user %>
289
+ <% for item in list %>
290
+ - <%= item %>
291
+ <% end %>
292
+ END
293
+ @expected = <<'END'
294
+ user = World
295
+ - aaa
296
+ - bbb
297
+ - ccc
298
+ END
299
+ @options = "-f #{yamlfile} -B "
300
+ #
301
+ yaml = <<-END
302
+ user: World
303
+ list:
304
+ - aaa
305
+ - bbb
306
+ - ccc
307
+ END
308
+ File.open(yamlfile, 'w') { |f| f.write(yaml) }
309
+ begin
310
+ _test()
311
+ ensure
312
+ File.unlink(yamlfile) if test(?f, yamlfile)
313
+ end
314
+ end
315
+
316
+
317
+ def test_include1 # -I
178
318
  dir = 'foo'
179
319
  lib = 'bar'
180
320
  Dir.mkdir dir unless test(?d, dir)
@@ -200,7 +340,7 @@ END
200
340
  end
201
341
 
202
342
 
203
- def test_require1
343
+ def test_require1 # -r
204
344
  dir = 'foo'
205
345
  lib = 'bar'
206
346
  Dir.mkdir dir unless test(?d, dir)
@@ -226,4 +366,41 @@ END
226
366
  end
227
367
 
228
368
 
369
+ def test_enhancers1 # -E
370
+ @input = <<END
371
+ <% list = %w[<aaa> b&b "ccc"] %>
372
+ % for item in list
373
+ - <%= item %> : <%== item %>
374
+ - [= item =] : [== item =]
375
+ % end
376
+ END
377
+ @expected = <<END
378
+ - &lt;aaa&gt; : <aaa>
379
+ - &lt;aaa&gt; : <aaa>
380
+ - b&amp;b : b&b
381
+ - b&amp;b : b&b
382
+ - &quot;ccc&quot; : "ccc"
383
+ - &quot;ccc&quot; : "ccc"
384
+ END
385
+ @options = "-E Escape,PercentLine,HeaderFooter,BiPattern"
386
+ _test()
387
+ end
388
+
389
+
390
+ def test_bodyonly1 # -b
391
+ @input = INPUT
392
+ @expected = SRC.sub(/\A_buf = \[\];/,'').sub(/\n_buf.join\n\z/,'')
393
+ @options = '-b -x'
394
+ _test()
395
+ end
396
+
397
+
398
+ def test_escape1 # -e
399
+ @input = INPUT
400
+ @expected = SRC.gsub(/<< \((.*?)\).to_s;/, '<< Erubis::XmlHelper.escape_xml(\1);')
401
+ @options = '-ex'
402
+ _test()
403
+ end
404
+
405
+
229
406
  end
@@ -0,0 +1,343 @@
1
+ ##
2
+ ## $Rev: 21 $
3
+ ## $Release: 2.0.0 $
4
+ ## copyright(c) 2006 kuwata-lab all rights reserved.
5
+ ##
6
+
7
+ require "#{File.dirname(__FILE__)}/test.rb"
8
+
9
+ require 'erubis'
10
+ require 'erubis/engine/eruby'
11
+ require 'erubis/engine/ephp'
12
+ require 'erubis/engine/ec'
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
+ extend TestEnhancer
21
+
22
+ #load_yaml_documents(__FILE__)
23
+ testdata_list = load_yaml_document(__FILE__)
24
+ define_testmethods(testdata_list)
25
+
26
+ def _test()
27
+ klass = Erubis.const_get(@class)
28
+ engine = klass.new(@input, @options || {})
29
+ actual = engine.src
30
+ assert_text_equal(@expected, actual)
31
+ end
32
+
33
+ end
34
+
35
+ __END__
36
+ - name: ruby1
37
+ lang: ruby
38
+ class: Eruby
39
+ options:
40
+ input: |
41
+ <table>
42
+ <tbody>
43
+ <% i = 0
44
+ list.each_with_index do |item, i| %>
45
+ <tr>
46
+ <td><%= i+1 %></td>
47
+ <td><%== list %></td>
48
+ </tr>
49
+ <% end %>
50
+ </tbody>
51
+ </table>
52
+ <%=== i+1 %>
53
+ expected: |
54
+ _buf = []; _buf << '<table>
55
+ <tbody>
56
+ '; i = 0
57
+ list.each_with_index do |item, i|
58
+ _buf << ' <tr>
59
+ <td>'; _buf << ( i+1 ).to_s; _buf << '</td>
60
+ <td>'; _buf << Erubis::XmlHelper.escape_xml( list ); _buf << '</td>
61
+ </tr>
62
+ '; end
63
+ _buf << ' </tbody>
64
+ </table>
65
+ '; $stderr.puts("*** debug: i+1=#{(i+1).inspect}"); _buf << '
66
+ ';
67
+ _buf.join
68
+ ##
69
+ - name: php1
70
+ lang: php
71
+ class: Ephp
72
+ options:
73
+ input: |
74
+ <table>
75
+ <tbody>
76
+ <%
77
+ $i = 0;
78
+ foreach ($list as $item) {
79
+ $i++;
80
+ %>
81
+ <tr>
82
+ <td><%= $i %></td>
83
+ <td><%== $item %></td>
84
+ </tr>
85
+ <%
86
+ }
87
+ %>
88
+ </tbody>
89
+ </table>
90
+ <%=== $i %>
91
+ expected: |
92
+ <table>
93
+ <tbody>
94
+ <?php
95
+ $i = 0;
96
+ foreach ($list as $item) {
97
+ $i++;
98
+ ?>
99
+ <tr>
100
+ <td><?php echo $i; ?></td>
101
+ <td><?php echo htmlspecialchars($item); ?></td>
102
+ </tr>
103
+ <?php
104
+ }
105
+ ?>
106
+ </tbody>
107
+ </table>
108
+ <?php error_log('*** debug: $i='.($i), 0); ?>
109
+ ##
110
+ - name: c1
111
+ lang: c
112
+ class: Ec
113
+ options: { :filename: foo.html, :indent: ' ' }
114
+ input: |4
115
+ <table>
116
+ <tbody>
117
+ <% for (i = 0; i < list; i++) { %>
118
+ <tr>
119
+ <td><%= "%d", i %></td>
120
+ <td><%== "%s", list[i] %></td>
121
+ </tr>
122
+ <% } %>
123
+ </tbody>
124
+ </table>
125
+ <%=== "%d", i %>
126
+ expected: |
127
+ #line 1 "foo.html"
128
+ fputs("<table>\n"
129
+ " <tbody>\n", stdout);
130
+ for (i = 0; i < list; i++) {
131
+ fputs(" <tr>\n"
132
+ " <td>", stdout); fprintf(stdout, "%d", i); fputs("</td>\n"
133
+ " <td>", stdout); fprintf(stdout, "%s", escape(list[i])); fputs("</td>\n"
134
+ " </tr>\n", stdout);
135
+ }
136
+ fputs(" </tbody>\n"
137
+ "</table>\n", stdout);
138
+ fprintf(stderr, "*** debug: i=" "%d", i); fputs("\n", stdout);
139
+ ##
140
+ - name: java1
141
+ lang: java
142
+ class: Ejava
143
+ options: { :buf: _buf, :bufclass: StringBuilder, :indent: ' ' }
144
+ input: |
145
+ <table>
146
+ <tbody>
147
+ <%
148
+ int i = 0;
149
+ for (Iterator it = list.iterator(); it.hasNext(); ) {
150
+ String s = (String)it.next();
151
+ i++;
152
+ %>
153
+ <tr class="<%= i%2==0 ? "even" : "odd" %>">
154
+ <td><%= i %></td>
155
+ <td><%== s %></td>
156
+ </tr>
157
+ <%
158
+ }
159
+ %>
160
+ <tbody>
161
+ </table>
162
+ <%=== i %>
163
+ expected: |4
164
+ StringBuilder _buf = new StringBuilder(); _buf.append("<table>\n"
165
+ + " <tbody>\n");
166
+
167
+ int i = 0;
168
+ for (Iterator it = list.iterator(); it.hasNext(); ) {
169
+ String s = (String)it.next();
170
+ i++;
171
+
172
+ _buf.append(" <tr class=\""); _buf.append(i%2==0 ? "even" : "odd"); _buf.append("\">\n"
173
+ + " <td>"); _buf.append(i); _buf.append("</td>\n"
174
+ + " <td>"); _buf.append(escape(s)); _buf.append("</td>\n"
175
+ + " </tr>\n");
176
+
177
+ }
178
+
179
+ _buf.append(" <tbody>\n"
180
+ + "</table>\n");
181
+ System.err.println("*** debug: i="+(i)); _buf.append("\n");
182
+ return _buf.toString();
183
+ ##
184
+ - name: scheme1
185
+ lang: scheme
186
+ class: Escheme
187
+ options:
188
+ input: &scheme1_input|
189
+ <% (let ((i 0)) %>
190
+ <table>
191
+ <tbody>
192
+ <%
193
+ (for-each
194
+ (lambda (item)
195
+ (set! i (+ i 1))
196
+ %>
197
+ <tr>
198
+ <td><%= i %></td>
199
+ <td><%== item %></td>
200
+ </tr>
201
+ <%
202
+ ); lambda end
203
+ list); for-each end
204
+ %>
205
+ </tbody>
206
+ </table>
207
+ <%=== i %>
208
+ <% ); let end %>
209
+ expected: |4
210
+ (let ((_buf '())) (define (_add x) (set! _buf (cons x _buf))) (let ((i 0))
211
+ (_add "<table>
212
+ <tbody>\n")
213
+
214
+ (for-each
215
+ (lambda (item)
216
+ (set! i (+ i 1))
217
+
218
+ (_add " <tr>
219
+ <td>")(_add i)(_add "</td>
220
+ <td>")(_add (escape item))(_add "</td>
221
+ </tr>\n")
222
+
223
+ ); lambda end
224
+ list); for-each end
225
+
226
+ (_add " </tbody>
227
+ </table>\n")
228
+ (display "*** debug: i=")(display i)(display "\n")(_add "\n")
229
+ ); let end
230
+ (reverse _buf))
231
+
232
+ ##
233
+ - name: scheme2
234
+ lang: scheme
235
+ class: Escheme
236
+ options: { :func: 'display' }
237
+ input: *scheme1_input
238
+ expected: |4
239
+ (let ((i 0))
240
+ (display "<table>
241
+ <tbody>\n")
242
+
243
+ (for-each
244
+ (lambda (item)
245
+ (set! i (+ i 1))
246
+
247
+ (display " <tr>
248
+ <td>")(display i)(display "</td>
249
+ <td>")(display (escape item))(display "</td>
250
+ </tr>\n")
251
+
252
+ ); lambda end
253
+ list); for-each end
254
+
255
+ (display " </tbody>
256
+ </table>\n")
257
+ (display "*** debug: i=")(display i)(display "\n")(display "\n")
258
+ ); let end
259
+ ##
260
+ - name: perl1
261
+ lang: perl
262
+ class: Eperl
263
+ options:
264
+ input: |
265
+ <%
266
+ my $user = 'Erubis';
267
+ my @list = ('<aaa>', 'b&b', '"ccc"');
268
+ %>
269
+ <p>Hello <%= $user %>!</p>
270
+ <table>
271
+ <tbody>
272
+ <% $i = 0; %>
273
+ <% for $item (@list) { %>
274
+ <tr bgcolor=<%= ++$i % 2 == 0 ? '#FFCCCC' : '#CCCCFF' %>">
275
+ <td><%= $i %></td>
276
+ <td><%== $item %></td>
277
+ </tr>
278
+ <% } %>
279
+ </tbody>
280
+ </table>
281
+ <%=== $i %>
282
+ expected: |4
283
+
284
+ my $user = 'Erubis';
285
+ my @list = ('<aaa>', 'b&b', '"ccc"');
286
+
287
+ print('<p>Hello '); print($user); print('!</p>
288
+ <table>
289
+ <tbody>
290
+ '); $i = 0;
291
+ for $item (@list) {
292
+ print(' <tr bgcolor='); print(++$i % 2 == 0 ? '#FFCCCC' : '#CCCCFF'); print('">
293
+ <td>'); print($i); print('</td>
294
+ <td>'); print(escape($item)); print('</td>
295
+ </tr>
296
+ '); }
297
+ print(' </tbody>
298
+ </table>
299
+ '); print('*** debug: $i=', $i, "\n");print('
300
+ ');
301
+ ##
302
+ - name: javascript
303
+ lang: javascript
304
+ class: Ejavascript
305
+ options:
306
+ input: |
307
+ <%
308
+ var user = 'Erubis';
309
+ var list = ['<aaa>', 'b&b', '"ccc"'];
310
+ %>
311
+ <p>Hello <%= user %>!</p>
312
+ <table>
313
+ <tbody>
314
+ <% var i; %>
315
+ <% for (i = 0; i < list.length; i++) { %>
316
+ <tr bgcolor=<%= ++i % 2 == 0 ? '#FFCCCC' : '#CCCCFF' %>">
317
+ <td><%= i %></td>
318
+ <td><%= list[i] %></td>
319
+ </tr>
320
+ <% } %>
321
+ </tbody>
322
+ </table>
323
+ <%=== i %>
324
+ expected: |4
325
+ var _buf = [];
326
+ var user = 'Erubis';
327
+ var list = ['<aaa>', 'b&b', '"ccc"'];
328
+
329
+ _buf.push("<p>Hello "); _buf.push(user); _buf.push("!</p>\n\
330
+ <table>\n\
331
+ <tbody>\n");
332
+ var i;
333
+ for (i = 0; i < list.length; i++) {
334
+ _buf.push(" <tr bgcolor="); _buf.push(++i % 2 == 0 ? '#FFCCCC' : '#CCCCFF'); _buf.push("\">\n\
335
+ <td>"); _buf.push(i); _buf.push("</td>\n\
336
+ <td>"); _buf.push(list[i]); _buf.push("</td>\n\
337
+ </tr>\n");
338
+ }
339
+ _buf.push(" </tbody>\n\
340
+ </table>\n");
341
+ alert("*** debug: i="+(i)); _buf.push("\n");
342
+ document.write(_buf.join(""));
343
+ ##