2009-03-17 21:04:22 -04:00
|
|
|
module ActionController
|
|
|
|
module Renderer
|
2009-05-07 11:29:22 -04:00
|
|
|
extend ActiveSupport::DependencyModule
|
|
|
|
|
2009-04-07 17:57:18 -04:00
|
|
|
depends_on AbstractController::Renderer
|
2009-03-19 16:35:39 -04:00
|
|
|
|
2009-03-19 18:45:48 -04:00
|
|
|
def initialize(*)
|
|
|
|
self.formats = [:html]
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2009-04-29 20:32:39 -04:00
|
|
|
def render(options = {})
|
2009-03-18 18:58:47 -04:00
|
|
|
_process_options(options)
|
|
|
|
|
2009-04-29 15:19:17 -04:00
|
|
|
super(options)
|
2009-03-18 18:58:47 -04:00
|
|
|
end
|
2009-03-19 16:35:39 -04:00
|
|
|
|
2009-04-17 19:34:49 -04:00
|
|
|
def render_to_body(options)
|
2009-03-18 18:58:47 -04:00
|
|
|
if options.key?(:text)
|
2009-03-20 19:13:13 -04:00
|
|
|
options[:_template] = ActionView::TextTemplate.new(_text(options))
|
|
|
|
template = nil
|
2009-05-01 21:17:08 -04:00
|
|
|
elsif options.key?(:inline)
|
|
|
|
handler = ActionView::Template.handler_class_for_extension(options[:type] || "erb")
|
|
|
|
template = ActionView::Template.new(options[:inline], "inline #{options[:inline].inspect}", handler, {})
|
|
|
|
options[:_template] = template
|
2009-03-18 18:58:47 -04:00
|
|
|
elsif options.key?(:template)
|
2009-03-20 19:50:51 -04:00
|
|
|
options[:_template_name] = options[:template]
|
2009-05-11 17:48:58 -04:00
|
|
|
else
|
|
|
|
options[:_template_name] = (options[:action] || action_name).to_s
|
2009-03-19 18:45:48 -04:00
|
|
|
options[:_prefix] = _prefix
|
2009-03-17 21:04:22 -04:00
|
|
|
end
|
2009-03-20 19:13:13 -04:00
|
|
|
|
2009-04-29 20:50:11 -04:00
|
|
|
ret = super(options)
|
|
|
|
response.content_type ||= options[:_template].mime_type
|
|
|
|
ret
|
2009-03-17 21:04:22 -04:00
|
|
|
end
|
|
|
|
|
2009-03-19 16:35:39 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def _prefix
|
|
|
|
controller_path
|
|
|
|
end
|
|
|
|
|
2009-03-20 19:13:13 -04:00
|
|
|
def _text(options)
|
2009-03-20 19:50:51 -04:00
|
|
|
text = options[:text]
|
2009-03-19 16:35:39 -04:00
|
|
|
|
|
|
|
case text
|
|
|
|
when nil then " "
|
2009-03-20 19:13:13 -04:00
|
|
|
else text.to_s
|
2009-03-19 16:35:39 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-03-18 18:58:47 -04:00
|
|
|
def _process_options(options)
|
2009-04-29 20:50:11 -04:00
|
|
|
status, content_type = options.values_at(:status, :content_type)
|
|
|
|
response.status = status.to_i if status
|
|
|
|
response.content_type = content_type if content_type
|
2009-03-18 18:58:47 -04:00
|
|
|
end
|
2009-03-17 21:04:22 -04:00
|
|
|
end
|
2009-04-17 19:34:49 -04:00
|
|
|
end
|