decent_decoration
decent_decoration allows you to use excellent decent_exposure 3.0 gem with decorators.
Installation
Add this line to your application's Gemfile:
gem 'decent_decoration', '~> 0.1.0'
And then execute:
$ bundle
Usage
class ConferencesController < ApplicationController
expose(:conference) { ConferenceDecorator.new(build_conference) }
private
def build_conference
end
end
class ConferencesController < ApplicationController
expose_decorated(:conference)
end
decent_decoration makes decorated objects accessible in views. They remain undecorated in your controllers.
Define a decorator explicitly:
class ConferencesController < ApplicationController
expose_decorated(:conference, decorator: SponsoredConferenceDecorator)
end
decent_decoration detect automatically if you want to decorate a collection. To circumvent this pass collection: true/false
class ConferencesController < ApplicationController
expose_decorated(:conferences, collection: false)
end
decent_decoration supports most of the awesome decent_exposure api. Read more about it!
class AttendeesController < ApplicationController
expose_decorated(:conference)
expose_decorated(:attendees, scope: :conference)
end
You can use any decorator mechanism as long as ConferenceDecorator
responds to #decorate
or #new
. Try draper.
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Copyright © 2012–2014 netguru. See LICENSE for further details.