2008-07-03 14:06:00 -04:00
|
|
|
module ActionView
|
2008-07-05 13:05:50 -04:00
|
|
|
module Renderable
|
2008-07-03 14:06:00 -04:00
|
|
|
# TODO: Local assigns should not be tied to template instance
|
|
|
|
attr_accessor :locals
|
|
|
|
|
|
|
|
# TODO: These readers should be private
|
2008-07-06 00:54:11 -04:00
|
|
|
attr_reader :filename, :source, :handler
|
2008-07-03 14:06:00 -04:00
|
|
|
|
|
|
|
def render
|
|
|
|
prepare!
|
2008-07-11 16:39:22 -04:00
|
|
|
@handler.render(self, @locals)
|
2008-07-03 14:06:00 -04:00
|
|
|
end
|
|
|
|
|
2008-07-06 00:54:11 -04:00
|
|
|
def method
|
2008-07-06 02:13:15 -04:00
|
|
|
['_run', @extension, @method_segment, local_assigns_keys].compact.join('_').to_sym
|
2008-07-05 17:27:43 -04:00
|
|
|
end
|
|
|
|
|
2008-07-03 14:06:00 -04:00
|
|
|
private
|
|
|
|
def prepare!
|
|
|
|
unless @prepared
|
|
|
|
@view.send(:evaluate_assigns)
|
|
|
|
@view.current_render_extension = @extension
|
|
|
|
|
|
|
|
if @handler.compilable?
|
|
|
|
@handler.compile_template(self) # compile the given template, if necessary
|
|
|
|
end
|
|
|
|
|
|
|
|
@prepared = true
|
|
|
|
end
|
|
|
|
end
|
2008-07-06 02:13:15 -04:00
|
|
|
|
|
|
|
def local_assigns_keys
|
|
|
|
if @locals && @locals.any?
|
|
|
|
"locals_#{@locals.keys.map { |k| k.to_s }.sort.join('_')}"
|
|
|
|
end
|
|
|
|
end
|
2008-07-03 14:06:00 -04:00
|
|
|
end
|
|
|
|
end
|