Module: Lokap::ActionView

Defined in:
lib/lokap/presenter/ext/action_view.rb

Defined Under Namespace

Classes: MissingTemplate

Instance Method Summary collapse

Instance Method Details

#present(entity, klass = nil, options = {}) ⇒ Lokap::Presenter

Helper method which allows access to your presenters

Examples:

present(@person, :share).render
present(@person, :share).render(:twitter)
present(@person, :share).render('social/twitter')

Parameters:

  • entity (Object)

    The object to present

  • klass (Object) (defaults to: nil)

    The underscored class name of your presenter

  • options (Hash) (defaults to: {})

    Passed to the presenter (and template)

Returns:



19
20
21
22
23
24
25
# File 'lib/lokap/presenter/ext/action_view.rb', line 19

def present(entity, klass = nil, options={})
  base_klass = klass ? klass.to_s.titleize.gsub(' ', '') : entity.class
  klass = "#{base_klass}Presenter".constantize
  presenter = klass.new(entity, self, options)
  yield presenter and return if block_given?
  presenter
end