From 38a6e0cdd97f780764c6bff548c185dae2d18dcf Mon Sep 17 00:00:00 2001 From: makoto kuwata Date: Sun, 7 May 2006 09:33:34 +0000 Subject: - [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 --- lib/erubis/enhancer.rb | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) (limited to 'lib/erubis/enhancer.rb') 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 @@ -217,6 +225,27 @@ module Erubis end + ## + ## 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. ## -- cgit v1.2.1