Class: BasePresenter
- Inherits:
-
Object
- Object
- BasePresenter
- Defined in:
- app/presenters/base_presenter.rb
Overview
Presenters:
* http://railscasts.com/episodes/287-presenters-from-scratch
* https://github.com/railscasts/287-presenters-from-scratch
Example:
class FooPresenter < BasePresenter
presents :foo
def present
"html code"
end
def some_generated_code
"some generated code"
end
end
present @foo do |foo_presenter|
foo_presenter.some_generated_code
end # => "some generated code"
# or:
present @foo # => "html code"
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(object, template) ⇒ BasePresenter
constructor
A new instance of BasePresenter.
- #present ⇒ Object
Constructor Details
#initialize(object, template) ⇒ BasePresenter
Returns a new instance of BasePresenter.
24 25 26 27 |
# File 'app/presenters/base_presenter.rb', line 24 def initialize(object, template) @object = object @template = template end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args, &block) ⇒ Object (private)
49 50 51 |
# File 'app/presenters/base_presenter.rb', line 49 def method_missing(*args, &block) @template.send(*args, &block) end |
Instance Method Details
#present ⇒ Object
29 30 31 |
# File 'app/presenters/base_presenter.rb', line 29 def present raise "Please override the #present method to return the presenter's html code or use a block. For more information, see BasePresenter." end |