class Presents::BasePresenter

Public Class Methods

new(object, template = nil) click to toggle source

Internal: Create a new presenter.

Called by present method in ApplicationHelper.

# File lib/presents/base_presenter.rb, line 8
def initialize(object, template = nil)
  @object = object
  @template = template
end
presents(name) click to toggle source

Public: Create an accessor to the wrapped object.

Examples

class DuckPresenter < BasePresenter
  presents :duck

  ...

  def my_attribute
    h.number_as_currency(duck.attribute)
  end

end
# File lib/presents/base_presenter.rb, line 28
def self.presents(name)
  define_method(name) do
    @object
  end
end

Public Instance Methods

h() click to toggle source

Public: Access the view for helper methods.

Examples

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

Returns the template.

# File lib/presents/base_presenter.rb, line 47
def h
  @template
end
method_missing(*args, &block) click to toggle source

Internal: Send any unknown methods to the template.

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

Examples

class XxxPresenter < BasePresenter
  ...
  def my_attribute
    content_tag :span, "Duck", :class => "mallard"
  end
  ...
end
# File lib/presents/base_presenter.rb, line 65
def method_missing(*args, &block)
  @template.send(*args, &block) if @template
end