From 9853134b4fec468962260f0e713d2f87046eb8b3 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 26 Aug 2008 15:13:28 -0500 Subject: Require missing libraries and check for defined ActionController constant so ActionView can be used standalone --- actionpack/lib/action_controller/mime_type.rb | 2 ++ actionpack/lib/action_view/helpers/sanitize_helper.rb | 11 ++++++++++- actionpack/lib/action_view/helpers/text_helper.rb | 11 ++++++++++- actionpack/lib/action_view/renderable.rb | 2 +- actionpack/lib/action_view/renderable_partial.rb | 6 +++++- actionpack/lib/action_view/template.rb | 2 ++ 6 files changed, 30 insertions(+), 4 deletions(-) diff --git a/actionpack/lib/action_controller/mime_type.rb b/actionpack/lib/action_controller/mime_type.rb index a7215e6ea3..26edca3b69 100644 --- a/actionpack/lib/action_controller/mime_type.rb +++ b/actionpack/lib/action_controller/mime_type.rb @@ -1,3 +1,5 @@ +require 'set' + module Mime SET = [] EXTENSION_LOOKUP = Hash.new { |h, k| h[k] = Type.new(k) unless k.blank? } diff --git a/actionpack/lib/action_view/helpers/sanitize_helper.rb b/actionpack/lib/action_view/helpers/sanitize_helper.rb index 637caf203b..435ba936e1 100644 --- a/actionpack/lib/action_view/helpers/sanitize_helper.rb +++ b/actionpack/lib/action_view/helpers/sanitize_helper.rb @@ -1,5 +1,14 @@ require 'action_view/helpers/tag_helper' -require 'html/document' + +begin + require 'html/document' +rescue LoadError + html_scanner_path = "#{File.dirname(__FILE__)}/../../action_controller/vendor/html-scanner" + if File.directory?(html_scanner_path) + $:.unshift html_scanner_path + require 'html/document' + end +end module ActionView module Helpers #:nodoc: diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index f9096d0029..ccd6c54cc8 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -1,5 +1,14 @@ require 'action_view/helpers/tag_helper' -require 'html/document' + +begin + require 'html/document' +rescue LoadError + html_scanner_path = "#{File.dirname(__FILE__)}/../../action_controller/vendor/html-scanner" + if File.directory?(html_scanner_path) + $:.unshift html_scanner_path + require 'html/document' + end +end module ActionView module Helpers #:nodoc: diff --git a/actionpack/lib/action_view/renderable.rb b/actionpack/lib/action_view/renderable.rb index c011f21550..3a79b2b01e 100644 --- a/actionpack/lib/action_view/renderable.rb +++ b/actionpack/lib/action_view/renderable.rb @@ -72,7 +72,7 @@ module ActionView end_src begin - logger = Base.logger + logger = defined? ActionController && Base.logger logger.debug "Compiling template #{render_symbol}" if logger ActionView::Base::CompiledTemplates.module_eval(source, filename, 0) diff --git a/actionpack/lib/action_view/renderable_partial.rb b/actionpack/lib/action_view/renderable_partial.rb index 342850f0f0..5203e57ead 100644 --- a/actionpack/lib/action_view/renderable_partial.rb +++ b/actionpack/lib/action_view/renderable_partial.rb @@ -16,7 +16,11 @@ module ActionView memoize :counter_name def render(view, local_assigns = {}) - ActionController::Base.benchmark("Rendered #{path_without_format_and_extension}", Logger::DEBUG, false) do + if defined? ActionController + ActionController::Base.benchmark("Rendered #{path_without_format_and_extension}", Logger::DEBUG, false) do + super + end + else super end end diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb index 5dc6708431..64597b3d39 100644 --- a/actionpack/lib/action_view/template.rb +++ b/actionpack/lib/action_view/template.rb @@ -1,3 +1,5 @@ +require 'action_controller/mime_type' + module ActionView #:nodoc: class Template extend TemplateHandlers -- cgit v1.2.3