Class: Wee::Decoration
Overview
Abstract base class of all decorations. Forwards the methods #process_callbacks, #render_on and #state to the next decoration in the chain. Subclasses should provide special behaviour in these methods, otherwise the decoration does not make sense.
For example, a HeaderFooterDecoration class could draw a header and footer around the decorations or components below itself:
class HeaderFooterDecoration < Wee::Decoration
alias render_on render_presenter_on
def render(r)
r.text "header"
r.render_decoration(@next)
r.text "footer"
end
end
Direct Known Subclasses
Instance Attribute Summary collapse
-
#next ⇒ Object
Points to the next decoration in the chain.
Instance Method Summary collapse
-
#global? ⇒ Boolean
Is this decoration a global or a local one? By default all decorations are local unless this method is overwritten.
-
#process_callbacks(callbacks) ⇒ Object
Forwards method call to the next decoration in the chain.
-
#render_on(r) ⇒ Object
Forwards method call to the next decoration in the chain.
- #render_presenter_on ⇒ Object
-
#state(s) ⇒ Object
We have to save the @next attribute to be able to correctly backtrack calls, as method Wee::Component#call modifies it in the call to
component.remove_decoration(answer)
.
Methods inherited from Presenter
Instance Attribute Details
#next ⇒ Object
Points to the next decoration in the chain. A decoration is responsible for all decorations or components “below” it (everything that follows this decoration in the chain). In other words, it’s the owner of everything “below” itself.
31 32 33 |
# File 'lib/wee/decoration.rb', line 31 def next @next end |
Instance Method Details
#global? ⇒ Boolean
Is this decoration a global or a local one? By default all decorations are local unless this method is overwritten.
A global decoration is added in front of the decoration chain, a local decoration is added in front of all other local decorations but after all global decorations.
41 |
# File 'lib/wee/decoration.rb', line 41 def global?() false end |
#process_callbacks(callbacks) ⇒ Object
Forwards method call to the next decoration in the chain.
46 47 48 |
# File 'lib/wee/decoration.rb', line 46 def process_callbacks(callbacks) @next.process_callbacks(callbacks) end |
#render_on(r) ⇒ Object
Forwards method call to the next decoration in the chain.
54 55 56 |
# File 'lib/wee/decoration.rb', line 54 def render_on(r) @next.render_on(r) end |
#render_presenter_on ⇒ Object
50 |
# File 'lib/wee/decoration.rb', line 50 alias render_presenter_on render_on |
#state(s) ⇒ Object
We have to save the @next attribute to be able to correctly backtrack calls, as method Wee::Component#call modifies it in the call to component.remove_decoration(answer)
. Removing the answer-decoration has the advantage to be able to call a component more than once!
65 66 67 68 |
# File 'lib/wee/decoration.rb', line 65 def state(s) @next.state(s) s.add_ivar(self, :@next, @next) end |