jcasimir/draper — pull request #265 by stevenbristol (2012-08-29 21:23:23+00:00)
Title: Allowing enumerable proxys to be decorated

Let's you do stuff like this:

class InvoicesDecorator < Draper::DecoratedEnumerableProxy
def most_used_contacts
h.current_business.contacts.limit(20)
end
end

class InvoicesController < ApplicationController
def index
respond_with InvoicesDecorator.decorate(current_business.invoices)
end

Why would you want to do this?

Currently Draper only decorates objects, which is great, but it means my views still need to have code in them to display other stuffs.

1. With this patch I can put 100% of my view logic and code into Draper.
2. If the current_business.invoices returns an empty array, then draper doesn't have anything to decorate. With this patch I can still display links, conditional text and anything else that is acting outside the object, but still needs to be displayed.