diff options
Diffstat (limited to 'lib/erubis/helpers/rails_helper.rb')
-rw-r--r-- | lib/erubis/helpers/rails_helper.rb | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/lib/erubis/helpers/rails_helper.rb b/lib/erubis/helpers/rails_helper.rb index 6346ba6..11a2595 100644 --- a/lib/erubis/helpers/rails_helper.rb +++ b/lib/erubis/helpers/rails_helper.rb @@ -97,12 +97,12 @@ module Erubis if ::Erubis::Helpers::RailsHelper.preprocessing preprocessor = _create_preprocessor(template) template = preprocessor.evaluate(_preprocessing_context_object()) - logger.info "** Erubis: preprocessed==<<'END'\n#{template}END\n" if show_src + _logger_info "** Erubis: preprocessed==<<'END'\n#{template}END\n" if show_src end ## convert into ruby code src = klass.new(template, properties).src #src.insert(0, '_erbout = ') - logger.info "** Erubis: src==<<'END'\n#{src}END\n" if show_src + _logger_info "** Erubis: src==<<'END'\n#{src}END\n" if show_src return src end def _create_preprocessor(template) @@ -111,6 +111,9 @@ module Erubis def _preprocessing_context_object return self end + def _logger_info(message) + logger.info message + end end end @@ -134,11 +137,37 @@ end require 'action_pack/version' +rails22 = false if ActionPack::VERSION::MAJOR >= 2 ### Rails 2.X - if ActionPack::VERSION::MINOR >=1 ### Rails 2.1 or higher + if ActionPack::VERSION::MINOR >=2 ### Rails 2.2 or higher + + rails22 = true + module ActionView + module TemplateHandlers + class ErubisHandler < TemplateHandler + include Compilable + include ::Erubis::Helpers::RailsHelper::TemplateConverter + include ::Erubis::PreprocessingHelper + def compile(template) + #src = ::ERB.new("<% __in_erb_template=true %>#{template.source}", nil, erb_trim_mode, '@output_buffer').src + return _convert_template("<% __in_erb_template=true %>#{template.source}") + end + end + end + handler_klass = TemplateHandlers::ErubisHandler + Template.register_default_template_handler :erb, handler_klass + Template.register_template_handler :rhtml, handler_klass + end + module Erubis::Helpers::RailsHelper::TemplateConverter + def _logger_info(message) + $stderr.puts message # logger.info seems not available in Rails 2.2 + end + end + + elsif ActionPack::VERSION::MINOR >=1 ### Rails 2.1 module ActionView module TemplateHandlers # :nodoc: @@ -322,4 +351,4 @@ end ### ## finish ac = ActionController::Base.new ac.logger.info "** Erubis #{::Erubis::VERSION}" -#$stdout.puts "** Erubis #{::Erubis::VERSION}" +$stdout.puts "** Erubis #{::Erubis::VERSION}" if rails22 |