summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authormakoto kuwata <kwa@kuwata-lab.com>2006-12-25 22:22:05 +0000
committermakoto kuwata <kwa@kuwata-lab.com>2006-12-25 22:22:05 +0000
commite084cdd5d66e84f99be954787361a899eb5ebced (patch)
tree7493125c5b4934e6323055e66f22d548c1281bff /lib
parent953573ac6c2878ec63c36cf507f0e60a5dc10b96 (diff)
downloaderubis-e084cdd5d66e84f99be954787361a899eb5ebced.tar.gz
- [enhance] add Context#each() method
- [change] rename ChangeLog to CHANGES
Diffstat (limited to 'lib')
-rw-r--r--lib/erubis/context.rb11
-rw-r--r--lib/erubis/converter.rb26
-rw-r--r--lib/erubis/engine/eruby.rb1
-rw-r--r--lib/erubis/generator.rb3
-rw-r--r--lib/erubis/helper.rb1
-rw-r--r--lib/erubis/local-setting.rb2
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
##