vedeu 0.8.4 → 0.8.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/TODO.md +4 -0
  3. data/docs/dsl.md +1 -11
  4. data/docs/dsl/by_method/geometry/align.md +1 -0
  5. data/docs/dsl/by_method/geometry/align_bottom.md +40 -0
  6. data/docs/dsl/by_method/geometry/align_centre.md +40 -0
  7. data/docs/dsl/by_method/geometry/align_left.md +40 -0
  8. data/docs/dsl/by_method/geometry/align_middle.md +40 -0
  9. data/docs/dsl/by_method/geometry/align_right.md +40 -0
  10. data/docs/dsl/by_method/geometry/align_top.md +40 -0
  11. data/docs/dsl/by_method/geometry/columns.md +1 -0
  12. data/docs/dsl/by_method/geometry/height.md +0 -0
  13. data/docs/dsl/by_method/geometry/horizontal_alignment.md +1 -0
  14. data/docs/dsl/by_method/geometry/rows.md +1 -0
  15. data/docs/dsl/by_method/geometry/vertical_alignment.md +1 -0
  16. data/docs/dsl/by_method/geometry/width.md +0 -0
  17. data/docs/dsl/by_method/geometry/x.md +1 -0
  18. data/docs/dsl/by_method/geometry/xn.md +1 -0
  19. data/docs/dsl/by_method/geometry/y.md +1 -0
  20. data/docs/dsl/by_method/geometry/yn.md +1 -0
  21. data/docs/dsl/by_method/render.md +5 -1
  22. data/docs/dsl/by_method/renders.md +31 -1
  23. data/docs/dsl/by_method/view.md +26 -0
  24. data/docs/dsl/by_method/view/stream.md +18 -0
  25. data/docs/dsl/by_method/views.md +32 -1
  26. data/docs/events/by_name/set_border_caption.md +2 -4
  27. data/docs/events/by_name/set_border_title.md +2 -4
  28. data/examples/views/empty_template.rb +0 -4
  29. data/examples/views/full_screen.rb +30 -5
  30. data/examples/views/misc_view.rb +464 -0
  31. data/examples/views/wordwrap.rb +72 -0
  32. data/examples/views/wordwrap.txt +8 -0
  33. data/integrations/dsl_app_021.rb +127 -0
  34. data/integrations/dsl_app_022.rb +133 -0
  35. data/integrations/expected/342_streams.out +1 -1
  36. data/integrations/expected/dsl_app_001.out +1 -1
  37. data/integrations/expected/dsl_app_002.out +1 -1
  38. data/integrations/expected/dsl_app_003.out +1 -1
  39. data/integrations/expected/dsl_app_004.out +1 -1
  40. data/integrations/expected/dsl_app_005.out +1 -1
  41. data/integrations/expected/dsl_app_006.out +1 -1
  42. data/integrations/expected/dsl_app_007.out +1 -1
  43. data/integrations/expected/dsl_app_008.out +1 -1
  44. data/integrations/expected/dsl_app_009.out +1 -1
  45. data/integrations/expected/dsl_app_010.out +1 -1
  46. data/integrations/expected/dsl_app_011.out +1 -1
  47. data/integrations/expected/dsl_app_012.out +1 -1
  48. data/integrations/expected/dsl_app_013.out +1 -1
  49. data/integrations/expected/dsl_app_014.out +1 -1
  50. data/integrations/expected/dsl_app_015.out +1 -1
  51. data/integrations/expected/dsl_app_016.out +1 -1
  52. data/integrations/expected/dsl_app_021.out +1 -0
  53. data/integrations/expected/dsl_app_022.out +1 -0
  54. data/integrations/support/test_interface_021.rb +7 -0
  55. data/integrations/support/test_interface_022.rb +15 -0
  56. data/lib/vedeu/all.rb +4 -2
  57. data/lib/vedeu/borders/border.rb +22 -6
  58. data/lib/vedeu/borders/repository.rb +4 -8
  59. data/lib/vedeu/buffers/buffer.rb +9 -6
  60. data/lib/vedeu/buffers/empty.rb +26 -23
  61. data/lib/vedeu/buffers/view.rb +44 -41
  62. data/lib/vedeu/cells/cursor.rb +0 -2
  63. data/lib/vedeu/cells/empty.rb +0 -1
  64. data/lib/vedeu/cells/escape.rb +0 -2
  65. data/lib/vedeu/coercers/alignment.rb +58 -8
  66. data/lib/vedeu/coercers/horizontal_alignment.rb +13 -9
  67. data/lib/vedeu/coercers/vertical_alignment.rb +13 -8
  68. data/lib/vedeu/common.rb +1 -1
  69. data/lib/vedeu/configuration/configuration.rb +41 -3
  70. data/lib/vedeu/cursors/coordinate.rb +1 -3
  71. data/lib/vedeu/cursors/cursor.rb +2 -6
  72. data/lib/vedeu/dsl/all.rb +1 -2
  73. data/lib/vedeu/dsl/border.rb +6 -6
  74. data/lib/vedeu/dsl/elements.rb +2 -2
  75. data/lib/vedeu/dsl/geometry.rb +7 -7
  76. data/lib/vedeu/dsl/{string → helpers}/align.rb +0 -0
  77. data/lib/vedeu/dsl/helpers/all.rb +17 -0
  78. data/lib/vedeu/dsl/{attributes.rb → helpers/attributes.rb} +0 -0
  79. data/lib/vedeu/dsl/{string → helpers}/text.rb +0 -0
  80. data/lib/vedeu/dsl/{string → helpers}/truncate.rb +0 -0
  81. data/lib/vedeu/dsl/{string → helpers}/wordwrap.rb +0 -0
  82. data/lib/vedeu/dsl/view.rb +11 -19
  83. data/lib/vedeu/dsl/views.rb +16 -106
  84. data/lib/vedeu/geometries/all.rb +0 -1
  85. data/lib/vedeu/geometries/area/area.rb +6 -12
  86. data/lib/vedeu/geometries/area/dimension.rb +21 -44
  87. data/lib/vedeu/geometries/dsl/all.rb +0 -1
  88. data/lib/vedeu/geometries/dsl/dsl.rb +22 -31
  89. data/lib/vedeu/geometries/geometry.rb +6 -0
  90. data/lib/vedeu/geometries/position.rb +6 -3
  91. data/lib/vedeu/geometries/repository.rb +1 -1
  92. data/lib/vedeu/input/mouse.rb +1 -0
  93. data/lib/vedeu/logging/log.rb +3 -6
  94. data/lib/vedeu/menus/dsl.rb +4 -5
  95. data/lib/vedeu/output/compressor.rb +11 -1
  96. data/lib/vedeu/output/viewport.rb +59 -59
  97. data/lib/vedeu/presentation/all.rb +1 -2
  98. data/lib/vedeu/presentation/colour.rb +75 -3
  99. data/lib/vedeu/{geometries/positionable.rb → presentation/position.rb} +4 -4
  100. data/lib/vedeu/presentation/presentation.rb +1 -3
  101. data/lib/vedeu/presentation/styles.rb +16 -1
  102. data/lib/vedeu/repositories/all.rb +0 -1
  103. data/lib/vedeu/sentence.rb +91 -0
  104. data/lib/vedeu/support/point.rb +72 -0
  105. data/lib/vedeu/terminal/terminal.rb +11 -53
  106. data/lib/vedeu/version.rb +1 -1
  107. data/lib/vedeu/views/composition.rb +11 -1
  108. data/lib/vedeu/views/default_attributes.rb +2 -0
  109. data/lib/vedeu/views/line.rb +16 -1
  110. data/lib/vedeu/views/stream.rb +16 -1
  111. data/lib/vedeu/views/view.rb +25 -17
  112. data/test/lib/vedeu/borders/border_test.rb +20 -2
  113. data/test/lib/vedeu/buffers/buffer_test.rb +15 -2
  114. data/test/lib/vedeu/buffers/empty_test.rb +51 -18
  115. data/test/lib/vedeu/buffers/view_test.rb +2 -2
  116. data/test/lib/vedeu/coercers/alignment_test.rb +32 -0
  117. data/test/lib/vedeu/coercers/horizontal_alignment_test.rb +16 -0
  118. data/test/lib/vedeu/coercers/vertical_alignment_test.rb +16 -0
  119. data/test/lib/vedeu/cursors/cursor_test.rb +4 -4
  120. data/test/lib/vedeu/cursors/dsl_test.rb +35 -21
  121. data/test/lib/vedeu/dsl/elements_test.rb +94 -2
  122. data/test/lib/vedeu/dsl/{string → helpers}/align_test.rb +0 -0
  123. data/test/lib/vedeu/dsl/{attributes_test.rb → helpers/attributes_test.rb} +0 -0
  124. data/test/lib/vedeu/dsl/{string → helpers}/text_test.rb +0 -0
  125. data/test/lib/vedeu/dsl/{string → helpers}/truncate_test.rb +0 -0
  126. data/test/lib/vedeu/dsl/{string → helpers}/wordwrap_test.rb +0 -0
  127. data/test/lib/vedeu/dsl/view_test.rb +22 -4
  128. data/test/lib/vedeu/dsl/views_test.rb +8 -5
  129. data/test/lib/vedeu/geometries/dsl/dsl_test.rb +2 -159
  130. data/test/lib/vedeu/geometries/position_test.rb +118 -60
  131. data/test/lib/vedeu/input/mouse_test.rb +1 -6
  132. data/test/lib/vedeu/logging/log_test.rb +14 -3
  133. data/test/lib/vedeu/presentation/colour_test.rb +77 -0
  134. data/test/lib/vedeu/{geometries/positionable_test.rb → presentation/position_test.rb} +4 -4
  135. data/test/lib/vedeu/sentence_test.rb +49 -0
  136. data/test/lib/vedeu/support/point_test.rb +139 -0
  137. data/test/lib/vedeu/terminal/terminal_test.rb +3 -44
  138. data/test/lib/vedeu/views/composition_test.rb +24 -4
  139. data/test/lib/vedeu/views/default_attributes_test.rb +10 -2
  140. data/test/lib/vedeu/views/view_test.rb +8 -15
  141. data/test/support/examples/material_colours_app.rb +0 -6
  142. data/vedeu.gemspec +1 -1
  143. metadata +58 -38
  144. data/examples/views/lines_line_stream.rb +0 -95
  145. data/examples/views/lines_line_streams.rb +0 -75
  146. data/examples/views/lines_line_streams_stream.rb +0 -78
  147. data/examples/views/lines_line_streams_stream_stream.rb +0 -50
  148. data/examples/views/lines_streams.rb +0 -93
  149. data/lib/vedeu/dsl/string/all.rb +0 -16
  150. data/lib/vedeu/geometries/dsl/validator.rb +0 -62
  151. data/lib/vedeu/presentation/background.rb +0 -54
  152. data/lib/vedeu/presentation/foreground.rb +0 -54
  153. data/lib/vedeu/repositories/parent.rb +0 -34
  154. data/test/lib/vedeu/geometries/dsl/validator_test.rb +0 -85
  155. data/test/lib/vedeu/presentation/background_test.rb +0 -74
  156. data/test/lib/vedeu/presentation/foreground_test.rb +0 -75
@@ -10,17 +10,21 @@ module Vedeu
10
10
  #
11
11
  class HorizontalAlignment < Vedeu::Coercers::Alignment
12
12
 
13
+ # @raise (see Vedeu::Coercers::Alignment#validate)
14
+ # @return (see Vedeu::Coercers::Alignment#validate)
15
+ def validate
16
+ return coerce if valid_horizontal?
17
+
18
+ fail Vedeu::Error::InvalidSyntax,
19
+ 'Missing or invalid horizontal alignment value. ' \
20
+ "Valid values are: #{to_sentence}"
21
+ end
22
+
13
23
  private
14
24
 
15
- # @return [Array<Symbol>]
16
- def values
17
- [
18
- :centre,
19
- :center,
20
- :left,
21
- :none,
22
- :right,
23
- ]
25
+ # @return [String]
26
+ def to_sentence
27
+ Vedeu::Sentence.construct(horizontal_values)
24
28
  end
25
29
 
26
30
  end # HorizontalAlignment
@@ -10,16 +10,21 @@ module Vedeu
10
10
  #
11
11
  class VerticalAlignment < Vedeu::Coercers::Alignment
12
12
 
13
+ # @raise (see Vedeu::Coercers::Alignment#validate)
14
+ # @return (see Vedeu::Coercers::Alignment#validate)
15
+ def validate
16
+ return coerce if valid_vertical?
17
+
18
+ fail Vedeu::Error::InvalidSyntax,
19
+ 'Missing or invalid vertical alignment value. ' \
20
+ "Valid values are: #{to_sentence}"
21
+ end
22
+
13
23
  private
14
24
 
15
- # @return [Array<Symbol>]
16
- def values
17
- [
18
- :bottom,
19
- :middle,
20
- :none,
21
- :top,
22
- ]
25
+ # @return [String]
26
+ def to_sentence
27
+ Vedeu::Sentence.construct(vertical_values)
23
28
  end
24
29
 
25
30
  end # VerticalAlignment
data/lib/vedeu/common.rb CHANGED
@@ -90,7 +90,7 @@ module Vedeu
90
90
  # check.
91
91
  # @return [Boolean]
92
92
  def present?(variable)
93
- return true if variable.is_a?(Fixnum)
93
+ return true if numeric?(variable)
94
94
  return true unless variable.nil? ||
95
95
  (variable.respond_to?(:empty?) && variable.empty?)
96
96
 
@@ -133,9 +133,25 @@ module Vedeu
133
133
 
134
134
  # Returns the client defined height for the terminal.
135
135
  #
136
+ # {include:file:docs/dsl/by_method/height.md}
137
+ #
136
138
  # @return [Fixnum]
137
139
  def height
138
- instance.options[:height]
140
+ if drb?
141
+ drb_height
142
+
143
+ elsif height?
144
+ instance.options[:height]
145
+
146
+ else
147
+ Vedeu::Terminal.size[0]
148
+
149
+ end
150
+ end
151
+
152
+ # @return [Boolean]
153
+ def height?
154
+ instance.options[:height].is_a?(Fixnum)
139
155
  end
140
156
 
141
157
  # Returns whether the application is interactive (required user
@@ -257,9 +273,25 @@ module Vedeu
257
273
 
258
274
  # Returns the client defined width for the terminal.
259
275
  #
276
+ # {include:file:docs/dsl/by_method/width.md}
277
+ #
260
278
  # @return [Fixnum]
261
279
  def width
262
- instance.options[:width]
280
+ if drb?
281
+ drb_width
282
+
283
+ elsif width?
284
+ instance.options[:width]
285
+
286
+ else
287
+ Vedeu::Terminal.size[-1]
288
+
289
+ end
290
+ end
291
+
292
+ # @return [Boolean]
293
+ def width?
294
+ instance.options[:width].is_a?(Fixnum)
263
295
  end
264
296
 
265
297
  # @param value [void]
@@ -374,10 +406,16 @@ module Vedeu
374
406
  # @see Vedeu::Configuration.configure
375
407
  # @!method configuration
376
408
  # @see Vedeu::Configuration.configuration
409
+ # @!method height
410
+ # @see Vedeu::Configuration.height
411
+ # @!method width
412
+ # @see Vedeu::Configuration.width
377
413
  def_delegators Vedeu::Configuration,
378
414
  :config,
379
415
  :configure,
380
- :configuration
416
+ :configuration,
417
+ :height,
418
+ :width
381
419
 
382
420
  # Sets up a default configuration. Client applications calling using
383
421
  # the `Vedeu.configure` API method will override these settings.
@@ -61,9 +61,7 @@ module Vedeu
61
61
 
62
62
  end
63
63
 
64
- pos = pos < bd ? bd : pos
65
- pos = pos > bdn ? bdn : pos
66
- pos
64
+ Vedeu::Point.coerce(value: pos, min: bd, max: bdn).value
67
65
  end
68
66
  alias_method :x, :d_position
69
67
  alias_method :y, :d_position
@@ -244,16 +244,12 @@ module Vedeu
244
244
 
245
245
  # @return [Fixnum] The column/character coordinate.
246
246
  def x
247
- @x = (@x < bx) ? bx : @x
248
- @x = (@x > bxn) ? bxn : @x
249
- @x
247
+ @x = Vedeu::Point.coerce(value: @x, min: bx, max: bxn).value
250
248
  end
251
249
 
252
250
  # @return [Fixnum] The row/line coordinate.
253
251
  def y
254
- @y = (@y < by) ? by : @y
255
- @y = (@y > byn) ? byn : @y
256
- @y
252
+ @y = Vedeu::Point.coerce(value: @y, min: by, max: byn).value
257
253
  end
258
254
 
259
255
  private
data/lib/vedeu/dsl/all.rb CHANGED
@@ -10,11 +10,10 @@ module Vedeu
10
10
 
11
11
  end # Vedeu
12
12
 
13
- require 'vedeu/dsl/string/all'
13
+ require 'vedeu/dsl/helpers/all'
14
14
  require 'vedeu/dsl/border'
15
15
  require 'vedeu/dsl/cursors'
16
16
  require 'vedeu/dsl/dsl'
17
- require 'vedeu/dsl/attributes'
18
17
  require 'vedeu/dsl/geometry'
19
18
  require 'vedeu/dsl/use'
20
19
  require 'vedeu/dsl/presentation'
@@ -27,9 +27,9 @@ module Vedeu
27
27
  # @param name [String|Symbol] The name of the interface or
28
28
  # view to which this border belongs.
29
29
  # @param block [Proc]
30
- # @raise [Vedeu::Error::MissingRequired|
31
- # Vedeu::Error::RequiresBlock] When a name or block
32
- # respectively are not given.
30
+ # @macro raise_requires_block
31
+ # @raise [Vedeu::Error::MissingRequired] When a name is not
32
+ # given.
33
33
  # @return [Vedeu::Borders::Border]
34
34
  # @see Vedeu::Borders::DSL
35
35
  def border(name, &block)
@@ -71,9 +71,9 @@ module Vedeu
71
71
  # setting it here is just mirroring functionality of
72
72
  # {Vedeu::DSL::Border::ClassMethods.border}.
73
73
  # @param block [Proc]
74
- # @raise [Vedeu::Error::MissingRequired|
75
- # Vedeu::Error::RequiresBlock] When a name or block
76
- # respectively are not given.
74
+ # @macro raise_requires_block
75
+ # @raise [Vedeu::Error::MissingRequired] When a name is not
76
+ # given.
77
77
  # @return [Vedeu::Borders::Border]
78
78
  # @see Vedeu::Borders::DSL
79
79
  def border(name = nil, &block)
@@ -63,11 +63,11 @@ module Vedeu
63
63
  # @macro raise_requires_block
64
64
  # @raise [Vedeu::Error::Fatal]
65
65
  # @return [void]
66
- def lines(&block)
66
+ def lines(opts = {}, &block)
67
67
  requires_block!(&block)
68
68
  requires_model!
69
69
 
70
- attrs = Vedeu::DSL::Attributes.build(self, model, nil, {}, &block)
70
+ attrs = Vedeu::DSL::Attributes.build(self, model, nil, opts, &block)
71
71
 
72
72
  if view_model?
73
73
  if model.lines?
@@ -27,9 +27,9 @@ module Vedeu
27
27
  # @param name [String|Symbol] The name of the interface or
28
28
  # view to which this geometry belongs.
29
29
  # @param block [Proc]
30
- # @raise [Vedeu::Error::MissingRequired|
31
- # Vedeu::Error::RequiresBlock] When a name or block
32
- # respectively are not given.
30
+ # @macro raise_requires_block
31
+ # @raise [Vedeu::Error::MissingRequired] When a name is not
32
+ # given.
33
33
  # @return [Vedeu::Geometries::Geometry]
34
34
  # @see Vedeu::Geometries::DSL
35
35
  def geometry(name = nil, &block)
@@ -80,11 +80,11 @@ module Vedeu
80
80
  # @param name [String|Symbol] The name of the interface; this
81
81
  # is already provided when we define the interface or view,
82
82
  # setting it here is just mirroring functionality of
83
- # {Vedeu::DSL::Geometry::ClassMethods.geometry}.
83
+ # {Vedeu::DSL::Geometry::ClassMethods#geometry}.
84
84
  # @param block [Proc]
85
- # @raise [Vedeu::Error::MissingRequired|
86
- # Vedeu::Error::RequiresBlock] When a name or block
87
- # respectively are not given.
85
+ # @macro raise_requires_block
86
+ # @raise [Vedeu::Error::MissingRequired] When a name is not
87
+ # given.
88
88
  # @return [Vedeu::Geometries::Geometry]
89
89
  # @see Vedeu::Geometries::DSL
90
90
  def geometry(name = nil, &block)
File without changes
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Vedeu
4
+
5
+ # Provides a mechanism to help configure and use Vedeu.
6
+ #
7
+ module DSL
8
+
9
+ end # DSL
10
+
11
+ end # Vedeu
12
+
13
+ require 'vedeu/dsl/helpers/attributes'
14
+ require 'vedeu/dsl/helpers/align'
15
+ require 'vedeu/dsl/helpers/truncate'
16
+ require 'vedeu/dsl/helpers/wordwrap'
17
+ require 'vedeu/dsl/helpers/text'
File without changes
File without changes
File without changes
@@ -42,31 +42,22 @@ module Vedeu
42
42
  #
43
43
  class View
44
44
 
45
+ include Vedeu::Common
45
46
  include Vedeu::DSL
46
47
 
47
- # Define a view.
48
- #
49
- # A view is just an Interface object.
50
- #
51
- # When a view already exists, we take its attributes and use
52
- # them as the basis for the newly defined view. This way we
53
- # don't need to specify everything again.
54
- #
55
- # @todo More documentation required.
48
+ # {include:file:docs/dsl/by_method/view.md}
56
49
  # @param name [String|Symbol] The name of the interface you are
57
50
  # targetting for this view.
58
51
  # @param block [Proc] The directives you wish to send to this
59
- # interface.
60
- #
61
- # @example
62
- # view :my_interface do
63
- # # ...
64
- # end
65
- #
52
+ # view.
66
53
  # @macro raise_requires_block
54
+ # @raise [Vedeu::Error::MissingRequired]
67
55
  # @return [Vedeu::Views::Views<Vedeu::Views::View>]
68
- def view(name = '', &block)
56
+ # @todo More documentation required.
57
+ def view(name, &block)
69
58
  fail Vedeu::Error::RequiresBlock unless block_given?
59
+ fail Vedeu::Error::MissingRequired,
60
+ 'Cannot add view without a name.' unless present?(name)
70
61
 
71
62
  new_model = Vedeu::Views::View.build(new_attributes(name), &block)
72
63
 
@@ -97,9 +88,10 @@ module Vedeu
97
88
  def template_for(name, filename, object = nil, options = {})
98
89
  fail Vedeu::Error::MissingRequired,
99
90
  'Cannot render template without the name of the ' \
100
- 'view.' unless name
91
+ 'view.' unless present?(name)
101
92
  fail Vedeu::Error::MissingRequired,
102
- 'Cannot render template without a filename.' unless filename
93
+ 'Cannot render template without a ' \
94
+ 'filename.' unless present?(filename)
103
95
 
104
96
  options.merge!(name: name)
105
97
 
@@ -93,137 +93,47 @@ module Vedeu
93
93
 
94
94
  class << self
95
95
 
96
- include Vedeu::Common
97
-
98
- # Directly write a view buffer to the terminal. Using this
99
- # method means that the refresh event does not need to be
100
- # triggered after creating the views, though can be later
101
- # triggered when needed.
102
- #
103
- # Vedeu.renders do
104
- # view :some_interface do
105
- # line do
106
- # stream do
107
- # left 'Title goes here', width: 35
108
- # end
109
- # stream do
110
- # right Time.now.strftime('%H:%m'), width: 7
111
- # end
112
- # end
113
- # end
114
- # view :other_interface do
115
- # lines do
116
- # line 'This is content for the main interface.'
117
- # line ''
118
- # line 'Pretty easy eh?'
119
- # end
120
- # end
121
- # # ... some code
122
- # end
123
- #
124
- # # or...
125
- #
126
- # Vedeu.render do
127
- # view :my_interface do
128
- # # ... some code
129
- # end
130
- # end
131
- #
96
+ # {include:file:docs/dsl/by_method/renders.md}
132
97
  # @param block [Proc] The directives you wish to send to
133
98
  # render. Typically includes `view` with associated
134
99
  # sub-directives.
135
100
  # @macro raise_requires_block
136
- # @return [Array<View>]
101
+ # @return [Vedeu::Views::Composition]
137
102
  def renders(&block)
138
103
  fail Vedeu::Error::RequiresBlock unless block_given?
139
104
 
140
- store(:store_immediate, client(&block), &block)
105
+ composition(eval('self', block.binding), true, &block)
141
106
  end
142
107
  alias_method :render, :renders
143
108
 
144
- # Define a view (content) for an interface.
145
- #
146
- # As you can see by comparing the examples above to these
147
- # below, the immediate render simply wraps what is already
148
- # here in the deferred view.
149
- #
150
- # The views declared within this block are stored in their
151
- # respective interface back buffers until a refresh event
152
- # occurs. When the refresh event is triggered, the back
153
- # buffers are swapped into the front buffers and the content
154
- # here will be rendered to {Vedeu::Terminal#output}.
155
- #
156
- # Vedeu.views do
157
- # view :some_interface do
158
- # line do
159
- # stream do
160
- # left 'Title goes here', width: 35
161
- # end
162
- # stream do
163
- # right Time.now.strftime('%H:%m'), width: 7
164
- # end
165
- # end
166
- # end
167
- # view :other_interface do
168
- # lines do
169
- # line 'This is content for the main interface.'
170
- # line ''
171
- # line 'Pretty easy eh?'
172
- # end
173
- # end
174
- # # ... some code
175
- # end
176
- #
109
+ # {include:file:docs/dsl/by_method/views.md}
177
110
  # @param block [Proc] The directives you wish to send to
178
111
  # render. Typically includes `view` with associated
179
112
  # sub-directives.
180
113
  # @macro raise_requires_block
181
- # @return [Array<View>]
114
+ # @return [Vedeu::Views::Composition]
182
115
  def views(&block)
183
116
  fail Vedeu::Error::RequiresBlock unless block_given?
184
117
 
185
- store(:store_deferred, client(&block), &block)
118
+ composition(eval('self', block.binding), false, &block)
186
119
  end
187
120
 
188
121
  private
189
122
 
190
- # Returns the client object which called the DSL method.
191
- #
192
- # @param block [Proc]
193
- # @return [Object]
194
- def client(&block)
195
- eval('self', block.binding)
196
- end
197
-
198
123
  # Creates a new Vedeu::Views::Composition which may contain
199
- # one or more views (Vedeu::Views::View objects).
124
+ # one or more view {Vedeu::Views::View} objects.
200
125
  #
201
- # @param client [Object]
202
- # @param block [Proc]
203
- # @return [Vedeu::Views::Composition]
204
- def composition(client, &block)
205
- attrs = { client: client, colour: Vedeu.config.colour }
206
-
207
- Vedeu::Views::Composition.build(attrs, &block)
208
- end
209
-
210
- # Creates a new Vedeu::Views::Composition which may contain
211
- # one or more views (Vedeu::Views::View objects).
212
- #
213
- # Stores each of the views defined in their respective buffers
214
- # ready to be rendered on next refresh.
215
- #
216
- # @param method [Symbol] An instruction; `:store_immediate` or
217
- # `:store_deferred` which determines whether the view will
218
- # be shown immediately or later respectively.
219
126
  # @param client [Object] The client class which called the DSL
220
127
  # object.
221
- # @param block [Proc]
222
- # @return [Array]
223
- def store(method, client, &block)
224
- composition(client, &block).views.map do |view|
225
- view.public_send(method)
226
- end
128
+ # @param refresh [Boolean]
129
+ # @param block [Proc] The directives you wish to send to
130
+ # render. Typically includes `view` with associated
131
+ # sub-directives.
132
+ # # @return [Vedeu::Views::Composition]
133
+ def composition(client, refresh = false, &block)
134
+ attrs = { client: client, colour: Vedeu.config.colour }
135
+
136
+ Vedeu::Views::Composition.build(attrs, &block).update_buffers(refresh)
227
137
  end
228
138
 
229
139
  end # Eigenclass