vedeu 0.6.36 → 0.6.37

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 (43) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +3 -3
  3. data/.yardopts +2 -0
  4. data/bin/vedeu_drb_server +0 -1
  5. data/docs/api.md +6 -2
  6. data/docs/cell.md +9 -0
  7. data/docs/chars.md +7 -0
  8. data/docs/colours_styles.md +8 -0
  9. data/docs/dsl.md +6 -2
  10. data/docs/input.md +98 -0
  11. data/docs/lines.md +8 -0
  12. data/docs/output.md +2 -0
  13. data/docs/streams.md +6 -0
  14. data/docs/template.md +3 -0
  15. data/docs/view.md +3 -6
  16. data/examples/dsl_demo_groups.rb +12 -4
  17. data/examples/dsl_hello_worlds.rb +2 -6
  18. data/lib/vedeu/distributed/templates/default_geometries.vedeu +0 -1
  19. data/lib/vedeu/dsl/view.rb +0 -1
  20. data/lib/vedeu/geometry/alignment.rb +65 -1
  21. data/lib/vedeu/geometry/area.rb +10 -15
  22. data/lib/vedeu/geometry/dimension.rb +19 -81
  23. data/lib/vedeu/geometry/dsl.rb +2 -25
  24. data/lib/vedeu/geometry/geometry.rb +6 -25
  25. data/lib/vedeu/geometry/x_dimension.rb +4 -9
  26. data/lib/vedeu/geometry/y_dimension.rb +4 -9
  27. data/lib/vedeu/null/generic.rb +0 -1
  28. data/lib/vedeu/output/renderers/file.rb +4 -0
  29. data/lib/vedeu/version.rb +1 -1
  30. data/test/lib/vedeu/geometry/alignment_test.rb +118 -0
  31. data/test/lib/vedeu/geometry/area_test.rb +0 -2
  32. data/test/lib/vedeu/geometry/dimension_test.rb +13 -19
  33. data/test/lib/vedeu/geometry/dsl_test.rb +4 -39
  34. data/test/lib/vedeu/geometry/geometry_test.rb +0 -68
  35. data/test/lib/vedeu/geometry/horizontal_alignment_test.rb +6 -0
  36. data/test/lib/vedeu/geometry/vertical_alignment_test.rb +6 -0
  37. data/test/lib/vedeu/geometry/x_dimension_test.rb +0 -2
  38. data/test/lib/vedeu/geometry/y_dimension_test.rb +0 -2
  39. data/test/lib/vedeu/null/generic_test.rb +0 -1
  40. data/test/support/examples/drb_app.rb +0 -1
  41. data/test/support/examples/hello_world.rb +1 -3
  42. data/test/support/examples/view_templates_app/view_templates_app.rb +1 -3
  43. metadata +10 -2
@@ -6,6 +6,17 @@ module Vedeu
6
6
  #
7
7
  class Dimension
8
8
 
9
+ extend Forwardable
10
+
11
+ def_delegators :alignment,
12
+ :bottom_aligned?,
13
+ :centre_aligned?,
14
+ :left_aligned?,
15
+ :middle_aligned?,
16
+ :right_aligned?,
17
+ :top_aligned?,
18
+ :unaligned?
19
+
9
20
  # @param (see #initialize)
10
21
  # @return [Array<Fixnum>]
11
22
  def self.pair(attributes = {})
@@ -23,9 +34,7 @@ module Vedeu
23
34
  # @option attributes default [Fixnum|NilClass]
24
35
  # The terminal width or height.
25
36
  # @option attributes maximised [Boolean]
26
- # @option attributes centered [Boolean]
27
- # @option attributes horizontal_alignment [Symbol]
28
- # @option attributes vertical_alignment [Symbol]
37
+ # @option attributes alignment [Symbol]
29
38
  # @return [Vedeu::Geometry::Dimension]
30
39
  def initialize(attributes = {})
31
40
  defaults.merge!(attributes).each do |key, value|
@@ -63,19 +72,6 @@ module Vedeu
63
72
  attr_reader :maximised
64
73
  alias_method :maximised?, :maximised
65
74
 
66
- # @!attribute [r] centred
67
- # @return [Boolean]
68
- attr_reader :centred
69
- alias_method :centred?, :centred
70
-
71
- # @!attribute [r] horizontal_alignment
72
- # @return [Symbol]
73
- attr_reader :horizontal_alignment
74
-
75
- # @!attribute [r] vertical_alignment
76
- # @return [Symbol]
77
- attr_reader :vertical_alignment
78
-
79
75
  private
80
76
 
81
77
  # @raise [Vedeu::Error::NotImplemented] Subclasses of this class
@@ -96,26 +92,14 @@ module Vedeu
96
92
  @dimension = if maximised?
97
93
  [1, default]
98
94
 
99
- elsif bottom_aligned?
100
- [bottom_d, default]
101
-
102
- elsif centre_aligned?
103
- [centred_d, centred_dn]
104
-
105
- elsif left_aligned?
106
- [1, left_dn]
95
+ elsif bottom_aligned? || right_aligned?
96
+ [start_coordinate, default]
107
97
 
108
- elsif middle_aligned?
98
+ elsif centre_aligned? || middle_aligned?
109
99
  [centred_d, centred_dn]
110
100
 
111
- elsif right_aligned?
112
- [right_d, default]
113
-
114
- elsif top_aligned?
115
- [1, top_dn]
116
-
117
- elsif centred? && length?
118
- [centred_d, centred_dn]
101
+ elsif left_aligned? || top_aligned?
102
+ [1, end_coordinate]
119
103
 
120
104
  else
121
105
  [_d, _dn]
@@ -187,7 +171,7 @@ module Vedeu
187
171
  # 3) Default to the terminal width or height.
188
172
  #
189
173
  # @return [Fixnum]
190
- def left_dn
174
+ def end_coordinate
191
175
  if d_dn
192
176
  (d_dn > default) ? default : d_dn
193
177
 
@@ -199,7 +183,6 @@ module Vedeu
199
183
 
200
184
  end
201
185
  end
202
- alias_method :top_dn, :left_dn
203
186
 
204
187
  # Ascertains the starting coordinate for a right or bottom
205
188
  # aligned interface/view.
@@ -209,7 +192,7 @@ module Vedeu
209
192
  # 3) Default to 1.
210
193
  #
211
194
  # @return [Fixnum]
212
- def right_d
195
+ def start_coordinate
213
196
  if d_dn
214
197
  (default - d_dn) < 1 ? 1 : (default - d_dn)
215
198
 
@@ -221,7 +204,6 @@ module Vedeu
221
204
 
222
205
  end
223
206
  end
224
- alias_method :bottom_d, :right_d
225
207
 
226
208
  # Fetch the starting coordinate, or use 1 when not set.
227
209
  #
@@ -259,48 +241,6 @@ module Vedeu
259
241
  end
260
242
  end
261
243
 
262
- # Return a boolean indicating alignment was set to :left.
263
- #
264
- # @return [Boolean]
265
- def left_aligned?
266
- alignment == :left
267
- end
268
-
269
- # Return a boolean indicating alignment was set to :middle.
270
- #
271
- # @return [Boolean]
272
- def middle_aligned?
273
- alignment == :middle
274
- end
275
-
276
- # Return a boolean indicating alignment was set to :bottom.
277
- #
278
- # @return [Boolean]
279
- def bottom_aligned?
280
- alignment == :bottom
281
- end
282
-
283
- # Return a boolean indicating alignment was set to :centre.
284
- #
285
- # @return [Boolean]
286
- def centre_aligned?
287
- alignment == :centre
288
- end
289
-
290
- # Return a boolean indicating alignment was set to :right.
291
- #
292
- # @return [Boolean]
293
- def right_aligned?
294
- alignment == :right
295
- end
296
-
297
- # Return a boolean indicating alignment was set to :top.
298
- #
299
- # @return [Boolean]
300
- def top_aligned?
301
- alignment == :top
302
- end
303
-
304
244
  # Returns the default options/attributes for this class.
305
245
  #
306
246
  # @return [Hash<Symbol => NilClass,Boolean,Symbol>]
@@ -309,8 +249,6 @@ module Vedeu
309
249
  d: nil,
310
250
  dn: nil,
311
251
  d_dn: nil,
312
- default: nil,
313
- centred: false,
314
252
  maximised: false,
315
253
  }
316
254
  end
@@ -180,7 +180,7 @@ module Vedeu
180
180
  'No width given.'.freeze unless present?(width)
181
181
 
182
182
  model.horizontal_alignment = Vedeu::Geometry::HorizontalAlignment
183
- .align(value)
183
+ .coerce(value)
184
184
  model.width = width
185
185
  model
186
186
  end
@@ -196,7 +196,7 @@ module Vedeu
196
196
  'No height given.'.freeze unless present?(height)
197
197
 
198
198
  model.vertical_alignment = Vedeu::Geometry::VerticalAlignment
199
- .align(value)
199
+ .coerce(value)
200
200
  model.height = height
201
201
  model
202
202
  end
@@ -369,29 +369,6 @@ module Vedeu
369
369
  vertical_alignment(:top, height)
370
370
  end
371
371
 
372
- # Instructs Vedeu to calculate x and y geometry automatically
373
- # based on the centre character of the terminal, the width and
374
- # the height.
375
- #
376
- # Vedeu.geometry :some_interface do
377
- # centred false # or...
378
- #
379
- # centred true # or...
380
- # centred! # or...
381
- # # ... some code
382
- # end
383
- #
384
- # @param value [Boolean] Any value other than nil or false will
385
- # evaluate to true.
386
- # @return [Boolean]
387
- def centred(value = true)
388
- boolean = value ? true : false
389
-
390
- model.centred = boolean
391
- end
392
- alias_method :centred!, :centred
393
- alias_method :centred=, :centred
394
-
395
372
  # Returns the width in characters for the number of columns
396
373
  # specified.
397
374
  #
@@ -39,10 +39,6 @@ module Vedeu
39
39
  # @return [Symbol]
40
40
  attr_accessor :vertical_alignment
41
41
 
42
- # @!attribute [rw] centred
43
- # @return [Boolean]
44
- attr_accessor :centred
45
-
46
42
  # @!attribute [rw] name
47
43
  # @return [String]
48
44
  attr_accessor :name
@@ -91,7 +87,6 @@ module Vedeu
91
87
  # @param attributes [Hash]
92
88
  # @option attributes horizontal_alignment [Symbol]
93
89
  # @option attributes vertical_alignment [Symbol]
94
- # @option attributes centred [Boolean]
95
90
  # @option attributes maximised [Boolean]
96
91
  # @option attributes height [Fixnum]
97
92
  # @option attributes name [String|Symbol]
@@ -112,7 +107,6 @@ module Vedeu
112
107
  def attributes
113
108
  {
114
109
  client: @client,
115
- centred: @centred,
116
110
  height: height,
117
111
  horizontal_alignment: @horizontal_alignment,
118
112
  maximised: @maximised,
@@ -234,7 +228,6 @@ module Vedeu
234
228
  # @return [Hash<Symbol => Boolean, Fixnum>]
235
229
  def area_attributes
236
230
  {
237
- centred: @centred,
238
231
  horizontal_alignment: @horizontal_alignment,
239
232
  maximised: @maximised,
240
233
  vertical_alignment: @vertical_alignment,
@@ -248,9 +241,9 @@ module Vedeu
248
241
  end
249
242
 
250
243
  # When moving an interface;
251
- # 1) Reset the alignment, centred and maximised states to false;
252
- # it wont be aligned to a side if moved, nor centred if
253
- # moved, and cannot be moved if maximised.
244
+ # 1) Reset the alignment and maximised states to false;
245
+ # it wont be aligned to a side if moved, and cannot be moved
246
+ # if maximised.
254
247
  # 2) Get the current coordinates of the interface, then:
255
248
  # 3) Override the attributes with the new coordinates for
256
249
  # desired movement; these are usually +/- 1 of the current
@@ -265,8 +258,7 @@ module Vedeu
265
258
  # @option coordinates yn [Fixnum] The ending row/line position.
266
259
  # @return [Hash<Symbol => Boolean, Fixnum>]
267
260
  def move(coordinates = {})
268
- attrs = attributes.merge!(centred: false,
269
- horizontal_alignment: :none,
261
+ attrs = attributes.merge!(horizontal_alignment: :none,
270
262
  maximised: false,
271
263
  vertical_alignment: :none)
272
264
  .merge!(coordinates)
@@ -280,13 +272,12 @@ module Vedeu
280
272
  def defaults
281
273
  {
282
274
  client: nil,
283
- centred: false,
284
275
  height: nil,
285
- horizontal_alignment: default_horizontal_alignment,
276
+ horizontal_alignment: :none,
286
277
  maximised: false,
287
278
  name: nil,
288
279
  repository: Vedeu.geometries,
289
- vertical_alignment: default_vertical_alignment,
280
+ vertical_alignment: :none,
290
281
  width: nil,
291
282
  x: nil,
292
283
  xn: nil,
@@ -295,16 +286,6 @@ module Vedeu
295
286
  }
296
287
  end
297
288
 
298
- # @return [Symbol]
299
- def default_horizontal_alignment
300
- Vedeu::Geometry::HorizontalAlignment.align(:none)
301
- end
302
-
303
- # @return [Symbol]
304
- def default_vertical_alignment
305
- Vedeu::Geometry::VerticalAlignment.align(:none)
306
- end
307
-
308
289
  end # Geometry
309
290
 
310
291
  end # Geometry
@@ -8,24 +8,19 @@ module Vedeu
8
8
 
9
9
  private
10
10
 
11
- # @return [Symbol]
11
+ # @return [Vedeu::Geometry::HorizontalAlignment]
12
12
  def alignment
13
- horizontal_alignment
13
+ Vedeu::Geometry::Alignment.coerce(@alignment)
14
14
  end
15
15
 
16
16
  # @return [Hash<Symbol => NilClass,Boolean,Symbol>]
17
17
  def defaults
18
18
  super.merge!(
19
- default: Vedeu.width,
20
- horizontal_alignment: default_alignment,
19
+ default: Vedeu.width,
20
+ alignment: :none,
21
21
  )
22
22
  end
23
23
 
24
- # @return [Symbol]
25
- def default_alignment
26
- Vedeu::Geometry::HorizontalAlignment.align(:none)
27
- end
28
-
29
24
  end # XDimension
30
25
 
31
26
  end # Geometry
@@ -8,24 +8,19 @@ module Vedeu
8
8
 
9
9
  private
10
10
 
11
- # @return [Symbol]
11
+ # @return [Vedeu::Geometry::VerticalAlignment]
12
12
  def alignment
13
- vertical_alignment
13
+ Vedeu::Geometry::Alignment.coerce(@alignment)
14
14
  end
15
15
 
16
16
  # @return [Hash<Symbol => NilClass,Boolean,Symbol>]
17
17
  def defaults
18
18
  super.merge!(
19
- default: Vedeu.height,
20
- vertical_alignment: default_alignment,
19
+ default: Vedeu.height,
20
+ alignment: :none,
21
21
  )
22
22
  end
23
23
 
24
- # @return [Symbol]
25
- def default_alignment
26
- Vedeu::Geometry::VerticalAlignment.align(:none)
27
- end
28
-
29
24
  end # YDimension
30
25
 
31
26
  end # Geometry
@@ -28,7 +28,6 @@ module Vedeu
28
28
  def falsy
29
29
  false
30
30
  end
31
- alias_method :centred, :falsy
32
31
  alias_method :enabled?, :falsy
33
32
  alias_method :maximise, :falsy
34
33
  alias_method :maximised?, :falsy
@@ -48,6 +48,10 @@ module Vedeu
48
48
 
49
49
  private
50
50
 
51
+ # Compresses the output depending on configuration.
52
+ #
53
+ # @param output [Vedeu::Models::Page]
54
+ # @return [String]
51
55
  def out(output)
52
56
  if compress?
53
57
  Vedeu::Output::Compressor.render(output, options)
data/lib/vedeu/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Vedeu
2
2
 
3
3
  # The current version of Vedeu.
4
- VERSION = '0.6.36'.freeze
4
+ VERSION = '0.6.37'.freeze
5
5
 
6
6
  end
@@ -21,12 +21,130 @@ module Vedeu
21
21
  it { proc { subject }.must_raise(Vedeu::Error::NotImplemented) }
22
22
  end
23
23
 
24
+ describe '.coerce' do
25
+ subject { described.coerce(_value) }
26
+
27
+ context 'when the value is a Vedeu::Geometry::Alignment' do
28
+ let(:_value) { Vedeu::Geometry::Alignment.new(:none) }
29
+
30
+ it { subject.must_equal(_value) }
31
+ end
32
+
33
+ context 'when the value is a Symbol' do
34
+ let(:_value) { :centre }
35
+
36
+ it { subject.must_be_instance_of(described) }
37
+ end
38
+
39
+ context 'when the value is nil or something else' do
40
+ it { subject.must_be_instance_of(described) }
41
+ end
42
+ end
43
+
24
44
  describe '#align' do
25
45
  subject { instance.align }
26
46
 
27
47
  it { proc { subject }.must_raise(Vedeu::Error::NotImplemented) }
28
48
  end
29
49
 
50
+ describe '#bottom_aligned?' do
51
+ subject { instance.bottom_aligned? }
52
+
53
+ context 'when the value is :bottom' do
54
+ let(:_value) { :bottom }
55
+
56
+ it { subject.must_equal(true) }
57
+ end
58
+
59
+ context 'when the value is not :bottom' do
60
+ it { subject.must_equal(false) }
61
+ end
62
+ end
63
+
64
+ describe '#centre_aligned?' do
65
+ subject { instance.centre_aligned? }
66
+
67
+ context 'when the value is :centre' do
68
+ let(:_value) { :centre }
69
+
70
+ it { subject.must_equal(true) }
71
+ end
72
+
73
+ context 'when the value is not :centre' do
74
+ it { subject.must_equal(false) }
75
+ end
76
+ end
77
+
78
+ describe '#left_aligned?' do
79
+ subject { instance.left_aligned? }
80
+
81
+ context 'when the value is :left' do
82
+ let(:_value) { :left }
83
+
84
+ it { subject.must_equal(true) }
85
+ end
86
+
87
+ context 'when the value is not :left' do
88
+ it { subject.must_equal(false) }
89
+ end
90
+ end
91
+
92
+ describe '#middle_aligned?' do
93
+ subject { instance.middle_aligned? }
94
+
95
+ context 'when the value is :middle' do
96
+ let(:_value) { :middle }
97
+
98
+ it { subject.must_equal(true) }
99
+ end
100
+
101
+ context 'when the value is not :middle' do
102
+ it { subject.must_equal(false) }
103
+ end
104
+ end
105
+
106
+ describe '#right_aligned?' do
107
+ subject { instance.right_aligned? }
108
+
109
+ context 'when the value is :right' do
110
+ let(:_value) { :right }
111
+
112
+ it { subject.must_equal(true) }
113
+ end
114
+
115
+ context 'when the value is not :right' do
116
+ it { subject.must_equal(false) }
117
+ end
118
+ end
119
+
120
+ describe '#top_aligned?' do
121
+ subject { instance.top_aligned? }
122
+
123
+ context 'when the value is :top' do
124
+ let(:_value) { :top }
125
+
126
+ it { subject.must_equal(true) }
127
+ end
128
+
129
+ context 'when the value is not :top' do
130
+ it { subject.must_equal(false) }
131
+ end
132
+ end
133
+
134
+ describe '#unaligned?' do
135
+ subject { instance.unaligned? }
136
+
137
+ context 'when the value is :none' do
138
+ it { subject.must_equal(true) }
139
+ end
140
+
141
+ context 'when the value is not :none' do
142
+ let(:_value) { :centre }
143
+
144
+ it { subject.must_equal(false) }
145
+ end
146
+ end
147
+
30
148
  end # Alignment
31
149
 
32
150
  end # Geometry