2008-07-12 15:33:46 -04:00
|
|
|
module ActionView
|
|
|
|
module RenderablePartial
|
|
|
|
# NOTE: The template that this mixin is beening include into is frozen
|
|
|
|
# So you can not set or modify any instance variables
|
|
|
|
|
2008-07-18 16:32:28 -04:00
|
|
|
extend ActiveSupport::Memoizable
|
2008-07-14 20:51:43 -04:00
|
|
|
|
2008-07-14 18:40:03 -04:00
|
|
|
def variable_name
|
2008-07-14 20:51:43 -04:00
|
|
|
name.sub(/\A_/, '').to_sym
|
2008-07-14 18:40:03 -04:00
|
|
|
end
|
2008-07-14 21:02:59 -04:00
|
|
|
memoize :variable_name
|
2008-07-14 18:40:03 -04:00
|
|
|
|
|
|
|
def counter_name
|
2008-07-14 20:51:43 -04:00
|
|
|
"#{variable_name}_counter".to_sym
|
2008-07-14 18:40:03 -04:00
|
|
|
end
|
2008-07-14 21:02:59 -04:00
|
|
|
memoize :counter_name
|
2008-07-14 18:40:03 -04:00
|
|
|
|
2008-07-12 15:33:46 -04:00
|
|
|
def render(view, local_assigns = {})
|
|
|
|
ActionController::Base.benchmark("Rendered #{path_without_format_and_extension}", Logger::DEBUG, false) do
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-07-14 18:40:03 -04:00
|
|
|
def render_partial(view, object = nil, local_assigns = {}, as = nil)
|
|
|
|
object ||= local_assigns[:object] ||
|
|
|
|
local_assigns[variable_name] ||
|
|
|
|
view.controller.instance_variable_get("@#{variable_name}") if view.respond_to?(:controller)
|
|
|
|
|
|
|
|
# Ensure correct object is reassigned to other accessors
|
|
|
|
local_assigns[:object] = local_assigns[variable_name] = object
|
|
|
|
local_assigns[as] = object if as
|
|
|
|
|
2008-07-12 15:33:46 -04:00
|
|
|
render_template(view, local_assigns)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|