Tidy vews, decorator and presenter
-
Upload
carlos-sanchez-perez -
Category
Software
-
view
179 -
download
1
Transcript of Tidy vews, decorator and presenter
![Page 1: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/1.jpg)
Decorator Decorator & &
PresenterPresenterBy: Carlos Sánchez Pérez madridrbBy: Carlos Sánchez Pérez madridrb
Tidy VIEWSTidy VIEWS
![Page 2: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/2.jpg)
WHO AM I?
Person.new(NameName : 'Carlos Sánchez Pérez',LoveLove : 'Web Dev Ruby & Rails',TwitterTwitter : '@carlossanchezp',JobJob : 'ASPgems',GithubGithub : 'carlossanchezp',Blog Blog ::'carlossanchezperez.wordpress.com')
Let me show you about my ideas, in my blog. I'll be there for you tomorrow....
![Page 3: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/3.jpg)
The Problem
![Page 4: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/4.jpg)
VIEWS: Responsibility Overload
![Page 5: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/5.jpg)
FAT MODEL
![Page 6: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/6.jpg)
BIGGEST HELPERS
![Page 7: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/7.jpg)
What's wrong with it?
![Page 8: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/8.jpg)
![Page 9: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/9.jpg)
app/views/users/show.html.erb
![Page 10: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/10.jpg)
DECORATOR PRESENTER
![Page 11: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/11.jpg)
PRESENTERS Pattern
Tidy Views
![Page 12: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/12.jpg)
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
![Page 13: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/13.jpg)
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 objectoriented approach to logic in the view.
![Page 14: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/14.jpg)
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.
![Page 15: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/15.jpg)
![Page 16: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/16.jpg)
![Page 17: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/17.jpg)
![Page 18: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/18.jpg)
![Page 19: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/19.jpg)
app/views/users/show.html.rb
![Page 20: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/20.jpg)
DECORATOR Pattern
Tidy Views
![Page 21: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/21.jpg)
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.
![Page 22: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/22.jpg)
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.
![Page 23: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/23.jpg)
CHANGE: UserDecorator.find(params[:id]
![Page 24: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/24.jpg)
![Page 25: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/25.jpg)
App/views/users/show.html.erb
![Page 26: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/26.jpg)
DECORATOR PRESENTER
PRESENTERDECORATOR
![Page 27: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/27.jpg)
How to share?In a view with decorator and without decorator
![Page 28: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/28.jpg)
![Page 29: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/29.jpg)
![Page 30: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/30.jpg)
DRAPPER
def helpers Draper::ViewContext.current end alias_method :h, :helpers
![Page 31: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/31.jpg)
![Page 32: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/32.jpg)
Is there anything else?
![Page 33: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/33.jpg)
Decorator
OTHER SIDE
Sending Notifications Using Decorators
![Page 34: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/34.jpg)
CALLBACK
MODEL
SEND
![Page 35: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/35.jpg)
![Page 36: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/36.jpg)
“Single Responsibility Principle”
MODELFIND USER
DECORATOR
CALLING METHOD DECORATOR
![Page 37: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/37.jpg)
One more
Notifications
![Page 38: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/38.jpg)
![Page 39: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/39.jpg)
![Page 40: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/40.jpg)
![Page 41: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/41.jpg)
The same object diferent Render
![Page 42: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/42.jpg)
Exhibit Pattern
![Page 43: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/43.jpg)
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“.
![Page 44: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/44.jpg)
![Page 45: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/45.jpg)
![Page 46: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/46.jpg)
Conclusion
![Page 47: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/47.jpg)
The power of decorators
![Page 48: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/48.jpg)
LINKS
Decorator gem: Decorator gem: https://github.com/drapergem/draperhttps://github.com/drapergem/draper
Objects In Rails Objects In Rails http://objectsonrails.com/http://objectsonrails.com/
http://blog.jayfields.com/2007/03/railspresenterpattern.htmlhttp://blog.jayfields.com/2007/03/railspresenterpattern.html
http://railscasts.com/episodes/286draperhttp://railscasts.com/episodes/286draper
![Page 49: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/49.jpg)
Any questions?
![Page 50: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/50.jpg)
Dedication to....
![Page 51: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/51.jpg)
Thanks ASPgems and twitter people!!
THANKS A LOT!!
![Page 52: Tidy vews, decorator and presenter](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a9b45e1a28abcc698b46e7/html5/thumbnails/52.jpg)
That's all folks!!and
Thanks a lot for your attention