Module: Showcase::Helpers::Present

Extended by:
ActiveSupport::Concern
Included in:
Presenter
Defined in:
lib/showcase/helpers/present.rb

Instance Method Summary collapse

Instance Method Details

#present(obj, klass = nil, context = presenter_context, options = {}) ⇒ Object


20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/showcase/helpers/present.rb', line 20

def present(obj, klass = nil, context = presenter_context, options = {})
  options.assert_valid_keys(:nil_presenter)

  if obj || options.fetch(:nil_presenter, false)
    klass ||= presenter_class(obj)
    if klass.nil?
      raise Showcase::PresenterClassNotFound, "Unable to guess a presenter class for #{obj.inspect}!"
    end
    klass.new(obj, context)
  else
    nil
  end
end

#present_collection(obj, klass = nil, context = presenter_context, options = {}) ⇒ Object


34
35
36
# File 'lib/showcase/helpers/present.rb', line 34

def present_collection(obj, klass = nil, context = presenter_context, options = {})
  obj.map { |o| present(o, klass, context, options) }
end

#presenter_contextObject


12
13
14
15
16
17
18
# File 'lib/showcase/helpers/present.rb', line 12

def presenter_context
  if respond_to? :view_context
    view_context
  else
    self
  end
end