aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/abstract/renderer.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib/action_controller/abstract/renderer.rb')
-rw-r--r--actionpack/lib/action_controller/abstract/renderer.rb58
1 files changed, 58 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/abstract/renderer.rb b/actionpack/lib/action_controller/abstract/renderer.rb
new file mode 100644
index 0000000000..68c3b07b84
--- /dev/null
+++ b/actionpack/lib/action_controller/abstract/renderer.rb
@@ -0,0 +1,58 @@
+require "action_controller/abstract/logger"
+
+module AbstractController
+ module Renderer
+ depends_on AbstractController::Logger
+
+ setup do
+ attr_internal :formats
+
+ extlib_inheritable_accessor :_view_paths
+
+ self._view_paths ||= ActionView::PathSet.new
+ end
+
+ def _action_view
+ @_action_view ||= ActionView::Base.new(self.class.view_paths, {}, self)
+ end
+
+ def render(options = {})
+ self.response_body = render_to_string(options)
+ end
+
+ # Raw rendering of a template.
+ # ====
+ # @option _prefix<String> The template's path prefix
+ # @option _layout<String> The relative path to the layout template to use
+ #
+ # :api: plugin
+ def render_to_string(options = {})
+ name = options[:_template_name] || action_name
+
+ template = options[:_template] || view_paths.find_by_parts(name.to_s, formats, options[:_prefix])
+ _render_template(template, options)
+ end
+
+ def _render_template(template, options)
+ _action_view._render_template_with_layout(template)
+ end
+
+ def view_paths() _view_paths end
+
+ module ClassMethods
+
+ def append_view_path(path)
+ self.view_paths << path
+ end
+
+ def view_paths
+ self._view_paths
+ end
+
+ def view_paths=(paths)
+ self._view_paths = paths.is_a?(ActionView::PathSet) ?
+ paths : ActionView::Base.process_view_paths(paths)
+ end
+ end
+ end
+end \ No newline at end of file