From 2a12686832fbcf0566454904a5d733998506bf56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 12 Mar 2010 14:25:10 +0100 Subject: Allow anything that responds to render to be given as :template and use find_template instead of find in views. --- actionpack/lib/action_view/render/layouts.rb | 4 ++-- actionpack/lib/action_view/render/partials.rb | 2 +- actionpack/lib/action_view/render/rendering.rb | 9 ++++----- 3 files changed, 7 insertions(+), 8 deletions(-) (limited to 'actionpack/lib/action_view/render') diff --git a/actionpack/lib/action_view/render/layouts.rb b/actionpack/lib/action_view/render/layouts.rb index 8688de3d18..91a92a833a 100644 --- a/actionpack/lib/action_view/render/layouts.rb +++ b/actionpack/lib/action_view/render/layouts.rb @@ -49,10 +49,10 @@ module ActionView def _find_layout(layout) #:nodoc: begin layout =~ /^\// ? - with_fallbacks { find(layout) } : find(layout) + with_fallbacks { find_template(layout) } : find_template(layout) rescue ActionView::MissingTemplate => e update_details(:formats => nil) do - raise unless exists?(layout) + raise unless template_exists?(layout) end end end diff --git a/actionpack/lib/action_view/render/partials.rb b/actionpack/lib/action_view/render/partials.rb index 950c9d2cd8..0fe2d560f7 100644 --- a/actionpack/lib/action_view/render/partials.rb +++ b/actionpack/lib/action_view/render/partials.rb @@ -294,7 +294,7 @@ module ActionView def find_template(path=@path) return path unless path.is_a?(String) prefix = @view.controller_path unless path.include?(?/) - @view.find(path, prefix, true) + @view.find_template(path, prefix, true) end def partial_path(object = @object) diff --git a/actionpack/lib/action_view/render/rendering.rb b/actionpack/lib/action_view/render/rendering.rb index 47ea70f5ad..d9ac1f6290 100644 --- a/actionpack/lib/action_view/render/rendering.rb +++ b/actionpack/lib/action_view/render/rendering.rb @@ -59,13 +59,12 @@ module ActionView 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] + Template::Text.new(options[:text], formats.try(:first)) elsif options.key?(:file) - with_fallbacks { find(options[:file], options[:prefix]) } + with_fallbacks { find_template(options[:file], options[:prefix]) } elsif options.key?(:template) - find(options[:template], options[:prefix]) + options[:template].respond_to?(:render) ? + options[:template] : find_template(options[:template], options[:prefix]) end end -- cgit v1.2.3 From f2c0a353aef41a6df2de8e1fe3eaa3d8bbd8a6dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 12 Mar 2010 20:39:53 +0100 Subject: Finish cleaning up rendering stack from views and move assigns evaluation to controller (so plugins and/or controllers can overwrite just one method). --- actionpack/lib/action_view/render/layouts.rb | 5 +--- actionpack/lib/action_view/render/rendering.rb | 37 ++++++-------------------- 2 files changed, 9 insertions(+), 33 deletions(-) (limited to 'actionpack/lib/action_view/render') diff --git a/actionpack/lib/action_view/render/layouts.rb b/actionpack/lib/action_view/render/layouts.rb index 91a92a833a..0cb688ca77 100644 --- a/actionpack/lib/action_view/render/layouts.rb +++ b/actionpack/lib/action_view/render/layouts.rb @@ -1,8 +1,5 @@ -require 'active_support/core_ext/object/try' - module ActionView module Layouts - # You can think of a layout as a method that is called with a block. _layout_for # returns the contents that are yielded to the layout. If the user calls yield # :some_name, the block, by default, returns content_for(:some_name). If the user @@ -46,7 +43,7 @@ module ActionView # This is the method which actually finds the layout using details in the lookup # context object. If no layout is found, it checkes if at least a layout with # the given name exists across all details before raising the error. - def _find_layout(layout) #:nodoc: + def find_layout(layout) #:nodoc: begin layout =~ /^\// ? with_fallbacks { find_template(layout) } : find_template(layout) diff --git a/actionpack/lib/action_view/render/rendering.rb b/actionpack/lib/action_view/render/rendering.rb index d9ac1f6290..9b5b976727 100644 --- a/actionpack/lib/action_view/render/rendering.rb +++ b/actionpack/lib/action_view/render/rendering.rb @@ -12,14 +12,17 @@ module ActionView # # If no options hash is passed or :update specified, the default is to render a partial and use the second parameter # as the locals hash. - def render(options = {}, locals = {}, &block) #:nodoc: + def render(options = {}, locals = {}, &block) case options when Hash if block_given? content = _render_partial(options.merge(:partial => options[:layout]), &block) safe_concat(content) + elsif options.key?(:partial) + _render_partial(options) else - _render(options) + template = _determine_template(options) + _render_template(template, options[:layout], options) end when :update update_page(&block) @@ -28,31 +31,6 @@ module ActionView end end - # This is the API to render a ViewContext's template from a controller. - def render_template(options, &block) - _evaluate_assigns_and_ivars - - # TODO Layout for partials should be handled here, because inside the - # partial renderer it looks for the layout as a partial. - if options.key?(:partial) && options[:layout] - options[:layout] = _find_layout(options[:layout]) - end - - _render(options, &block) - end - - # This method holds the common render logic for both controllers and - # views rendering stacks. - def _render(options) #:nodoc: - 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 - # Determine the template to be rendered using the given options. def _determine_template(options) #:nodoc: if options.key?(:inline) @@ -71,8 +49,10 @@ module ActionView # Renders the given template. An string representing the layout can be # supplied as well. def _render_template(template, layout = nil, options = {}) #:nodoc: + self.formats = template.formats + locals = options[:locals] || {} - layout = _find_layout(layout) if layout + layout = find_layout(layout) if layout ActiveSupport::Notifications.instrument("action_view.render_template", :identifier => template.identifier, :layout => layout.try(:identifier)) do @@ -88,6 +68,5 @@ module ActionView content end end - end end -- cgit v1.2.3 From ee4c89627ad5d7b041b88ab4027d3f0d5d582d8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 13 Mar 2010 09:14:09 +0100 Subject: Remove formats setters from render template, speeding up partial and collection renderings. --- actionpack/lib/action_view/render/rendering.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'actionpack/lib/action_view/render') diff --git a/actionpack/lib/action_view/render/rendering.rb b/actionpack/lib/action_view/render/rendering.rb index 9b5b976727..310efe40e2 100644 --- a/actionpack/lib/action_view/render/rendering.rb +++ b/actionpack/lib/action_view/render/rendering.rb @@ -22,6 +22,7 @@ module ActionView _render_partial(options) else template = _determine_template(options) + self.formats = template.formats _render_template(template, options[:layout], options) end when :update @@ -49,8 +50,6 @@ module ActionView # Renders the given template. An string representing the layout can be # supplied as well. def _render_template(template, layout = nil, options = {}) #:nodoc: - self.formats = template.formats - locals = options[:locals] || {} layout = find_layout(layout) if layout -- cgit v1.2.3