From 81e814adfad6d4bba1af5f70a5a409f6d71f8f6c Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Fri, 20 Mar 2009 16:13:13 -0700 Subject: Working on being able to render :text with layouts --- actionpack/lib/action_controller/abstract/renderer.rb | 2 +- actionpack/lib/action_controller/new_base/renderer.rb | 13 +++++++------ actionpack/lib/action_view.rb | 1 + actionpack/lib/action_view/render/rendering.rb | 6 ++---- actionpack/lib/action_view/template/renderable.rb | 7 +++++++ actionpack/lib/action_view/template/template.rb | 2 +- actionpack/lib/action_view/template/text.rb | 9 +++++++++ 7 files changed, 28 insertions(+), 12 deletions(-) create mode 100644 actionpack/lib/action_view/template/text.rb (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/abstract/renderer.rb b/actionpack/lib/action_controller/abstract/renderer.rb index ad996d0daf..d95158be42 100644 --- a/actionpack/lib/action_controller/abstract/renderer.rb +++ b/actionpack/lib/action_controller/abstract/renderer.rb @@ -31,7 +31,7 @@ module AbstractController # # :api: plugin def render_to_string(name = action_name, options = {}) - template = view_paths.find_by_parts(name.to_s, formats, options[:_prefix]) + template = options[:_template] || view_paths.find_by_parts(name.to_s, formats, options[:_prefix]) _render_template(template, options) end diff --git a/actionpack/lib/action_controller/new_base/renderer.rb b/actionpack/lib/action_controller/new_base/renderer.rb index 1308537160..6abf3cef11 100644 --- a/actionpack/lib/action_controller/new_base/renderer.rb +++ b/actionpack/lib/action_controller/new_base/renderer.rb @@ -35,15 +35,16 @@ module ActionController end if options.key?(:text) - _render_text(options) + options[:_template] = ActionView::TextTemplate.new(_text(options)) + template = nil elsif options.key?(:template) - template = options.delete(:template) - super(template) + template = options.delete(:template) elsif options.key?(:action) template = options.delete(:action).to_s options[:_prefix] = _prefix - super(template, options) end + + super(template, options) end private @@ -52,12 +53,12 @@ module ActionController controller_path end - def _render_text(options) + def _text(options) text = options.delete(:text) case text when nil then " " - else text.to_s + else text.to_s end end diff --git a/actionpack/lib/action_view.rb b/actionpack/lib/action_view.rb index aa06c19a48..14bd2a1297 100644 --- a/actionpack/lib/action_view.rb +++ b/actionpack/lib/action_view.rb @@ -50,6 +50,7 @@ module ActionView autoload :TemplateError, 'action_view/template/error' autoload :TemplateHandler, 'action_view/template/handler' autoload :TemplateHandlers, 'action_view/template/handlers' + autoload :TextTemplate, 'action_view/template/text' autoload :Helpers, 'action_view/helpers' end diff --git a/actionpack/lib/action_view/render/rendering.rb b/actionpack/lib/action_view/render/rendering.rb index a02c058725..68b343de77 100644 --- a/actionpack/lib/action_view/render/rendering.rb +++ b/actionpack/lib/action_view/render/rendering.rb @@ -62,20 +62,18 @@ module ActionView end def _render_template(template, local_assigns = {}) - template.compile(local_assigns) - @_render_stack.push(template) _evaluate_assigns_and_ivars _set_controller_content_type(template.mime_type) if template.respond_to?(:mime_type) - result = send(template.method_name(local_assigns), local_assigns) do |*names| + result = template.render(self, local_assigns) do |*names| if !instance_variable_defined?(:"@content_for_#{names.first}") && instance_variable_defined?(:@_proc_for_layout) && (proc = @_proc_for_layout) capture(*names, &proc) elsif instance_variable_defined?(ivar = :"@content_for_#{names.first || :layout}") instance_variable_get(ivar) - end + end end @_render_stack.pop diff --git a/actionpack/lib/action_view/template/renderable.rb b/actionpack/lib/action_view/template/renderable.rb index 35c832aaba..fde37544f3 100644 --- a/actionpack/lib/action_view/template/renderable.rb +++ b/actionpack/lib/action_view/template/renderable.rb @@ -4,6 +4,13 @@ module ActionView module Renderable #:nodoc: extend ActiveSupport::Memoizable + def render(view, locals) + compile(locals) + view.send(method_name(locals), locals) {|*args| yield(*args) } + end + + private + def filename 'compiled-template' end diff --git a/actionpack/lib/action_view/template/template.rb b/actionpack/lib/action_view/template/template.rb index 1ee073c3e9..73e319b489 100644 --- a/actionpack/lib/action_view/template/template.rb +++ b/actionpack/lib/action_view/template/template.rb @@ -206,7 +206,7 @@ module ActionView #:nodoc: def load! @cached = true - freeze + # freeze end private diff --git a/actionpack/lib/action_view/template/text.rb b/actionpack/lib/action_view/template/text.rb new file mode 100644 index 0000000000..f81174d707 --- /dev/null +++ b/actionpack/lib/action_view/template/text.rb @@ -0,0 +1,9 @@ +module ActionView #:nodoc: + class TextTemplate < String #:nodoc: + + def render(*) self end + + def exempt_from_layout?() false end + + end +end -- cgit v1.2.3