From 0a85380966e47a38292242e6c3b259d77c738ab5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 8 Mar 2010 11:32:01 +0100 Subject: Finally moved the find template logic to the views. --- actionpack/lib/action_view/render/rendering.rb | 40 +++++++++++++++----------- actionpack/lib/action_view/template/text.rb | 7 ++--- 2 files changed, 27 insertions(+), 20 deletions(-) (limited to 'actionpack/lib/action_view') diff --git a/actionpack/lib/action_view/render/rendering.rb b/actionpack/lib/action_view/render/rendering.rb index 17fb110eb4..c6d95e88e2 100644 --- a/actionpack/lib/action_view/render/rendering.rb +++ b/actionpack/lib/action_view/render/rendering.rb @@ -24,18 +24,8 @@ module ActionView return _render_partial(options) end - template = if options[:file] - find(options[:file]) - elsif options[:inline] - handler = Template.handler_class_for_extension(options[:type] || "erb") - Template.new(options[:inline], "inline template", handler, {}) - elsif options[:text] - Template::Text.new(options[:text]) - end - - if template - _render_template(template, layout, :locals => options[:locals]) - end + template = _determine_template(options) + _render_template(template, layout, :locals => options[:locals]) if template when :update update_page(&block) else @@ -87,8 +77,28 @@ module ActionView # _layout:: The layout, if any, to wrap the Template in def render_template(options) _evaluate_assigns_and_ivars - template, layout = options.values_at(:_template, :layout) - _render_template(template, layout, options) + if options.key?(:partial) + _render_partial(options) + else + template = _determine_template(options) + yield template if block_given? + _render_template(template, options[:layout], options) + end + end + + def _determine_template(options) + if options.key?(:inline) + handler = Template.handler_class_for_extension(options[:type] || "erb") + Template.new(options[:inline], "inline template", handler, {}) + elsif options.key?(:text) + Template::Text.new(options[:text], self.formats.try(:first)) + elsif options.key?(:_template) + options[:_template] + elsif options.key?(:file) + find(options[:file], options[:_prefix]) + elsif options.key?(:template) + find(options[:template], options[:_prefix]) + end end def _find_layout(layout) @@ -102,8 +112,6 @@ module ActionView end def _render_template(template, layout = nil, options = {}) - self.formats = template.details[:formats] - locals = options[:locals] || {} layout = _find_layout(layout) if layout diff --git a/actionpack/lib/action_view/template/text.rb b/actionpack/lib/action_view/template/text.rb index 2abb352d4e..5978a8a3ac 100644 --- a/actionpack/lib/action_view/template/text.rb +++ b/actionpack/lib/action_view/template/text.rb @@ -1,11 +1,10 @@ module ActionView #:nodoc: class Template class Text < String #:nodoc: - HTML = Mime[:html] - - def initialize(string, content_type = HTML) + def initialize(string, content_type = nil) super(string.to_s) - @content_type = Mime[content_type] || content_type + @content_type = Mime[content_type] || content_type if content_type + @content_type ||= Mime::TEXT end def details -- cgit v1.2.3