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, *args, &block) ⇒ 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(*objects, &blk) ⇒ 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.
71 72 73 |
# File 'lib/keynote/presenter.rb', line 71 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, *args, &block) ⇒ 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.
108 109 110 111 112 113 114 |
# File 'lib/keynote/presenter.rb', line 108 def method_missing(method_name, *args, &block) if @view.respond_to?(method_name, true) @view.send(method_name, *args, &block) 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]
.
59 60 61 |
# File 'lib/keynote/presenter.rb', line 59 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 { |o| "@#{o}" }.join(', ') class_eval <<-RUBY def initialize(#{param_list}) # def initialize(view, foo) #{ivar_list} = #{param_list} # @view, @foo = view, foo end # end RUBY end |
.use_html_5_tags ⇒ Object
Define a more complete set of HTML5 tag methods. The extra tags are listed in Rumble::COMPLETE.
51 52 53 |
# File 'lib/keynote/presenter.rb', line 51 def Rumble.(self) end |