module SWX #:nodoc: module ModelView #:nodoc def render_model(options = {}) #:nodoc: # needed for scope controller = self.controller_name action = self.action_name model_def_method = ActionController::Base.class_eval do begin @model_view_registry[controller][action][:method] rescue NoMethodError nil end end method = options[:method] || model_def_method || action template = options[:object].send(method) render(:text => ERB.new(template).result(binding), :layout => options[:layout] || true, :status => options[:status] || nil) end end module ActsAsRenderable #:nodoc: def self.included(base) base.extend(ClassMethods) end module ClassMethods def acts_as_renderable(options = {}) klass = self.name ActionController::Base.class_eval do @model_view_registry[options[:controller]] = {options[:action] => {:class => klass, :method => options[:method] } } end end end end end