vedeu 0.6.35 → 0.6.36

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 (32) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +3 -3
  3. data/examples/dsl_alignment.rb +162 -0
  4. data/examples/{demo_groups.rb → dsl_demo_groups.rb} +0 -0
  5. data/examples/{hello_worlds.rb → dsl_hello_worlds.rb} +0 -0
  6. data/examples/{alignment.rb → dsl_horizontal_alignment.rb} +13 -25
  7. data/examples/dsl_vertical_alignment.rb +183 -0
  8. data/lib/vedeu/geometry/alignment.rb +14 -25
  9. data/lib/vedeu/geometry/all.rb +4 -0
  10. data/lib/vedeu/geometry/area.rb +18 -17
  11. data/lib/vedeu/geometry/dimension.rb +61 -19
  12. data/lib/vedeu/geometry/dsl.rb +193 -13
  13. data/lib/vedeu/geometry/geometry.rb +58 -38
  14. data/lib/vedeu/geometry/horizontal_alignment.rb +25 -0
  15. data/lib/vedeu/geometry/vertical_alignment.rb +25 -0
  16. data/lib/vedeu/geometry/x_dimension.rb +33 -0
  17. data/lib/vedeu/geometry/y_dimension.rb +33 -0
  18. data/lib/vedeu/output/compressor.rb +9 -6
  19. data/lib/vedeu/output/renderers/file.rb +35 -11
  20. data/lib/vedeu/output/renderers/json.rb +2 -2
  21. data/lib/vedeu/version.rb +1 -1
  22. data/test/lib/vedeu/geometry/alignment_test.rb +4 -70
  23. data/test/lib/vedeu/geometry/area_test.rb +24 -22
  24. data/test/lib/vedeu/geometry/dimension_test.rb +97 -189
  25. data/test/lib/vedeu/geometry/dsl_test.rb +191 -24
  26. data/test/lib/vedeu/geometry/geometry_test.rb +31 -26
  27. data/test/lib/vedeu/geometry/horizontal_alignment_test.rb +61 -0
  28. data/test/lib/vedeu/geometry/vertical_alignment_test.rb +55 -0
  29. data/test/lib/vedeu/geometry/x_dimension_test.rb +74 -0
  30. data/test/lib/vedeu/geometry/y_dimension_test.rb +74 -0
  31. data/test/lib/vedeu/output/renderers/file_test.rb +6 -4
  32. metadata +19 -5
@@ -38,30 +38,32 @@ module Vedeu
38
38
  describe '.from_attributes' do
39
39
  let(:attributes) {
40
40
  {
41
- y: y,
42
- yn: yn,
43
- y_yn: y_yn,
44
- y_default: y_default,
45
- x: x,
46
- xn: xn,
47
- x_xn: x_xn,
48
- x_default: x_default,
49
- maximised: maximised,
50
- centred: centred,
51
- alignment: alignment,
41
+ y: y,
42
+ yn: yn,
43
+ y_yn: y_yn,
44
+ y_default: y_default,
45
+ x: x,
46
+ xn: xn,
47
+ x_xn: x_xn,
48
+ x_default: x_default,
49
+ maximised: maximised,
50
+ centred: centred,
51
+ horizontal_alignment: horizontal_alignment,
52
+ vertical_alignment: vertical_alignment,
52
53
  }
53
54
  }
54
- let(:y) {}
55
- let(:yn) {}
56
- let(:y_yn) {}
57
- let(:y_default) {}
58
- let(:x) {}
59
- let(:xn) {}
60
- let(:x_xn) {}
61
- let(:x_default) {}
62
- let(:maximised) {}
63
- let(:centred) {}
64
- let(:alignment) {}
55
+ let(:y) {}
56
+ let(:yn) {}
57
+ let(:y_yn) {}
58
+ let(:y_default) {}
59
+ let(:x) {}
60
+ let(:xn) {}
61
+ let(:x_xn) {}
62
+ let(:x_default) {}
63
+ let(:maximised) {}
64
+ let(:centred) {}
65
+ let(:horizontal_alignment) {}
66
+ let(:vertical_alignment) {}
65
67
 
66
68
  subject { described.from_attributes(attributes) }
67
69
 
@@ -10,22 +10,24 @@ module Vedeu
10
10
  let(:instance) { described.new(attributes) }
11
11
  let(:attributes) {
12
12
  {
13
- d: d,
14
- dn: dn,
15
- d_dn: d_dn,
16
- default: default,
17
- maximised: maximised,
18
- centred: centred,
19
- alignment: alignment,
13
+ d: d,
14
+ dn: dn,
15
+ d_dn: d_dn,
16
+ default: default,
17
+ maximised: maximised,
18
+ centred: centred,
19
+ horizontal_alignment: horizontal_alignment,
20
+ vertical_alignment: vertical_alignment,
20
21
  }
21
22
  }
22
- let(:d) {}
23
- let(:dn) {}
24
- let(:d_dn) {}
25
- let(:default) {}
26
- let(:maximised) {}
27
- let(:centred) {}
28
- let(:alignment) {}
23
+ let(:d) {}
24
+ let(:dn) {}
25
+ let(:d_dn) {}
26
+ let(:default) {}
27
+ let(:maximised) {}
28
+ let(:centred) {}
29
+ let(:horizontal_alignment) {}
30
+ let(:vertical_alignment) {}
29
31
 
30
32
  describe '#initialize' do
31
33
  it { instance.must_be_instance_of(described) }
@@ -35,216 +37,122 @@ module Vedeu
35
37
  it { instance.instance_variable_get('@default').must_equal(default) }
36
38
  it { instance.instance_variable_get('@maximised').must_equal(maximised) }
37
39
  it { instance.instance_variable_get('@centred').must_equal(centred) }
38
- it { instance.instance_variable_get('@alignment').must_equal(alignment) }
40
+ it { instance.instance_variable_get('@horizontal_alignment').must_equal(horizontal_alignment) }
41
+ it { instance.instance_variable_get('@vertical_alignment').must_equal(vertical_alignment) }
39
42
  end
40
43
 
41
- describe '.pair' do
42
- let(:d) { 15 }
43
- let(:dn) { 38 }
44
+ # describe '.pair' do
45
+ # let(:d) { 15 }
46
+ # let(:dn) { 38 }
44
47
 
45
- subject { described.pair(attributes) }
48
+ # subject { described.pair(attributes) }
46
49
 
47
- it { subject.must_be_instance_of(Array) }
48
- it { subject.must_equal([15, 38]) }
50
+ # it { subject.must_be_instance_of(Array) }
51
+ # it { subject.must_equal([15, 38]) }
49
52
 
50
- context 'when maximised' do
51
- let(:maximised) { true }
52
- let(:default) { 80 }
53
+ # context 'when maximised' do
54
+ # let(:maximised) { true }
55
+ # let(:default) { 80 }
53
56
 
54
- it { subject.must_equal([1, 80]) }
55
- end
57
+ # it { subject.must_equal([1, 80]) }
58
+ # end
56
59
 
57
- context 'when left aligned' do
58
- let(:alignment) { :left }
59
- let(:default) { 80 }
60
+ # context 'when bottom aligned' do
61
+ # let(:alignment) { :bottom }
60
62
 
61
- context 'when a width (d_dn) is set' do
62
- let(:d_dn) { 20 }
63
+ # it { proc { subject }.must_raise(Vedeu::Error::NotImplemented) }
64
+ # end
63
65
 
64
- it { subject.must_equal([1, 20]) }
66
+ # context 'when left aligned' do
67
+ # let(:alignment) { :left }
68
+ # let(:default) { 80 }
65
69
 
66
- context 'when the width is greater than the terminal width' do
67
- let(:d_dn) { 100 }
70
+ # context 'when a width (d_dn) is set' do
71
+ # let(:d_dn) { 20 }
68
72
 
69
- it { subject.must_equal([1, 80]) }
70
- end
71
- end
73
+ # it { subject.must_equal([1, 20]) }
72
74
 
73
- context 'when a dn is set' do
74
- it { subject.must_equal([1, 38]) }
75
- end
75
+ # context 'when the width is greater than the terminal width' do
76
+ # let(:d_dn) { 100 }
76
77
 
77
- context 'when neither width nor dn is set' do
78
- let(:dn) {}
78
+ # it { subject.must_equal([1, 80]) }
79
+ # end
80
+ # end
79
81
 
80
- it { subject.must_equal([1, 80]) }
81
- end
82
- end
82
+ # context 'when a dn is set' do
83
+ # it { subject.must_equal([1, 38]) }
84
+ # end
83
85
 
84
- context 'when right aligned' do
85
- let(:alignment) { :right }
86
- let(:default) { 80 }
86
+ # context 'when neither width nor dn is set' do
87
+ # let(:dn) {}
87
88
 
88
- context 'when a width (d_dn) is set' do
89
- let(:d_dn) { 20 }
89
+ # it { subject.must_equal([1, 80]) }
90
+ # end
91
+ # end
90
92
 
91
- it { subject.must_equal([60, 80]) }
93
+ # context 'when middle aligned' do
94
+ # let(:alignment) { :middle }
92
95
 
93
- context 'when the width is greater than the terminal width' do
94
- let(:d_dn) { 100 }
96
+ # it { proc { subject }.must_raise(Vedeu::Error::NotImplemented) }
97
+ # end
95
98
 
96
- it { subject.must_equal([1, 80]) }
97
- end
98
- end
99
+ # context 'when right aligned' do
100
+ # let(:alignment) { :right }
101
+ # let(:default) { 80 }
99
102
 
100
- context 'when a d is set' do
101
- let(:d) { 58 }
103
+ # context 'when a width (d_dn) is set' do
104
+ # let(:d_dn) { 20 }
102
105
 
103
- it { subject.must_equal([58, 80]) }
104
- end
106
+ # it { subject.must_equal([60, 80]) }
105
107
 
106
- context 'when neither width nor d is set' do
107
- let(:d) {}
108
+ # context 'when the width is greater than the terminal width' do
109
+ # let(:d_dn) { 100 }
108
110
 
109
- it { subject.must_equal([1, 80]) }
110
- end
111
- end
111
+ # it { subject.must_equal([1, 80]) }
112
+ # end
113
+ # end
112
114
 
113
- context 'when centre aligned' do
114
- let(:alignment) { :centre }
115
- let(:default) { 80 }
115
+ # context 'when a d is set' do
116
+ # let(:d) { 58 }
116
117
 
117
- context 'when d and dn are given' do
118
- let(:d) { 7 }
119
- let(:dn) { 47 }
118
+ # it { subject.must_equal([58, 80]) }
119
+ # end
120
120
 
121
- it { subject.must_equal([20, 60]) }
122
- end
121
+ # context 'when neither width nor d is set' do
122
+ # let(:d) {}
123
123
 
124
- context 'when only a d_dn is given' do
125
- let(:d_dn) { 30 }
124
+ # it { subject.must_equal([1, 80]) }
125
+ # end
126
+ # end
126
127
 
127
- it { subject.must_equal([28, 52]) }
128
- end
128
+ # context 'when top aligned' do
129
+ # let(:alignment) { :top }
129
130
 
130
- context 'when only a default is given' do
131
- it { subject.must_equal([28, 52]) }
132
- end
133
- end
134
- end
135
-
136
- describe '#d1' do
137
- subject { instance.d1 }
138
-
139
- it { subject.must_be_instance_of(Fixnum) }
140
-
141
- # context 'when not centred and/or a length cannot be determined' do
142
- # context 'when d is given' do
143
- # let(:d) { 5 }
144
-
145
- # it { subject.must_equal(5) }
146
- # end
147
-
148
- # context 'when d is not given' do
149
- # it { subject.must_equal(1) }
150
- # end
151
- # end
152
-
153
- # context 'when centred and a length can be determined' do
154
- # let(:centred) { true }
155
- # let(:default) { 80 }
156
-
157
- # context 'when d and dn are given' do
158
- # let(:d) { 7 }
159
- # let(:dn) { 47 }
160
-
161
- # it { subject.must_equal(20) }
162
- # end
163
-
164
- # context 'when only a d_dn is given' do
165
- # let(:d_dn) { 30 }
166
-
167
- # it { subject.must_equal(25) }
168
- # end
169
-
170
- # context 'when only a default is given' do
171
- # it { subject.must_equal(1) }
172
- # end
173
- # end
174
- end
175
-
176
- describe '#d2' do
177
- subject { instance.d2 }
178
-
179
- it { subject.must_be_instance_of(Fixnum) }
131
+ # it { proc { subject }.must_raise(Vedeu::Error::NotImplemented) }
132
+ # end
180
133
 
181
- # context 'when not centred and/or a length cannot be determined' do
182
- # context 'when d and dn are given' do
183
- # let(:d) { 5 }
184
- # let(:dn) { 8 }
134
+ # context 'when centre aligned' do
135
+ # let(:alignment) { :centre }
136
+ # let(:default) { 80 }
185
137
 
186
- # it { subject.must_equal(8) }
187
- # end
138
+ # context 'when d and dn are given' do
139
+ # let(:d) { 7 }
140
+ # let(:dn) { 47 }
188
141
 
189
- # context 'when d and d_dn are given' do
190
- # let(:d) { 5 }
191
- # let(:d_dn) { 2 }
142
+ # it { subject.must_equal([20, 60]) }
143
+ # end
192
144
 
193
- # it { subject.must_equal(6) }
194
- # end
145
+ # context 'when only a d_dn is given' do
146
+ # let(:d_dn) { 30 }
195
147
 
196
- # context 'when only d_dn is given' do
197
- # let(:d_dn) { 6 }
148
+ # it { subject.must_equal([28, 52]) }
149
+ # end
198
150
 
199
- # it { subject.must_equal(6) }
200
- # end
201
-
202
- # context 'when only dn is given' do
203
- # let(:dn) { 8 }
204
-
205
- # it { subject.must_equal(8) }
206
- # end
207
-
208
- # context 'when d and a default is given' do
209
- # let(:d) { 1 }
210
- # let(:default) { 40 }
211
-
212
- # it { subject.must_equal(40) }
213
- # end
214
-
215
- # context 'when only a default is given' do
216
- # let(:default) { 25 }
217
-
218
- # it { subject.must_equal(25) }
219
- # end
220
-
221
- # context 'when no default is given' do
222
- # it { subject.must_equal(nil) }
223
- # end
224
- # end
225
-
226
- # context 'when centred and a length can be determined' do
227
- # let(:centred) { true }
228
- # let(:default) { 80 }
229
-
230
- # context 'when d and dn are given' do
231
- # let(:d) { 7 }
232
- # let(:dn) { 47 }
233
-
234
- # it { subject.must_equal(60) }
235
- # end
236
-
237
- # context 'when only a d_dn is given' do
238
- # let(:d_dn) { 30 }
239
-
240
- # it { subject.must_equal(55) }
241
- # end
242
-
243
- # context 'when only a default is given' do
244
- # it { subject.must_equal(80) }
245
- # end
246
- # end
247
- end
151
+ # context 'when only a default is given' do
152
+ # it { subject.must_equal([28, 52]) }
153
+ # end
154
+ # end
155
+ # end
248
156
 
249
157
  end # Dimension
250
158
 
@@ -14,49 +14,184 @@ module Vedeu
14
14
  it { described.must_respond_to(:geometry) }
15
15
  end
16
16
 
17
- describe '#alignment' do
18
- let(:_value) { :none }
19
- let(:width) { 20 }
17
+ # describe '#alignment' do
18
+ # let(:_value) { :none }
19
+ # let(:width) { 20 }
20
20
 
21
- subject { instance.alignment(_value, width) }
21
+ # subject { instance.alignment(_value, width) }
22
22
 
23
- context 'when a value and width is given' do
24
- it { subject.must_be_instance_of(Vedeu::Geometry::Geometry) }
23
+ # context 'when a value and width is given' do
24
+ # it { subject.must_be_instance_of(Vedeu::Geometry::Geometry) }
25
+
26
+ # context 'when the value is :center' do
27
+ # let(:_value) { :center }
28
+
29
+ # it { subject.alignment.must_equal(:centre) }
30
+ # end
31
+
32
+ # context 'when the value is :centre' do
33
+ # let(:_value) { :centre }
34
+
35
+ # it { subject.alignment.must_equal(:centre) }
36
+ # end
37
+
38
+ # context 'when the value is :left' do
39
+ # let(:_value) { :left }
40
+
41
+ # it { subject.alignment.must_equal(:left) }
42
+ # end
43
+
44
+ # context 'when the value is :right' do
45
+ # let(:_value) { :right }
46
+
47
+ # it { subject.alignment.must_equal(:right) }
48
+ # end
49
+ # end
50
+
51
+ # context 'when a value is not given' do
52
+ # let(:_value) {}
25
53
 
26
- context 'when the value is :center' do
27
- let(:_value) { :center }
54
+ # it { proc { subject }.must_raise(Vedeu::Error::InvalidSyntax) }
55
+ # end
28
56
 
29
- it { subject.alignment.must_equal(:centre) }
57
+ # context 'when a width is not given' do
58
+ # let(:_value) { :none }
59
+ # let(:width) {}
60
+
61
+ # it { proc { subject }.must_raise(Vedeu::Error::InvalidSyntax) }
62
+ # end
63
+ # end
64
+
65
+ describe '#align' do
66
+ let(:vertical) { :top }
67
+ let(:horizontal) { :left }
68
+ let(:width) { 20 }
69
+ let(:height) { 20 }
70
+
71
+ subject { instance.align(vertical, horizontal, width, height) }
72
+
73
+ context 'when the vertical argument is not given' do
74
+ let(:vertical) {}
75
+
76
+ it { proc { subject }.must_raise(Vedeu::Error::InvalidSyntax).
77
+ message.must_match(/No vertical alignment/)
78
+ }
79
+ end
80
+
81
+ context 'when the vertical argument is given' do
82
+ context 'when the height is not given' do
83
+ let(:height) {}
84
+
85
+ it { proc { subject }.must_raise(Vedeu::Error::InvalidSyntax).
86
+ message.must_equal('No height given.')
87
+ }
30
88
  end
31
89
 
32
- context 'when the value is :centre' do
33
- let(:_value) { :centre }
90
+ context 'when the height is given' do
91
+ it { subject.must_be_instance_of(Vedeu::Geometry::Geometry) }
92
+ it { subject.vertical_alignment.must_equal(:top) }
93
+ it { subject.horizontal_alignment.must_equal(:left) }
94
+ it { subject.height.must_equal(20) }
95
+ it { subject.width.must_equal(20) }
96
+ end
97
+ end
98
+
99
+ context 'when the horizontal argument is not given' do
100
+ let(:horizontal) {}
101
+
102
+ it { proc { subject }.must_raise(Vedeu::Error::InvalidSyntax).
103
+ message.must_match(/No horizontal alignment/)
104
+ }
105
+ end
106
+
107
+ context 'when the horizontal argument is given' do
108
+ context 'when the width is not given' do
109
+ let(:width) {}
34
110
 
35
- it { subject.alignment.must_equal(:centre) }
111
+ it { proc { subject }.must_raise(Vedeu::Error::InvalidSyntax).
112
+ message.must_equal('No width given.')
113
+ }
36
114
  end
37
115
 
38
- context 'when the value is :left' do
39
- let(:_value) { :left }
116
+ context 'when the width is given' do
117
+ it { subject.must_be_instance_of(Vedeu::Geometry::Geometry) }
118
+ it { subject.vertical_alignment.must_equal(:top) }
119
+ it { subject.horizontal_alignment.must_equal(:left) }
120
+ it { subject.height.must_equal(20) }
121
+ it { subject.width.must_equal(20) }
122
+ end
123
+ end
124
+ end
125
+
126
+ describe '#horizontal_alignment' do
127
+ let(:_value) {}
128
+ let(:width) {}
129
+
130
+ subject { instance.horizontal_alignment(_value, width) }
40
131
 
41
- it { subject.alignment.must_equal(:left) }
132
+ context 'when the value is not given' do
133
+ it { proc { subject }.must_raise(Vedeu::Error::InvalidSyntax).
134
+ message.must_match(/No horizontal alignment/)
135
+ }
136
+ end
137
+
138
+ context 'when the value is given' do
139
+ let(:_value) { :right }
140
+
141
+ context 'when a width is not given' do
142
+ it { proc { subject }.must_raise(Vedeu::Error::InvalidSyntax).
143
+ message.must_equal('No width given.')
144
+ }
42
145
  end
43
146
 
44
- context 'when the value is :right' do
45
- let(:_value) { :right }
147
+ context 'when a width is given' do
148
+ let(:width) { 20 }
46
149
 
47
- it { subject.alignment.must_equal(:right) }
150
+ it { subject.must_be_instance_of(Vedeu::Geometry::Geometry) }
48
151
  end
49
152
  end
153
+ end
50
154
 
51
- context 'when a value is not given' do
52
- let(:_value) {}
155
+ describe '#vertical_alignment' do
156
+ let(:_value) {}
157
+ let(:height) {}
53
158
 
54
- it { proc { subject }.must_raise(Vedeu::Error::InvalidSyntax) }
159
+ subject { instance.vertical_alignment(_value, height) }
160
+
161
+ context 'when the value is not given' do
162
+ it { proc { subject }.must_raise(Vedeu::Error::InvalidSyntax).
163
+ message.must_match(/No vertical alignment/)
164
+ }
55
165
  end
56
166
 
57
- context 'when a width is not given' do
58
- let(:_value) { :none }
59
- let(:width) {}
167
+ context 'when the value is given' do
168
+ let(:_value) { :bottom }
169
+
170
+ context 'when a height is not given' do
171
+ it { proc { subject }.must_raise(Vedeu::Error::InvalidSyntax).
172
+ message.must_equal('No height given.')
173
+ }
174
+ end
175
+
176
+ context 'when a height is given' do
177
+ let(:height) { 20 }
178
+
179
+ it { subject.must_be_instance_of(Vedeu::Geometry::Geometry) }
180
+ end
181
+ end
182
+ end
183
+
184
+ describe '#align_bottom' do
185
+ let(:height) { 20 }
186
+
187
+ subject { instance.align_bottom(height) }
188
+
189
+ context 'when a height is given' do
190
+ it { subject.must_be_instance_of(Vedeu::Geometry::Geometry) }
191
+ end
192
+
193
+ context 'when a height is not given' do
194
+ let(:height) {}
60
195
 
61
196
  it { proc { subject }.must_raise(Vedeu::Error::InvalidSyntax) }
62
197
  end
@@ -95,6 +230,22 @@ module Vedeu
95
230
  end
96
231
  end
97
232
 
233
+ describe '#align_middle' do
234
+ let(:height) { 20 }
235
+
236
+ subject { instance.align_middle(height) }
237
+
238
+ context 'when a height is given' do
239
+ it { subject.must_be_instance_of(Vedeu::Geometry::Geometry) }
240
+ end
241
+
242
+ context 'when a height is not given' do
243
+ let(:height) {}
244
+
245
+ it { proc { subject }.must_raise(Vedeu::Error::InvalidSyntax) }
246
+ end
247
+ end
248
+
98
249
  describe '#align_right' do
99
250
  let(:width) { 20 }
100
251
 
@@ -110,6 +261,22 @@ module Vedeu
110
261
  end
111
262
  end
112
263
 
264
+ describe '#align_top' do
265
+ let(:height) { 20 }
266
+
267
+ subject { instance.align_top(height) }
268
+
269
+ context 'when a height is given' do
270
+ it { subject.must_be_instance_of(Vedeu::Geometry::Geometry) }
271
+ end
272
+
273
+ context 'when a height is not given' do
274
+ let(:height) {}
275
+
276
+ it { proc { subject }.must_raise(Vedeu::Error::InvalidSyntax) }
277
+ end
278
+ end
279
+
113
280
  describe '#centred' do
114
281
  subject { instance.centred(true) }
115
282