diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/erubis/context.rb | 11 | ||||
-rw-r--r-- | lib/erubis/converter.rb | 26 | ||||
-rw-r--r-- | lib/erubis/engine/eruby.rb | 1 | ||||
-rw-r--r-- | lib/erubis/generator.rb | 3 | ||||
-rw-r--r-- | lib/erubis/helper.rb | 1 | ||||
-rw-r--r-- | lib/erubis/local-setting.rb | 2 |
6 files changed, 27 insertions, 17 deletions
diff --git a/lib/erubis/context.rb b/lib/erubis/context.rb index e2bae7a..008aa11 100644 --- a/lib/erubis/context.rb +++ b/lib/erubis/context.rb @@ -29,6 +29,7 @@ module Erubis ## print eruby.evaluate(context) ## class Context + include Enumerable def initialize(hash=nil) hash.each do |name, value| @@ -45,7 +46,15 @@ module Erubis end def keys - return instance_variables.collect { |name| name[1,name.length-1] } + return instance_variables.collect { |name| name[1..-1] } + end + + def each + instance_variables.each do |name| + key = name[1..-1] + value = instance_variable_get(name) + yield(key, value) + end end end diff --git a/lib/erubis/converter.rb b/lib/erubis/converter.rb index 11d0fab..12456ad 100644 --- a/lib/erubis/converter.rb +++ b/lib/erubis/converter.rb @@ -96,9 +96,9 @@ module Erubis pos = 0 input.scan(regexp) do |lspace, indicator, code, rspace| match = Regexp.last_match() - index = match.begin(0) - text = input[pos, index - pos] - pos = match.end(0) + len = match.begin(0) - pos + text = input[pos, len] + pos = match.end(0) add_text(src, text) ## * when '<%= %>', do nothing ## * when '<% %>' or '<%# %>', delete spaces iff only spaces are around '<% %>' @@ -171,7 +171,7 @@ module Erubis def init_converter(properties={}) super(properties) - @trim = !(properties[:trim] == false) + @trim = properties[:trim] != false @pi = properties[:pi] if properties[:pi] @embchar = properties[:embchar] || '@' @pattern = properties[:pattern] @@ -197,9 +197,9 @@ module Erubis pos = 0 input.scan(@stmt_pattern) do |lspace, pi_arg, code, rspace| match = Regexp.last_match - index = match.begin(0) - text = input[pos, index - pos] - pos = match.end(0) + len = match.begin(0) - pos + text = input[pos, len] + pos = match.end(0) parse_exprs(codebuf, text) # unless text.empty? if @trim && lspace && rspace add_pi_stmt(codebuf, "#{lspace}#{code}#{rspace}", pi_arg) @@ -228,9 +228,9 @@ module Erubis indicator = indicator1 || indicator2 code = code1 || code2 match = Regexp.last_match - index = match.begin(0) - text = input[pos, index - pos] - pos = match.end(0) + len = match.begin(0) - pos + text = input[pos, len] + pos = match.end(0) add_text(codebuf, text) # unless text.empty? add_pi_expr(codebuf, code, indicator) end @@ -278,9 +278,9 @@ module Erubis input.scan(@embedded_pattern) do |lspace, pi_arg, stmt, rspace, indicator1, expr1, indicator2, expr2| match = Regexp.last_match - index = match.begin(0) - text = input[pos, index - pos] - pos = match.end(0) + len = match.begin(0) - pos + text = input[pos, len] + pos = match.end(0) add_text(codebuf, text) # unless text.empty? if stmt code = stmt diff --git a/lib/erubis/engine/eruby.rb b/lib/erubis/engine/eruby.rb index 5c841cd..9390253 100644 --- a/lib/erubis/engine/eruby.rb +++ b/lib/erubis/engine/eruby.rb @@ -6,7 +6,6 @@ require 'erubis/engine' require 'erubis/enhancer' -require 'abstract' module Erubis diff --git a/lib/erubis/generator.rb b/lib/erubis/generator.rb index 046a6ef..9a26ddf 100644 --- a/lib/erubis/generator.rb +++ b/lib/erubis/generator.rb @@ -9,6 +9,9 @@ require 'abstract' module Erubis + ## + ## code generator, called by Converter module + ## module Generator def self.supported_properties() # :nodoc: diff --git a/lib/erubis/helper.rb b/lib/erubis/helper.rb index cd46fa5..bf05763 100644 --- a/lib/erubis/helper.rb +++ b/lib/erubis/helper.rb @@ -26,7 +26,6 @@ module Erubis #table = ESCAPE_TABLE #obj.to_s.gsub(/[&<>"]/) { |s| table[s] } # or /[&<>"']/ obj.to_s.gsub(/[&<>"]/) { |s| ESCAPE_TABLE[s] } # or /[&<>"']/ - #obj.to_s.gsub(SCAN_REGEXP) { |s| ESCAPE_TABLE[s] } #obj.to_s.gsub(/[&<>"]/) { ESCAPE_TABLE[$&] } end diff --git a/lib/erubis/local-setting.rb b/lib/erubis/local-setting.rb index 747b313..c2f75e8 100644 --- a/lib/erubis/local-setting.rb +++ b/lib/erubis/local-setting.rb @@ -6,5 +6,5 @@ ## ## you can add site-local settings here. -## this files is 'require'd by erubis.rb +## this files is required by erubis.rb ## |