diff options
author | makoto kuwata <kwa@kuwata-lab.com> | 2006-05-07 09:33:34 +0000 |
---|---|---|
committer | makoto kuwata <kwa@kuwata-lab.com> | 2006-05-07 09:33:34 +0000 |
commit | 38a6e0cdd97f780764c6bff548c185dae2d18dcf (patch) | |
tree | db1b8c478384615a541cf62825bf3d08360fa748 /lib/erubis/enhancer.rb | |
parent | 0f4453c60d6f1a1992ac5f7a085c03fc5b77269e (diff) | |
download | erubis-38a6e0cdd97f780764c6bff548c185dae2d18dcf.tar.gz |
- [enhance] new module NoTextEnhancer added
- [change] Eruby#add_stmt() desn't add ';' when the last character is ?\n
- [bugfix] PrintEnableEnhancer#evaluate() added to evaluate with it's context
Diffstat (limited to 'lib/erubis/enhancer.rb')
-rw-r--r-- | lib/erubis/enhancer.rb | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/lib/erubis/enhancer.rb b/lib/erubis/enhancer.rb index cbcecdb..db518f7 100644 --- a/lib/erubis/enhancer.rb +++ b/lib/erubis/enhancer.rb @@ -101,10 +101,6 @@ module Erubis src << " print '" << escape_text(text) << "';" unless text.empty? end - def add_stmt(src, code) - src << code << ';' - end - def add_expr_literal(src, code) src << ' print((' << code << ').to_s);' end @@ -131,7 +127,7 @@ module Erubis module PrintEnabledEnhancer def self.desc # :nodoc: - "enable to use print statement in '<% %>'" + "enable to use print function in '<% %>'" end def add_preamble(src) @@ -145,6 +141,18 @@ module Erubis end end + def evaluate(context=Context.new) + _src = @src + if context.is_a?(Hash) + context.each do |key, val| instance_variable_set("@#{key}", val) end + else + context.instance_variables.each do |name| + instance_variable_set(name, context.instance_variable_get(name)) + end + end + return instance_eval(_src, (@filename || '(erubis)')) + end + end @@ -218,6 +226,27 @@ module Erubis ## + ## remove text and leave code, especially useful when debugging. + ## + ## ex. + ## $ erubis -s -e NoText file.eruby | more + ## + ## this is language independent. + ## + module NoTextEnhancer + + def self.desc # :nodoc: + "remove text and leave code (useful when debugging)" + end + + def add_text(src, text) + src << ("\n" * text.count("\n")) + end + + end + + + ## ## get compile faster, but spaces around '<%...%>' are not trimmed. ## ## this is language-independent. |