Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Tidy Views: Decorator and Presenter

Tidy Views: Decorator and Presenter

Carlos Sánchez Pérez

March 27, 2014
Tweet

More Decks by Carlos Sánchez Pérez

Other Decks in Programming

Transcript

  1. Decorator Decorator & & Presenter Presenter By: Carlos Sánchez Pérez

    madrid­rb By: Carlos Sánchez Pérez madrid­rb Tidy VIEWS Tidy VIEWS
  2. WHO AM I? Person.new( Name Name : 'Carlos Sánchez Pérez',

    Love Love : 'Web Dev ­ Ruby & Rails', Twitter Twitter : '@carlossanchezp', Job Job : 'ASPgems', Github Github : 'carlossanchezp', Blog Blog : :'carlossanchezperez.wordpress.com ' ) Let me show you about my ideas, in my blog. I'll be there for you tomorrow....
  3. The idea of a Presenter was first introduced to the

    Rails community by Jay Fields in a series of blog articles in 2006 and 2007. Rails Presenter Pattern Jay Fields Wikipedia:Model–view–presenter
  4. PRESENTER • Presenters are also decorators. • The presenters is

    their proximity to the view and live very close to the view layer. • In fact, they are meant to be a representation of the delegate object within the view. • The main goal of presenters is to keep logic out of the view. • Presenters maintain an object­ oriented approach to logic in the view.
  5. MODEL VIEW My name is Presenter, Can I help you?

    This way, presenters act like decorators. Wrap a Rails model and aid in the presentation.
  6. DECORATOR • Start needing logic in the view or start

    thinking about a helper method, you can implement a method on the decorator instead. • Attach additional responsibilities to an object dynamically. • A decorator changes an object's skin.
  7. Jeff Casimir's draper is a gem that embodies the pattern

    and also allows you to invoke Rails' view helpers by exposing the view context in your decorators.
  8. EXHIBIT • Exhibits are just decorators. • Add some additional

    functionality. • The additional functionality added will extend, but not disrupt. • Introducing the Exhibit Pattern by Avdi Grimm in his book “Objects on Rails“.
  9. LINKS Decorator gem: Decorator gem: https://github.com/drapergem/draper https://github.com/drapergem/draper Objects In Rails

    Objects In Rails http://objectsonrails.com/ http://objectsonrails.com/ http://blog.jayfields.com/2007/03/rails­presenter­pattern.html http://blog.jayfields.com/2007/03/rails­presenter­pattern.html http://railscasts.com/episodes/286­draper http://railscasts.com/episodes/286­draper