diff options
author | makoto kuwata <kwa@kuwata-lab.com> | 2008-06-12 11:22:01 +0000 |
---|---|---|
committer | makoto kuwata <kwa@kuwata-lab.com> | 2008-06-12 11:22:01 +0000 |
commit | 738c2a167611f86837186673975514997c59c69b (patch) | |
tree | 330be7e8860f606e26ea6e2efaec954989249266 | |
parent | 718698c5c7beba5b76f1300192a1ec5e2c5231f9 (diff) | |
download | erubis-738c2a167611f86837186673975514997c59c69b.tar.gz |
- [enhance] test/testutil.rb: add TestCase::post_definition
- [enhance] Ruby 1.9 support
- [change] Evaluator#evaluate() changed not to use Erubis::EMPTY_BINDING to support Ruby1.9
-rw-r--r-- | ChangeLog.txt | 9 | ||||
-rw-r--r-- | ReleaseNote.txt | 3 | ||||
-rw-r--r-- | Rookbook.props | 2 | ||||
-rw-r--r-- | doc/users-guide.html | 2 | ||||
-rw-r--r-- | doc/users-guide.txt | 2 | ||||
-rw-r--r-- | lib/erubis/converter.rb | 6 | ||||
-rw-r--r-- | lib/erubis/enhancer.rb | 19 | ||||
-rw-r--r-- | lib/erubis/evaluator.rb | 25 | ||||
-rw-r--r-- | lib/erubis/main.rb | 56 | ||||
-rw-r--r-- | lib/erubis/tiny.rb | 6 | ||||
-rw-r--r-- | test/test-engines.rb | 3 | ||||
-rw-r--r-- | test/test-enhancers.rb | 2 | ||||
-rw-r--r-- | test/test-erubis.rb | 12 | ||||
-rw-r--r-- | test/test-main.rb | 6 | ||||
-rw-r--r-- | test/test-users-guide.rb | 2 | ||||
-rw-r--r-- | test/testutil.rb | 13 |
16 files changed, 114 insertions, 54 deletions
diff --git a/ChangeLog.txt b/ChangeLog.txt index 3a8a0cd..c5a554d 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,7 +1,16 @@ .=document: ChangeLog +.# -*- coding: utf-8 -*- .?lastupdate: $Date$ .?version: $Rev$ +: Rev.115 (2008-06-12) + .- [enhance] test/testutil.rb: add TestCase::post_definition + .- [enhance] Ruby 1.9 support + .- [change] Evaluator#evaluate() changed not to use Erubis::EMPTY_BINDING to support Ruby1.9 + +: Rev.114 (2008-06-06) + .- [release] 2.6.1 + : Rev.113 (2008-06-06) .- [release] preparation for 2.6.1 diff --git a/ReleaseNote.txt b/ReleaseNote.txt index 8dd48c1..97fc71e 100644 --- a/ReleaseNote.txt +++ b/ReleaseNote.txt @@ -1,3 +1,6 @@ +.# -*- coding: utf-8 -*- + + $ [ANN] Erubis 2.6.1 released - a fast and extensible eRuby I have released Erubis 2.6.1. diff --git a/Rookbook.props b/Rookbook.props index 0de5dcc..d12aae5 100644 --- a/Rookbook.props +++ b/Rookbook.props @@ -1,2 +1,2 @@ -release: 2.6.0 +release: 2.6.1 copyright: copyright(c) 2006-2008 kuwata-lab.com all rights reserved. diff --git a/doc/users-guide.html b/doc/users-guide.html index 27bd83f..5ae28cb 100644 --- a/doc/users-guide.html +++ b/doc/users-guide.html @@ -2750,7 +2750,7 @@ Result:</div> item = foo item = bar item = baz -** debug: local variables=["x", "_buf"] +** debug: local variables=["_context", "x", "_buf"] ** debug: x=1 </pre> <br> diff --git a/doc/users-guide.txt b/doc/users-guide.txt index 635fca9..b5e3e60 100644 --- a/doc/users-guide.txt +++ b/doc/users-guide.txt @@ -2865,7 +2865,7 @@ $ ruby main_program2.rb item = foo item = bar item = baz -** debug: local variables=["x", "_buf"] +** debug: local variables=["_context", "x", "_buf"] ** debug: x=1 .==================== diff --git a/lib/erubis/converter.rb b/lib/erubis/converter.rb index 3bfb2bf..0a955b3 100644 --- a/lib/erubis/converter.rb +++ b/lib/erubis/converter.rb @@ -168,7 +168,8 @@ module Erubis end end end - rest = $' || input # add input when no matched + #rest = $' || input # ruby1.8 + rest = pos == 0 ? input : input[pos..-1] # ruby1.9 add_text(src, rest) end @@ -264,7 +265,8 @@ module Erubis add_pi_expr(codebuf, expr1 || expr2, indicator1 || indicator2) end end - rest = $' || input + #rest = $' || input # ruby1.8 + rest = pos == 0 ? input : input[pos..-1] # ruby1.9 add_text(codebuf, rest) end diff --git a/lib/erubis/enhancer.rb b/lib/erubis/enhancer.rb index 48b455a..fd69d45 100644 --- a/lib/erubis/enhancer.rb +++ b/lib/erubis/enhancer.rb @@ -360,7 +360,8 @@ module Erubis add_expr(src, code, indicator) end end - rest = $' || input + #rest = $' || input # ruby1.8 + rest = pos == 0 ? input : input[pos..-1] # ruby1.9 add_text(src, rest) add_postamble(src) return src @@ -419,11 +420,14 @@ module Erubis def add_text(src, text) return unless text + m = nil text.scan(@bipattern_regexp) do |txt, indicator, code| + m = Regexp.last_match super(src, txt) add_expr(src, code, '=' + indicator) end - rest = $' || text + #rest = $' || text # ruby1.8 + rest = m ? text[m.end(0)..-1] : text # ruby1.9 super(src, rest) end @@ -465,7 +469,8 @@ module Erubis add_stmt(src, line) end end - rest = pos == 0 ? text : $' # or $' || text + #rest = pos == 0 ? text : $' # ruby1.8 + rest = pos == 0 ? text : text[pos..-1] # ruby1.9 unless text2.empty? text2 << rest if rest rest = text2 @@ -535,7 +540,9 @@ module Erubis HEADER_FOOTER_PATTERN = /(.*?)(^[ \t]*)?<!--\#(\w+):(.*?)\#-->([ \t]*\r?\n)?/m def add_text(src, text) + m = nil text.scan(HEADER_FOOTER_PATTERN) do |txt, lspace, word, content, rspace| + m = Regexp.last_match flag_trim = @trim && lspace && rspace super(src, txt) content = "#{lspace}#{content}#{rspace}" if flag_trim @@ -543,7 +550,8 @@ module Erubis instance_variable_set("@#{word}", content) super(src, rspace) if !flag_trim && rspace end - rest = $' || text + #rest = $' || text # ruby1.8 + rest = m ? text[m.end(0)..-1] : text # ruby1.9 super(src, rest) end @@ -636,7 +644,8 @@ module Erubis end end end - rest = $' || input # add input when no matched + #rest = $' || input # ruby1.8 + rest = pos == 0 ? input : input[pos..-1] # ruby1.9 _add_text_to_str(str, rest) add_text(src, str) end diff --git a/lib/erubis/evaluator.rb b/lib/erubis/evaluator.rb index 8a76bc4..f824016 100644 --- a/lib/erubis/evaluator.rb +++ b/lib/erubis/evaluator.rb @@ -54,20 +54,25 @@ module Erubis def result(_binding_or_hash=TOPLEVEL_BINDING) _arg = _binding_or_hash if _arg.is_a?(Hash) - ## load _context data as local variables by eval - #eval _arg.keys.inject("") { |s, k| s << "#{k.to_s} = _arg[#{k.inspect}];" } - eval _arg.collect{|k,v| "#{k} = _arg[#{k.inspect}]; "}.join - _arg = binding() + _b = binding() + eval _arg.collect{|k,v| "#{k} = _arg[#{k.inspect}]; "}.join, _b + elsif _arg.is_a?(Binding) + _b = _arg + elsif _arg.nil? + _b = binding() + else + raise ArgumentError.new("#{self.class.name}#result(): argument should be Binding or Hash but passed #{_arg.class.name} object.") end - return eval(@src, _arg, (@filename || '(erubis)')) + return eval(@src, _b, (@filename || '(erubis')) end ## invoke context.instance_eval(@src) - def evaluate(context=Context.new) - context = Context.new(context) if context.is_a?(Hash) - #return context.instance_eval(@src, @filename || '(erubis)') - @_proc ||= eval("proc { #{@src} }", Erubis::EMPTY_BINDING, @filename || '(erubis)') - return context.instance_eval(&@_proc) + def evaluate(_context=Context.new) + _context = Context.new(_context) if _context.is_a?(Hash) + #return _context.instance_eval(@src, @filename || '(erubis)') + #@_proc ||= eval("proc { #{@src} }", Erubis::EMPTY_BINDING, @filename || '(erubis)') + @_proc ||= eval("proc { #{@src} }", binding(), @filename || '(erubis)') + return _context.instance_eval(&@_proc) end ## if object is an Class or Module then define instance method to it, diff --git a/lib/erubis/main.rb b/lib/erubis/main.rb index 76ddb2c..1cdba6d 100644 --- a/lib/erubis/main.rb +++ b/lib/erubis/main.rb @@ -52,34 +52,34 @@ module Erubis @single_options = "hvxztTSbeBXNUC" @arg_options = "pcrfKIlaE" #C @option_names = { - ?h => :help, - ?v => :version, - ?x => :source, - ?z => :syntax, - ?T => :unexpand, - ?t => :untabify, # obsolete - ?S => :intern, - ?b => :bodyonly, - ?B => :binding, - ?p => :pattern, - ?c => :context, - #?C => :class, - ?e => :escape, - ?r => :requires, - ?f => :datafiles, - ?K => :kanji, - ?I => :includes, - ?l => :lang, - ?a => :action, - ?E => :enhancers, - ?X => :notext, - ?N => :linenum, - ?U => :unique, - ?C => :compact, + 'h' => :help, + 'v' => :version, + 'x' => :source, + 'z' => :syntax, + 'T' => :unexpand, + 't' => :untabify, # obsolete + 'S' => :intern, + 'b' => :bodyonly, + 'B' => :binding, + 'p' => :pattern, + 'c' => :context, + #'C' => :class, + 'e' => :escape, + 'r' => :requires, + 'f' => :datafiles, + 'K' => :kanji, + 'I' => :includes, + 'l' => :lang, + 'a' => :action, + 'E' => :enhancers, + 'X' => :notext, + 'N' => :linenum, + 'U' => :unique, + 'C' => :compact, } assert unless @single_options.length + @arg_options.length == @option_names.length (@single_options + @arg_options).each_byte do |ch| - assert unless @option_names.key?(ch) + assert unless @option_names.key?(ch.chr) end end @@ -88,7 +88,7 @@ module Erubis ## parse command-line options options, properties = parse_argv(argv, @single_options, @arg_options) filenames = argv - options[?h] = true if properties[:help] + options['h'] = true if properties[:help] opts = Object.new arr = @option_names.collect { |ch, name| "def #{name}; @#{name}; end\n" } opts.instance_eval arr.join @@ -287,7 +287,7 @@ module Erubis s = "enhancers:\n" list = [] ObjectSpace.each_object(Module) do |m| list << m end - list.sort_by { |m| m.name }.each do |m| + list.sort_by { |m| m.name.to_s }.each do |m| next unless m.name =~ /\AErubis::(.*)Enhancer\z/ name = $1 desc = m.desc @@ -319,7 +319,7 @@ module Erubis # else # options while optstr && !optstr.empty? - optchar = optstr[0] + optchar = optstr[0].chr optstr[0,1] = "" if arg_none.include?(optchar) options[optchar] = true diff --git a/lib/erubis/tiny.rb b/lib/erubis/tiny.rb index d3b3639..a64c574 100644 --- a/lib/erubis/tiny.rb +++ b/lib/erubis/tiny.rb @@ -43,7 +43,8 @@ module Erubis src << " _buf << (" << code << ").to_s;" end end - rest = $' || input + #rest = $' || input # ruby1.8 + rest = pos == 0 ? input : input[pos..-1] # ruby1.9 #src << " _buf << '" << escape_text(rest) << "';" rest.gsub!(/['\\]/, '\\\\\&') src << " _buf << '" << rest << "';" unless rest.empty? @@ -113,7 +114,8 @@ module Erubis end end end - rest = $' || input + #rest = $' || input # ruby1.8 + rest = pos == 0 ? input : input[pos..-1] # ruby1.9 #src << " _buf << '" << escape_text(rest) << "';" rest.gsub!(/['\\]/, '\\\\\&') src << " _buf << '" << rest << "';" unless rest.empty? diff --git a/test/test-engines.rb b/test/test-engines.rb index 56e9e62..f4ed1bb 100644 --- a/test/test-engines.rb +++ b/test/test-engines.rb @@ -29,6 +29,9 @@ class EnginesTest < Test::Unit::TestCase assert_text_equal(@expected, actual) end + + self.post_definition() + end __END__ diff --git a/test/test-enhancers.rb b/test/test-enhancers.rb index 0b9e025..44a27de 100644 --- a/test/test-enhancers.rb +++ b/test/test-enhancers.rb @@ -98,6 +98,8 @@ class EnhancersTest < Test::Unit::TestCase end + self.post_definition() + end __END__ diff --git a/test/test-erubis.rb b/test/test-erubis.rb index 6f0578a..0d31665 100644 --- a/test/test-erubis.rb +++ b/test/test-erubis.rb @@ -157,12 +157,16 @@ END class Dummy end + def _class_has_instance_method(klass, method) + return klass.instance_methods.collect{|m| m.to_s}.include?(method.to_s) + end + def test_def_method1 s = "<%for i in list%>i=<%=i%>\n<%end%>" eruby = Erubis::Eruby.new(s) - assert(! Dummy.instance_methods.include?('render')) + assert(! _class_has_instance_method(Dummy, 'render')) eruby.def_method(Dummy, 'render(list)', 'foo.rhtml') - assert(Dummy.instance_methods.include?('render')) + assert(_class_has_instance_method(Dummy, 'render')) actual = Dummy.new().render(%w[1 2 3]) assert_equal("i=1\ni=2\ni=3\n", actual) end @@ -175,7 +179,7 @@ END assert eruby.respond_to?(:render) actual = eruby.render([1, 2, 3]) assert_equal("i=1\ni=2\ni=3\n", actual) - assert !(eruby.class.instance_methods.include? :render) + assert(! _class_has_instance_method(eruby.class, 'render')) end def test_evaluate_creates_proc @@ -203,6 +207,8 @@ END # puts "*** actual=#{actual.inspect}, x=#{_x.inspect}, y=#{_y.inspect}" #end + self.post_definition() + end x = 10 diff --git a/test/test-main.rb b/test/test-main.rb index 3270b62..65a0059 100644 --- a/test/test-main.rb +++ b/test/test-main.rb @@ -22,6 +22,9 @@ class StringWriter < String def write(arg) self << arg end + def flush(*args) + # pass + end end class Erubis::Main @@ -144,6 +147,7 @@ END end if @filename.nil? method = (caller[0] =~ /in `(.*)'/) && $1 #' + method =~ /block in (.*)/ and method = $1 # for Ruby 1.9 @filename = "tmp.#{method}" end File.open(@filename, 'w') { |f| f.write(@input) } if @filename @@ -650,4 +654,6 @@ END end + self.post_definition() + end diff --git a/test/test-users-guide.rb b/test/test-users-guide.rb index fc82a66..1ce91aa 100644 --- a/test/test-users-guide.rb +++ b/test/test-users-guide.rb @@ -53,4 +53,6 @@ class KwarkUsersGuideTest < Test::Unit::TestCase end + self.post_definition() + end diff --git a/test/testutil.rb b/test/testutil.rb index 15cba2b..8fd49b7 100644 --- a/test/testutil.rb +++ b/test/testutil.rb @@ -21,7 +21,7 @@ class Test::Unit::TestCase end # untabify unless options[:tabify] == false - s = s.inject('') do |sb, line| + s = s.split(/^/).inject('') do |sb, line| sb << line.gsub(/([^\t]{8})|([^\t]*)\t/n) { [$+].pack("A8") } end end @@ -72,4 +72,15 @@ class Test::Unit::TestCase end + def self.post_definition + if ENV['TEST'] + target = "test_#{ENV['TEST']}" + self.instance_methods.each do |method_name| + m = method_name.to_s + private m if m =~ /\Atest_/ && m != target + end + end + end + + end |