| Module | Wee::DecorationMixin |
| In: |
lib/wee/decoration.rb
|
| decoration | [RW] |
Adds decoration d to the decoration chain.
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.
Returns: self
# File lib/wee/decoration.rb, line 96 def add_decoration(d) if d.global? d.next = @decoration @decoration = d else last_global = nil each_decoration {|i| if i.global? last_global = i else break end } if last_global.nil? # no global decorations specified -> add in front d.next = @decoration @decoration = d else # add after last_global d.next = last_global.next last_global.next = d end end return self end
Iterates over all decorations (note that the component itself is excluded).
# File lib/wee/decoration.rb, line 79 def each_decoration # :yields: decoration d = @decoration while d and d != self yield d d = d.next end end
Remove decoration d from the decoration chain.
Returns the removed decoration or nil if it did not exist in the decoration chain.
# File lib/wee/decoration.rb, line 129 def remove_decoration(d) if d == @decoration # 'd' is in front @decoration = d.next else last_decoration = @decoration next_decoration = nil loop do return nil if last_decoration == self or last_decoration.nil? next_decoration = last_decoration.next break if d == next_decoration last_decoration = next_decoration end last_decoration.next = d.next end d.next = nil # decoration 'd' no longer is an owner of anything! return d end
Remove all decorations that match the block condition.
Example (removes all decorations of class HaloDecoration):
remove_decoration_if {|d| d.class == HaloDecoration}
# File lib/wee/decoration.rb, line 154 def remove_decoration_if # :yields: decoration to_remove = [] each_decoration {|d| to_remove << d if yield d} to_remove.each {|d| remove_decoration(d)} end