vedeu 0.4.60 → 0.4.61

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/lib/vedeu.rb +2 -0
  3. data/lib/vedeu/all.rb +8 -4
  4. data/lib/vedeu/{output → borders}/border.rb +0 -0
  5. data/lib/vedeu/{output → borders}/borders.rb +0 -0
  6. data/lib/vedeu/{output → borders}/render_border.rb +24 -18
  7. data/lib/vedeu/cursor/move.rb +5 -16
  8. data/lib/vedeu/cursor/reposition.rb +3 -17
  9. data/lib/vedeu/dsl/view.rb +1 -1
  10. data/lib/vedeu/geometry/coordinate.rb +21 -11
  11. data/lib/vedeu/geometry/geometry.rb +1 -1
  12. data/lib/vedeu/geometry/position.rb +2 -2
  13. data/lib/vedeu/output/compressor.rb +3 -7
  14. data/lib/vedeu/output/style.rb +1 -1
  15. data/lib/vedeu/plugins.rb +12 -13
  16. data/lib/vedeu/plugins/plugin.rb +4 -2
  17. data/lib/vedeu/repositories/collection.rb +9 -0
  18. data/lib/vedeu/templating/all.rb +9 -0
  19. data/lib/vedeu/templating/decoder.rb +62 -0
  20. data/lib/vedeu/templating/directive.rb +0 -1
  21. data/lib/vedeu/templating/encoder.rb +62 -0
  22. data/lib/vedeu/templating/helpers.rb +10 -22
  23. data/lib/vedeu/templating/post_processor.rb +81 -0
  24. data/lib/vedeu/templating/template.rb +1 -7
  25. data/lib/vedeu/terminal_mode.rb +2 -0
  26. data/lib/vedeu/version.rb +1 -1
  27. data/test/lib/vedeu/{output → borders}/border_test.rb +0 -0
  28. data/test/lib/vedeu/{output → borders}/borders_test.rb +0 -0
  29. data/test/lib/vedeu/{output → borders}/render_border_test.rb +0 -0
  30. data/test/lib/vedeu/geometry/coordinate_test.rb +20 -17
  31. data/test/lib/vedeu/geometry/position_test.rb +1 -1
  32. data/test/lib/vedeu/models/char_test.rb +17 -18
  33. data/test/lib/vedeu/output/compressor_test.rb +5 -5
  34. data/test/lib/vedeu/output/{renderers/all_test.rb → renderers_test.rb} +0 -0
  35. data/test/lib/vedeu/output/viewport_test.rb +63 -63
  36. data/test/lib/vedeu/plugins_test.rb +12 -6
  37. data/test/lib/vedeu/repositories/collection_test.rb +14 -0
  38. data/test/lib/vedeu/templating/decoder_test.rb +37 -0
  39. data/test/lib/vedeu/templating/encoder_test.rb +38 -0
  40. data/test/lib/vedeu/templating/helpers_test.rb +11 -0
  41. data/test/lib/vedeu/templating/{preprocessor_test.rb → post_processor_test.rb} +14 -18
  42. data/test/lib/vedeu/templating/template_test.rb +3 -2
  43. data/test/support/templates/{inline.erb → plain.erb} +0 -0
  44. metadata +25 -18
  45. 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,9 @@
1
+ module Vedeu
2
+
3
+ # Provides means to use templates with Vedeu.
4
+ #
5
+ module Templating
6
+
7
+ end # Templating
8
+
9
+ end # Vedeu
@@ -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
@@ -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
  # Converts a directive found in a template into a Vedeu::Stream object.
@@ -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
- private
49
-
50
- # @see Vedeu::Templating::Helpers#colours
51
- def define_colour(attributes = {})
52
- attributes.delete_if do |k, v|
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
- # @see Vedeu::Templating::Helpers#colours
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: define_colour(attributes),
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 [void]
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)
@@ -1,5 +1,7 @@
1
1
  module Vedeu
2
2
 
3
+ # Store the current mode of the terminal.
4
+ #
3
5
  module TerminalMode
4
6
 
5
7
  extend self
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.4.60'
4
+ VERSION = '0.4.61'
5
5
 
6
6
  end
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
- enabled: true).store
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: width,
21
- x: x,
22
- y: y).store
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(:index) { 0 }
66
+ let(:oy) { 0 }
64
67
 
65
- subject { instance.y_position(index) }
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(:index) { -3 }
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(:index) { 9 }
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(:index) { 3 }
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(:index) { 0 }
98
+ let(:ox) { 0 }
96
99
 
97
- subject { instance.x_position(index) }
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(:index) { -3 }
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(:index) { 9 }
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(:index) { 3 }
123
+ let(:ox) { 3 }
121
124
 
122
125
  it { subject.must_equal(10) }
123
126
  end