vedeu 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/Guardfile +1 -1
  3. data/README.md +13 -0
  4. data/deps.md +13 -4
  5. data/lib/vedeu.rb +1 -1
  6. data/lib/vedeu/models/interface.rb +5 -1
  7. data/lib/vedeu/output/render_interface.rb +1 -3
  8. data/lib/vedeu/parsing/erb_parser.rb +43 -0
  9. data/lib/vedeu/parsing/json_parser.rb +13 -3
  10. data/lib/vedeu/parsing/menu_parser.rb +7 -12
  11. data/lib/vedeu/parsing/raw_parser.rb +34 -0
  12. data/lib/vedeu/parsing/text_adaptor.rb +0 -6
  13. data/lib/vedeu/parsing/view.rb +46 -0
  14. data/lib/vedeu/support/events.rb +0 -19
  15. data/lib/vedeu/support/geometry.rb +66 -46
  16. data/lib/vedeu/support/helpers.rb +43 -0
  17. data/lib/vedeu/support/input.rb +2 -0
  18. data/lib/vedeu/support/queue.rb +0 -12
  19. data/test/lib/vedeu/parsing/erb_parser_test.rb +154 -0
  20. data/test/lib/vedeu/parsing/menu_parser_test.rb +9 -0
  21. data/test/lib/vedeu/parsing/{hash_parser_test.rb → raw_parser_test.rb} +5 -5
  22. data/test/lib/vedeu/parsing/view_test.rb +38 -0
  23. data/test/lib/vedeu/support/geometry_test.rb +8 -8
  24. data/test/lib/vedeu/support/helpers_test.rb +68 -0
  25. data/test/lib/vedeu/support/queue_test.rb +3 -35
  26. data/test/lib/vedeu_test.rb +39 -0
  27. data/test/support/erb/colour.erb +3 -0
  28. data/test/support/erb/colour_style.erb +1 -0
  29. data/test/support/erb/style.erb +3 -0
  30. data/test/support/template.erb +6 -1
  31. data/vedeu.gemspec +2 -2
  32. metadata +24 -13
  33. data/lib/vedeu/output/template.rb +0 -23
  34. data/lib/vedeu/parsing/hash_parser.rb +0 -68
  35. data/lib/vedeu/parsing/parser.rb +0 -52
  36. data/test/lib/vedeu/output/template.rb +0 -21
  37. data/test/lib/vedeu/parsing/parser_test.rb +0 -31
@@ -0,0 +1,43 @@
1
+ require 'vedeu/support/esc'
2
+ require 'vedeu/models/colour'
3
+
4
+ module Vedeu
5
+ module Helpers
6
+ def foreground(value, &block)
7
+ @output = ''
8
+ @output << Esc.foreground_colour(value)
9
+ @output << block.call if block_given?
10
+ @output
11
+ end
12
+ alias_method :fg, :foreground
13
+
14
+ def background(value, &block)
15
+ @output = ''
16
+ @output << Esc.background_colour(value)
17
+ @output << block.call if block_given?
18
+ @output
19
+ end
20
+ alias_method :bg, :background
21
+
22
+ def colour(attributes = {}, &block)
23
+ @output = ''
24
+ @output << Colour.new(attributes).to_s
25
+ @output << block.call if block_given?
26
+ @output
27
+ end
28
+
29
+ def style(*value_or_values, &block)
30
+ @output = ''
31
+ if value_or_values.one?
32
+ @output << Esc.string(value_or_values.first)
33
+ @output << block.call if block_given?
34
+ else
35
+ @output << value_or_values.map do |s|
36
+ Esc.string(s)
37
+ end.join
38
+ @output << block.call if block_given?
39
+ end
40
+ @output
41
+ end
42
+ end
43
+ end
@@ -7,6 +7,8 @@ module Vedeu
7
7
  new.capture
8
8
  end
9
9
 
10
+ def initialize; end
11
+
10
12
  def capture
11
13
  Vedeu.trigger(:_keypress_, keypress)
12
14
  end
@@ -16,22 +16,10 @@ module Vedeu
16
16
  store.size > 0
17
17
  end
18
18
 
19
- def entries
20
- store
21
- end
22
-
23
- def size
24
- store.size
25
- end
26
-
27
19
  def reset
28
20
  store.clear
29
21
  end
30
22
 
31
- def view
32
- store.inspect
33
- end
34
-
35
23
  private
36
24
 
37
25
  def store
@@ -0,0 +1,154 @@
1
+ require 'test_helper'
2
+ require 'vedeu/parsing/erb_parser'
3
+ require 'vedeu/support/helpers'
4
+
5
+ class UserView
6
+ def initialize
7
+ @output = ''
8
+ end
9
+
10
+ def value
11
+ 'Testing Vedeu.'
12
+ end
13
+
14
+ def interface
15
+ 'test'
16
+ end
17
+
18
+ def path
19
+ 'test/support/template.erb'
20
+ end
21
+ end
22
+
23
+ module Vedeu
24
+ describe ERBParser do
25
+ describe '.parse' do
26
+ it 'parses the template when the template file was found' do
27
+ skip
28
+ parser = ERBParser.parse(UserView.new)
29
+ parser.must_equal("This is the test template.\n\n\e[38;5;55mTesting Vedeu.\n\e[48;5;226mTesting Vedeu.\n\e[38;5;208m\e[48;5;226mTesting Vedeu.\n\e[4mTesting Vedeu.\n\nSome more content...\n")
30
+ end
31
+
32
+ it 'parses the template when the template file was found' do
33
+ parser = ERBParser.parse(UserView.new)
34
+ parser.must_equal(
35
+ {
36
+ interfaces: [
37
+ {
38
+ name: 'test',
39
+ lines: [
40
+ {
41
+ streams: { text: 'This is the test template.' }
42
+ }, {
43
+ streams: { text: '' }
44
+ }, {
45
+ streams: { text: "\e[38;5;55mTesting Vedeu." }
46
+ }, {
47
+ streams: { text: "\e[48;5;226mTesting Vedeu." }
48
+ }, {
49
+ streams: { text: "\e[38;5;208m\e[48;5;226mTesting Vedeu." }
50
+ }, {
51
+ streams: { text: "\e[4mTesting Vedeu." }
52
+ }, {
53
+ streams: { text: '' }
54
+ }, {
55
+ streams: { text: 'Some more content...' }
56
+ }
57
+ ]
58
+ }
59
+ ]
60
+ }
61
+ )
62
+ end
63
+
64
+ it 'raises an exception when the template file cannot be found' do
65
+ user_view = UserView.new
66
+ user_view.stub(:path, '/some/wrong/path/template.erb') do
67
+ proc { ERBParser.parse(user_view) }.must_raise(Errno::ENOENT)
68
+ end
69
+ end
70
+
71
+ describe 'colour parsing' do
72
+ it 'parses the template and colour directives within' do
73
+ user_view = UserView.new
74
+ user_view.stub(:path, 'test/support/erb/colour.erb') do
75
+ ERBParser.parse(user_view).must_equal(
76
+ {
77
+ interfaces: [
78
+ {
79
+ name: 'test',
80
+ lines: [
81
+ {
82
+ streams: {
83
+ text: "\e[38;5;52mDark red text on default background."
84
+ }
85
+ }, {
86
+ streams: {
87
+ text: "\e[48;5;201mDefault text on magenta background."
88
+ }
89
+ }, {
90
+ streams: {
91
+ text: "\e[38;5;196m\e[48;5;17mRed text on dark blue background."
92
+ }
93
+ }
94
+ ]
95
+ }
96
+ ]
97
+ }
98
+ )
99
+ end
100
+ end
101
+ end
102
+
103
+ describe 'style parsing' do
104
+ it 'parses the template and style directives within' do
105
+ user_view = UserView.new
106
+ user_view.stub(:path, 'test/support/erb/style.erb') do
107
+ ERBParser.parse(user_view).must_equal(
108
+ {
109
+ interfaces: [
110
+ {
111
+ name: 'test',
112
+ lines: [
113
+ {
114
+ streams: { text: 'Empty style leads to nothing.' }
115
+ }, {
116
+ streams: { text: "\e[4mUnderlined text." }
117
+ }, {
118
+ streams: { text: 'Unknown style leads to nothing.' }
119
+ }
120
+ ]
121
+ }
122
+ ]
123
+ }
124
+ )
125
+ end
126
+ end
127
+ end
128
+
129
+ describe 'colour and style parsing' do
130
+ it 'parses the template and both colour and style directives within' do
131
+ user_view = UserView.new
132
+ user_view.stub(:path, 'test/support/erb/colour_style.erb') do
133
+ ERBParser.parse(user_view).must_equal(
134
+ {
135
+ interfaces: [
136
+ {
137
+ name: 'test',
138
+ lines: [
139
+ {
140
+ streams: {
141
+ text: "\e[38;5;21m\e[4m\e[48;5;17mBlue underline text on dark blue background."
142
+ }
143
+ }
144
+ ]
145
+ }
146
+ ]
147
+ }
148
+ )
149
+ end
150
+ end
151
+ end
152
+ end
153
+ end
154
+ end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+ require 'vedeu/parsing/menu_parser'
3
+
4
+ module Vedeu
5
+ describe MenuParser do
6
+ describe '.parse' do
7
+ end
8
+ end
9
+ end
@@ -1,11 +1,11 @@
1
1
  require 'test_helper'
2
- require 'vedeu/parsing/hash_parser'
2
+ require 'vedeu/parsing/raw_parser'
3
3
 
4
4
  module Vedeu
5
- describe HashParser do
5
+ describe RawParser do
6
6
  describe '.parse' do
7
7
  it 'returns a Hash when the output is content for multiple interfaces' do
8
- HashParser.parse({
8
+ RawParser.parse({
9
9
  test: 'Some content...',
10
10
  dummy: 'More content...'
11
11
  }).must_equal({
@@ -30,7 +30,7 @@ module Vedeu
30
30
  end
31
31
 
32
32
  it 'returns a Hash when the output is content for a single interface' do
33
- HashParser.parse({
33
+ RawParser.parse({
34
34
  dummy: 'Some content...'
35
35
  }).must_equal({
36
36
  interfaces: [
@@ -47,7 +47,7 @@ module Vedeu
47
47
  end
48
48
 
49
49
  it 'returns a Hash when the output is empty' do
50
- HashParser.parse({}).must_equal({ interfaces: [] })
50
+ RawParser.parse({}).must_equal({ interfaces: [] })
51
51
  end
52
52
  end
53
53
  end
@@ -0,0 +1,38 @@
1
+ require 'test_helper'
2
+ require 'vedeu/parsing/view'
3
+
4
+ module Vedeu
5
+ describe View do
6
+ describe '.render' do
7
+ # it 'returns when the type is :erb' do
8
+ # output = ''
9
+ # View.render(:erb, output).must_equal('')
10
+ # end
11
+
12
+ # it 'returns when the type is :json' do
13
+ # output = ''
14
+ # View.render(:json, output).must_equal('')
15
+ # end
16
+
17
+ # it 'returns when the type is :hash' do
18
+ # output = ''
19
+ # View.render(:hash, output).must_equal('')
20
+ # end
21
+
22
+ # it 'returns when the type is :menu' do
23
+ # output = ''
24
+ # View.render(:menu, output).must_equal('')
25
+ # end
26
+
27
+ # it 'returns when the type is not set' do
28
+ # output = ''
29
+ # View.render(nil, output).must_equal('')
30
+ # end
31
+
32
+ # it 'returns when the type is not recognised' do
33
+ # output = ''
34
+ # View.render(:unknown, output).must_equal('')
35
+ # end
36
+ end
37
+ end
38
+ end
@@ -3,14 +3,6 @@ require 'vedeu/support/geometry'
3
3
 
4
4
  module Vedeu
5
5
  describe Geometry do
6
- it 'raises an exception when the height attribute is not set' do
7
- proc { Geometry.new({ width: 18 }) }.must_raise(KeyError)
8
- end
9
-
10
- it 'raises an exception when the width attribute is not set' do
11
- proc { Geometry.new({ height: 6 }) }.must_raise(KeyError)
12
- end
13
-
14
6
  describe '#origin' do
15
7
  it 'returns the origin for the interface' do
16
8
  geometry = Geometry.new({ width: 5, height: 5, centred: false })
@@ -75,6 +67,10 @@ module Vedeu
75
67
  end
76
68
 
77
69
  describe '#height' do
70
+ it 'raises an exception when the height attribute is not set' do
71
+ proc { Geometry.new({ width: 18 }).height }.must_raise(InvalidHeight)
72
+ end
73
+
78
74
  it 'raises an exception when the value is less than 1' do
79
75
  geometry = Geometry.new({ height: -6, width: 18 })
80
76
  proc { geometry.height }.must_raise(OutOfBoundsError)
@@ -151,6 +147,10 @@ module Vedeu
151
147
  end
152
148
 
153
149
  describe '#width' do
150
+ it 'raises an exception when the width attribute is not set' do
151
+ proc { Geometry.new({ height: 6 }).width }.must_raise(InvalidWidth)
152
+ end
153
+
154
154
  it 'raises an exception when the value is less than 1' do
155
155
  geometry = Geometry.new({ height: 6, width: -18 })
156
156
  proc { geometry.width }.must_raise(OutOfBoundsError)
@@ -0,0 +1,68 @@
1
+ require 'test_helper'
2
+ require 'vedeu/support/helpers'
3
+
4
+ module Vedeu
5
+ class TestHelpers
6
+ include Helpers
7
+ end
8
+
9
+ describe Helpers do
10
+ describe '.foreground' do
11
+ it 'returns an escape sequence for the specified CSS foreground' do
12
+ TestHelpers.new.foreground('#a5f500').must_equal("\e[38;5;148m")
13
+
14
+ TestHelpers.new.fg('#851500').must_equal("\e[38;5;88m")
15
+ end
16
+
17
+ it 'returns an escape sequence plus interpolation when a block is given' do
18
+ TestHelpers.new.foreground('#a5f500') { 'Some text' }
19
+ .must_equal("\e[38;5;148mSome text")
20
+ end
21
+ end
22
+
23
+ describe '.background' do
24
+ it 'returns an escape sequence for the specified CSS background' do
25
+ TestHelpers.new.background('#2f2f2f').must_equal("\e[48;5;16m")
26
+
27
+ TestHelpers.new.bg('#ffffff').must_equal("\e[48;5;231m")
28
+ end
29
+
30
+ it 'returns an escape sequence plus interpolation when a block is given' do
31
+ TestHelpers.new.background('#2f2f2f') { 'Some text' }
32
+ .must_equal("\e[48;5;16mSome text")
33
+ end
34
+ end
35
+
36
+ describe '.colour' do
37
+ it 'returns an escape sequence for the specified CSS colours' do
38
+ TestHelpers.new.colour({ background: '#2f2f2f', foreground: '#a5ff00' })
39
+ .must_equal("\e[38;5;154m\e[48;5;16m")
40
+ end
41
+
42
+ it 'returns an escape sequence plus interpolation when a block is given' do
43
+ TestHelpers.new.colour({ background: '#2f2f2f', foreground: '#a5ff00' }) { 'Some text' }.must_equal("\e[38;5;154m\e[48;5;16mSome text")
44
+ end
45
+ end
46
+
47
+ describe '.style' do
48
+ it 'returns an escape sequence for multiple styles' do
49
+ TestHelpers.new.style('bold', 'underline')
50
+ .must_equal("\e[1m\e[4m")
51
+ end
52
+
53
+ it 'returns an escape sequence for a style' do
54
+ TestHelpers.new.style('colour_reset')
55
+ .must_equal("\e[38;2;39m\e[48;2;49m")
56
+ end
57
+
58
+ it 'returns an empty string for no styles' do
59
+ TestHelpers.new.style.must_equal('')
60
+ end
61
+
62
+ it 'returns an escape sequence plus interpolation when a block is given' do
63
+ TestHelpers.new.style('bold', 'underline') { 'Some text' }
64
+ .must_equal("\e[1m\e[4mSome text")
65
+ end
66
+ end
67
+ end
68
+ end
@@ -17,8 +17,9 @@ module Vedeu
17
17
  end
18
18
 
19
19
  describe '.enqueue' do
20
- it 'contains the enqueued item' do
21
- Queue.enqueue(:result).size.must_equal(1)
20
+ it 'stores an item on the queue' do
21
+ Queue.enqueue(:result)
22
+ Queue.enqueued?.must_equal(true)
22
23
  end
23
24
  end
24
25
 
@@ -33,44 +34,11 @@ module Vedeu
33
34
  end
34
35
  end
35
36
 
36
- describe '.entries' do
37
- it 'returns an empty collection when the queue is empty' do
38
- Queue.entries.must_equal([])
39
- end
40
-
41
- it 'returns all the enqueue items when the queue is not empty' do
42
- Queue.enqueue(:queued_entry)
43
- Queue.entries.must_equal([:queued_entry])
44
- end
45
- end
46
-
47
- describe '.size' do
48
- it 'returns the size of the queue when the queue is empty' do
49
- Queue.size.must_equal(0)
50
- end
51
-
52
- it 'returns the size of the queue when the queue is not empty' do
53
- Queue.enqueue(:result).enqueue(:result)
54
- Queue.size.must_equal(2)
55
- end
56
- end
57
-
58
37
  describe '.clear' do
59
38
  it 'returns an empty array' do
60
39
  Queue.enqueue(:result)
61
40
  Queue.reset.must_be_empty
62
41
  end
63
42
  end
64
-
65
- describe '.view' do
66
- it 'returns the queue as a String when the queue is empty' do
67
- Queue.view.must_equal('[]')
68
- end
69
-
70
- it 'returns the queue as a String when the queue is not empty' do
71
- Queue.enqueue(:result)
72
- Queue.view.must_equal('[:result]')
73
- end
74
- end
75
43
  end
76
44
  end