vedeu 0.1.6 → 0.1.7

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.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +10 -15
  3. data/deps.md +93 -96
  4. data/lib/vedeu.rb +1 -6
  5. data/lib/vedeu/api/line.rb +0 -4
  6. data/lib/vedeu/api/view.rb +0 -1
  7. data/lib/vedeu/application.rb +1 -3
  8. data/lib/vedeu/instrumentation.rb +1 -1
  9. data/lib/vedeu/models/colour.rb +3 -2
  10. data/lib/vedeu/models/geometry.rb +16 -0
  11. data/lib/vedeu/models/interface.rb +9 -1
  12. data/lib/vedeu/output/render_interface.rb +3 -0
  13. data/lib/vedeu/output/text_adaptor.rb +2 -0
  14. data/lib/vedeu/output/view.rb +17 -24
  15. data/lib/vedeu/support/esc.rb +1 -21
  16. data/test/lib/vedeu/api/base_test.rb +0 -11
  17. data/test/lib/vedeu/api/grid_test.rb +10 -0
  18. data/test/lib/vedeu/api/line_test.rb +0 -11
  19. data/test/lib/vedeu/api/stream_test.rb +0 -11
  20. data/test/lib/vedeu/api/view_test.rb +1 -4
  21. data/test/lib/vedeu/models/composition_test.rb +3 -0
  22. data/test/lib/vedeu/output/view_test.rb +0 -27
  23. data/test/lib/vedeu/support/esc_test.rb +1 -21
  24. data/vedeu.gemspec +1 -1
  25. metadata +2 -20
  26. data/lib/vedeu/output/dsl_parser.rb +0 -19
  27. data/lib/vedeu/output/erb_parser.rb +0 -59
  28. data/lib/vedeu/output/json_parser.rb +0 -23
  29. data/lib/vedeu/output/menu_parser.rb +0 -51
  30. data/lib/vedeu/output/raw_parser.rb +0 -42
  31. data/lib/vedeu/support/helpers.rb +0 -66
  32. data/test/lib/vedeu/output/dsl_parser_test.rb +0 -19
  33. data/test/lib/vedeu/output/erb_parser_test.rb +0 -242
  34. data/test/lib/vedeu/output/json_parser_test.rb +0 -17
  35. data/test/lib/vedeu/output/menu_parser_test.rb +0 -46
  36. data/test/lib/vedeu/output/raw_parser_test.rb +0 -74
  37. data/test/lib/vedeu/support/helpers_test.rb +0 -71
@@ -1,59 +0,0 @@
1
- require 'erb'
2
- require 'vedeu/support/helpers'
3
- require 'vedeu/output/text_adaptor'
4
-
5
- module Vedeu
6
- class ERBParser
7
- include Helpers
8
-
9
- def self.parse(object)
10
- new(object).parse
11
- end
12
-
13
- def initialize(object)
14
- @object = object
15
- @output = ''
16
- end
17
-
18
- def parse
19
- {
20
- interfaces: [
21
- {
22
- name: interface,
23
- lines: TextAdaptor.adapt(erb_output)
24
- }
25
- ]
26
- }
27
- end
28
-
29
- private
30
-
31
- attr_reader :object
32
-
33
- def capture(&block)
34
- erbout = eval('_erbout', block.binding)
35
- erbout_length = erbout.length
36
- block.call
37
- erbout_addition = erbout[erbout_length..-1]
38
- erbout[erbout_length..-1] = ''
39
- erbout_addition = erbout_addition.join if erbout_addition.is_a? Array
40
- erbout_addition
41
- end
42
-
43
- def erb_output
44
- ERB.new(template, nil, '-').result(get_binding)
45
- end
46
-
47
- def interface
48
- object.interface
49
- end
50
-
51
- def template
52
- File.read(object.path)
53
- end
54
-
55
- def get_binding
56
- object.send(:binding)
57
- end
58
- end
59
- end
@@ -1,23 +0,0 @@
1
- require 'json'
2
-
3
- module Vedeu
4
- class JSONParser
5
- def self.parse(json)
6
- new(json).parse
7
- end
8
-
9
- def initialize(json)
10
- @json = json
11
- end
12
-
13
- def parse
14
- JSON.load(json, nil, symbolize_names: true)
15
- rescue JSON::ParserError
16
- {}
17
- end
18
-
19
- private
20
-
21
- attr_reader :json
22
- end
23
- end
@@ -1,51 +0,0 @@
1
- module Vedeu
2
- class MenuParser
3
- def self.parse(args)
4
- new(args).parse
5
- end
6
-
7
- def initialize(args)
8
- @args = args
9
- end
10
-
11
- def parse
12
- { interfaces: interface }
13
- end
14
-
15
- private
16
-
17
- attr_reader :args
18
-
19
- def interface
20
- { name: name, lines: lines }
21
- end
22
-
23
- def lines
24
- lines = []
25
- items.each do |sel, cur, item|
26
- if sel && cur
27
- lines << { streams: { text: "*> #{item}" } }
28
-
29
- elsif cur
30
- lines << { streams: { text: " > #{item}" } }
31
-
32
- elsif sel
33
- lines << { streams: { text: "* #{item}" } }
34
-
35
- else
36
- lines << { streams: { text: " #{item}" } }
37
-
38
- end
39
- end
40
- lines
41
- end
42
-
43
- def items
44
- args.last
45
- end
46
-
47
- def name
48
- args.first
49
- end
50
- end
51
- end
@@ -1,42 +0,0 @@
1
- require 'vedeu/output/text_adaptor'
2
-
3
- module Vedeu
4
- class RawParser
5
- def self.parse(attributes)
6
- new(attributes).parse
7
- end
8
-
9
- def initialize(attributes)
10
- @attributes = attributes
11
- end
12
-
13
- def parse
14
- { interfaces: interfaces }
15
- end
16
-
17
- private
18
-
19
- attr_reader :attributes
20
-
21
- def interfaces
22
- stringified_keys.map do |name, content|
23
- {
24
- name: name,
25
- lines: lines(content)
26
- }
27
- end
28
- end
29
-
30
- def lines(content)
31
- if content.is_a?(Array) && content.first.is_a?(Hash)
32
- content
33
- else
34
- TextAdaptor.adapt(content)
35
- end
36
- end
37
-
38
- def stringified_keys
39
- attributes.inject({}) { |a, (k, v)| a[k.to_s] = v; a }
40
- end
41
- end
42
- end
@@ -1,66 +0,0 @@
1
- require 'pry'
2
- require 'vedeu/support/esc'
3
- require 'vedeu/models/colour'
4
-
5
- # Todo: style method (actually whole thing)
6
-
7
- module Vedeu
8
- module Helpers
9
- def line(&block)
10
- output = capture(&block)
11
- ERB.new(output.gsub(/\n/, ''), nil, '-').result(block.binding)
12
- end
13
-
14
- def foreground(value, &block)
15
- output = Esc.foreground_colour(value)
16
-
17
- if block_given?
18
- output << block.call
19
- output << Esc.string('fg_reset')
20
- end
21
-
22
- output
23
- end
24
- alias_method :fg, :foreground
25
-
26
- def background(value, &block)
27
- output = Esc.background_colour(value)
28
-
29
- if block_given?
30
- output << block.call
31
- output << Esc.string('bg_reset')
32
- end
33
-
34
- output
35
- end
36
- alias_method :bg, :background
37
-
38
- def colour(attributes = {}, &block)
39
- output = Colour.new(attributes).to_s
40
-
41
- if block_given?
42
- output << block.call
43
- output << Esc.string('colour_reset')
44
- end
45
-
46
- output
47
- end
48
-
49
- def style(*value_or_values, &block)
50
- if value_or_values.one?
51
- output = Esc.string(value_or_values.first)
52
- else
53
- output = value_or_values.map do |s|
54
- Esc.string(s)
55
- end.join
56
- end
57
-
58
- if block_given?
59
- output << block.call
60
- output << Esc.string('reset')
61
- end
62
-
63
- output
64
- end
65
- end
66
- end
@@ -1,19 +0,0 @@
1
- require 'test_helper'
2
-
3
- require 'vedeu/output/dsl_parser'
4
-
5
- module Vedeu
6
- describe DSLParser do
7
- it 'returns attributes suitable for Composition' do
8
- DSLParser.parse({ name: 'dummy' }).must_equal(
9
- {
10
- interfaces: [
11
- {
12
- name: 'dummy'
13
- }
14
- ]
15
- }
16
- )
17
- end
18
- end
19
- end
@@ -1,242 +0,0 @@
1
- require 'test_helper'
2
- require 'vedeu/output/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
-
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
-
102
- it 'parses the template and style directives within' do
103
- user_view = UserView.new
104
- user_view.stub(:path, 'test/support/erb/style.erb') do
105
- ERBParser.parse(user_view).must_equal(
106
- {
107
- interfaces: [
108
- {
109
- name: 'test',
110
- lines: [
111
- {
112
- streams: { text: 'Empty style leads to nothing.' }
113
- }, {
114
- streams: { text: "\e[4mUnderlined text." }
115
- }, {
116
- streams: { text: 'Unknown style leads to nothing.' }
117
- }
118
- ]
119
- }
120
- ]
121
- }
122
- )
123
- end
124
- end
125
-
126
- it 'parses the template and both colour and style directives within' do
127
- user_view = UserView.new
128
- user_view.stub(:path, 'test/support/erb/colour_style.erb') do
129
- ERBParser.parse(user_view).must_equal(
130
- {
131
- interfaces: [
132
- {
133
- name: 'test',
134
- lines: [
135
- {
136
- streams: {
137
- text: "\e[38;5;21m\e[4m\e[48;5;17mBlue underline text on dark blue background."
138
- }
139
- }
140
- ]
141
- }
142
- ]
143
- }
144
- )
145
- end
146
- end
147
-
148
- it 'treats sections of the template as one line' do
149
- user_view = UserView.new
150
- user_view.stub(:path, 'test/support/erb/line.erb') do
151
- ERBParser.parse(user_view).must_equal(
152
- {
153
- interfaces: [
154
- {
155
- name: 'test',
156
- lines: [
157
- {
158
- streams: {
159
- text: " This is line one. This is line two."
160
- }
161
- }
162
- ]
163
- }
164
- ]
165
- }
166
- )
167
- end
168
- end
169
-
170
- it 'treats sections of the template as one line with a foreground' do
171
- user_view = UserView.new
172
- user_view.stub(:path, 'test/support/erb/line_foreground.erb') do
173
- ERBParser.parse(user_view).must_equal(
174
- {
175
- interfaces: [
176
- {
177
- name: 'test',
178
- lines: [
179
- {
180
- streams: {
181
- text: " \e[38;5;226mThis is line one.\e[38;2;39m This is line two."
182
- }
183
- }
184
- ]
185
- }
186
- ]
187
- }
188
- )
189
- end
190
- end
191
-
192
- it 'treats sections of the template as one line with a foreground' do
193
- user_view = UserView.new
194
- user_view.stub(:path, 'test/support/erb/line_foreground_2x.erb') do
195
- ERBParser.parse(user_view).must_equal(
196
- {
197
- interfaces: [
198
- {
199
- name: 'test',
200
- lines: [
201
- {
202
- streams: {
203
- text: " \e[38;5;226mThis is line one.\e[38;2;39m \e[38;5;196mThis is line two.\e[38;2;39m This is line three."
204
- }
205
- }
206
- ]
207
- }
208
- ]
209
- }
210
- )
211
- end
212
- end
213
-
214
- it 'treats sections of the template as one line' do
215
- skip
216
- user_view = UserView.new
217
- user_view.stub(:path, 'test/support/erb/line_2x.erb') do
218
- ERBParser.parse(user_view).must_equal(
219
- {
220
- interfaces: [
221
- {
222
- name: 'test',
223
- lines: [
224
- {
225
- streams: {
226
- text: " This is line one. This is line two."
227
- }
228
- }, {
229
- streams: {
230
- text: " This is line three. This is line four."
231
- }
232
- }
233
- ]
234
- }
235
- ]
236
- }
237
- )
238
- end
239
- end
240
- end
241
- end
242
- end