zendesk/curly

Question - Global presenter

gauravtiwari opened this issue · 2 comments

Hello there,

Thanks for this gem. I was wondering if I have to make a global presenter class which could be available in all the views (to keep code DRY). How can I accomplish this? Shall I put it in ApplicationPresenter? How to share presenter methods?

Thanks,
Gaurav

You can have an ApplicationPresenter base class and simply inherit from that:

# app/presenters/application_presenter.rb
class ApplicationPresenter < Curly::Presenter
  def something
    content_tag :h1, "something"
  end

  private

  def some_helper(arg)
    ...
  end
end

# app/presenters/posts/show_presenter.rb
class Posts::ShowPresenter < ApplicationPresenter
  presents :post

  def title
    some_helper(@post)
  end
end

thanks @dasch (Daniel). :)