lib/action_view/base.rb in actionpack-1.8.1 vs lib/action_view/base.rb in actionpack-1.9.0
- old
+ new
@@ -120,10 +120,12 @@
include ERB::Util
attr_reader :first_render
attr_accessor :base_path, :assigns, :template_extension
attr_accessor :controller
+
+ attr_reader :logger, :params, :response, :session, :headers, :flash
# Turn on to cache the reading of templates from the file system. Doing so means that you have to restart the server
# when changing templates, but that rendering will be faster.
@@cache_template_loading = false
cattr_accessor :cache_template_loading
@@ -140,20 +142,10 @@
class_eval("include ActionView::Helpers::#{helper_module_name}") if Helpers.const_defined?(helper_module_name)
end
end
- def self.controller_delegate(*methods)#:nodoc:
- methods.flatten.each do |method|
- class_eval <<-end_eval
- def #{method}(*args, &block)
- controller.send(%(#{method}), *args, &block)
- end
- end_eval
- end
- end
-
def self.register_template_handler(extension, klass)
@@template_handlers[extension] = klass
end
def initialize(base_path = nil, assigns_for_first_render = {}, controller = nil)#:nodoc:
@@ -189,12 +181,27 @@
end
end
# Renders the template present at <tt>template_path</tt> (relative to the template_root).
# The hash in <tt>local_assigns</tt> is made available as local variables.
- def render(template_path, local_assigns = {})
- render_file(template_path, true, local_assigns)
+ def render(options = {}, old_local_assigns = {})
+ if options.is_a?(String)
+ render_file(options, true, old_local_assigns)
+ elsif options.is_a?(Hash)
+ options[:locals] ||= {}
+ options[:use_full_path] = options[:use_full_path].nil? ? true : options[:use_full_path]
+
+ if options[:file]
+ render_file(options[:file], options[:use_full_path], options[:locals])
+ elsif options[:partial] && options[:collection]
+ render_partial_collection(options[:partial], options[:collection], options[:spacer_template], options[:locals])
+ elsif options[:partial]
+ render_partial(options[:partial], options[:object], options[:locals])
+ elsif options[:inline]
+ render_template(options[:type] || :rhtml, options[:inline], options[:locals] || {})
+ end
+ end
end
# Renders the +template+ which is given as a string as either rhtml or rxml depending on <tt>template_extension</tt>.
# The hash in <tt>local_assigns</tt> is made available as local variables.
def render_template(template_extension, template, local_assigns = {})
@@ -216,11 +223,11 @@
def pick_rendering_method(template_extension)#:nodoc:
if @@template_handlers[template_extension]
"delegate_render"
else
- (template_extension == "rxml" ? "rxml" : "rhtml") + "_render"
+ (template_extension.to_s == "rxml" ? "rxml" : "rhtml") + "_render"
end
end
def delegate_template_exists?(template_path)#:nodoc:
@@template_handlers.find { |k,| template_exists?(template_path, k) }
@@ -288,6 +295,6 @@
delegator.render(template, local_assigns)
end
end
end
-require 'action_view/template_error'
\ No newline at end of file
+require 'action_view/template_error'