Class: Presents::BasePresenter
- Inherits:
-
Object
- Object
- Presents::BasePresenter
- Defined in:
- lib/presents/base_presenter.rb
Class Method Summary collapse
-
.presents(name) ⇒ Object
Public: Create an accessor to the wrapped object.
Instance Method Summary collapse
-
#h ⇒ Object
Public: Access the view for helper methods.
-
#initialize(object, template = nil) ⇒ BasePresenter
constructor
Internal: Create a new presenter.
-
#method_missing(*args, &block) ⇒ Object
Internal: Send any unknown methods to the template.
Constructor Details
#initialize(object, template = nil) ⇒ BasePresenter
Internal: Create a new presenter.
Called by present method in ApplicationHelper.
8 9 10 11 |
# File 'lib/presents/base_presenter.rb', line 8 def initialize(object, template = nil) @object = object @template = template 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 < BasePresenter
...
def my_attribute
content_tag :span, "Duck", :class => "mallard"
end
...
end
65 66 67 |
# File 'lib/presents/base_presenter.rb', line 65 def method_missing(*args, &block) @template.send(*args, &block) if @template end |
Class Method Details
.presents(name) ⇒ Object
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
28 29 30 31 32 |
# File 'lib/presents/base_presenter.rb', line 28 def self.presents(name) define_method(name) do @object end end |
Instance Method Details
#h ⇒ Object
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.
47 48 49 |
# File 'lib/presents/base_presenter.rb', line 47 def h @template end |