2016-01-12 18:43:00 -06:00
|
|
|
module ApplicationHelper
|
2016-01-18 15:10:25 -06:00
|
|
|
|
2016-04-04 14:28:23 -05:00
|
|
|
# Given a model or collection of models, returns them with the given decorator. If a block is passed, yields the
|
|
|
|
# decorated objects as well
|
|
|
|
#
|
|
|
|
# Useful in this context:
|
|
|
|
# <% decorate(@model_obj, ModelObjDecorator) do |model_obj| %>
|
|
|
|
# <%= model_obj.decorator_method %>
|
|
|
|
# <% end %>
|
|
|
|
def decorate(obj, decorator_class)
|
|
|
|
decorated = decorator_class.decorate(obj, self)
|
|
|
|
yield(decorated) if block_given?
|
|
|
|
decorated
|
|
|
|
end
|
|
|
|
|
2016-01-12 18:43:00 -06:00
|
|
|
end
|