Class: Presents::AggregatePresenter

Inherits:
Object
  • Object
show all
Defined in:
lib/presents/aggregate_presenter.rb

Instance Method Summary collapse

Constructor Details

#initialize(presenters, template) ⇒ AggregatePresenter

Internal: Create a new presenter.

Called by present method in ApplicationHelper.

presenters - A hash of the access method name and the presenter

Returns self.



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/presents/aggregate_presenter.rb', line 11

def initialize(presenters, template)
  @presenters = presenters
  @template = template

  @presenters.each do |presenter|
    class_eval do
      define_method(presenter.class.name.underscore.to_sym) do
        presenter
      end
    end
  end
  self
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object

Internal: Send any unknown methods to the template.

This is done so you don’t have to access them through h.

Examples

class XxxPresenter < AggregatePresenter
  ...
  def my_attribute
    content_tag :span, "Duck", :class => "mallard"
  end
  ...
end


56
57
58
# File 'lib/presents/aggregate_presenter.rb', line 56

def method_missing(*args, &block)
  @template.send(*args, &block)
end

Instance Method Details

#hObject

Public: Access the view for helper methods.

Examples

class XxxPresenter < AggregatePresenter
  ...
  def my_attribute
    h.content_tag :span, "Duck", :class => "mallard"
  end
  ...
end

Returns the template.



38
39
40
# File 'lib/presents/aggregate_presenter.rb', line 38

def h
  @template
end