Module: PresenterHelper

Included in:
Www::VideoCardComponent, Www::VideoSectionComponent
Defined in:
app/helpers/presenter_helper.rb

Overview

View helper: presenter.

Instance Method Summary collapse

Instance Method Details

#generic_present(presenter_class, options = {}) {|presenter| ... } ⇒ Object

Instantiates a presenter without a model, using the current view as context.

Parameters:

  • presenter_class (Class)

    the presenter class to instantiate

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

    options passed through to the presenter constructor

Options Hash (options):

  • current_account (Account, nil)

    account available to the presenter

Yields:

  • (presenter)

Returns:

  • (Object)

    the presenter instance



25
26
27
28
29
30
# File 'app/helpers/presenter_helper.rb', line 25

def generic_present(presenter_class, options = {})
  klass = presenter_class
  presenter = klass.new(self, options)
  yield presenter if block_given?
  presenter
end

#present(model, presenter_class = nil, options = {}) {|presenter| ... } ⇒ Object

Instantiates a presenter for the given model, yielding it when a block is given.

Parameters:

  • model (Object)

    the model to present

  • presenter_class (Class, nil) (defaults to: nil)

    presenter class (defaults to "#{model.class}Presenter")

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

    options passed through to the presenter constructor

Options Hash (options):

  • current_account (Account, nil)

    defaults to the view's current_account

  • view_context (Object, nil)

    view context for the presenter (defaults to the current view)

Yields:

  • (presenter)

Returns:

  • (Object)

    the presenter instance



11
12
13
14
15
16
17
18
# File 'app/helpers/presenter_helper.rb', line 11

def present(model, presenter_class = nil, options = {})
  options[:current_account] ||= try(:current_account)
  klass = presenter_class || "#{model.class}Presenter".constantize
  view_context = options[:view_context] || self
  presenter = klass.new(model, view_context, options)
  yield presenter if block_given?
  presenter
end