erubis 2.6.1 → 2.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. data/CHANGES.txt +16 -2
  2. data/README.txt +2 -1
  3. data/benchmark/bench.rb +1 -1
  4. data/bin/erubis +1 -1
  5. data/contrib/erubis +1 -1
  6. data/contrib/inline-require +1 -1
  7. data/doc-api/classes/Erubis.html +1 -1
  8. data/doc-api/classes/Erubis/Basic/Converter.html +3 -2
  9. data/doc-api/classes/Erubis/BiPatternEnhancer.html +6 -3
  10. data/doc-api/classes/Erubis/DeleteIndentEnhancer.html +1 -1
  11. data/doc-api/classes/Erubis/HeaderFooterEnhancer.html +6 -3
  12. data/doc-api/classes/Erubis/InterpolationEnhancer.html +7 -6
  13. data/doc-api/classes/Erubis/Main.html +26 -26
  14. data/doc-api/classes/Erubis/PI/Converter.html +5 -4
  15. data/doc-api/classes/Erubis/PI/TinyEruby.html +6 -5
  16. data/doc-api/classes/Erubis/PercentLineEnhancer.html +3 -2
  17. data/doc-api/classes/Erubis/RubyEvaluator.html +18 -13
  18. data/doc-api/classes/Erubis/SimplifyEnhancer.html +2 -1
  19. data/doc-api/classes/Erubis/TinyEruby.html +4 -3
  20. data/doc-api/created.rid +1 -1
  21. data/doc-api/files/README_txt.html +4 -3
  22. data/doc-api/files/erubis/context_rb.html +1 -1
  23. data/doc-api/files/erubis/converter_rb.html +2 -2
  24. data/doc-api/files/erubis/engine/ec_rb.html +1 -1
  25. data/doc-api/files/erubis/engine/ejava_rb.html +1 -1
  26. data/doc-api/files/erubis/engine/ejavascript_rb.html +1 -1
  27. data/doc-api/files/erubis/engine/enhanced_rb.html +1 -1
  28. data/doc-api/files/erubis/engine/eperl_rb.html +1 -1
  29. data/doc-api/files/erubis/engine/ephp_rb.html +1 -1
  30. data/doc-api/files/erubis/engine/eruby_rb.html +1 -1
  31. data/doc-api/files/erubis/engine/escheme_rb.html +1 -1
  32. data/doc-api/files/erubis/engine/optimized_rb.html +1 -1
  33. data/doc-api/files/erubis/engine_rb.html +1 -1
  34. data/doc-api/files/erubis/enhancer_rb.html +2 -2
  35. data/doc-api/files/erubis/error_rb.html +1 -1
  36. data/doc-api/files/erubis/evaluator_rb.html +2 -2
  37. data/doc-api/files/erubis/generator_rb.html +1 -1
  38. data/doc-api/files/erubis/helper_rb.html +1 -1
  39. data/doc-api/files/erubis/helpers/rails_form_helper_rb.html +1 -1
  40. data/doc-api/files/erubis/helpers/rails_helper_rb.html +1 -1
  41. data/doc-api/files/erubis/local-setting_rb.html +1 -1
  42. data/doc-api/files/erubis/main_rb.html +2 -2
  43. data/doc-api/files/erubis/preprocessing_rb.html +1 -1
  44. data/doc-api/files/erubis/tiny_rb.html +2 -2
  45. data/doc-api/files/erubis_rb.html +1 -1
  46. data/doc/users-guide.html +13 -11
  47. data/lib/erubis.rb +2 -2
  48. data/lib/erubis/context.rb +1 -1
  49. data/lib/erubis/converter.rb +6 -4
  50. data/lib/erubis/engine.rb +1 -1
  51. data/lib/erubis/engine/ec.rb +1 -1
  52. data/lib/erubis/engine/ejava.rb +1 -1
  53. data/lib/erubis/engine/ejavascript.rb +1 -1
  54. data/lib/erubis/engine/enhanced.rb +1 -1
  55. data/lib/erubis/engine/eperl.rb +1 -1
  56. data/lib/erubis/engine/ephp.rb +1 -1
  57. data/lib/erubis/engine/eruby.rb +1 -1
  58. data/lib/erubis/engine/escheme.rb +1 -1
  59. data/lib/erubis/engine/optimized.rb +1 -1
  60. data/lib/erubis/enhancer.rb +16 -7
  61. data/lib/erubis/error.rb +1 -1
  62. data/lib/erubis/evaluator.rb +17 -12
  63. data/lib/erubis/generator.rb +1 -1
  64. data/lib/erubis/helper.rb +1 -1
  65. data/lib/erubis/helpers/rails_form_helper.rb +1 -1
  66. data/lib/erubis/helpers/rails_helper.rb +1 -1
  67. data/lib/erubis/local-setting.rb +1 -1
  68. data/lib/erubis/main.rb +32 -31
  69. data/lib/erubis/preprocessing.rb +1 -1
  70. data/lib/erubis/tiny.rb +6 -4
  71. data/test/assert-text-equal.rb +1 -1
  72. data/test/assert-text-equal.rbc +0 -0
  73. data/test/data/users-guide/example1.rb +1 -0
  74. data/test/data/users-guide/main_program2.result +1 -1
  75. data/test/hoge.rb +5 -0
  76. data/test/test-engines.rb +5 -2
  77. data/test/test-engines.rbc +0 -0
  78. data/test/test-enhancers.rb +4 -2
  79. data/test/test-erubis.rb +11 -5
  80. data/test/test-erubis.rbc +0 -0
  81. data/test/test-main.rb +27 -6
  82. data/test/test-users-guide.rb +4 -2
  83. data/test/test-users-guide.rbc +0 -0
  84. data/test/test.rb +1 -1
  85. data/test/test.rbc +0 -0
  86. data/test/testutil.rb +29 -3
  87. data/test/testutil.rbc +0 -0
  88. metadata +9 -4
  89. data/lib/erubis/converter.rb: +0 -0
  90. data/test/data/users-guide/stderr.log +0 -3
@@ -1,6 +1,6 @@
1
1
  ##
2
2
  ## $Rev: 77 $
3
- ## $Release: 2.6.1 $
3
+ ## $Release: 2.6.2 $
4
4
  ## copyright(c) 2006-2008 kuwata-lab.com all rights reserved.
5
5
  ##
6
6
 
@@ -1,6 +1,6 @@
1
1
  ##
2
- ## $Rev: 104 $
3
- ## $Release: 2.6.1 $
2
+ ## $Rev: 115 $
3
+ ## $Release: 2.6.2 $
4
4
  ## copyright(c) 2006-2008 kuwata-lab.com all rights reserved.
5
5
  ##
6
6
 
@@ -168,7 +168,8 @@ module Erubis
168
168
  end
169
169
  end
170
170
  end
171
- rest = $' || input # add input when no matched
171
+ #rest = $' || input # ruby1.8
172
+ rest = pos == 0 ? input : input[pos..-1] # ruby1.9
172
173
  add_text(src, rest)
173
174
  end
174
175
 
@@ -264,7 +265,8 @@ module Erubis
264
265
  add_pi_expr(codebuf, expr1 || expr2, indicator1 || indicator2)
265
266
  end
266
267
  end
267
- rest = $' || input
268
+ #rest = $' || input # ruby1.8
269
+ rest = pos == 0 ? input : input[pos..-1] # ruby1.9
268
270
  add_text(codebuf, rest)
269
271
  end
270
272
 
@@ -1,6 +1,6 @@
1
1
  ##
2
2
  ## $Rev: 104 $
3
- ## $Release: 2.6.1 $
3
+ ## $Release: 2.6.2 $
4
4
  ## copyright(c) 2006-2008 kuwata-lab.com all rights reserved.
5
5
  ##
6
6
 
@@ -1,6 +1,6 @@
1
1
  ##
2
2
  ## $Rev: 77 $
3
- ## $Release: 2.6.1 $
3
+ ## $Release: 2.6.2 $
4
4
  ## copyright(c) 2006-2008 kuwata-lab.com all rights reserved.
5
5
  ##
6
6
 
@@ -1,6 +1,6 @@
1
1
  ##
2
2
  ## $Rev: 77 $
3
- ## $Release: 2.6.1 $
3
+ ## $Release: 2.6.2 $
4
4
  ## copyright(c) 2006-2008 kuwata-lab.com all rights reserved.
5
5
  ##
6
6
 
@@ -1,6 +1,6 @@
1
1
  ##
2
2
  ## $Rev: 95 $
3
- ## $Release: 2.6.1 $
3
+ ## $Release: 2.6.2 $
4
4
  ## copyright(c) 2006-2008 kuwata-lab.com all rights reserved.
5
5
  ##
6
6
 
@@ -1,6 +1,6 @@
1
1
  ##
2
2
  ## $Rev: 77 $
3
- ## $Release: 2.6.1 $
3
+ ## $Release: 2.6.2 $
4
4
  ## copyright(c) 2006-2008 kuwata-lab.com all rights reserved.
5
5
  ##
6
6
 
@@ -1,6 +1,6 @@
1
1
  ##
2
2
  ## $Rev: 77 $
3
- ## $Release: 2.6.1 $
3
+ ## $Release: 2.6.2 $
4
4
  ## copyright(c) 2006-2008 kuwata-lab.com all rights reserved.
5
5
  ##
6
6
 
@@ -1,6 +1,6 @@
1
1
  ##
2
2
  ## $Rev: 77 $
3
- ## $Release: 2.6.1 $
3
+ ## $Release: 2.6.2 $
4
4
  ## copyright(c) 2006-2008 kuwata-lab.com all rights reserved.
5
5
  ##
6
6
 
@@ -1,6 +1,6 @@
1
1
  ##
2
2
  ## $Rev: 77 $
3
- ## $Release: 2.6.1 $
3
+ ## $Release: 2.6.2 $
4
4
  ## copyright(c) 2006-2008 kuwata-lab.com all rights reserved.
5
5
  ##
6
6
 
@@ -1,6 +1,6 @@
1
1
  ##
2
2
  ## $Rev: 77 $
3
- ## $Release: 2.6.1 $
3
+ ## $Release: 2.6.2 $
4
4
  ## copyright(c) 2006-2008 kuwata-lab.com all rights reserved.
5
5
  ##
6
6
 
@@ -1,6 +1,6 @@
1
1
  ##
2
2
  ## $Rev: 77 $
3
- ## $Release: 2.6.1 $
3
+ ## $Release: 2.6.2 $
4
4
  ## copyright(c) 2006-2008 kuwata-lab.com all rights reserved.
5
5
  ##
6
6
 
@@ -1,6 +1,6 @@
1
1
  ##
2
- ## $Rev: 103 $
3
- ## $Release: 2.6.1 $
2
+ ## $Rev: 115 $
3
+ ## $Release: 2.6.2 $
4
4
  ## copyright(c) 2006-2008 kuwata-lab.com all rights reserved.
5
5
  ##
6
6
 
@@ -360,7 +360,8 @@ module Erubis
360
360
  add_expr(src, code, indicator)
361
361
  end
362
362
  end
363
- rest = $' || input
363
+ #rest = $' || input # ruby1.8
364
+ rest = pos == 0 ? input : input[pos..-1] # ruby1.9
364
365
  add_text(src, rest)
365
366
  add_postamble(src)
366
367
  return src
@@ -419,11 +420,14 @@ module Erubis
419
420
 
420
421
  def add_text(src, text)
421
422
  return unless text
423
+ m = nil
422
424
  text.scan(@bipattern_regexp) do |txt, indicator, code|
425
+ m = Regexp.last_match
423
426
  super(src, txt)
424
427
  add_expr(src, code, '=' + indicator)
425
428
  end
426
- rest = $' || text
429
+ #rest = $' || text # ruby1.8
430
+ rest = m ? text[m.end(0)..-1] : text # ruby1.9
427
431
  super(src, rest)
428
432
  end
429
433
 
@@ -465,7 +469,8 @@ module Erubis
465
469
  add_stmt(src, line)
466
470
  end
467
471
  end
468
- rest = pos == 0 ? text : $' # or $' || text
472
+ #rest = pos == 0 ? text : $' # ruby1.8
473
+ rest = pos == 0 ? text : text[pos..-1] # ruby1.9
469
474
  unless text2.empty?
470
475
  text2 << rest if rest
471
476
  rest = text2
@@ -535,7 +540,9 @@ module Erubis
535
540
  HEADER_FOOTER_PATTERN = /(.*?)(^[ \t]*)?<!--\#(\w+):(.*?)\#-->([ \t]*\r?\n)?/m
536
541
 
537
542
  def add_text(src, text)
543
+ m = nil
538
544
  text.scan(HEADER_FOOTER_PATTERN) do |txt, lspace, word, content, rspace|
545
+ m = Regexp.last_match
539
546
  flag_trim = @trim && lspace && rspace
540
547
  super(src, txt)
541
548
  content = "#{lspace}#{content}#{rspace}" if flag_trim
@@ -543,7 +550,8 @@ module Erubis
543
550
  instance_variable_set("@#{word}", content)
544
551
  super(src, rspace) if !flag_trim && rspace
545
552
  end
546
- rest = $' || text
553
+ #rest = $' || text # ruby1.8
554
+ rest = m ? text[m.end(0)..-1] : text # ruby1.9
547
555
  super(src, rest)
548
556
  end
549
557
 
@@ -636,7 +644,8 @@ module Erubis
636
644
  end
637
645
  end
638
646
  end
639
- rest = $' || input # add input when no matched
647
+ #rest = $' || input # ruby1.8
648
+ rest = pos == 0 ? input : input[pos..-1] # ruby1.9
640
649
  _add_text_to_str(str, rest)
641
650
  add_text(src, str)
642
651
  end
@@ -1,6 +1,6 @@
1
1
  ##
2
2
  ## $Rev: 77 $
3
- ## $Release: 2.6.1 $
3
+ ## $Release: 2.6.2 $
4
4
  ## copyright(c) 2006-2008 kuwata-lab.com all rights reserved.
5
5
  ##
6
6
 
@@ -1,6 +1,6 @@
1
1
  ##
2
- ## $Rev: 94 $
3
- ## $Release: 2.6.1 $
2
+ ## $Rev: 115 $
3
+ ## $Release: 2.6.2 $
4
4
  ## copyright(c) 2006-2008 kuwata-lab.com all rights reserved.
5
5
  ##
6
6
 
@@ -54,20 +54,25 @@ module Erubis
54
54
  def result(_binding_or_hash=TOPLEVEL_BINDING)
55
55
  _arg = _binding_or_hash
56
56
  if _arg.is_a?(Hash)
57
- ## load _context data as local variables by eval
58
- #eval _arg.keys.inject("") { |s, k| s << "#{k.to_s} = _arg[#{k.inspect}];" }
59
- eval _arg.collect{|k,v| "#{k} = _arg[#{k.inspect}]; "}.join
60
- _arg = binding()
57
+ _b = binding()
58
+ eval _arg.collect{|k,v| "#{k} = _arg[#{k.inspect}]; "}.join, _b
59
+ elsif _arg.is_a?(Binding)
60
+ _b = _arg
61
+ elsif _arg.nil?
62
+ _b = binding()
63
+ else
64
+ raise ArgumentError.new("#{self.class.name}#result(): argument should be Binding or Hash but passed #{_arg.class.name} object.")
61
65
  end
62
- return eval(@src, _arg, (@filename || '(erubis)'))
66
+ return eval(@src, _b, (@filename || '(erubis'))
63
67
  end
64
68
 
65
69
  ## invoke context.instance_eval(@src)
66
- def evaluate(context=Context.new)
67
- context = Context.new(context) if context.is_a?(Hash)
68
- #return context.instance_eval(@src, @filename || '(erubis)')
69
- @_proc ||= eval("proc { #{@src} }", Erubis::EMPTY_BINDING, @filename || '(erubis)')
70
- return context.instance_eval(&@_proc)
70
+ def evaluate(_context=Context.new)
71
+ _context = Context.new(_context) if _context.is_a?(Hash)
72
+ #return _context.instance_eval(@src, @filename || '(erubis)')
73
+ #@_proc ||= eval("proc { #{@src} }", Erubis::EMPTY_BINDING, @filename || '(erubis)')
74
+ @_proc ||= eval("proc { #{@src} }", binding(), @filename || '(erubis)')
75
+ return _context.instance_eval(&@_proc)
71
76
  end
72
77
 
73
78
  ## if object is an Class or Module then define instance method to it,
@@ -1,6 +1,6 @@
1
1
  ##
2
2
  ## $Rev: 77 $
3
- ## $Release: 2.6.1 $
3
+ ## $Release: 2.6.2 $
4
4
  ## copyright(c) 2006-2008 kuwata-lab.com all rights reserved.
5
5
  ##
6
6
 
@@ -1,6 +1,6 @@
1
1
  ##
2
2
  ## $Rev: 89 $
3
- ## $Release: 2.6.1 $
3
+ ## $Release: 2.6.2 $
4
4
  ## copyright(c) 2006-2008 kuwata-lab.com all rights reserved.
5
5
  ##
6
6
 
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 109 $
3
- ### $Release: 2.6.1 $
3
+ ### $Release: 2.6.2 $
4
4
  ### copyright(c) 2006-2008 kuwata-lab.com all rights reserved.
5
5
  ###
6
6
 
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 112 $
3
- ### $Release: 2.6.1 $
3
+ ### $Release: 2.6.2 $
4
4
  ### copyright(c) 2006-2008 kuwata-lab.com all rights reserved.
5
5
  ###
6
6
 
@@ -1,6 +1,6 @@
1
1
  ##
2
2
  ## $Rev: 77 $
3
- ## $Release: 2.6.1 $
3
+ ## $Release: 2.6.2 $
4
4
  ## copyright(c) 2006-2008 kuwata-lab.com all rights reserved.
5
5
  ##
6
6
 
@@ -1,6 +1,6 @@
1
1
  ###
2
- ### $Rev: 91 $
3
- ### $Release: 2.6.1 $
2
+ ### $Rev: 116 $
3
+ ### $Release: 2.6.2 $
4
4
  ### copyright(c) 2006-2008 kuwata-lab.com all rights reserved.
5
5
  ###
6
6
 
@@ -52,34 +52,34 @@ module Erubis
52
52
  @single_options = "hvxztTSbeBXNUC"
53
53
  @arg_options = "pcrfKIlaE" #C
54
54
  @option_names = {
55
- ?h => :help,
56
- ?v => :version,
57
- ?x => :source,
58
- ?z => :syntax,
59
- ?T => :unexpand,
60
- ?t => :untabify, # obsolete
61
- ?S => :intern,
62
- ?b => :bodyonly,
63
- ?B => :binding,
64
- ?p => :pattern,
65
- ?c => :context,
66
- #?C => :class,
67
- ?e => :escape,
68
- ?r => :requires,
69
- ?f => :datafiles,
70
- ?K => :kanji,
71
- ?I => :includes,
72
- ?l => :lang,
73
- ?a => :action,
74
- ?E => :enhancers,
75
- ?X => :notext,
76
- ?N => :linenum,
77
- ?U => :unique,
78
- ?C => :compact,
55
+ 'h' => :help,
56
+ 'v' => :version,
57
+ 'x' => :source,
58
+ 'z' => :syntax,
59
+ 'T' => :unexpand,
60
+ 't' => :untabify, # obsolete
61
+ 'S' => :intern,
62
+ 'b' => :bodyonly,
63
+ 'B' => :binding,
64
+ 'p' => :pattern,
65
+ 'c' => :context,
66
+ #'C' => :class,
67
+ 'e' => :escape,
68
+ 'r' => :requires,
69
+ 'f' => :datafiles,
70
+ 'K' => :kanji,
71
+ 'I' => :includes,
72
+ 'l' => :lang,
73
+ 'a' => :action,
74
+ 'E' => :enhancers,
75
+ 'X' => :notext,
76
+ 'N' => :linenum,
77
+ 'U' => :unique,
78
+ 'C' => :compact,
79
79
  }
80
80
  assert unless @single_options.length + @arg_options.length == @option_names.length
81
81
  (@single_options + @arg_options).each_byte do |ch|
82
- assert unless @option_names.key?(ch)
82
+ assert unless @option_names.key?(ch.chr)
83
83
  end
84
84
  end
85
85
 
@@ -88,7 +88,7 @@ module Erubis
88
88
  ## parse command-line options
89
89
  options, properties = parse_argv(argv, @single_options, @arg_options)
90
90
  filenames = argv
91
- options[?h] = true if properties[:help]
91
+ options['h'] = true if properties[:help]
92
92
  opts = Object.new
93
93
  arr = @option_names.collect { |ch, name| "def #{name}; @#{name}; end\n" }
94
94
  opts.instance_eval arr.join
@@ -287,7 +287,7 @@ module Erubis
287
287
  s = "enhancers:\n"
288
288
  list = []
289
289
  ObjectSpace.each_object(Module) do |m| list << m end
290
- list.sort_by { |m| m.name }.each do |m|
290
+ list.sort_by { |m| m.name.to_s }.each do |m|
291
291
  next unless m.name =~ /\AErubis::(.*)Enhancer\z/
292
292
  name = $1
293
293
  desc = m.desc
@@ -319,7 +319,7 @@ module Erubis
319
319
  #
320
320
  else # options
321
321
  while optstr && !optstr.empty?
322
- optchar = optstr[0]
322
+ optchar = optstr[0].chr
323
323
  optstr[0,1] = ""
324
324
  if arg_none.include?(optchar)
325
325
  options[optchar] = true
@@ -472,7 +472,8 @@ module Erubis
472
472
 
473
473
  def check_syntax(filename, src)
474
474
  require 'open3'
475
- stdin, stdout, stderr = Open3.popen3('ruby -wc')
475
+ command = (ENV['_'] || 'ruby') + ' -wc' # ENV['_'] stores command name
476
+ stdin, stdout, stderr = Open3.popen3(command)
476
477
  stdin.write(src)
477
478
  stdin.close
478
479
  result = stdout.read()
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 102 $
3
- ### $Release: 2.6.1 $
3
+ ### $Release: 2.6.2 $
4
4
  ### copyright(c) 2006-2008 kuwata-lab.com all rights reserved.
5
5
  ###
6
6
 
@@ -1,6 +1,6 @@
1
1
  ##
2
- ## $Rev: 77 $
3
- ## $Release: 2.6.1 $
2
+ ## $Rev: 115 $
3
+ ## $Release: 2.6.2 $
4
4
  ## copyright(c) 2006-2008 kuwata-lab.com all rights reserved.
5
5
  ##
6
6
 
@@ -43,7 +43,8 @@ module Erubis
43
43
  src << " _buf << (" << code << ").to_s;"
44
44
  end
45
45
  end
46
- rest = $' || input
46
+ #rest = $' || input # ruby1.8
47
+ rest = pos == 0 ? input : input[pos..-1] # ruby1.9
47
48
  #src << " _buf << '" << escape_text(rest) << "';"
48
49
  rest.gsub!(/['\\]/, '\\\\\&')
49
50
  src << " _buf << '" << rest << "';" unless rest.empty?
@@ -113,7 +114,8 @@ module Erubis
113
114
  end
114
115
  end
115
116
  end
116
- rest = $' || input
117
+ #rest = $' || input # ruby1.8
118
+ rest = pos == 0 ? input : input[pos..-1] # ruby1.9
117
119
  #src << " _buf << '" << escape_text(rest) << "';"
118
120
  rest.gsub!(/['\\]/, '\\\\\&')
119
121
  src << " _buf << '" << rest << "';" unless rest.empty?
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 77 $
3
- ### $Release: 2.6.1 $
3
+ ### $Release: 2.6.2 $
4
4
  ### copyright(c) 2006-2008 kuwata-lab.com all rights reserved.
5
5
  ###
6
6