You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using Presenters allows you to encapsulate logic that tends to become smeared across many view helpers and templates. The established pattern is to have a View Helper method that instantiates your Presenter and then yields that presenter to a block for rendering.
this leads into a vortex of helper methods with names like render_grouped_document_index, which in turn rely on a nested set of helper methods and view partials that reference each other. A DocumentListPresenter and DocumentPresenter should allow us to contain most of that sprawl, making it much more readable, predictable, testable and customizable.
I started doing a little bit of this on the Temple instance and quickly realized that moving everything to presenters is a really big haul. Perhaps this can be broken up into smaller chunks by targeting specific helper modules and methods?
The Pattern
Using Presenters allows you to encapsulate logic that tends to become smeared across many view helpers and templates. The established pattern is to have a View Helper method that instantiates your Presenter and then yields that presenter to a block for rendering.
In Blacklight, if we are using the default Presenter and pass a SolrDocument into that method, it would be the equivalent of calling
Applying this to Blacklight
this allows us to have a view partial that says
which could be wrapped in another presenter like this
Why Blacklight needs this
Rendering search results in blacklight involves diving head-first down a rabbit hole that starts here:
this leads into a vortex of helper methods with names like
render_grouped_document_index
, which in turn rely on a nested set of helper methods and view partials that reference each other. A DocumentListPresenter and DocumentPresenter should allow us to contain most of that sprawl, making it much more readable, predictable, testable and customizable.References
http://nithinbekal.com/posts/rails-presenters/
http://railscasts.com/episodes/287-presenters-from-scratch?autoplay=true
The text was updated successfully, but these errors were encountered: