Module: Vedeu::Presentation

Included in:
Border, Char, Composition, Interface, Line, Stream
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

Instance Method Details

#_colourvoid (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

#_stylevoid (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

#backgroundVedeu::Background

Returns:



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

Returns:



21
22
23
24
# File 'lib/vedeu/output/presentation.rb', line 21

def background=(value)
  attributes[:background] = value
  colour.background = value
end

#colourVedeu::Colour

Returns:



27
28
29
# File 'lib/vedeu/output/presentation.rb', line 27

def colour
  @colour ||= Vedeu::Colour.coerce(_colour)
end

#colour=(value) ⇒ Vedeu::Colour

Returns:



32
33
34
35
# File 'lib/vedeu/output/presentation.rb', line 32

def colour=(value)
  attributes[:colour] = value
  @colour = Vedeu::Colour.coerce(value)
end

#foregroundVedeu::Foreground

Returns:



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

Returns:



50
51
52
53
# File 'lib/vedeu/output/presentation.rb', line 50

def foreground=(value)
  attributes[:foreground] = value
  colour.foreground = value
end

#parent_backgroundVedeu::Background

Returns:



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_colourString|NilClass

Returns:

  • (String|NilClass)


67
68
69
# File 'lib/vedeu/output/presentation.rb', line 67

def parent_colour
  parent.colour if parent
end

#parent_foregroundVedeu::Foreground

Returns:



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_styleString|NilClass

Returns:

  • (String|NilClass)


83
84
85
# File 'lib/vedeu/output/presentation.rb', line 83

def parent_style
  parent.style if parent
end

#render_colourString (private)

Renders the colour attributes of the receiver and yields (to then render the styles).

Returns:

  • (String)


123
124
125
# File 'lib/vedeu/output/presentation.rb', line 123

def render_colour
  [colour, yield].join
end

#render_positionString (private)

Returns:

  • (String)


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_styleString (private)

Renders the style attributes of the receiver and yields (to then render the next model, or finally, the content).

Returns:

  • (String)


142
143
144
# File 'lib/vedeu/output/presentation.rb', line 142

def render_style
  [style, yield].join
end

#styleVedeu::Style

Returns:



88
89
90
# File 'lib/vedeu/output/presentation.rb', line 88

def style
  @style ||= Vedeu::Style.coerce(_style)
end

#style=(value) ⇒ Vedeu::Style

Returns:



93
94
95
# File 'lib/vedeu/output/presentation.rb', line 93

def style=(value)
  @style = Vedeu::Style.coerce(value)
end

#to_sString

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.

Returns:

  • (String)

    An escape sequence with value interpolated.



102
103
104
# File 'lib/vedeu/output/presentation.rb', line 102

def to_s
  render_position { render_colour { render_style { value } } }
end