diff options
author | Yehuda Katz <wycats@gmail.com> | 2009-07-19 22:12:15 +0900 |
---|---|---|
committer | Yehuda Katz <wycats@gmail.com> | 2009-07-19 22:31:44 +0900 |
commit | 0f2914be405410e824b40dcff28e5dfa541bdb2a (patch) | |
tree | 5d29a561a0ab34a0b56d2bb8e90668d03c9934d7 /actionpack | |
parent | bb530923bcd5c643f9bfca8e36cd3fa36365032d (diff) | |
download | rails-0f2914be405410e824b40dcff28e5dfa541bdb2a.tar.gz rails-0f2914be405410e824b40dcff28e5dfa541bdb2a.tar.bz2 rails-0f2914be405410e824b40dcff28e5dfa541bdb2a.zip |
Separate ActionView::Context so something else can easily be made into an AV context
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_view.rb | 3 | ||||
-rw-r--r-- | actionpack/lib/action_view/base.rb | 7 | ||||
-rw-r--r-- | actionpack/lib/action_view/context.rb | 40 | ||||
-rw-r--r-- | actionpack/lib/action_view/template/renderable.rb | 8 | ||||
-rw-r--r-- | actionpack/lib/action_view/template/template.rb | 2 | ||||
-rw-r--r-- | actionpack/test/template/compiled_templates_test.rb | 2 |
6 files changed, 49 insertions, 13 deletions
diff --git a/actionpack/lib/action_view.rb b/actionpack/lib/action_view.rb index 2a17faf99a..70176a0ea4 100644 --- a/actionpack/lib/action_view.rb +++ b/actionpack/lib/action_view.rb @@ -30,10 +30,11 @@ require File.join(File.dirname(__FILE__), "action_pack") module ActionView def self.load_all! - [Base, InlineTemplate, TemplateError] + [Context, Base, InlineTemplate, TemplateError] end autoload :Base, 'action_view/base' + autoload :Context, 'action_view/context' autoload :Helpers, 'action_view/helpers' autoload :InlineTemplate, 'action_view/template/inline' autoload :MissingTemplate, 'action_view/base' 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<Hash>:: see _render_partial in ActionView::Base + # Context#_render_template_from_controller[template, layout, options, partial] + # - Returns String with the rendered template + # template<ActionView::Template>:: The template to render + # layout<ActionView::Template>:: The layout to render around the template + # options<Hash>:: See _render_template_with_layout in ActionView::Base + # partial<Boolean>:: 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) diff --git a/actionpack/test/template/compiled_templates_test.rb b/actionpack/test/template/compiled_templates_test.rb index 9c268aef27..7734e6da73 100644 --- a/actionpack/test/template/compiled_templates_test.rb +++ b/actionpack/test/template/compiled_templates_test.rb @@ -3,7 +3,7 @@ require 'controller/fake_models' class CompiledTemplatesTest < Test::Unit::TestCase def setup - @compiled_templates = ActionView::Base::CompiledTemplates + @compiled_templates = ActionView::CompiledTemplates @compiled_templates.instance_methods.each do |m| @compiled_templates.send(:remove_method, m) if m =~ /^_render_template_/ end |