erubis 2.4.0 → 2.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. data/CHANGES +55 -2
  2. data/README.txt +1 -1
  3. data/benchmark/bench.rb +1 -1
  4. data/bin/erubis +1 -1
  5. data/contrib/erubis +57 -34
  6. data/contrib/inline-require +1 -1
  7. data/doc-api/classes/Erubis.html +6 -1
  8. data/doc-api/classes/Erubis/DeleteIndentEnhancer.html +1 -1
  9. data/doc-api/classes/Erubis/Evaluator.html +3 -3
  10. data/doc-api/classes/Erubis/HeaderFooterEnhancer.html +2 -2
  11. data/doc-api/classes/Erubis/InterpolationEnhancer.html +5 -5
  12. data/doc-api/classes/Erubis/JavascriptGenerator.html +16 -11
  13. data/doc-api/classes/Erubis/PI/Ejavascript.html +1 -1
  14. data/doc-api/classes/Erubis/PercentLineEnhancer.html +22 -18
  15. data/doc-api/classes/Erubis/RubyEvaluator.html +4 -4
  16. data/doc-api/created.rid +1 -1
  17. data/doc-api/files/README_txt.html +2 -2
  18. data/doc-api/files/erubis/context_rb.html +1 -1
  19. data/doc-api/files/erubis/converter_rb.html +1 -1
  20. data/doc-api/files/erubis/engine/ec_rb.html +1 -1
  21. data/doc-api/files/erubis/engine/ejava_rb.html +1 -1
  22. data/doc-api/files/erubis/engine/ejavascript_rb.html +2 -2
  23. data/doc-api/files/erubis/engine/enhanced_rb.html +1 -1
  24. data/doc-api/files/erubis/engine/eperl_rb.html +1 -1
  25. data/doc-api/files/erubis/engine/ephp_rb.html +1 -1
  26. data/doc-api/files/erubis/engine/eruby_rb.html +1 -1
  27. data/doc-api/files/erubis/engine/escheme_rb.html +1 -1
  28. data/doc-api/files/erubis/engine/optimized_rb.html +1 -1
  29. data/doc-api/files/erubis/engine_rb.html +1 -1
  30. data/doc-api/files/erubis/enhancer_rb.html +2 -2
  31. data/doc-api/files/erubis/error_rb.html +1 -1
  32. data/doc-api/files/erubis/evaluator_rb.html +2 -2
  33. data/doc-api/files/erubis/generator_rb.html +1 -1
  34. data/doc-api/files/erubis/helper_rb.html +1 -1
  35. data/doc-api/files/erubis/helpers/rails_helper_rb.html +1 -1
  36. data/doc-api/files/erubis/local-setting_rb.html +1 -1
  37. data/doc-api/files/erubis/main_rb.html +1 -1
  38. data/doc-api/files/erubis/tiny_rb.html +1 -1
  39. data/doc-api/files/erubis_rb.html +1 -1
  40. data/doc/users-guide.html +126 -14
  41. data/lib/erubis.rb +2 -2
  42. data/lib/erubis/context.rb +1 -1
  43. data/lib/erubis/converter.rb +1 -1
  44. data/lib/erubis/engine.rb +1 -1
  45. data/lib/erubis/engine/ec.rb +1 -1
  46. data/lib/erubis/engine/ejava.rb +1 -1
  47. data/lib/erubis/engine/ejavascript.rb +9 -3
  48. data/lib/erubis/engine/enhanced.rb +1 -1
  49. data/lib/erubis/engine/eperl.rb +1 -1
  50. data/lib/erubis/engine/ephp.rb +1 -1
  51. data/lib/erubis/engine/eruby.rb +1 -1
  52. data/lib/erubis/engine/escheme.rb +1 -1
  53. data/lib/erubis/engine/optimized.rb +1 -1
  54. data/lib/erubis/enhancer.rb +23 -8
  55. data/lib/erubis/error.rb +1 -1
  56. data/lib/erubis/evaluator.rb +5 -3
  57. data/lib/erubis/generator.rb +1 -1
  58. data/lib/erubis/helper.rb +1 -1
  59. data/lib/erubis/helpers/rails_helper.rb +1 -1
  60. data/lib/erubis/local-setting.rb +1 -1
  61. data/lib/erubis/main.rb +1 -1
  62. data/lib/erubis/tiny.rb +1 -1
  63. data/test/assert-text-equal.rb +1 -1
  64. data/test/data/users-guide/main_program1.rb +8 -0
  65. data/test/data/users-guide/main_program1.result +6 -0
  66. data/test/data/users-guide/main_program2.rb +8 -0
  67. data/test/data/users-guide/main_program2.result +6 -0
  68. data/test/data/users-guide/stderr.log +3 -0
  69. data/test/data/users-guide/template1.rhtml +4 -0
  70. data/test/data/users-guide/template2.rhtml +4 -0
  71. data/test/test-engines.rb +29 -4
  72. data/test/test-enhancers.rb +4 -4
  73. data/test/test-erubis.rb +17 -2
  74. data/test/test-main.rb +2 -2
  75. data/test/test-users-guide.rb +1 -1
  76. data/test/test.rb +1 -1
  77. data/test/testutil.rb +1 -1
  78. metadata +9 -2
@@ -1,6 +1,6 @@
1
1
  ##
2
2
  ## $Rev: 77 $
3
- ## $Release: 2.4.0 $
3
+ ## $Release: 2.4.1 $
4
4
  ## copyright(c) 2006-2007 kuwata-lab.com all rights reserved.
5
5
  ##
6
6
 
@@ -1,6 +1,6 @@
1
1
  ##
2
- ## $Rev: 91 $
3
- ## $Release: 2.4.0 $
2
+ ## $Rev: 94 $
3
+ ## $Release: 2.4.1 $
4
4
  ## copyright(c) 2006-2007 kuwata-lab.com all rights reserved.
5
5
  ##
6
6
 
@@ -10,6 +10,8 @@ require 'erubis/context'
10
10
 
11
11
  module Erubis
12
12
 
13
+ EMPTY_BINDING = binding()
14
+
13
15
 
14
16
  ##
15
17
  ## evaluate code
@@ -64,7 +66,7 @@ module Erubis
64
66
  def evaluate(context=Context.new)
65
67
  context = Context.new(context) if context.is_a?(Hash)
66
68
  #return context.instance_eval(@src, @filename || '(erubis)')
67
- @_proc ||= eval("proc { #{@src} }", TOPLEVEL_BINDING, @filename || '(erubis)')
69
+ @_proc ||= eval("proc { #{@src} }", Erubis::EMPTY_BINDING, @filename || '(erubis)')
68
70
  return context.instance_eval(&@_proc)
69
71
  end
70
72
 
@@ -1,6 +1,6 @@
1
1
  ##
2
2
  ## $Rev: 77 $
3
- ## $Release: 2.4.0 $
3
+ ## $Release: 2.4.1 $
4
4
  ## copyright(c) 2006-2007 kuwata-lab.com all rights reserved.
5
5
  ##
6
6
 
@@ -1,6 +1,6 @@
1
1
  ##
2
2
  ## $Rev: 89 $
3
- ## $Release: 2.4.0 $
3
+ ## $Release: 2.4.1 $
4
4
  ## copyright(c) 2006-2007 kuwata-lab.com all rights reserved.
5
5
  ##
6
6
 
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 90 $
3
- ### $Release: 2.4.0 $
3
+ ### $Release: 2.4.1 $
4
4
  ### copyright(c) 2006-2007 kuwata-lab.com all rights reserved.
5
5
  ###
6
6
 
@@ -1,6 +1,6 @@
1
1
  ##
2
2
  ## $Rev: 77 $
3
- ## $Release: 2.4.0 $
3
+ ## $Release: 2.4.1 $
4
4
  ## copyright(c) 2006-2007 kuwata-lab.com all rights reserved.
5
5
  ##
6
6
 
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 91 $
3
- ### $Release: 2.4.0 $
3
+ ### $Release: 2.4.1 $
4
4
  ### copyright(c) 2006-2007 kuwata-lab.com all rights reserved.
5
5
  ###
6
6
 
@@ -1,6 +1,6 @@
1
1
  ##
2
2
  ## $Rev: 77 $
3
- ## $Release: 2.4.0 $
3
+ ## $Release: 2.4.1 $
4
4
  ## copyright(c) 2006-2007 kuwata-lab.com all rights reserved.
5
5
  ##
6
6
 
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 77 $
3
- ### $Release: 2.4.0 $
3
+ ### $Release: 2.4.1 $
4
4
  ### copyright(c) 2006-2007 kuwata-lab.com all rights reserved.
5
5
  ###
6
6
 
@@ -0,0 +1,8 @@
1
+ require 'erubis'
2
+ eruby = Erubis::Eruby.new(File.read('template1.rhtml'))
3
+ items = ['foo', 'bar', 'baz']
4
+ x = 1
5
+ ## local variable 'x' and 'eruby' are passed to template as well as 'items'!
6
+ print eruby.result(binding())
7
+ ## local variable 'x' is changed unintendedly because it is changed in template!
8
+ puts "** debug: x=#{x.inspect}" #=> "baz"
@@ -0,0 +1,6 @@
1
+ $ ruby main_program1.rb
2
+ item = foo
3
+ item = bar
4
+ item = baz
5
+ ** debug: local variables=["eruby", "items", "x", "_buf"]
6
+ ** debug: x="baz"
@@ -0,0 +1,8 @@
1
+ require 'erubis'
2
+ eruby = Erubis::Eruby.new(File.read('template2.rhtml'))
3
+ items = ['foo', 'bar', 'baz']
4
+ x = 1
5
+ ## only 'items' are passed to template
6
+ print eruby.evaluate(:items=>items)
7
+ ## local variable 'x' is not changed!
8
+ puts "** debug: x=#{x.inspect}" #=> 1
@@ -0,0 +1,6 @@
1
+ $ ruby main_program2.rb
2
+ item = foo
3
+ item = bar
4
+ item = baz
5
+ ** debug: local variables=["x", "_buf"]
6
+ ** debug: x=1
@@ -0,0 +1,3 @@
1
+ *** debug: item="<aaa>"
2
+ *** debug: item="b&b"
3
+ *** debug: item="\"ccc\""
@@ -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() %>
@@ -1,6 +1,6 @@
1
1
  ##
2
- ## $Rev: 77 $
3
- ## $Release: 2.4.0 $
2
+ ## $Rev: 95 $
3
+ ## $Release: 2.4.1 $
4
4
  ## copyright(c) 2006-2007 kuwata-lab.com all rights reserved.
5
5
  ##
6
6
 
@@ -298,11 +298,11 @@ __END__
298
298
  '); print('*** debug: $i=', $i, "\n");print('
299
299
  ');
300
300
  ##
301
- - name: javascript
301
+ - name: javascript1
302
302
  lang: javascript
303
303
  class: Ejavascript
304
304
  options:
305
- input: |
305
+ input: &javascript_input |
306
306
  <%
307
307
  var user = 'Erubis';
308
308
  var list = ['<aaa>', 'b&b', '"ccc"'];
@@ -340,3 +340,28 @@ __END__
340
340
  alert("*** debug: i="+(i)); _buf.push("\n");
341
341
  document.write(_buf.join(""));
342
342
  ##
343
+ - name: javascript2
344
+ lang: javascript
345
+ class: Ejavascript
346
+ options: { :docwrite: false }
347
+ input: *javascript_input
348
+ expected: |4
349
+ var _buf = [];
350
+ var user = 'Erubis';
351
+ var list = ['<aaa>', 'b&b', '"ccc"'];
352
+
353
+ _buf.push("<p>Hello "); _buf.push(user); _buf.push("!</p>\n\
354
+ <table>\n\
355
+ <tbody>\n");
356
+ var i;
357
+ for (i = 0; i < list.length; i++) {
358
+ _buf.push(" <tr bgcolor="); _buf.push(++i % 2 == 0 ? '#FFCCCC' : '#CCCCFF'); _buf.push("\">\n\
359
+ <td>"); _buf.push(i); _buf.push("</td>\n\
360
+ <td>"); _buf.push(list[i]); _buf.push("</td>\n\
361
+ </tr>\n");
362
+ }
363
+ _buf.push(" </tbody>\n\
364
+ </table>\n");
365
+ alert("*** debug: i="+(i)); _buf.push("\n");
366
+ _buf.join("");
367
+ ##
@@ -1,6 +1,6 @@
1
1
  ##
2
- ## $Rev: 77 $
3
- ## $Release: 2.4.0 $
2
+ ## $Rev: 93 $
3
+ ## $Release: 2.4.1 $
4
4
  ## copyright(c) 2006-2007 kuwata-lab.com all rights reserved.
5
5
  ##
6
6
 
@@ -471,8 +471,8 @@ __END__
471
471
  '; end
472
472
  _buf << '</table>
473
473
  <pre>
474
- '; _buf << '% double percent
475
- '; _buf << ' % spaced percent
474
+ % double percent
475
+ % spaced percent
476
476
  </pre>
477
477
  ';
478
478
  _buf.to_s
@@ -1,6 +1,6 @@
1
1
  ##
2
- ## $Rev: 91 $
3
- ## $Release: 2.4.0 $
2
+ ## $Rev: 94 $
3
+ ## $Release: 2.4.1 $
4
4
  ## copyright(c) 2006-2007 kuwata-lab.com all rights reserved.
5
5
  ##
6
6
 
@@ -192,8 +192,23 @@ END
192
192
  assert_nil(eruby.instance_variable_get('@_proc'))
193
193
  end
194
194
 
195
+ #def test_toplevel_binding
196
+ # s = "locals = <%= local_variables().inspect %>\n<% x = 50 %>\n"
197
+ # eruby = Erubis::Eruby.new(s)
198
+ # _x = eval 'x', TOPLEVEL_BINDING
199
+ # _y = eval 'y', TOPLEVEL_BINDING
200
+ # actual = eruby.evaluate(:x=>_x, :y=>_y)
201
+ # _x = eval 'x', TOPLEVEL_BINDING
202
+ # _y = eval 'y', TOPLEVEL_BINDING
203
+ # puts "*** actual=#{actual.inspect}, x=#{_x.inspect}, y=#{_y.inspect}"
204
+ #end
205
+
195
206
  end
196
207
 
208
+ x = 10
209
+ y = 20
210
+
211
+
197
212
  __END__
198
213
  - name: basic1
199
214
  input: &basic1_input|
@@ -1,6 +1,6 @@
1
1
  ##
2
2
  ## $Rev: 87 $
3
- ## $Release: 2.4.0 $
3
+ ## $Release: 2.4.1 $
4
4
  ## $Date: 2007-07-12 05:01:24 +0900 (Thu, 12 Jul 2007) $
5
5
  ##
6
6
 
@@ -178,7 +178,7 @@ END
178
178
 
179
179
  def test_version # -v
180
180
  @options = '-v'
181
- @expected = (("$Release: 2.4.0 $" =~ /[.\d]+/) && $&) + "\n"
181
+ @expected = (("$Release: 2.4.1 $" =~ /[.\d]+/) && $&) + "\n"
182
182
  @filename = false
183
183
  _test()
184
184
  end
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 77 $
3
- ### $Release: 2.4.0 $
3
+ ### $Release: 2.4.1 $
4
4
  ### copyright(c) 2006-2007 kuwata-lab.com all rights reserved.
5
5
  ###
6
6
 
@@ -1,6 +1,6 @@
1
1
  ##
2
2
  ## $Rev: 77 $
3
- ## $Release: 2.4.0 $
3
+ ## $Release: 2.4.1 $
4
4
  ## copyright(c) 2006-2007 kuwata-lab.com all rights reserved.
5
5
  ##
6
6
 
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 77 $
3
- ### $Release: 2.4.0 $
3
+ ### $Release: 2.4.1 $
4
4
  ### copyright(c) 2006-2007 kuwata-lab.com all rights reserved.
5
5
  ###
6
6
 
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: erubis
5
5
  version: !ruby/object:Gem::Version
6
- version: 2.4.0
7
- date: 2007-07-19 00:00:00 +09:00
6
+ version: 2.4.1
7
+ date: 2007-09-25 00:00:00 +09:00
8
8
  summary: a fast and extensible eRuby implementation which supports multi-language
9
9
  require_paths:
10
10
  - lib
@@ -153,6 +153,10 @@ files:
153
153
  - test/data/users-guide/headerfooter_example.result
154
154
  - test/data/users-guide/headerfooter_example2.result
155
155
  - test/data/users-guide/interpolation_example.result
156
+ - test/data/users-guide/main_program1.rb
157
+ - test/data/users-guide/main_program1.result
158
+ - test/data/users-guide/main_program2.rb
159
+ - test/data/users-guide/main_program2.result
156
160
  - test/data/users-guide/nocode-example.eruby
157
161
  - test/data/users-guide/nocode-php.result
158
162
  - test/data/users-guide/nocode_example.result
@@ -169,8 +173,11 @@ files:
169
173
  - test/data/users-guide/printenabled-example.rb
170
174
  - test/data/users-guide/printstatement_example.result
171
175
  - test/data/users-guide/simplify_example.result
176
+ - test/data/users-guide/stderr.log
172
177
  - test/data/users-guide/stdout_exmple.result
173
178
  - test/data/users-guide/stringbuffer_example.result
179
+ - test/data/users-guide/template1.rhtml
180
+ - test/data/users-guide/template2.rhtml
174
181
  - test/test-engines.rb
175
182
  - test/test-enhancers.rb
176
183
  - test/test-erubis.rb