Class: Keynote::Presenter
- Inherits:
-
Object
- Object
- Keynote::Presenter
- Includes:
- Rumble
- Defined in:
- lib/keynote/presenter.rb
Overview
Keynote::Presenter is a base class for presenters, objects that encapsulate view logic.
Constant Summary
Constants included from Rumble
Rumble::BASIC, Rumble::COMPLETE
Class Attribute Summary collapse
-
.object_names ⇒ Array<Symbol>
List the object names this presenter wraps.
Class Method Summary collapse
-
.presents(*objects) ⇒ Object
Define the names and number of the objects presented by this class.
-
.use_html_5_tags ⇒ Object
Define a more complete set of HTML5 tag methods.
Instance Method Summary collapse
-
#initialize(view_context) ⇒ Presenter
constructor
Create a presenter.
-
#method_missing(method_name) ⇒ Object
Presenters proxy unknown method calls to the view context, allowing you to call
h,link_to, and anything else defined in a helper module. -
#present ⇒ Object
(also: #k)
Instantiate another presenter.
Methods included from Rumble
Constructor Details
#initialize(view_context) ⇒ Presenter
Create a presenter. The default constructor takes one parameter, but
calling presents replaces it with a generated constructor.
69 70 71 |
# File 'lib/keynote/presenter.rb', line 69 def initialize(view_context) @view = view_context end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name) ⇒ Object
Presenters proxy unknown method calls to the view context, allowing you
to call h, link_to, and anything else defined in a helper module.
106 107 108 109 110 111 112 |
# File 'lib/keynote/presenter.rb', line 106 def method_missing(method_name, ...) if @view.respond_to?(method_name, true) @view.send(method_name, ...) else super end end |
Class Attribute Details
.object_names ⇒ Array<Symbol>
List the object names this presenter wraps. The default is an empty
array; calling presents :foo, :bar in the presenter's class body will
cause object_names to return [:foo, :bar].
57 58 59 |
# File 'lib/keynote/presenter.rb', line 57 def object_names @object_names ||= [] end |
Class Method Details
.presents(*objects) ⇒ Object
Define the names and number of the objects presented by this class. This replaces the default one-parameter constructor with one that takes an extra parameter for each presented object.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/keynote/presenter.rb', line 33 def presents(*objects) self.object_names = objects.dup objects.unshift :view attr_reader(*objects) param_list = objects.join(", ") ivar_list = objects.map { "@#{it}" }.join(", ") class_eval " def initialize(\#{param_list}) # def initialize(view, foo)\n \#{ivar_list} = \#{param_list} # @view, @foo = view, foo\n end # end\n RUBY\nend\n", __FILE__, __LINE__ + 1 |
.use_html_5_tags ⇒ Object
Define a more complete set of HTML5 tag methods. The extra tags are listed in Rumble::COMPLETE.
51 |
# File 'lib/keynote/presenter.rb', line 51 def = Rumble.(self) |
Instance Method Details
#present ⇒ Object Also known as: k
Instantiate another presenter.
75 76 77 |
# File 'lib/keynote/presenter.rb', line 75 def present(...) Keynote.present(@view, ...) end |