vedeu 0.8.3 → 0.8.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/integrations/342_streams.rb +74 -0
- data/integrations/dsl_app_001.rb +58 -0
- data/integrations/dsl_app_002.rb +59 -0
- data/integrations/dsl_app_003.rb +58 -0
- data/integrations/dsl_app_004.rb +63 -0
- data/integrations/dsl_app_005.rb +62 -0
- data/integrations/dsl_app_006.rb +57 -0
- data/integrations/dsl_app_007.rb +63 -0
- data/integrations/dsl_app_008.rb +65 -0
- data/integrations/dsl_app_009.rb +70 -0
- data/integrations/dsl_app_010.rb +71 -0
- data/integrations/dsl_app_011.rb +61 -0
- data/integrations/dsl_app_012.rb +59 -0
- data/integrations/dsl_app_013.rb +60 -0
- data/integrations/dsl_app_014.rb +60 -0
- data/integrations/dsl_app_015.rb +60 -0
- data/integrations/dsl_app_016.rb +64 -0
- data/integrations/dsl_app_017.rb +56 -0
- data/integrations/dsl_app_018.rb +56 -0
- data/integrations/dsl_app_019.rb +56 -0
- data/integrations/dsl_app_020.rb +56 -0
- data/integrations/expected/342_streams.out +1 -0
- data/integrations/expected/dsl_app_001.out +1 -0
- data/integrations/expected/dsl_app_002.out +1 -0
- data/integrations/expected/dsl_app_003.out +1 -0
- data/integrations/expected/dsl_app_004.out +1 -0
- data/integrations/expected/dsl_app_005.out +1 -0
- data/integrations/expected/dsl_app_006.out +1 -0
- data/integrations/expected/dsl_app_007.out +1 -0
- data/integrations/expected/dsl_app_008.out +1 -0
- data/integrations/expected/dsl_app_009.out +1 -0
- data/integrations/expected/dsl_app_010.out +1 -0
- data/integrations/expected/dsl_app_011.out +1 -0
- data/integrations/expected/dsl_app_012.out +1 -0
- data/integrations/expected/dsl_app_013.out +1 -0
- data/integrations/expected/dsl_app_014.out +1 -0
- data/integrations/expected/dsl_app_015.out +1 -0
- data/integrations/expected/dsl_app_016.out +1 -0
- data/integrations/support/test_interface.rb +13 -0
- data/integrations/test_runner.sh +32 -0
- data/lib/vedeu/cells/empty.rb +14 -0
- data/lib/vedeu/colours/background.rb +13 -0
- data/lib/vedeu/colours/colour.rb +11 -4
- data/lib/vedeu/colours/foreground.rb +13 -0
- data/lib/vedeu/common.rb +42 -0
- data/lib/vedeu/dsl/attributes.rb +1 -1
- data/lib/vedeu/dsl/elements.rb +57 -23
- data/lib/vedeu/dsl/string/align.rb +17 -2
- data/lib/vedeu/geometries/position.rb +5 -0
- data/lib/vedeu/geometries/positionable.rb +2 -2
- data/lib/vedeu/presentation/style.rb +5 -0
- data/lib/vedeu/renderers/all.rb +1 -0
- data/lib/vedeu/renderers/escape.rb +96 -0
- data/lib/vedeu/repositories/defaults.rb +14 -6
- data/lib/vedeu/runtime/launcher.rb +5 -1
- data/lib/vedeu/version.rb +1 -1
- data/lib/vedeu/views/lines.rb +5 -0
- data/lib/vedeu/views/stream.rb +8 -1
- data/lib/vedeu/views/streams.rb +6 -1
- data/lib/vedeu/views/value.rb +2 -8
- data/lib/vedeu/views/view.rb +1 -1
- data/test/lib/vedeu/colours/colour_test.rb +0 -8
- data/test/lib/vedeu/common_test.rb +72 -0
- data/test/lib/vedeu/dsl/string/align_test.rb +1 -1
- metadata +43 -17
- data/examples/284_slow_rendering.rb +0 -108
- data/examples/views/expected/vedeu_line.html +0 -140
- data/examples/views/expected/vedeu_line.json +0 -96050
- data/examples/views/expected/vedeu_line.out +0 -1
- data/examples/views/expected/vedeu_line.txt +0 -58
- data/examples/views/expected/vedeu_lines.html +0 -140
- data/examples/views/expected/vedeu_lines.json +0 -96050
- data/examples/views/expected/vedeu_lines.out +0 -1
- data/examples/views/expected/vedeu_lines_alignment.html +0 -80
- data/examples/views/expected/vedeu_lines_alignment.json +0 -46370
- data/examples/views/expected/vedeu_lines_alignment.out +0 -1
- data/examples/views/line.rb +0 -128
- data/examples/views/lines.rb +0 -165
- data/examples/views/lines_alignment.rb +0 -126
- data/examples/views/runner.sh +0 -73
data/lib/vedeu/renderers/all.rb
CHANGED
@@ -0,0 +1,96 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Vedeu
|
4
|
+
|
5
|
+
module Renderers
|
6
|
+
|
7
|
+
# Converts a grid of {Vedeu::Cells} objects or
|
8
|
+
# {Vedeu::Cells::Char} objects into a stream of characters without
|
9
|
+
# escape sequences.
|
10
|
+
#
|
11
|
+
class Escape < Vedeu::Renderers::File
|
12
|
+
|
13
|
+
include Vedeu::Renderers::Options
|
14
|
+
|
15
|
+
# Render a cleared output.
|
16
|
+
#
|
17
|
+
# @return [String]
|
18
|
+
def clear
|
19
|
+
render('[[:clear]]')
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
# Combine all characters in a row to produce a line, then all
|
25
|
+
# lines should be terminated with `\n`. Convert to an array of
|
26
|
+
# UTF8 codepoints, and any codepoint above 255 should be
|
27
|
+
# converted to a space.
|
28
|
+
#
|
29
|
+
# @return [String]
|
30
|
+
def content
|
31
|
+
return '[[:empty]]' if string?(output) || absent?(output)
|
32
|
+
|
33
|
+
buffer.map { |row| row.join("\n") }.join("\n\n")
|
34
|
+
end
|
35
|
+
|
36
|
+
# @return [Array<String>]
|
37
|
+
def buffer
|
38
|
+
empty = Array.new(Vedeu.height) { Array.new(Vedeu.width) { '[:cell]' } }
|
39
|
+
|
40
|
+
output.each do |row|
|
41
|
+
row.each do |char|
|
42
|
+
next unless renderable?(char) &&
|
43
|
+
positionable?(char) &&
|
44
|
+
escapable?(char)
|
45
|
+
|
46
|
+
empty[char.position.y - 1][char.position.x - 1] = char.to_ast
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
empty
|
51
|
+
end
|
52
|
+
|
53
|
+
# @return [Boolean]
|
54
|
+
def positionable?(char)
|
55
|
+
char.respond_to?(:position) &&
|
56
|
+
char.position.is_a?(Vedeu::Geometries::Position)
|
57
|
+
end
|
58
|
+
|
59
|
+
# @return [Array<Class>]
|
60
|
+
def renderables
|
61
|
+
[
|
62
|
+
Vedeu::Cells::Border,
|
63
|
+
Vedeu::Cells::BottomHorizontal,
|
64
|
+
Vedeu::Cells::BottomLeft,
|
65
|
+
Vedeu::Cells::BottomRight,
|
66
|
+
Vedeu::Cells::Corner,
|
67
|
+
Vedeu::Cells::Char,
|
68
|
+
Vedeu::Cells::Clear,
|
69
|
+
Vedeu::Cells::Cursor,
|
70
|
+
Vedeu::Cells::Empty,
|
71
|
+
Vedeu::Cells::Escape,
|
72
|
+
Vedeu::Cells::Horizontal,
|
73
|
+
Vedeu::Cells::LeftVertical,
|
74
|
+
Vedeu::Cells::RightVertical,
|
75
|
+
Vedeu::Cells::TopHorizontal,
|
76
|
+
Vedeu::Cells::TopLeft,
|
77
|
+
Vedeu::Cells::TopRight,
|
78
|
+
Vedeu::Cells::Vertical,
|
79
|
+
]
|
80
|
+
end
|
81
|
+
|
82
|
+
# @return [Boolean]
|
83
|
+
def renderable?(char)
|
84
|
+
renderables.include?(char.class)
|
85
|
+
end
|
86
|
+
|
87
|
+
# @return [Boolean]
|
88
|
+
def escapable?(char)
|
89
|
+
char.respond_to?(:to_ast)
|
90
|
+
end
|
91
|
+
|
92
|
+
end # Escape
|
93
|
+
|
94
|
+
end # Renderers
|
95
|
+
|
96
|
+
end # Vedeu
|
@@ -12,6 +12,8 @@ module Vedeu
|
|
12
12
|
#
|
13
13
|
module Defaults
|
14
14
|
|
15
|
+
include Vedeu::Common
|
16
|
+
|
15
17
|
# Returns a new instance of the class including this module.
|
16
18
|
#
|
17
19
|
# @note
|
@@ -23,12 +25,7 @@ module Vedeu
|
|
23
25
|
# @return [void] A new instance of the class including this
|
24
26
|
# module.
|
25
27
|
def initialize(attributes = {})
|
26
|
-
|
27
|
-
'Argument :attributes is not a Hash.' unless attributes.is_a?(Hash)
|
28
|
-
|
29
|
-
attrs = attributes.keep_if { |key, _| defaults.key?(key) }
|
30
|
-
|
31
|
-
defaults.merge!(attrs).each do |key, value|
|
28
|
+
defaults.merge!(validate(attributes)).each do |key, value|
|
32
29
|
instance_variable_set("@#{key}", value || defaults.fetch(key))
|
33
30
|
end
|
34
31
|
end
|
@@ -40,6 +37,17 @@ module Vedeu
|
|
40
37
|
{}
|
41
38
|
end
|
42
39
|
|
40
|
+
# @param attributes [Hash]
|
41
|
+
# @raise [Vedeu::Error::InvalidSyntax] When the :attributes
|
42
|
+
# param is not a Hash.
|
43
|
+
# @return [Hash]
|
44
|
+
def validate(attributes)
|
45
|
+
fail Vedeu::Error::InvalidSyntax,
|
46
|
+
'Argument :attributes is not a Hash.' unless hash?(attributes)
|
47
|
+
|
48
|
+
attributes.keep_if { |key, _| defaults.key?(key) }
|
49
|
+
end
|
50
|
+
|
43
51
|
end # Defaults
|
44
52
|
|
45
53
|
end # Repositories
|
@@ -112,7 +112,11 @@ module Vedeu
|
|
112
112
|
$stdout = STDOUT
|
113
113
|
$stderr = STDERR
|
114
114
|
|
115
|
-
|
115
|
+
# Commenting out this line means Vedeu can be run as a module within an
|
116
|
+
# application. Specifically, this allows me to run some very basic
|
117
|
+
# integration tests.
|
118
|
+
#
|
119
|
+
# @kernel.exit(exit_code)
|
116
120
|
end
|
117
121
|
# :nocov:
|
118
122
|
|
data/lib/vedeu/version.rb
CHANGED
data/lib/vedeu/views/lines.rb
CHANGED
@@ -18,6 +18,11 @@ module Vedeu
|
|
18
18
|
if collection.is_a?(Vedeu::Views::Lines)
|
19
19
|
collection
|
20
20
|
|
21
|
+
elsif collection.is_a?(Vedeu::Views::Streams)
|
22
|
+
if collection.empty?
|
23
|
+
# @todo Investigate whether this is being used.
|
24
|
+
end
|
25
|
+
|
21
26
|
elsif collection.is_a?(Array)
|
22
27
|
return new(collection, parent, name) if collection.empty?
|
23
28
|
|
data/lib/vedeu/views/stream.rb
CHANGED
@@ -68,7 +68,14 @@ module Vedeu
|
|
68
68
|
# @param child [Vedeu::Views::Stream]
|
69
69
|
# @return [Vedeu::Views::Streams]
|
70
70
|
def add(child)
|
71
|
-
parent
|
71
|
+
if defined?(parent) && present?(parent)
|
72
|
+
parent.add(child)
|
73
|
+
|
74
|
+
else
|
75
|
+
@value = child
|
76
|
+
|
77
|
+
self
|
78
|
+
end
|
72
79
|
end
|
73
80
|
alias_method :<<, :add
|
74
81
|
|
data/lib/vedeu/views/streams.rb
CHANGED
@@ -37,6 +37,11 @@ module Vedeu
|
|
37
37
|
elsif collection.is_a?(Vedeu::Views::Stream)
|
38
38
|
new([collection], parent, name)
|
39
39
|
|
40
|
+
elsif collection.is_a?(Vedeu::Views::Chars)
|
41
|
+
return new([], parent, name) if collection.empty?
|
42
|
+
|
43
|
+
new([Vedeu::Views::Stream.new(value: collection)], parent, name)
|
44
|
+
|
40
45
|
elsif collection.is_a?(String)
|
41
46
|
return new([], parent, name) if collection.empty?
|
42
47
|
|
@@ -45,7 +50,7 @@ module Vedeu
|
|
45
50
|
else
|
46
51
|
fail Vedeu::Error::InvalidSyntax,
|
47
52
|
'Cannot coerce for Vedeu::View::Streams, as collection ' \
|
48
|
-
|
53
|
+
"unrecognised. (#{collection.class.name})"
|
49
54
|
|
50
55
|
end
|
51
56
|
end
|
data/lib/vedeu/views/value.rb
CHANGED
@@ -109,19 +109,13 @@ module Vedeu
|
|
109
109
|
|
110
110
|
# @return [void]
|
111
111
|
def value
|
112
|
-
@
|
113
|
-
collection.coerce(@value, self)
|
114
|
-
|
115
|
-
else
|
116
|
-
collection.coerce([], self)
|
117
|
-
|
118
|
-
end
|
112
|
+
collection.coerce(@value || [], self)
|
119
113
|
end
|
120
114
|
|
121
115
|
# @param value [void]
|
122
116
|
# @return [void]
|
123
117
|
def value=(value)
|
124
|
-
@
|
118
|
+
@value = collection.coerce(value, self)
|
125
119
|
end
|
126
120
|
|
127
121
|
# Returns a boolean indicating whether this model has a
|
data/lib/vedeu/views/view.rb
CHANGED
@@ -167,6 +167,30 @@ module Vedeu
|
|
167
167
|
end
|
168
168
|
end
|
169
169
|
|
170
|
+
describe '#line_model?' do
|
171
|
+
subject { instance.line_model? }
|
172
|
+
|
173
|
+
context 'when a model method is available in the including class' do
|
174
|
+
let(:model) { Vedeu::Views::Line.new }
|
175
|
+
|
176
|
+
before { instance.stubs(:model).returns(model) }
|
177
|
+
|
178
|
+
context 'when the model is a line' do
|
179
|
+
it { subject.must_equal(true) }
|
180
|
+
end
|
181
|
+
|
182
|
+
context 'when the model is not a line' do
|
183
|
+
let(:model) { :invalid }
|
184
|
+
|
185
|
+
it { subject.must_equal(false) }
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
context 'when a model method is not available in the including class' do
|
190
|
+
it { subject.must_equal(false) }
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
170
194
|
describe '#numeric?' do
|
171
195
|
let(:_value) {}
|
172
196
|
|
@@ -252,6 +276,30 @@ module Vedeu
|
|
252
276
|
end
|
253
277
|
end
|
254
278
|
|
279
|
+
describe '#stream_model?' do
|
280
|
+
subject { instance.stream_model? }
|
281
|
+
|
282
|
+
context 'when a model method is available in the including class' do
|
283
|
+
let(:model) { Vedeu::Views::Stream.new }
|
284
|
+
|
285
|
+
before { instance.stubs(:model).returns(model) }
|
286
|
+
|
287
|
+
context 'when the model is a stream' do
|
288
|
+
it { subject.must_equal(true) }
|
289
|
+
end
|
290
|
+
|
291
|
+
context 'when the model is not a stream' do
|
292
|
+
let(:model) { :invalid }
|
293
|
+
|
294
|
+
it { subject.must_equal(false) }
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
context 'when a model method is not available in the including class' do
|
299
|
+
it { subject.must_equal(false) }
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
255
303
|
describe '#string?' do
|
256
304
|
let(:_value) {}
|
257
305
|
|
@@ -296,6 +344,30 @@ module Vedeu
|
|
296
344
|
end
|
297
345
|
end
|
298
346
|
|
347
|
+
describe '#view_model?' do
|
348
|
+
subject { instance.view_model? }
|
349
|
+
|
350
|
+
context 'when a model method is available in the including class' do
|
351
|
+
let(:model) { Vedeu::Views::View.new }
|
352
|
+
|
353
|
+
before { instance.stubs(:model).returns(model) }
|
354
|
+
|
355
|
+
context 'when the model is a view' do
|
356
|
+
it { subject.must_equal(true) }
|
357
|
+
end
|
358
|
+
|
359
|
+
context 'when the model is not a view' do
|
360
|
+
let(:model) { :invalid }
|
361
|
+
|
362
|
+
it { subject.must_equal(false) }
|
363
|
+
end
|
364
|
+
end
|
365
|
+
|
366
|
+
context 'when a model method is not available in the including class' do
|
367
|
+
it { subject.must_equal(false) }
|
368
|
+
end
|
369
|
+
end
|
370
|
+
|
299
371
|
end # Common
|
300
372
|
|
301
373
|
end # Vedeu
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vedeu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gavin Laking
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: guard
|
@@ -460,7 +460,6 @@ files:
|
|
460
460
|
- docs/streams.md
|
461
461
|
- docs/template.md
|
462
462
|
- docs/view.md
|
463
|
-
- examples/284_slow_rendering.rb
|
464
463
|
- examples/dsl_alignment.rb
|
465
464
|
- examples/dsl_colours.rb
|
466
465
|
- examples/dsl_demo_groups.rb
|
@@ -475,26 +474,52 @@ files:
|
|
475
474
|
- examples/views/expected/vedeu_full_screen.json
|
476
475
|
- examples/views/expected/vedeu_full_screen.out
|
477
476
|
- examples/views/expected/vedeu_full_screen.txt
|
478
|
-
- examples/views/expected/vedeu_line.html
|
479
|
-
- examples/views/expected/vedeu_line.json
|
480
|
-
- examples/views/expected/vedeu_line.out
|
481
|
-
- examples/views/expected/vedeu_line.txt
|
482
|
-
- examples/views/expected/vedeu_lines.html
|
483
|
-
- examples/views/expected/vedeu_lines.json
|
484
|
-
- examples/views/expected/vedeu_lines.out
|
485
|
-
- examples/views/expected/vedeu_lines_alignment.html
|
486
|
-
- examples/views/expected/vedeu_lines_alignment.json
|
487
|
-
- examples/views/expected/vedeu_lines_alignment.out
|
488
477
|
- examples/views/full_screen.rb
|
489
|
-
- examples/views/line.rb
|
490
|
-
- examples/views/lines.rb
|
491
|
-
- examples/views/lines_alignment.rb
|
492
478
|
- examples/views/lines_line_stream.rb
|
493
479
|
- examples/views/lines_line_streams.rb
|
494
480
|
- examples/views/lines_line_streams_stream.rb
|
495
481
|
- examples/views/lines_line_streams_stream_stream.rb
|
496
482
|
- examples/views/lines_streams.rb
|
497
|
-
-
|
483
|
+
- integrations/342_streams.rb
|
484
|
+
- integrations/dsl_app_001.rb
|
485
|
+
- integrations/dsl_app_002.rb
|
486
|
+
- integrations/dsl_app_003.rb
|
487
|
+
- integrations/dsl_app_004.rb
|
488
|
+
- integrations/dsl_app_005.rb
|
489
|
+
- integrations/dsl_app_006.rb
|
490
|
+
- integrations/dsl_app_007.rb
|
491
|
+
- integrations/dsl_app_008.rb
|
492
|
+
- integrations/dsl_app_009.rb
|
493
|
+
- integrations/dsl_app_010.rb
|
494
|
+
- integrations/dsl_app_011.rb
|
495
|
+
- integrations/dsl_app_012.rb
|
496
|
+
- integrations/dsl_app_013.rb
|
497
|
+
- integrations/dsl_app_014.rb
|
498
|
+
- integrations/dsl_app_015.rb
|
499
|
+
- integrations/dsl_app_016.rb
|
500
|
+
- integrations/dsl_app_017.rb
|
501
|
+
- integrations/dsl_app_018.rb
|
502
|
+
- integrations/dsl_app_019.rb
|
503
|
+
- integrations/dsl_app_020.rb
|
504
|
+
- integrations/expected/342_streams.out
|
505
|
+
- integrations/expected/dsl_app_001.out
|
506
|
+
- integrations/expected/dsl_app_002.out
|
507
|
+
- integrations/expected/dsl_app_003.out
|
508
|
+
- integrations/expected/dsl_app_004.out
|
509
|
+
- integrations/expected/dsl_app_005.out
|
510
|
+
- integrations/expected/dsl_app_006.out
|
511
|
+
- integrations/expected/dsl_app_007.out
|
512
|
+
- integrations/expected/dsl_app_008.out
|
513
|
+
- integrations/expected/dsl_app_009.out
|
514
|
+
- integrations/expected/dsl_app_010.out
|
515
|
+
- integrations/expected/dsl_app_011.out
|
516
|
+
- integrations/expected/dsl_app_012.out
|
517
|
+
- integrations/expected/dsl_app_013.out
|
518
|
+
- integrations/expected/dsl_app_014.out
|
519
|
+
- integrations/expected/dsl_app_015.out
|
520
|
+
- integrations/expected/dsl_app_016.out
|
521
|
+
- integrations/support/test_interface.rb
|
522
|
+
- integrations/test_runner.sh
|
498
523
|
- lib/vedeu.rb
|
499
524
|
- lib/vedeu/all.rb
|
500
525
|
- lib/vedeu/application/all.rb
|
@@ -704,6 +729,7 @@ files:
|
|
704
729
|
- lib/vedeu/presentation/style.rb
|
705
730
|
- lib/vedeu/presentation/styles.rb
|
706
731
|
- lib/vedeu/renderers/all.rb
|
732
|
+
- lib/vedeu/renderers/escape.rb
|
707
733
|
- lib/vedeu/renderers/file.rb
|
708
734
|
- lib/vedeu/renderers/html.rb
|
709
735
|
- lib/vedeu/renderers/json.rb
|