From 0f2914be405410e824b40dcff28e5dfa541bdb2a Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Sun, 19 Jul 2009 22:12:15 +0900 Subject: Separate ActionView::Context so something else can easily be made into an AV context --- actionpack/lib/action_view/base.rb | 7 +--- actionpack/lib/action_view/context.rb | 40 +++++++++++++++++++++++ actionpack/lib/action_view/template/renderable.rb | 8 ++--- actionpack/lib/action_view/template/template.rb | 2 +- 4 files changed, 46 insertions(+), 11 deletions(-) create mode 100644 actionpack/lib/action_view/context.rb (limited to 'actionpack/lib/action_view') diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index 5915337dd2..9e696af83b 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -172,8 +172,6 @@ module ActionView #:nodoc: attr_accessor :controller attr_internal :captures - attr_accessor :output_buffer - class << self delegate :erb_trim_mode=, :to => 'ActionView::TemplateHandlers::ERB' delegate :logger, :to => 'ActionController::Base', :allow_nil => true @@ -206,10 +204,7 @@ module ActionView #:nodoc: delegate :find_by_parts, :to => :view_paths - module CompiledTemplates #:nodoc: - # holds compiled template code - end - include CompiledTemplates + include Context def self.process_view_paths(value) ActionView::PathSet.new(Array(value)) diff --git a/actionpack/lib/action_view/context.rb b/actionpack/lib/action_view/context.rb new file mode 100644 index 0000000000..63651fa3f1 --- /dev/null +++ b/actionpack/lib/action_view/context.rb @@ -0,0 +1,40 @@ +module ActionView + module CompiledTemplates #:nodoc: + # holds compiled template code + end + + # ActionView contexts are supplied to ActionController + # to render template. The default ActionView context + # is ActionView::Base. + # + # In order to work with ActionController, a Context + # must implement: + # + # Context.for_controller[controller] Create a new ActionView instance for a + # controller + # Context#_render_partial_from_controller[options] + # - responsible for setting options[:_template] + # - Returns String with the rendered partial + # options:: see _render_partial in ActionView::Base + # Context#_render_template_from_controller[template, layout, options, partial] + # - Returns String with the rendered template + # template:: The template to render + # layout:: The layout to render around the template + # options:: See _render_template_with_layout in ActionView::Base + # partial:: Whether or not the template to render is a partial + # + # An ActionView context can also mix in ActionView's + # helpers. In order to mix in helpers, a context must + # implement: + # + # Context#controller + # - Returns an instance of AbstractController + # + # In any case, a context must mix in ActionView::Context, + # which stores compiled template and provides the output + # buffer. + module Context + include CompiledTemplates + attr_accessor :output_buffer + end +end \ No newline at end of file diff --git a/actionpack/lib/action_view/template/renderable.rb b/actionpack/lib/action_view/template/renderable.rb index 54857516ab..7687578165 100644 --- a/actionpack/lib/action_view/template/renderable.rb +++ b/actionpack/lib/action_view/template/renderable.rb @@ -12,9 +12,9 @@ module ActionView end def load! - names = Base::CompiledTemplates.instance_methods.grep(/#{method_name_without_locals}/) + names = CompiledTemplates.instance_methods.grep(/#{method_name_without_locals}/) names.each do |name| - Base::CompiledTemplates.class_eval do + CompiledTemplates.class_eval do remove_method(name) end end @@ -56,7 +56,7 @@ module ActionView def compile(local_assigns) render_symbol = method_name(local_assigns) - if !Base::CompiledTemplates.method_defined?(render_symbol) || recompile? + if !CompiledTemplates.method_defined?(render_symbol) || recompile? compile!(render_symbol, local_assigns) end end @@ -74,7 +74,7 @@ module ActionView end_src begin - ActionView::Base::CompiledTemplates.module_eval(source, filename.to_s, 0) + ActionView::CompiledTemplates.module_eval(source, filename.to_s, 0) rescue Exception => e # errors from template code if logger = defined?(ActionController) && Base.logger logger.debug "ERROR: compiling #{render_symbol} RAISED #{e}" diff --git a/actionpack/lib/action_view/template/template.rb b/actionpack/lib/action_view/template/template.rb index fac50cd692..4145045e2d 100644 --- a/actionpack/lib/action_view/template/template.rb +++ b/actionpack/lib/action_view/template/template.rb @@ -75,7 +75,7 @@ module ActionView end begin - ActionView::Base::CompiledTemplates.module_eval(source, identifier, line) + ActionView::CompiledTemplates.module_eval(source, identifier, line) method_name rescue Exception => e # errors from template code if logger = (view && view.logger) -- cgit v1.2.3