vedeu 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/docs/dsl.md +3 -3
  3. data/examples/borders_app.rb +2 -0
  4. data/examples/colours_app.rb +2 -0
  5. data/examples/configuration_app.rb +2 -0
  6. data/examples/drb_app.rb +2 -0
  7. data/examples/focus_app.rb +2 -0
  8. data/examples/hello_world.rb +2 -0
  9. data/examples/material_colours_app.rb +2 -0
  10. data/lib/vedeu.rb +2 -0
  11. data/lib/vedeu/all.rb +4 -13
  12. data/lib/vedeu/api.rb +7 -6
  13. data/lib/vedeu/borders/border.rb +1 -1
  14. data/lib/vedeu/borders/render_border.rb +18 -18
  15. data/lib/vedeu/buffers/buffer.rb +18 -28
  16. data/lib/vedeu/colours/colour.rb +1 -1
  17. data/lib/vedeu/colours/colour_translator.rb +1 -1
  18. data/lib/vedeu/cursor/cursor.rb +9 -6
  19. data/lib/vedeu/dsl/border.rb +1 -1
  20. data/lib/vedeu/dsl/composition.rb +5 -5
  21. data/lib/vedeu/dsl/geometry.rb +1 -1
  22. data/lib/vedeu/dsl/group.rb +1 -1
  23. data/lib/vedeu/dsl/interface.rb +69 -93
  24. data/lib/vedeu/dsl/keymap.rb +1 -1
  25. data/lib/vedeu/dsl/line.rb +11 -11
  26. data/lib/vedeu/dsl/shared.rb +81 -0
  27. data/lib/vedeu/dsl/stream.rb +3 -3
  28. data/lib/vedeu/dsl/view.rb +76 -64
  29. data/lib/vedeu/models/escape.rb +1 -1
  30. data/lib/vedeu/models/interface.rb +3 -57
  31. data/lib/vedeu/models/menu.rb +1 -1
  32. data/lib/vedeu/models/views/all.rb +22 -0
  33. data/lib/vedeu/models/views/char.rb +175 -0
  34. data/lib/vedeu/models/views/chars.rb +13 -0
  35. data/lib/vedeu/models/views/composition.rb +73 -0
  36. data/lib/vedeu/models/views/line.rb +111 -0
  37. data/lib/vedeu/models/views/lines.rb +13 -0
  38. data/lib/vedeu/models/views/stream.rb +122 -0
  39. data/lib/vedeu/models/views/streams.rb +13 -0
  40. data/lib/vedeu/models/views/view.rb +157 -0
  41. data/lib/vedeu/models/views/view_collection.rb +13 -0
  42. data/lib/vedeu/null/view.rb +67 -0
  43. data/lib/vedeu/output/clear/named_interface.rb +4 -4
  44. data/lib/vedeu/output/compressor.rb +6 -6
  45. data/lib/vedeu/output/html_char.rb +6 -6
  46. data/lib/vedeu/output/output.rb +3 -3
  47. data/lib/vedeu/output/presentation.rb +1 -1
  48. data/lib/vedeu/output/renderers/escape_sequence.rb +1 -1
  49. data/lib/vedeu/output/renderers/file.rb +1 -1
  50. data/lib/vedeu/output/renderers/html.rb +3 -3
  51. data/lib/vedeu/output/renderers/json.rb +4 -4
  52. data/lib/vedeu/output/renderers/null.rb +1 -1
  53. data/lib/vedeu/output/renderers/terminal.rb +5 -5
  54. data/lib/vedeu/output/renderers/text.rb +3 -3
  55. data/lib/vedeu/output/style.rb +1 -1
  56. data/lib/vedeu/output/text.rb +20 -15
  57. data/lib/vedeu/output/viewport.rb +16 -23
  58. data/lib/vedeu/output/virtual_buffer.rb +9 -8
  59. data/lib/vedeu/output/virtual_terminal.rb +11 -11
  60. data/lib/vedeu/output/wordwrap.rb +5 -5
  61. data/lib/vedeu/runtime/application.rb +1 -1
  62. data/lib/vedeu/runtime/main_loop.rb +1 -1
  63. data/lib/vedeu/templating/helpers.rb +11 -10
  64. data/lib/vedeu/templating/template.rb +1 -1
  65. data/lib/vedeu/templating/view_template.rb +6 -6
  66. data/lib/vedeu/version.rb +1 -2
  67. data/test/lib/vedeu/api_test.rb +30 -30
  68. data/test/lib/vedeu/buffers/buffer_test.rb +5 -139
  69. data/test/lib/vedeu/colours/colour_translator_test.rb +3 -3
  70. data/test/lib/vedeu/configuration/api_test.rb +3 -3
  71. data/test/lib/vedeu/cursor/refresh_cursor_test.rb +1 -1
  72. data/test/lib/vedeu/dsl/composition_test.rb +7 -7
  73. data/test/lib/vedeu/dsl/group_test.rb +2 -2
  74. data/test/lib/vedeu/dsl/interface_test.rb +31 -21
  75. data/test/lib/vedeu/dsl/keymap_test.rb +4 -4
  76. data/test/lib/vedeu/dsl/line_test.rb +8 -8
  77. data/test/lib/vedeu/dsl/stream_test.rb +4 -4
  78. data/test/lib/vedeu/dsl/text_test.rb +11 -11
  79. data/test/lib/vedeu/dsl/view_test.rb +24 -29
  80. data/test/lib/vedeu/geometry/grid_test.rb +4 -4
  81. data/test/lib/vedeu/input/key_test.rb +1 -1
  82. data/test/lib/vedeu/internal_api_test.rb +18 -18
  83. data/test/lib/vedeu/models/focus_test.rb +54 -54
  84. data/test/lib/vedeu/models/interface_test.rb +11 -105
  85. data/test/lib/vedeu/models/menu_test.rb +1 -1
  86. data/test/lib/vedeu/models/views/char_test.rb +257 -0
  87. data/test/lib/vedeu/models/views/chars_test.rb +22 -0
  88. data/test/lib/vedeu/models/views/composition_test.rb +61 -0
  89. data/test/lib/vedeu/models/views/line_test.rb +189 -0
  90. data/test/lib/vedeu/models/views/lines_test.rb +22 -0
  91. data/test/lib/vedeu/models/views/stream_test.rb +138 -0
  92. data/test/lib/vedeu/models/views/streams_test.rb +22 -0
  93. data/test/lib/vedeu/models/views/view_test.rb +40 -0
  94. data/test/lib/vedeu/null/view_test.rb +12 -0
  95. data/test/lib/vedeu/output/clear/named_interface_test.rb +4 -4
  96. data/test/lib/vedeu/output/compressor_test.rb +28 -28
  97. data/test/lib/vedeu/output/html_char_test.rb +2 -2
  98. data/test/lib/vedeu/output/presentation_test.rb +10 -14
  99. data/test/lib/vedeu/output/renderers/escape_sequence_test.rb +20 -4
  100. data/test/lib/vedeu/output/renderers/html_test.rb +4 -4
  101. data/test/lib/vedeu/output/renderers/json_test.rb +3 -3
  102. data/test/lib/vedeu/output/text_test.rb +10 -10
  103. data/test/lib/vedeu/output/viewport_test.rb +21 -23
  104. data/test/lib/vedeu/output/virtual_buffer_test.rb +1 -1
  105. data/test/lib/vedeu/output/virtual_terminal_test.rb +1 -1
  106. data/test/lib/vedeu/output/wordwrap_test.rb +9 -9
  107. data/test/lib/vedeu/repositories/repository_test.rb +2 -2
  108. data/test/lib/vedeu/templating/helpers_test.rb +6 -39
  109. data/test/lib/vedeu/templating/template_test.rb +2 -2
  110. data/test/lib/vedeu/templating/view_template_test.rb +91 -91
  111. data/test/lib/vedeu/terminal_test.rb +1 -1
  112. metadata +33 -27
  113. data/lib/vedeu/buffers/display_buffer.rb +0 -39
  114. data/lib/vedeu/models/char.rb +0 -170
  115. data/lib/vedeu/models/chars.rb +0 -9
  116. data/lib/vedeu/models/composition.rb +0 -66
  117. data/lib/vedeu/models/line.rb +0 -112
  118. data/lib/vedeu/models/lines.rb +0 -9
  119. data/lib/vedeu/models/stream.rb +0 -122
  120. data/lib/vedeu/models/streams.rb +0 -9
  121. data/test/lib/vedeu/buffers/display_buffer_test.rb +0 -61
  122. data/test/lib/vedeu/models/char_test.rb +0 -253
  123. data/test/lib/vedeu/models/chars_test.rb +0 -18
  124. data/test/lib/vedeu/models/composition_test.rb +0 -57
  125. data/test/lib/vedeu/models/line_test.rb +0 -189
  126. data/test/lib/vedeu/models/lines_test.rb +0 -18
  127. data/test/lib/vedeu/models/stream_test.rb +0 -141
  128. data/test/lib/vedeu/models/streams_test.rb +0 -18
@@ -46,7 +46,7 @@ module Vedeu
46
46
  def self.border(name, &block)
47
47
  fail Vedeu::InvalidSyntax, 'block not given' unless block_given?
48
48
 
49
- Vedeu::Border.build({ enabled: true, name: name }, &block).store
49
+ Vedeu::Border.build(enabled: true, name: name, &block).store
50
50
  end
51
51
 
52
52
  # Returns an instance of DSL::Border.
@@ -42,7 +42,7 @@ module Vedeu
42
42
 
43
43
  # Returns an instance of DSL::Composition.
44
44
  #
45
- # @param model [Vedeu::Composition]
45
+ # @param model [Vedeu::Views::Composition]
46
46
  # @param client [Object]
47
47
  # @return [Vedeu::DSL::Composition]
48
48
  def initialize(model, client = nil)
@@ -69,7 +69,7 @@ module Vedeu
69
69
  # end
70
70
  #
71
71
  # @raise [Vedeu::InvalidSyntax] The required block was not given.
72
- # @return [Vedeu::InterfaceCollection<Vedeu::Interface>]
72
+ # @return [Vedeu::Views::Views<Vedeu::Views::View>]
73
73
  def view(name = '', &block)
74
74
  fail Vedeu::InvalidSyntax, 'block not given' unless block_given?
75
75
 
@@ -97,7 +97,7 @@ module Vedeu
97
97
  # @param object [Object] The object for which the values of template's
98
98
  # variables can be obtained.
99
99
  # @param options [Hash] See {Vedeu::Wordwrap}
100
- # @return [Vedeu::InterfaceCollection<Vedeu::Interface>]
100
+ # @return [Vedeu::Views::Views<Vedeu::Views::View>]
101
101
  def template_for(name, filename, object = nil, options = {})
102
102
  fail Vedeu::MissingRequired,
103
103
  'Cannot render template without the name of the view.' unless name
@@ -124,13 +124,13 @@ module Vedeu
124
124
  attr_reader :client
125
125
 
126
126
  # @!attribute [r] model
127
- # @return [Vedeu::Composition]
127
+ # @return [Vedeu::Views::Composition]
128
128
  attr_reader :model
129
129
 
130
130
  private
131
131
 
132
132
  # @param name [String]
133
- # @param lines [Vedeu::Lines]
133
+ # @param lines [Vedeu::Views::Lines]
134
134
  # @return [Hash]
135
135
  def template_attributes(name, lines)
136
136
  new_attributes(name).merge!(lines: lines)
@@ -87,7 +87,7 @@ module Vedeu
87
87
  def self.geometry(name, &block)
88
88
  fail Vedeu::InvalidSyntax, 'block not given' unless block_given?
89
89
 
90
- Vedeu::Geometry.build({ name: name }, &block).store
90
+ Vedeu::Geometry.build(name: name, &block).store
91
91
  end
92
92
 
93
93
  # Returns an instance of DSL::Geometry.
@@ -46,7 +46,7 @@ module Vedeu
46
46
  def self.group(name, &block)
47
47
  fail Vedeu::InvalidSyntax, 'block not given' unless block_given?
48
48
 
49
- Vedeu::Group.build({ name: name }, &block).store
49
+ Vedeu::Group.build(name: name, &block).store
50
50
  end
51
51
 
52
52
  # Returns an instance of DSL::Group.
@@ -9,9 +9,78 @@ module Vedeu
9
9
  include Vedeu::Common
10
10
  include Vedeu::DSL
11
11
  include Vedeu::DSL::Presentation
12
+ include Vedeu::DSL::Shared
12
13
  include Vedeu::DSL::Text
13
14
  include Vedeu::DSL::Use
14
15
 
16
+ class << self
17
+
18
+ include Vedeu::Common
19
+
20
+ # Register an interface by name which will display output from a event
21
+ # or command. This provides the means for you to define your the views
22
+ # of your application without their content.
23
+ #
24
+ # Vedeu.interface 'my_interface' do
25
+ # # ... some code
26
+ # end
27
+ #
28
+ # @param name [String] The name of the interface. Used to reference the
29
+ # interface throughout your application's execution lifetime.
30
+ # @param block [Proc] A set of attributes which define the features of
31
+ # the interface.
32
+ # @raise [Vedeu::InvalidSyntax] The required block was not given.
33
+ # @return [Vedeu::Interface]
34
+ # @todo More documentation required.
35
+ def interface(name, &block)
36
+ fail Vedeu::InvalidSyntax, 'block not given' unless block_given?
37
+ fail Vedeu::MissingRequired, 'name not given' unless present?(name)
38
+
39
+ add_buffers!(name)
40
+ add_cursor!(name)
41
+ add_focusable!(name)
42
+
43
+ attributes = { client: client(&block), name: name }
44
+
45
+ Vedeu::Interface.build(attributes, &block).store
46
+ end
47
+
48
+ private
49
+
50
+ # Registers a set of buffers for the interface unless already
51
+ # registered, and also adds interface's name to list of focussable
52
+ # interfaces.
53
+ #
54
+ # @see Vedeu::Buffer
55
+ # @return [void]
56
+ def add_buffers!(name)
57
+ Vedeu::Buffer.new(name: name).store
58
+ end
59
+
60
+ # Registers a new cursor for the interface unless already registered.
61
+ #
62
+ # @return [void]
63
+ def add_cursor!(name)
64
+ Vedeu::Cursor.new(name: name).store
65
+ end
66
+
67
+ # Registers interface name in focus list unless already registered.
68
+ #
69
+ # @return [void]
70
+ def add_focusable!(name)
71
+ Vedeu.focusable.add(name) unless Vedeu.focusable.registered?(name)
72
+ end
73
+
74
+ # Returns the client object which called the DSL method.
75
+ #
76
+ # @param block [Proc]
77
+ # @return [Object]
78
+ def client(&block)
79
+ eval('self', block.binding)
80
+ end
81
+
82
+ end # Eigenclass
83
+
15
84
  # Returns an instance of Vedeu::DSL::Interface.
16
85
  #
17
86
  # @param model [Vedeu::DSL::Interface]
@@ -22,49 +91,6 @@ module Vedeu
22
91
  @client = client
23
92
  end
24
93
 
25
- # Allows the setting of a border for the interface.
26
- #
27
- # @example
28
- # Vedeu.interface 'my_interface' do
29
- # border do
30
- # # ... see Vedeu::DSL::Border for DSL methods for borders.
31
- # end
32
- # end
33
- #
34
- # @param name [String] The name of the interface; this is already provided
35
- # when we define the interface or view, setting it here is just
36
- # mirroring functionality of {Vedeu::DSL::Border.border}.
37
- # @param block [Proc]
38
- # @raise [Vedeu::InvalidSyntax] The required block was not given.
39
- # @return [Vedeu::Border]
40
- # @see Vedeu::DSL::Border
41
- def border(name = nil, &block)
42
- fail Vedeu::InvalidSyntax, 'block not given' unless block_given?
43
-
44
- model_name = name ? name : model.name
45
-
46
- border_attrs = attributes.merge!(enabled: true,
47
- name: model_name)
48
-
49
- Vedeu::Border.build(border_attrs, &block).store
50
- end
51
-
52
- # Applies the default border to the interface.
53
- #
54
- # @example
55
- # Vedeu.interface 'my_interface' do
56
- # border!
57
- #
58
- # # ... some code
59
- # end
60
- #
61
- # @return [Vedeu::Border]
62
- def border!
63
- border do
64
- # adds default border
65
- end
66
- end
67
-
68
94
  # Set the cursor visibility on an interface.
69
95
  #
70
96
  # @param value [Boolean] Any value other than nil or false will evaluate
@@ -141,30 +167,6 @@ module Vedeu
141
167
  Vedeu::Focus.add(model.name, true) if present?(model.name)
142
168
  end
143
169
 
144
- # Define the geometry for an interface.
145
- #
146
- # @example
147
- # Vedeu.interface 'my_interface' do
148
- # geometry do
149
- # # ... see Vedeu::DSL::Geometry for DSL methods for geometries.
150
- # end
151
- # end
152
- #
153
- # @param name [String] The name of the interface; this is already provided
154
- # when we define the interface or view, setting it here is just
155
- # mirroring functionality of {Vedeu::DSL::Geometry.geometry}.
156
- # @param block [Proc]
157
- # @raise [Vedeu::InvalidSyntax] The required block was not given.
158
- # @return [Vedeu::Geometry]
159
- # @see Vedeu::DSL::Geometry
160
- def geometry(name = nil, &block)
161
- fail Vedeu::InvalidSyntax, 'block not given' unless block_given?
162
-
163
- model_name = name ? name : model.name
164
-
165
- Vedeu::Geometry.build({ name: model_name }, &block).store
166
- end
167
-
168
170
  # Specify a group for an interface. Interfaces of the same group can be
169
171
  # targetted together; for example you may want to refresh multiple
170
172
  # interfaces at once.
@@ -192,32 +194,6 @@ module Vedeu
192
194
  end
193
195
  alias_method :keys, :keymap
194
196
 
195
- # Specify multiple lines in a view.
196
- #
197
- # @param block [Proc]
198
- #
199
- # @example
200
- # Vedeu.view 'my_interface' do
201
- # lines do
202
- # # ... see {Vedeu::DSL::Line} and {Vedeu::DSL::Stream}
203
- # end
204
- # end
205
- #
206
- # Vedeu.view 'my_interface' do
207
- # line do
208
- # # ... see {Vedeu::DSL::Line} and {Vedeu::DSL::Stream}
209
- # end
210
- # end
211
- #
212
- # @raise [Vedeu::InvalidSyntax] The required block was not given.
213
- # @return [Line]
214
- def lines(&block)
215
- fail Vedeu::InvalidSyntax, 'block not given' unless block_given?
216
-
217
- model.add(model.member.build(attributes, &block))
218
- end
219
- alias_method :line, :lines
220
-
221
197
  # The name of the interface. Used to reference the interface throughout
222
198
  # your application's execution lifetime.
223
199
  #
@@ -54,7 +54,7 @@ module Vedeu
54
54
  def self.keymap(name, &block)
55
55
  Vedeu::Keymap.new(name: name).store
56
56
 
57
- Vedeu::Keymap.build({ name: name }, &block).store
57
+ Vedeu::Keymap.build(name: name, &block).store
58
58
  end
59
59
 
60
60
  # Returns an instance of DSL::Keymap.
@@ -38,7 +38,7 @@ module Vedeu
38
38
 
39
39
  # Returns an instance of DSL::Line.
40
40
  #
41
- # @param model [Vedeu::Line]
41
+ # @param model [Vedeu::Views::Line]
42
42
  # @param client [Object]
43
43
  # @return [Vedeu::DSL::Line]
44
44
  def initialize(model, client = nil)
@@ -60,16 +60,16 @@ module Vedeu
60
60
  # end
61
61
  #
62
62
  # @raise [Vedeu::InvalidSyntax] When no block or value is provided.
63
- # @return [Vedeu::Lines]
63
+ # @return [Vedeu::Views::Lines]
64
64
  def line(value = '', &block)
65
65
  if block_given?
66
- content = Vedeu::Line.build({ client: client,
67
- parent: model.parent }, &block)
66
+ content = Vedeu::Views::Line.build(client: client,
67
+ parent: model.parent, &block)
68
68
 
69
69
  elsif value
70
- content = Vedeu::Line.build(client: client,
71
- parent: model.parent,
72
- streams: [build_stream(value)])
70
+ content = Vedeu::Views::Line.build(client: client,
71
+ parent: model.parent,
72
+ streams: [build_stream(value)])
73
73
 
74
74
  else
75
75
  fail Vedeu::InvalidSyntax, 'block not given'
@@ -98,7 +98,7 @@ module Vedeu
98
98
  #
99
99
  # @param block [Proc]
100
100
  # @raise [Vedeu::InvalidSyntax] The required block was not given.
101
- # @return [Vedeu::Streams<Vedeu::Stream>]
101
+ # @return [Vedeu::Views::Streams<Vedeu::Views::Stream>]
102
102
  # @see Vedeu::DSL::Stream for subdirectives.
103
103
  def streams(&block)
104
104
  fail Vedeu::InvalidSyntax, 'block not given' unless block_given?
@@ -114,7 +114,7 @@ module Vedeu
114
114
  attr_reader :client
115
115
 
116
116
  # @!attribute [r] model
117
- # @return [Vedeu::Line]
117
+ # @return [Vedeu::Views::Line]
118
118
  attr_reader :model
119
119
 
120
120
  private
@@ -128,9 +128,9 @@ module Vedeu
128
128
  end
129
129
 
130
130
  # @param value [String]
131
- # @return [Vedeu::Stream]
131
+ # @return [Vedeu::Views::Stream]
132
132
  def build_stream(value)
133
- Vedeu::Stream.build(client: client, parent: model, value: value)
133
+ Vedeu::Views::Stream.build(client: client, parent: model, value: value)
134
134
  end
135
135
 
136
136
  end # Line
@@ -0,0 +1,81 @@
1
+ module Vedeu
2
+
3
+ module DSL
4
+
5
+ # Provides behaviour to be shared between both {Vedeu::DSL::Interface} and
6
+ # {Vedeu::DSL::View} objects.
7
+ #
8
+ module Shared
9
+
10
+ # Allows the setting of a border for the interface.
11
+ #
12
+ # @example
13
+ # Vedeu.interface 'my_interface' do
14
+ # border do
15
+ # # ... see Vedeu::DSL::Border for DSL methods for borders.
16
+ # end
17
+ # end
18
+ #
19
+ # @param name [String] The name of the interface; this is already provided
20
+ # when we define the interface or view, setting it here is just
21
+ # mirroring functionality of {Vedeu::DSL::Border.border}.
22
+ # @param block [Proc]
23
+ # @raise [Vedeu::InvalidSyntax] The required block was not given.
24
+ # @return [Vedeu::Border]
25
+ # @see Vedeu::DSL::Border
26
+ def border(name = nil, &block)
27
+ fail Vedeu::InvalidSyntax, 'block not given' unless block_given?
28
+
29
+ model_name = name ? name : model.name
30
+
31
+ border_attrs = attributes.merge!(enabled: true,
32
+ name: model_name)
33
+
34
+ Vedeu::Border.build(border_attrs, &block).store
35
+ end
36
+
37
+ # Applies the default border to the interface.
38
+ #
39
+ # @example
40
+ # Vedeu.interface 'my_interface' do
41
+ # border!
42
+ #
43
+ # # ... some code
44
+ # end
45
+ #
46
+ # @return [Vedeu::Border]
47
+ def border!
48
+ border do
49
+ # adds default border
50
+ end
51
+ end
52
+
53
+ # Define the geometry for an interface.
54
+ #
55
+ # @example
56
+ # Vedeu.interface 'my_interface' do
57
+ # geometry do
58
+ # # ... see Vedeu::DSL::Geometry for DSL methods for geometries.
59
+ # end
60
+ # end
61
+ #
62
+ # @param name [String] The name of the interface; this is already provided
63
+ # when we define the interface or view, setting it here is just
64
+ # mirroring functionality of {Vedeu::DSL::Geometry.geometry}.
65
+ # @param block [Proc]
66
+ # @raise [Vedeu::InvalidSyntax] The required block was not given.
67
+ # @return [Vedeu::Geometry]
68
+ # @see Vedeu::DSL::Geometry
69
+ def geometry(name = nil, &block)
70
+ fail Vedeu::InvalidSyntax, 'block not given' unless block_given?
71
+
72
+ model_name = name ? name : model.name
73
+
74
+ Vedeu::Geometry.build(name: model_name, &block).store
75
+ end
76
+
77
+ end # Shared
78
+
79
+ end # DSL
80
+
81
+ end # Vedeu
@@ -10,9 +10,9 @@ module Vedeu
10
10
  include Vedeu::DSL::Presentation
11
11
  include Vedeu::DSL::Text
12
12
 
13
- # Returns an instance of DSL::Stream.
13
+ # Returns an instance of Vedeu::DSL::Stream.
14
14
  #
15
- # @param model [Vedeu::Stream]
15
+ # @param model [Vedeu::Views::Stream]
16
16
  # @param client [Object]
17
17
  # @return [Vedeu::DSL::Stream]
18
18
  def initialize(model, client = nil)
@@ -36,7 +36,7 @@ module Vedeu
36
36
  attr_reader :client
37
37
 
38
38
  # @!attribute [r] model
39
- # @return [Stream]
39
+ # @return [Vedeu::Views::Stream]
40
40
  attr_reader :model
41
41
 
42
42
  private
@@ -8,9 +8,10 @@ module Vedeu
8
8
  #
9
9
  # Both of these approaches require that you have defined an interface (or
10
10
  # 'visible area') first. You can find out how to define an interface with
11
- # Vedeu here. The examples in 'Immediate Render' and 'Deferred View' use
12
- # these interface definitions: (Note: should you use these examples, ensure
13
- # your terminal is at least 70 characters in width and 5 lines in height.)
11
+ # Vedeu below or in {Vedeu::DSL::Interface}. The examples in 'Immediate
12
+ # Render' and 'Deferred View' use these interface definitions: (Note: should
13
+ # you use these examples, ensure your terminal is at least 70 characters in
14
+ # width and 5 lines in height.)
14
15
  #
15
16
  # Vedeu.interface 'main' do
16
17
  # geometry do
@@ -79,38 +80,17 @@ module Vedeu
79
80
  #
80
81
  class View
81
82
 
83
+ include Vedeu::Common
84
+ include Vedeu::DSL
85
+ include Vedeu::DSL::Presentation
86
+ include Vedeu::DSL::Shared
87
+ include Vedeu::DSL::Text
88
+ include Vedeu::DSL::Use
89
+
82
90
  class << self
83
91
 
84
92
  include Vedeu::Common
85
93
 
86
- # Register an interface by name which will display output from a event
87
- # or command. This provides the means for you to define your the views
88
- # of your application without their content.
89
- #
90
- # Vedeu.interface 'my_interface' do
91
- # # ... some code
92
- # end
93
- #
94
- # @param name [String] The name of the interface. Used to reference the
95
- # interface throughout your application's execution lifetime.
96
- # @param block [Proc] A set of attributes which define the features of
97
- # the interface.
98
- # @raise [Vedeu::InvalidSyntax] The required block was not given.
99
- # @return [Vedeu::Interface]
100
- # @todo More documentation required.
101
- def interface(name, &block)
102
- fail Vedeu::InvalidSyntax, 'block not given' unless block_given?
103
- fail Vedeu::MissingRequired, 'name not given' unless present?(name)
104
-
105
- add_buffers!(name)
106
- add_cursor!(name)
107
- add_focusable!(name)
108
-
109
- attributes = { client: client(&block), name: name }
110
-
111
- Vedeu::Interface.build(attributes, &block).store
112
- end
113
-
114
94
  # Directly write a view buffer to the terminal. Using this method means
115
95
  # that the refresh event does not need to be triggered after creating
116
96
  # the views, though can be later triggered when needed.
@@ -147,7 +127,7 @@ module Vedeu
147
127
  # @param block [Proc] The directives you wish to send to render.
148
128
  # Typically includes `view` with associated sub-directives.
149
129
  # @raise [Vedeu::InvalidSyntax] The required block was not given.
150
- # @return [Array<Interface>]
130
+ # @return [Array<View>]
151
131
  def render(&block)
152
132
  fail Vedeu::InvalidSyntax, 'block not given' unless block_given?
153
133
 
@@ -191,39 +171,15 @@ module Vedeu
191
171
  # @param block [Proc] The directives you wish to send to render.
192
172
  # Typically includes `view` with associated sub-directives.
193
173
  # @raise [Vedeu::InvalidSyntax] The required block was not given.
194
- # @return [Array<Interface>]
195
- def view(&block)
174
+ # @return [Array<View>]
175
+ def views(&block)
196
176
  fail Vedeu::InvalidSyntax, 'block not given' unless block_given?
197
177
 
198
178
  store(:store_deferred, &block)
199
179
  end
200
- alias_method :views, :view
201
180
 
202
181
  private
203
182
 
204
- # Registers a set of buffers for the interface unless already registered,
205
- # and also adds interface's name to list of focussable interfaces.
206
- #
207
- # @see Vedeu::Buffer
208
- # @return [void]
209
- def add_buffers!(name)
210
- Vedeu::Buffer.new(name: name).store
211
- end
212
-
213
- # Registers a new cursor for the interface unless already registered.
214
- #
215
- # @return [void]
216
- def add_cursor!(name)
217
- Vedeu::Cursor.new(name: name).store
218
- end
219
-
220
- # Registers interface name in focus list unless already registered.
221
- #
222
- # @return [void]
223
- def add_focusable!(name)
224
- Vedeu.focusable.add(name) unless Vedeu.focusable.registered?(name)
225
- end
226
-
227
183
  # Returns the client object which called the DSL method.
228
184
  #
229
185
  # @param block [Proc]
@@ -232,14 +188,14 @@ module Vedeu
232
188
  eval('self', block.binding)
233
189
  end
234
190
 
235
- # Creates a new Composition which may contain one or more views
236
- # (Interface objects).
191
+ # Creates a new Vedeu::Views::Composition which may contain one or more
192
+ # views (Vedeu::Views::View objects).
237
193
  #
238
194
  # @param client [Object]
239
195
  # @param block [Proc]
240
- # @return [Vedeu::Composition]
196
+ # @return [Vedeu::Views::Composition]
241
197
  def composition(client, &block)
242
- Vedeu::Composition.build({ client: client }, &block)
198
+ Vedeu::Views::Composition.build(client: client, &block)
243
199
  end
244
200
 
245
201
  # Stores each of the views defined in their respective buffers ready to
@@ -251,13 +207,69 @@ module Vedeu
251
207
  # @param block [Proc]
252
208
  # @return [Array]
253
209
  def store(method, &block)
254
- composition(client(&block), &block).interfaces.map do |interface|
255
- interface.public_send(method)
210
+ composition(client(&block), &block).views.map do |view|
211
+ view.public_send(method)
256
212
  end
257
213
  end
258
214
 
259
215
  end # Eigenclass
260
216
 
217
+ # Returns an instance of Vedeu::DSL::View.
218
+ #
219
+ # @param model [Vedeu::DSL::View]
220
+ # @param client [Object]
221
+ # @return [Vedeu::DSL::View]
222
+ def initialize(model, client = nil)
223
+ @model = model
224
+ @client = client
225
+ end
226
+
227
+ # Specify multiple lines in a view.
228
+ #
229
+ # @param block [Proc]
230
+ #
231
+ # @example
232
+ # Vedeu.view 'my_interface' do
233
+ # lines do
234
+ # # ... see {Vedeu::DSL::Line} and {Vedeu::DSL::Stream}
235
+ # end
236
+ # end
237
+ #
238
+ # Vedeu.view 'my_interface' do
239
+ # line do
240
+ # # ... see {Vedeu::DSL::Line} and {Vedeu::DSL::Stream}
241
+ # end
242
+ # end
243
+ #
244
+ # @raise [Vedeu::InvalidSyntax] The required block was not given.
245
+ # @return [Vedeu::Views::Line]
246
+ def lines(&block)
247
+ fail Vedeu::InvalidSyntax, 'block not given' unless block_given?
248
+
249
+ model.add(model.member.build(attributes, &block))
250
+ end
251
+ alias_method :line, :lines
252
+
253
+ protected
254
+
255
+ # @!attribute [r] client
256
+ # @return [Object]
257
+ attr_reader :client
258
+
259
+ # @!attribute [r] model
260
+ # @return [Vedeu::Views::View]
261
+ attr_reader :model
262
+
263
+ private
264
+
265
+ # @return [Hash]
266
+ def attributes
267
+ {
268
+ client: client,
269
+ parent: model,
270
+ }
271
+ end
272
+
261
273
  end # View
262
274
 
263
275
  end # DSL