vedeu 0.6.35 → 0.6.36

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -31,9 +31,13 @@ module Vedeu
31
31
  :height,
32
32
  :width
33
33
 
34
- # @!attribute [rw] alignment
34
+ # @!attribute [rw] horizontal_alignment
35
35
  # @return [Symbol]
36
- attr_accessor :alignment
36
+ attr_accessor :horizontal_alignment
37
+
38
+ # @!attribute [rw] vertical_alignment
39
+ # @return [Symbol]
40
+ attr_accessor :vertical_alignment
37
41
 
38
42
  # @!attribute [rw] centred
39
43
  # @return [Boolean]
@@ -85,6 +89,8 @@ module Vedeu
85
89
  # Returns a new instance of Vedeu::Geometry::Geometry.
86
90
  #
87
91
  # @param attributes [Hash]
92
+ # @option attributes horizontal_alignment [Symbol]
93
+ # @option attributes vertical_alignment [Symbol]
88
94
  # @option attributes centred [Boolean]
89
95
  # @option attributes maximised [Boolean]
90
96
  # @option attributes height [Fixnum]
@@ -105,18 +111,19 @@ module Vedeu
105
111
  # @return [Hash]
106
112
  def attributes
107
113
  {
108
- alignment: @alignment,
109
- client: @client,
110
- centred: @centred,
111
- height: height,
112
- maximised: @maximised,
113
- name: @name,
114
- repository: @repository,
115
- width: width,
116
- x: x,
117
- xn: xn,
118
- y: y,
119
- yn: yn,
114
+ client: @client,
115
+ centred: @centred,
116
+ height: height,
117
+ horizontal_alignment: @horizontal_alignment,
118
+ maximised: @maximised,
119
+ name: @name,
120
+ repository: @repository,
121
+ vertical_alignment: @vertical_alignment,
122
+ width: width,
123
+ x: x,
124
+ xn: xn,
125
+ y: y,
126
+ yn: yn,
120
127
  }
121
128
  end
122
129
 
@@ -227,15 +234,16 @@ module Vedeu
227
234
  # @return [Hash<Symbol => Boolean, Fixnum>]
228
235
  def area_attributes
229
236
  {
230
- alignment: @alignment,
231
- centred: @centred,
232
- maximised: @maximised,
233
- x: @x.is_a?(Proc) ? @x.call : @x,
234
- xn: @xn.is_a?(Proc) ? @xn.call : @xn,
235
- x_xn: @width.is_a?(Proc) ? @width.call : @width,
236
- y: @y.is_a?(Proc) ? @y.call : @y,
237
- yn: @yn.is_a?(Proc) ? @yn.call : @yn,
238
- y_yn: @height.is_a?(Proc) ? @height.call : @height,
237
+ centred: @centred,
238
+ horizontal_alignment: @horizontal_alignment,
239
+ maximised: @maximised,
240
+ vertical_alignment: @vertical_alignment,
241
+ x: @x.is_a?(Proc) ? @x.call : @x,
242
+ xn: @xn.is_a?(Proc) ? @xn.call : @xn,
243
+ x_xn: @width.is_a?(Proc) ? @width.call : @width,
244
+ y: @y.is_a?(Proc) ? @y.call : @y,
245
+ yn: @yn.is_a?(Proc) ? @yn.call : @yn,
246
+ y_yn: @height.is_a?(Proc) ? @height.call : @height,
239
247
  }
240
248
  end
241
249
 
@@ -257,9 +265,10 @@ module Vedeu
257
265
  # @option coordinates yn [Fixnum] The ending row/line position.
258
266
  # @return [Hash<Symbol => Boolean, Fixnum>]
259
267
  def move(coordinates = {})
260
- attrs = attributes.merge!(alignment: :none,
261
- centred: false,
262
- maximised: false)
268
+ attrs = attributes.merge!(centred: false,
269
+ horizontal_alignment: :none,
270
+ maximised: false,
271
+ vertical_alignment: :none)
263
272
  .merge!(coordinates)
264
273
 
265
274
  Vedeu::Geometry::Geometry.store(attrs)
@@ -270,21 +279,32 @@ module Vedeu
270
279
  # @return [Hash]
271
280
  def defaults
272
281
  {
273
- alignment: Vedeu::Geometry::Alignment.align(:none),
274
- client: nil,
275
- centred: false,
276
- height: nil,
277
- maximised: false,
278
- name: nil,
279
- repository: Vedeu.geometries,
280
- width: nil,
281
- x: nil,
282
- xn: nil,
283
- y: nil,
284
- yn: nil,
282
+ client: nil,
283
+ centred: false,
284
+ height: nil,
285
+ horizontal_alignment: default_horizontal_alignment,
286
+ maximised: false,
287
+ name: nil,
288
+ repository: Vedeu.geometries,
289
+ vertical_alignment: default_vertical_alignment,
290
+ width: nil,
291
+ x: nil,
292
+ xn: nil,
293
+ y: nil,
294
+ yn: nil,
285
295
  }
286
296
  end
287
297
 
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
+
288
308
  end # Geometry
289
309
 
290
310
  end # Geometry
@@ -0,0 +1,25 @@
1
+ module Vedeu
2
+
3
+ module Geometry
4
+
5
+ # Provides the mechanism to align an interface/view horizontally
6
+ # within the available terminal space.
7
+ #
8
+ class HorizontalAlignment < Vedeu::Geometry::Alignment
9
+
10
+ # @raise [Vedeu::Error::InvalidSyntax] When the value is not one
11
+ # of :bottom, :centre, :left, :middle, :right, :top.
12
+ # @return [Symbol]
13
+ def align
14
+ return value if valid?
15
+
16
+ fail Vedeu::Error::InvalidSyntax,
17
+ 'No horizontal alignment value given. Valid values are :center, ' \
18
+ ':centre, :left, :none, :right.'.freeze
19
+ end
20
+
21
+ end # HorizontalAlignment
22
+
23
+ end # Geometry
24
+
25
+ end # Vedeu
@@ -0,0 +1,25 @@
1
+ module Vedeu
2
+
3
+ module Geometry
4
+
5
+ # Provides the mechanism to align an interface/view vertically
6
+ # within the available terminal space.
7
+ #
8
+ class VerticalAlignment < Vedeu::Geometry::Alignment
9
+
10
+ # @raise [Vedeu::Error::InvalidSyntax] When the value is not one
11
+ # of :bottom, :centre, :left, :middle, :right, :top.
12
+ # @return [Symbol]
13
+ def align
14
+ return value if valid?
15
+
16
+ fail Vedeu::Error::InvalidSyntax,
17
+ 'No vertical alignment value given. Valid values are :bottom, ' \
18
+ ':middle, :none, :top.'.freeze
19
+ end
20
+
21
+ end # VerticalAlignment
22
+
23
+ end # Geometry
24
+
25
+ end # Vedeu
@@ -0,0 +1,33 @@
1
+ module Vedeu
2
+
3
+ module Geometry
4
+
5
+ # The X Dimension provides the width of an entity.
6
+ #
7
+ class XDimension < Vedeu::Geometry::Dimension
8
+
9
+ private
10
+
11
+ # @return [Symbol]
12
+ def alignment
13
+ horizontal_alignment
14
+ end
15
+
16
+ # @return [Hash<Symbol => NilClass,Boolean,Symbol>]
17
+ def defaults
18
+ super.merge!(
19
+ default: Vedeu.width,
20
+ horizontal_alignment: default_alignment,
21
+ )
22
+ end
23
+
24
+ # @return [Symbol]
25
+ def default_alignment
26
+ Vedeu::Geometry::HorizontalAlignment.align(:none)
27
+ end
28
+
29
+ end # XDimension
30
+
31
+ end # Geometry
32
+
33
+ end # Vedeu
@@ -0,0 +1,33 @@
1
+ module Vedeu
2
+
3
+ module Geometry
4
+
5
+ # The Y Dimension provides the height of an entity.
6
+ #
7
+ class YDimension < Vedeu::Geometry::Dimension
8
+
9
+ private
10
+
11
+ # @return [Symbol]
12
+ def alignment
13
+ vertical_alignment
14
+ end
15
+
16
+ # @return [Hash<Symbol => NilClass,Boolean,Symbol>]
17
+ def defaults
18
+ super.merge!(
19
+ default: Vedeu.height,
20
+ vertical_alignment: default_alignment,
21
+ )
22
+ end
23
+
24
+ # @return [Symbol]
25
+ def default_alignment
26
+ Vedeu::Geometry::VerticalAlignment.align(:none)
27
+ end
28
+
29
+ end # YDimension
30
+
31
+ end # Geometry
32
+
33
+ end # Vedeu
@@ -13,18 +13,21 @@ module Vedeu
13
13
 
14
14
  # @param (see #initialize)
15
15
  # @return [String]
16
- def self.render(output)
17
- new(output).render
16
+ def self.render(output, options = {})
17
+ new(output, options).render
18
18
  end
19
19
 
20
20
  # Returns a new instance of Vedeu::Output::Compressor.
21
21
  #
22
22
  # @param output [Array<Array<Vedeu::Views::Char>>]
23
+ # @param options [Hash]
24
+ # @option options compression [Boolean]
23
25
  # @return [Vedeu::Output::Compressor]
24
- def initialize(output)
25
- @output = output
26
- @colour = ''
27
- @style = ''
26
+ def initialize(output, options = {})
27
+ @output = output
28
+ @options = options
29
+ @colour = ''
30
+ @style = ''
28
31
  end
29
32
 
30
33
  # @note
@@ -24,31 +24,54 @@ module Vedeu
24
24
 
25
25
  # Render a cleared output.
26
26
  #
27
+ # @param output [Vedeu::Models::Page]
28
+ # @param opts [Hash]
27
29
  # @return [String]
28
- def clear(output = '')
29
- ::File.write(filename, output) if write_file?
30
+ def clear(output = '', opts = {})
31
+ @options = options.merge!(opts)
32
+
33
+ ::File.write(filename, out(output)) if write_file?
30
34
 
31
- output
35
+ out(output)
32
36
  end
33
37
 
34
38
  # @param output [Vedeu::Models::Page]
39
+ # @param opts [Hash]
35
40
  # @return [String]
36
- def render(output)
37
- ::File.write(filename, output) if write_file?
41
+ def render(output = '', opts = {})
42
+ @options = options.merge!(opts)
43
+
44
+ ::File.write(filename, out(output)) if write_file?
38
45
 
39
- output
46
+ out(output)
40
47
  end
41
48
 
42
49
  private
43
50
 
51
+ def out(output)
52
+ if compress?
53
+ Vedeu::Output::Compressor.render(output, options)
54
+
55
+ else
56
+ output
57
+
58
+ end
59
+ end
60
+
44
61
  # @return [String]
45
62
  def filename
46
- options[:filename] + "_#{timestamp}".freeze
63
+ options[:filename] + timestamp
47
64
  end
48
65
 
49
66
  # @return [Float]
50
67
  def timestamp
51
- Time.now.to_f if options[:timestamp]
68
+ if options[:timestamp]
69
+ "_#{Time.now.to_f}".freeze
70
+
71
+ else
72
+ ''.freeze
73
+
74
+ end
52
75
  end
53
76
 
54
77
  # @return [Boolean]
@@ -61,9 +84,10 @@ module Vedeu
61
84
  # @return [Hash]
62
85
  def defaults
63
86
  {
64
- filename: 'out',
65
- timestamp: false,
66
- write_file: true,
87
+ compression: Vedeu::Configuration.compression?,
88
+ filename: 'out',
89
+ timestamp: false,
90
+ write_file: true,
67
91
  }
68
92
  end
69
93
 
@@ -20,7 +20,7 @@ module Vedeu
20
20
  def clear
21
21
  json = parse({})
22
22
 
23
- super(json)
23
+ super(json, { compression: false })
24
24
 
25
25
  json
26
26
  end
@@ -30,7 +30,7 @@ module Vedeu
30
30
  def render(output)
31
31
  json = parse(output)
32
32
 
33
- super(json)
33
+ super(json, { compression: false })
34
34
 
35
35
  json
36
36
  end
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.35'.freeze
4
+ VERSION = '0.6.36'.freeze
5
5
 
6
6
  end
@@ -18,79 +18,13 @@ module Vedeu
18
18
  describe '.align' do
19
19
  subject { described.align(_value) }
20
20
 
21
- context 'when the value is nil' do
22
- it { subject.must_equal(:none) }
23
- end
24
-
25
- context 'when the value is not a Symbol' do
26
- let(:_value) { 'invalid' }
27
-
28
- it { subject.must_equal(:none) }
29
- end
30
-
31
- context 'when the value is :center' do
32
- let(:_value) { :center }
33
-
34
- it { subject.must_equal(:centre) }
35
- end
36
-
37
- context 'when the value is :centre' do
38
- let(:_value) { :centre }
39
-
40
- it { subject.must_equal(:centre) }
41
- end
42
-
43
- context 'when the value is :left' do
44
- let(:_value) { :left }
45
-
46
- it { subject.must_equal(:left) }
47
- end
48
-
49
- context 'when the value is :right' do
50
- let(:_value) { :right }
51
-
52
- it { subject.must_equal(:right) }
53
- end
54
-
55
- context 'when the value is :alignment' do
56
- let(:_value) { :alignment }
57
-
58
- it { subject.must_equal(:none) }
59
- end
60
-
61
- context 'when the value is :align_center' do
62
- let(:_value) { :align_center }
63
-
64
- it { subject.must_equal(:centre) }
65
- end
66
-
67
- context 'when the value is :align_centre' do
68
- let(:_value) { :align_centre }
69
-
70
- it { subject.must_equal(:centre) }
71
- end
72
-
73
- context 'when the value is :align_left' do
74
- let(:_value) { :align_left }
75
-
76
- it { subject.must_equal(:left) }
77
- end
78
-
79
- context 'when the value is :align_right' do
80
- let(:_value) { :align_right }
81
-
82
- it { subject.must_equal(:right) }
83
- end
84
-
85
- context 'when the value is :align_invalid' do
86
- let(:_value) { :align_invalid }
87
-
88
- it { proc { subject }.must_raise(Vedeu::Error::InvalidSyntax) }
89
- end
21
+ it { proc { subject }.must_raise(Vedeu::Error::NotImplemented) }
90
22
  end
91
23
 
92
24
  describe '#align' do
93
- it { instance.must_respond_to(:align) }
25
+ subject { instance.align }
26
+
27
+ it { proc { subject }.must_raise(Vedeu::Error::NotImplemented) }
94
28
  end
95
29
 
96
30
  end # Alignment