vedeu 0.4.60 → 0.4.61
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.
- checksums.yaml +4 -4
- data/lib/vedeu.rb +2 -0
- data/lib/vedeu/all.rb +8 -4
- data/lib/vedeu/{output → borders}/border.rb +0 -0
- data/lib/vedeu/{output → borders}/borders.rb +0 -0
- data/lib/vedeu/{output → borders}/render_border.rb +24 -18
- data/lib/vedeu/cursor/move.rb +5 -16
- data/lib/vedeu/cursor/reposition.rb +3 -17
- data/lib/vedeu/dsl/view.rb +1 -1
- data/lib/vedeu/geometry/coordinate.rb +21 -11
- data/lib/vedeu/geometry/geometry.rb +1 -1
- data/lib/vedeu/geometry/position.rb +2 -2
- data/lib/vedeu/output/compressor.rb +3 -7
- data/lib/vedeu/output/style.rb +1 -1
- data/lib/vedeu/plugins.rb +12 -13
- data/lib/vedeu/plugins/plugin.rb +4 -2
- data/lib/vedeu/repositories/collection.rb +9 -0
- data/lib/vedeu/templating/all.rb +9 -0
- data/lib/vedeu/templating/decoder.rb +62 -0
- data/lib/vedeu/templating/directive.rb +0 -1
- data/lib/vedeu/templating/encoder.rb +62 -0
- data/lib/vedeu/templating/helpers.rb +10 -22
- data/lib/vedeu/templating/post_processor.rb +81 -0
- data/lib/vedeu/templating/template.rb +1 -7
- data/lib/vedeu/terminal_mode.rb +2 -0
- data/lib/vedeu/version.rb +1 -1
- data/test/lib/vedeu/{output → borders}/border_test.rb +0 -0
- data/test/lib/vedeu/{output → borders}/borders_test.rb +0 -0
- data/test/lib/vedeu/{output → borders}/render_border_test.rb +0 -0
- data/test/lib/vedeu/geometry/coordinate_test.rb +20 -17
- data/test/lib/vedeu/geometry/position_test.rb +1 -1
- data/test/lib/vedeu/models/char_test.rb +17 -18
- data/test/lib/vedeu/output/compressor_test.rb +5 -5
- data/test/lib/vedeu/output/{renderers/all_test.rb → renderers_test.rb} +0 -0
- data/test/lib/vedeu/output/viewport_test.rb +63 -63
- data/test/lib/vedeu/plugins_test.rb +12 -6
- data/test/lib/vedeu/repositories/collection_test.rb +14 -0
- data/test/lib/vedeu/templating/decoder_test.rb +37 -0
- data/test/lib/vedeu/templating/encoder_test.rb +38 -0
- data/test/lib/vedeu/templating/helpers_test.rb +11 -0
- data/test/lib/vedeu/templating/{preprocessor_test.rb → post_processor_test.rb} +14 -18
- data/test/lib/vedeu/templating/template_test.rb +3 -2
- data/test/support/templates/{inline.erb → plain.erb} +0 -0
- metadata +25 -18
- data/lib/vedeu/templating/preprocessor.rb +0 -81
|
@@ -78,6 +78,15 @@ module Vedeu
|
|
|
78
78
|
collection.empty?
|
|
79
79
|
end
|
|
80
80
|
|
|
81
|
+
# An object is equal when its values are the same.
|
|
82
|
+
#
|
|
83
|
+
# @param other [Vedeu::Collection]
|
|
84
|
+
# @return [Boolean]
|
|
85
|
+
def eql?(other)
|
|
86
|
+
self.class == other.class && collection == other.collection
|
|
87
|
+
end
|
|
88
|
+
alias_method :==, :eql?
|
|
89
|
+
|
|
81
90
|
# Returns the size of the collection.
|
|
82
91
|
#
|
|
83
92
|
# @return [Fixnum]
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
module Vedeu
|
|
2
|
+
|
|
3
|
+
module Templating
|
|
4
|
+
|
|
5
|
+
# Converts an encoded string back into an object or objects.
|
|
6
|
+
#
|
|
7
|
+
class Decoder
|
|
8
|
+
|
|
9
|
+
# @param data [String]
|
|
10
|
+
# @return [Object]
|
|
11
|
+
def self.process(data)
|
|
12
|
+
new(data).process
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Returns a new instance of Vedeu::Templating::Decoder.
|
|
16
|
+
#
|
|
17
|
+
# @param data [String]
|
|
18
|
+
# @return [Vedeu::Templating::Decoder]
|
|
19
|
+
def initialize(data)
|
|
20
|
+
@data = data
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# @return [Object]
|
|
24
|
+
def process
|
|
25
|
+
demarshal
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
protected
|
|
29
|
+
|
|
30
|
+
# @!attribute [r] data
|
|
31
|
+
# @return [String]
|
|
32
|
+
attr_reader :data
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
# Convert the marshalled object or objects back into an object(s).
|
|
37
|
+
#
|
|
38
|
+
# @return [Object]
|
|
39
|
+
def demarshal
|
|
40
|
+
Marshal.load(decompress)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Decompress the marshalled object or objects.
|
|
44
|
+
#
|
|
45
|
+
# @return [String]
|
|
46
|
+
def decompress
|
|
47
|
+
Zlib::Inflate.inflate(decode64)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Decode the Base64 string into a compressed, marshalled object or
|
|
51
|
+
# objects.
|
|
52
|
+
#
|
|
53
|
+
# @return [String]
|
|
54
|
+
def decode64
|
|
55
|
+
Base64.strict_decode64(data)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
end # Decoder
|
|
59
|
+
|
|
60
|
+
end # Templating
|
|
61
|
+
|
|
62
|
+
end # Vedeu
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
module Vedeu
|
|
2
|
+
|
|
3
|
+
module Templating
|
|
4
|
+
|
|
5
|
+
# Converts an object or objects into an encoded string.
|
|
6
|
+
#
|
|
7
|
+
class Encoder
|
|
8
|
+
|
|
9
|
+
# @param data [Object]
|
|
10
|
+
# @return [String]
|
|
11
|
+
def self.process(data)
|
|
12
|
+
new(data).process
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Returns a new instance of Vedeu::Templating::Encoder.
|
|
16
|
+
#
|
|
17
|
+
# @param data [Object]
|
|
18
|
+
# @return [Vedeu::Templating::Encoder]
|
|
19
|
+
def initialize(data)
|
|
20
|
+
@data = data
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# @return [String]
|
|
24
|
+
def process
|
|
25
|
+
encode64
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
protected
|
|
29
|
+
|
|
30
|
+
# @!attribute [r] data
|
|
31
|
+
# @return [Object]
|
|
32
|
+
attr_reader :data
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
# Encode the compressed, marshalled object or objects into a Base64
|
|
37
|
+
# string.
|
|
38
|
+
#
|
|
39
|
+
# @return [String]
|
|
40
|
+
def encode64
|
|
41
|
+
Base64.strict_encode64(compress)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Compress the marshalled object or objects.
|
|
45
|
+
#
|
|
46
|
+
# @return [String]
|
|
47
|
+
def compress
|
|
48
|
+
Zlib::Deflate.deflate(marshal)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Convert the object or objects into marshalled object(s).
|
|
52
|
+
#
|
|
53
|
+
# @return [String]
|
|
54
|
+
def marshal
|
|
55
|
+
Marshal.dump(data)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
end # Encoder
|
|
59
|
+
|
|
60
|
+
end # Templating
|
|
61
|
+
|
|
62
|
+
end # Vedeu
|
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
module Vedeu
|
|
2
2
|
|
|
3
|
-
# Provides means to use templates with Vedeu.
|
|
4
3
|
module Templating
|
|
5
4
|
|
|
6
5
|
# Provide helpers to be used with your Vedeu templates.
|
|
7
6
|
#
|
|
8
7
|
module Helpers
|
|
9
8
|
|
|
10
|
-
# @example
|
|
11
|
-
# Roses are {{ background('#ff0000', 'red') }},
|
|
12
|
-
# violets are {{ bg('#0000ff', 'blue') }},
|
|
13
|
-
# {{ background('#00ff00'), 'The test suite is all green!' }}
|
|
14
|
-
#
|
|
15
9
|
# @param value [String] The HTML/CSS colour.
|
|
16
10
|
# @param block [Proc]
|
|
17
11
|
# @return [Vedeu::Stream]
|
|
@@ -31,11 +25,6 @@ module Vedeu
|
|
|
31
25
|
define_stream(attributes, &block)
|
|
32
26
|
end
|
|
33
27
|
|
|
34
|
-
# @example
|
|
35
|
-
# Roses are {{ foreground('#ff0000', 'red') }},
|
|
36
|
-
# violets are {{ fg('#0000ff', 'blue') }},
|
|
37
|
-
# {{ foreground('#00ff00'), 'The test suite is all green!' }}
|
|
38
|
-
#
|
|
39
28
|
# @param value [String] The HTML/CSS colour.
|
|
40
29
|
# @param block [Proc]
|
|
41
30
|
# @return [Vedeu::Stream]
|
|
@@ -45,22 +34,21 @@ module Vedeu
|
|
|
45
34
|
end
|
|
46
35
|
alias_method :fg, :foreground
|
|
47
36
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
# @
|
|
51
|
-
def
|
|
52
|
-
|
|
53
|
-
[:background, :foreground].include?(k) == false || v.nil? || v.empty?
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
Vedeu::Colour.new(attributes)
|
|
37
|
+
# @param value [Symbol]
|
|
38
|
+
# @param block [Proc]
|
|
39
|
+
# @return [Vedeu::Stream]
|
|
40
|
+
def style(value, &block)
|
|
41
|
+
define_stream({ style: value }, &block)
|
|
57
42
|
end
|
|
58
43
|
|
|
59
|
-
|
|
44
|
+
private
|
|
45
|
+
|
|
46
|
+
# @see Vedeu::Templating::Helpers#colour
|
|
60
47
|
def define_stream(attributes = {}, &block)
|
|
61
48
|
fail Vedeu::InvalidSyntax, 'block not given' unless block_given?
|
|
62
49
|
|
|
63
|
-
Vedeu::Stream.build(colour:
|
|
50
|
+
Vedeu::Stream.build(colour: Vedeu::Colour.new(attributes),
|
|
51
|
+
style: Vedeu::Style.new(attributes[:style]),
|
|
64
52
|
value: block.call)
|
|
65
53
|
end
|
|
66
54
|
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
module Vedeu
|
|
2
|
+
|
|
3
|
+
module Templating
|
|
4
|
+
|
|
5
|
+
# Pre-processes a template, to convert all lines and lines with directives
|
|
6
|
+
# into Vedeu::Streams.
|
|
7
|
+
#
|
|
8
|
+
class PostProcessor
|
|
9
|
+
|
|
10
|
+
# @param content [String]
|
|
11
|
+
# @return [Array<Vedeu::Stream>]
|
|
12
|
+
def self.process(content)
|
|
13
|
+
new(content).process
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Returns a new instance of Vedeu::Templating::PostProcessor.
|
|
17
|
+
#
|
|
18
|
+
# @param content [String]
|
|
19
|
+
# @return [Vedeu::Templating::PostProcessor]
|
|
20
|
+
def initialize(content)
|
|
21
|
+
@content = content
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# @return [Vedeu::Streams]
|
|
25
|
+
def process
|
|
26
|
+
lines.each_with_object(Vedeu::Streams.new) do |line, acc|
|
|
27
|
+
if line =~ markers?
|
|
28
|
+
acc << Vedeu::Templating::Directive.process(unmark(line))
|
|
29
|
+
|
|
30
|
+
else
|
|
31
|
+
acc << Vedeu::Stream.new(value: line.chomp)
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
acc
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
protected
|
|
39
|
+
|
|
40
|
+
# @!attribute [r] content
|
|
41
|
+
# @return [String]
|
|
42
|
+
attr_reader :content
|
|
43
|
+
|
|
44
|
+
private
|
|
45
|
+
|
|
46
|
+
# @return [Array<String>]
|
|
47
|
+
def lines
|
|
48
|
+
content.lines
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Return a pattern to remove directive markers and spaces.
|
|
52
|
+
#
|
|
53
|
+
# @example
|
|
54
|
+
# line containing {{ or }}
|
|
55
|
+
#
|
|
56
|
+
# @return [Regexp]
|
|
57
|
+
def markers
|
|
58
|
+
/({{\s*|\s*}})/
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# @example
|
|
62
|
+
# line contains {{ or }}
|
|
63
|
+
#
|
|
64
|
+
# @return [Regexp]
|
|
65
|
+
def markers?
|
|
66
|
+
/^\s*({{)(.*?)(}})$/
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Removes the markers and any line returns from the given line.
|
|
70
|
+
#
|
|
71
|
+
# @param line [String]
|
|
72
|
+
# @return [String]
|
|
73
|
+
def unmark(line)
|
|
74
|
+
line.gsub(markers, '').chomp
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
end # PostProcessor
|
|
78
|
+
|
|
79
|
+
end # Templating
|
|
80
|
+
|
|
81
|
+
end # Vedeu
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
module Vedeu
|
|
2
2
|
|
|
3
|
-
# Provides means to use templates with Vedeu.
|
|
4
3
|
module Templating
|
|
5
4
|
|
|
6
5
|
# Generic class to loading a template and parsing it via ERb.
|
|
@@ -26,7 +25,7 @@ module Vedeu
|
|
|
26
25
|
@options = options || {}
|
|
27
26
|
end
|
|
28
27
|
|
|
29
|
-
# @return [
|
|
28
|
+
# @return [Vedeu::Stream]
|
|
30
29
|
def parse
|
|
31
30
|
ERB.new(load, nil, '-').result(binding)
|
|
32
31
|
end
|
|
@@ -43,11 +42,6 @@ module Vedeu
|
|
|
43
42
|
|
|
44
43
|
private
|
|
45
44
|
|
|
46
|
-
# @return [String]
|
|
47
|
-
def preprocess
|
|
48
|
-
Vedeu::Templating::Preprocessor.process(load)
|
|
49
|
-
end
|
|
50
|
-
|
|
51
45
|
# @return [String]
|
|
52
46
|
def load
|
|
53
47
|
File.read(path)
|
data/lib/vedeu/terminal_mode.rb
CHANGED
data/lib/vedeu/version.rb
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -5,21 +5,22 @@ module Vedeu
|
|
|
5
5
|
describe Coordinate do
|
|
6
6
|
|
|
7
7
|
let(:described) { Vedeu::Coordinate }
|
|
8
|
-
let(:instance) { described.new(_name) }
|
|
8
|
+
let(:instance) { described.new(_name, oy, ox) }
|
|
9
9
|
let(:_name) { 'coordinate' }
|
|
10
|
+
let(:oy) { 0 }
|
|
11
|
+
let(:ox) { 0 }
|
|
10
12
|
let(:height) { 6 }
|
|
11
13
|
let(:width) { 6 }
|
|
12
14
|
let(:x) { 7 }
|
|
13
15
|
let(:y) { 5 }
|
|
14
16
|
|
|
15
17
|
before do
|
|
16
|
-
Vedeu::Border.new(name: _name,
|
|
17
|
-
|
|
18
|
-
Vedeu::Geometry.new(name: _name,
|
|
18
|
+
Vedeu::Border.new(name: _name, enabled: true).store
|
|
19
|
+
Vedeu::Geometry.new(name: _name,
|
|
19
20
|
height: height,
|
|
20
|
-
width:
|
|
21
|
-
x:
|
|
22
|
-
y:
|
|
21
|
+
width: width,
|
|
22
|
+
x: x,
|
|
23
|
+
y: y).store
|
|
23
24
|
end
|
|
24
25
|
after do
|
|
25
26
|
Vedeu.borders.reset
|
|
@@ -29,6 +30,8 @@ module Vedeu
|
|
|
29
30
|
describe '#initialize' do
|
|
30
31
|
it { instance.must_be_instance_of(described) }
|
|
31
32
|
it { instance.instance_variable_get('@name').must_equal(_name) }
|
|
33
|
+
it { instance.instance_variable_get('@oy').must_equal(oy) }
|
|
34
|
+
it { instance.instance_variable_get('@ox').must_equal(ox) }
|
|
32
35
|
end
|
|
33
36
|
|
|
34
37
|
describe '#yn' do
|
|
@@ -60,20 +63,20 @@ module Vedeu
|
|
|
60
63
|
end
|
|
61
64
|
|
|
62
65
|
describe '#y_position' do
|
|
63
|
-
let(:
|
|
66
|
+
let(:oy) { 0 }
|
|
64
67
|
|
|
65
|
-
subject { instance.y_position
|
|
68
|
+
subject { instance.y_position }
|
|
66
69
|
|
|
67
70
|
it { subject.must_be_instance_of(Fixnum) }
|
|
68
71
|
|
|
69
72
|
context 'with a negative index' do
|
|
70
|
-
let(:
|
|
73
|
+
let(:oy) { -3 }
|
|
71
74
|
|
|
72
75
|
it { subject.must_equal(6) }
|
|
73
76
|
end
|
|
74
77
|
|
|
75
78
|
context 'with an index greater than the maximum index for y' do
|
|
76
|
-
let(:
|
|
79
|
+
let(:oy) { 9 }
|
|
77
80
|
|
|
78
81
|
it { subject.must_equal(9) }
|
|
79
82
|
|
|
@@ -85,27 +88,27 @@ module Vedeu
|
|
|
85
88
|
end
|
|
86
89
|
|
|
87
90
|
context 'with an index within range' do
|
|
88
|
-
let(:
|
|
91
|
+
let(:oy) { 3 }
|
|
89
92
|
|
|
90
93
|
it { subject.must_equal(8) }
|
|
91
94
|
end
|
|
92
95
|
end
|
|
93
96
|
|
|
94
97
|
describe '#x_position' do
|
|
95
|
-
let(:
|
|
98
|
+
let(:ox) { 0 }
|
|
96
99
|
|
|
97
|
-
subject { instance.x_position
|
|
100
|
+
subject { instance.x_position }
|
|
98
101
|
|
|
99
102
|
it { subject.must_be_instance_of(Fixnum) }
|
|
100
103
|
|
|
101
104
|
context 'with a negative index' do
|
|
102
|
-
let(:
|
|
105
|
+
let(:ox) { -3 }
|
|
103
106
|
|
|
104
107
|
it { subject.must_equal(8) }
|
|
105
108
|
end
|
|
106
109
|
|
|
107
110
|
context 'with an index greater than the maximum index for x' do
|
|
108
|
-
let(:
|
|
111
|
+
let(:ox) { 9 }
|
|
109
112
|
|
|
110
113
|
it { subject.must_equal(11) }
|
|
111
114
|
|
|
@@ -117,7 +120,7 @@ module Vedeu
|
|
|
117
120
|
end
|
|
118
121
|
|
|
119
122
|
context 'with an index within range' do
|
|
120
|
-
let(:
|
|
123
|
+
let(:ox) { 3 }
|
|
121
124
|
|
|
122
125
|
it { subject.must_equal(10) }
|
|
123
126
|
end
|