Module: Vedeu::Presentation
- Defined in:
- lib/vedeu/output/presentation.rb
Overview
This module allows the sharing of presentation concerns between the models: Interface, Line and Stream.
Instance Method Summary collapse
- #_colour ⇒ void private
- #_style ⇒ void private
- #background ⇒ Vedeu::Background
- #background=(value) ⇒ Vedeu::Background
- #colour ⇒ Vedeu::Colour
- #colour=(value) ⇒ Vedeu::Colour
- #foreground ⇒ Vedeu::Foreground
- #foreground=(value) ⇒ Vedeu::Foreground
- #parent_background ⇒ Vedeu::Background
- #parent_colour ⇒ String|NilClass
- #parent_foreground ⇒ Vedeu::Foreground
- #parent_style ⇒ String|NilClass
-
#render_colour ⇒ String
private
Renders the colour attributes of the receiver and yields (to then render the styles).
- #render_position ⇒ String private
-
#render_style ⇒ String
private
Renders the style attributes of the receiver and yields (to then render the next model, or finally, the content).
- #style ⇒ Vedeu::Style
- #style=(value) ⇒ Vedeu::Style
-
#to_s ⇒ String
Converts the colours and styles to escape sequences, and if the parent model has previously set the colour and style, reverts back to that for consistent formatting.
Instance Method Details
#_colour ⇒ void (private)
This method returns an undefined value.
109 110 111 112 113 114 115 116 117 |
# File 'lib/vedeu/output/presentation.rb', line 109 def _colour if attributes[:colour] attributes[:colour] elsif parent_colour parent_colour end end |
#_style ⇒ void (private)
This method returns an undefined value.
147 148 149 150 151 152 153 154 155 |
# File 'lib/vedeu/output/presentation.rb', line 147 def _style if attributes[:style] attributes[:style] elsif parent_style parent_style end end |
#background ⇒ Vedeu::Background
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/vedeu/output/presentation.rb', line 9 def background if colour colour.background else Vedeu::Background.new # @todo: Should this be: parent_background end end |
#background=(value) ⇒ Vedeu::Background
21 22 23 24 |
# File 'lib/vedeu/output/presentation.rb', line 21 def background=(value) attributes[:background] = value colour.background = value end |
#colour ⇒ Vedeu::Colour
27 28 29 |
# File 'lib/vedeu/output/presentation.rb', line 27 def colour @colour ||= Vedeu::Colour.coerce(_colour) end |
#colour=(value) ⇒ Vedeu::Colour
32 33 34 35 |
# File 'lib/vedeu/output/presentation.rb', line 32 def colour=(value) attributes[:colour] = value @colour = Vedeu::Colour.coerce(value) end |
#foreground ⇒ Vedeu::Foreground
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/vedeu/output/presentation.rb', line 38 def foreground if colour colour.foreground else Vedeu::Foreground.new # @todo: Should this be: parent_foreground end end |
#foreground=(value) ⇒ Vedeu::Foreground
50 51 52 53 |
# File 'lib/vedeu/output/presentation.rb', line 50 def foreground=(value) attributes[:foreground] = value colour.foreground = value end |
#parent_background ⇒ Vedeu::Background
56 57 58 59 60 61 62 63 64 |
# File 'lib/vedeu/output/presentation.rb', line 56 def parent_background if parent_colour parent_colour.background else Vedeu::Background.new end end |
#parent_colour ⇒ String|NilClass
67 68 69 |
# File 'lib/vedeu/output/presentation.rb', line 67 def parent_colour parent.colour if parent end |
#parent_foreground ⇒ Vedeu::Foreground
72 73 74 75 76 77 78 79 80 |
# File 'lib/vedeu/output/presentation.rb', line 72 def parent_foreground if parent_colour parent_colour.foreground else Vedeu::Foreground.new end end |
#parent_style ⇒ String|NilClass
83 84 85 |
# File 'lib/vedeu/output/presentation.rb', line 83 def parent_style parent.style if parent end |
#render_colour ⇒ String (private)
Renders the colour attributes of the receiver and yields (to then render the styles).
123 124 125 |
# File 'lib/vedeu/output/presentation.rb', line 123 def render_colour [colour, yield].join end |
#render_position ⇒ String (private)
128 129 130 131 132 133 134 135 136 |
# File 'lib/vedeu/output/presentation.rb', line 128 def render_position if self.respond_to?(:position) && position.is_a?(Vedeu::Position) position.to_s { yield } else yield end end |
#render_style ⇒ String (private)
Renders the style attributes of the receiver and yields (to then render the next model, or finally, the content).
142 143 144 |
# File 'lib/vedeu/output/presentation.rb', line 142 def render_style [style, yield].join end |
#style ⇒ Vedeu::Style
88 89 90 |
# File 'lib/vedeu/output/presentation.rb', line 88 def style @style ||= Vedeu::Style.coerce(_style) end |
#style=(value) ⇒ Vedeu::Style
93 94 95 |
# File 'lib/vedeu/output/presentation.rb', line 93 def style=(value) @style = Vedeu::Style.coerce(value) end |
#to_s ⇒ String
Converts the colours and styles to escape sequences, and if the parent model has previously set the colour and style, reverts back to that for consistent formatting.
102 103 104 |
# File 'lib/vedeu/output/presentation.rb', line 102 def to_s render_position { render_colour { render_style { value } } } end |