vedeu 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Guardfile +1 -1
- data/README.md +13 -0
- data/deps.md +13 -4
- data/lib/vedeu.rb +1 -1
- data/lib/vedeu/models/interface.rb +5 -1
- data/lib/vedeu/output/render_interface.rb +1 -3
- data/lib/vedeu/parsing/erb_parser.rb +43 -0
- data/lib/vedeu/parsing/json_parser.rb +13 -3
- data/lib/vedeu/parsing/menu_parser.rb +7 -12
- data/lib/vedeu/parsing/raw_parser.rb +34 -0
- data/lib/vedeu/parsing/text_adaptor.rb +0 -6
- data/lib/vedeu/parsing/view.rb +46 -0
- data/lib/vedeu/support/events.rb +0 -19
- data/lib/vedeu/support/geometry.rb +66 -46
- data/lib/vedeu/support/helpers.rb +43 -0
- data/lib/vedeu/support/input.rb +2 -0
- data/lib/vedeu/support/queue.rb +0 -12
- data/test/lib/vedeu/parsing/erb_parser_test.rb +154 -0
- data/test/lib/vedeu/parsing/menu_parser_test.rb +9 -0
- data/test/lib/vedeu/parsing/{hash_parser_test.rb → raw_parser_test.rb} +5 -5
- data/test/lib/vedeu/parsing/view_test.rb +38 -0
- data/test/lib/vedeu/support/geometry_test.rb +8 -8
- data/test/lib/vedeu/support/helpers_test.rb +68 -0
- data/test/lib/vedeu/support/queue_test.rb +3 -35
- data/test/lib/vedeu_test.rb +39 -0
- data/test/support/erb/colour.erb +3 -0
- data/test/support/erb/colour_style.erb +1 -0
- data/test/support/erb/style.erb +3 -0
- data/test/support/template.erb +6 -1
- data/vedeu.gemspec +2 -2
- metadata +24 -13
- data/lib/vedeu/output/template.rb +0 -23
- data/lib/vedeu/parsing/hash_parser.rb +0 -68
- data/lib/vedeu/parsing/parser.rb +0 -52
- data/test/lib/vedeu/output/template.rb +0 -21
- data/test/lib/vedeu/parsing/parser_test.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6fee0507672be816ff50768dda87bcae402feddf
|
4
|
+
data.tar.gz: 4a8c9d298fda7eaafba079138bf87e408dbd7739
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6960df810fcdc92db6d6c0e753d9e8a7e372d33e3deed7bbe374b6dcb91b1243d4027d3445ffdd8a7b1fc9ea5a749f6935935a5eea62f06dbfecd3a892fe5af9
|
7
|
+
data.tar.gz: f40602cd24e26a9395dd95bc7a791b5542da1350f0ede53dc7a8b1af1ffa6835f3cb9810f9b7345b85321b133ff89269d174ceb69f64312bbd81e81330fa94e7
|
data/Guardfile
CHANGED
data/README.md
CHANGED
@@ -134,6 +134,19 @@ Vedeu has a range of symbol styles which are compatible with most terminals whic
|
|
134
134
|
Like colours, they can be defined in either interfaces, for specific lines or within streams. Styles are applied as encountered.
|
135
135
|
|
136
136
|
|
137
|
+
### Templates
|
138
|
+
|
139
|
+
The following helpers are available in to the ERBParser.
|
140
|
+
|
141
|
+
foreground (alias: `fg`)
|
142
|
+
|
143
|
+
background (alias: `bg`)
|
144
|
+
|
145
|
+
colour
|
146
|
+
|
147
|
+
style
|
148
|
+
|
149
|
+
|
137
150
|
## Contributing
|
138
151
|
|
139
152
|
1. Fork it ( http://github.com/gavinlaking/vedeu/fork )
|
data/deps.md
CHANGED
@@ -28,12 +28,14 @@ Geometry
|
|
28
28
|
Esc
|
29
29
|
Terminal
|
30
30
|
|
31
|
+
ERBParser
|
32
|
+
|
31
33
|
Esc
|
32
34
|
Translator
|
33
35
|
|
34
36
|
Events
|
35
37
|
|
36
|
-
|
38
|
+
RawParser
|
37
39
|
TextAdaptor
|
38
40
|
|
39
41
|
Input
|
@@ -70,10 +72,14 @@ LineCollection
|
|
70
72
|
|
71
73
|
Menu
|
72
74
|
|
75
|
+
MenuParser
|
76
|
+
|
73
77
|
Parser
|
74
78
|
Composition
|
75
|
-
|
79
|
+
ERBParser
|
80
|
+
RawParser
|
76
81
|
JSONParser
|
82
|
+
MenuParser
|
77
83
|
|
78
84
|
Persistence
|
79
85
|
Interface
|
@@ -102,6 +108,7 @@ Style
|
|
102
108
|
Esc
|
103
109
|
|
104
110
|
Template
|
111
|
+
Helpers
|
105
112
|
|
106
113
|
Terminal
|
107
114
|
Esc
|
@@ -118,7 +125,6 @@ Wordwrap
|
|
118
125
|
Orphans
|
119
126
|
----------------------------------------------------------------------
|
120
127
|
|
121
|
-
Template - orphaned
|
122
128
|
Wordwrap - orphaned
|
123
129
|
Menu - orphaned
|
124
130
|
|
@@ -184,9 +190,12 @@ Launcher
|
|
184
190
|
Terminal
|
185
191
|
Esc
|
186
192
|
Translator
|
187
|
-
|
193
|
+
ERBParser
|
194
|
+
Template
|
195
|
+
RawParser
|
188
196
|
TextAdaptor
|
189
197
|
JSONParser
|
198
|
+
MenuParser
|
190
199
|
Queue
|
191
200
|
Terminal
|
192
201
|
Esc
|
data/lib/vedeu.rb
CHANGED
@@ -34,6 +34,10 @@ module Vedeu
|
|
34
34
|
super
|
35
35
|
end
|
36
36
|
|
37
|
+
def clear
|
38
|
+
@_clear ||= ClearInterface.call(self)
|
39
|
+
end
|
40
|
+
|
37
41
|
def enqueue
|
38
42
|
super(self.to_s)
|
39
43
|
end
|
@@ -51,7 +55,7 @@ module Vedeu
|
|
51
55
|
self.current = dequeue
|
52
56
|
|
53
57
|
elsif no_content?
|
54
|
-
self.current =
|
58
|
+
self.current = clear
|
55
59
|
|
56
60
|
else
|
57
61
|
self.current
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'vedeu/output/clear_interface'
|
2
|
-
|
3
1
|
module Vedeu
|
4
2
|
class RenderInterface
|
5
3
|
def self.call(interface)
|
@@ -11,7 +9,7 @@ module Vedeu
|
|
11
9
|
end
|
12
10
|
|
13
11
|
def render
|
14
|
-
out = [
|
12
|
+
out = [interface.clear]
|
15
13
|
processed_lines.each_with_index do |line, index|
|
16
14
|
if index + 1 <= height
|
17
15
|
out << interface.origin(index)
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'vedeu/support/helpers'
|
3
|
+
require 'vedeu/parsing/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
|
+
end
|
16
|
+
|
17
|
+
def parse
|
18
|
+
{
|
19
|
+
interfaces: [{ name: interface, lines: TextAdaptor.adapt(erb_output) }]
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
attr_reader :object
|
26
|
+
|
27
|
+
def erb_output
|
28
|
+
ERB.new(template, nil, '-').result(get_binding)
|
29
|
+
end
|
30
|
+
|
31
|
+
def interface
|
32
|
+
object.interface
|
33
|
+
end
|
34
|
+
|
35
|
+
def template
|
36
|
+
File.read(object.path)
|
37
|
+
end
|
38
|
+
|
39
|
+
def get_binding
|
40
|
+
object.send(:binding)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -1,13 +1,23 @@
|
|
1
1
|
require 'json'
|
2
2
|
|
3
3
|
module Vedeu
|
4
|
-
|
5
|
-
|
4
|
+
class JSONParser
|
5
|
+
def self.parse(output)
|
6
|
+
new(output).parse
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(output)
|
10
|
+
@output = output
|
11
|
+
end
|
6
12
|
|
7
|
-
def parse
|
13
|
+
def parse
|
8
14
|
JSON.load(output, nil, symbolize_names: true)
|
9
15
|
rescue JSON::ParserError
|
10
16
|
{}
|
11
17
|
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
attr_reader :output
|
12
22
|
end
|
13
23
|
end
|
@@ -1,16 +1,11 @@
|
|
1
1
|
module Vedeu
|
2
2
|
class MenuParser
|
3
|
-
|
4
|
-
|
5
|
-
# @param output [Hash] a key/value pair.
|
6
|
-
#
|
7
|
-
# @return [Hash]
|
8
|
-
def self.parse(output = {})
|
9
|
-
new(output).parse
|
3
|
+
def self.parse(menu)
|
4
|
+
new(menu).parse
|
10
5
|
end
|
11
6
|
|
12
|
-
def initialize(
|
13
|
-
@
|
7
|
+
def initialize(menu)
|
8
|
+
@menu = menu
|
14
9
|
end
|
15
10
|
|
16
11
|
def parse
|
@@ -19,7 +14,7 @@ module Vedeu
|
|
19
14
|
|
20
15
|
private
|
21
16
|
|
22
|
-
attr_reader :
|
17
|
+
attr_reader :menu
|
23
18
|
|
24
19
|
def interface
|
25
20
|
{ name: name, lines: lines }
|
@@ -46,11 +41,11 @@ module Vedeu
|
|
46
41
|
end
|
47
42
|
|
48
43
|
def items
|
49
|
-
|
44
|
+
menu.last
|
50
45
|
end
|
51
46
|
|
52
47
|
def name
|
53
|
-
|
48
|
+
menu.first
|
54
49
|
end
|
55
50
|
end
|
56
51
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'vedeu/parsing/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: TextAdaptor.adapt(content)
|
26
|
+
}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def stringified_keys
|
31
|
+
attributes.inject({}) { |a, (k, v)| a[k.to_s] = v; a }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -1,11 +1,5 @@
|
|
1
1
|
module Vedeu
|
2
2
|
class TextAdaptor
|
3
|
-
# Convert a block of text into a collection of lines.
|
4
|
-
#
|
5
|
-
# @param text [String|Array] a block of text containing new line (\n)
|
6
|
-
# characters, or a collection of strings.
|
7
|
-
#
|
8
|
-
# @return [Array]
|
9
3
|
def self.adapt(text)
|
10
4
|
new(text).adapt
|
11
5
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'vedeu/models/composition'
|
2
|
+
require 'vedeu/parsing/erb_parser'
|
3
|
+
require 'vedeu/parsing/raw_parser'
|
4
|
+
require 'vedeu/parsing/json_parser'
|
5
|
+
require 'vedeu/parsing/menu_parser'
|
6
|
+
require 'vedeu/parsing/raw_parser'
|
7
|
+
|
8
|
+
module Vedeu
|
9
|
+
class View
|
10
|
+
def self.render(type, output)
|
11
|
+
new(type, output).render
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(type, output)
|
15
|
+
@type, @output = type, output
|
16
|
+
end
|
17
|
+
|
18
|
+
def render
|
19
|
+
Composition.enqueue(parsed_output)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
attr_reader :type, :output
|
25
|
+
|
26
|
+
def parsed_output
|
27
|
+
@parsed ||= parser.parse(output)
|
28
|
+
end
|
29
|
+
|
30
|
+
def parser
|
31
|
+
{
|
32
|
+
erb: ERBParser,
|
33
|
+
json: JSONParser,
|
34
|
+
hash: RawParser,
|
35
|
+
menu: MenuParser,
|
36
|
+
raw: RawRarser,
|
37
|
+
}.fetch(type)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# ERBParser: { :interface, :path, :object }
|
43
|
+
# RawParser: { 'interface_name' => String|Array }
|
44
|
+
# { :interface_name => String|Array }
|
45
|
+
# JSONParser: output (string which is converted into a hash)
|
46
|
+
# MenuParser: ['interface_name', Vedeu::Menu instance]
|
data/lib/vedeu/support/events.rb
CHANGED
@@ -2,37 +2,22 @@ module Vedeu
|
|
2
2
|
class Events
|
3
3
|
def initialize(&block)
|
4
4
|
@handlers = Hash.new { |h, k| h[k] = [] }
|
5
|
-
|
6
|
-
log("self: #{self.object_id}")
|
7
|
-
|
8
5
|
self.instance_eval(&block) if block_given?
|
9
|
-
|
10
6
|
self
|
11
7
|
end
|
12
8
|
|
13
9
|
def add(object, &block)
|
14
|
-
log("self: #{self.object_id}")
|
15
|
-
log("object: #{object.object_id}")
|
16
|
-
|
17
10
|
@self_before_instance_eval = eval 'self', block.binding
|
18
11
|
|
19
12
|
self.instance_eval(&block)
|
20
13
|
end
|
21
14
|
|
22
15
|
def on(event, &block)
|
23
|
-
log("self: #{self.object_id}")
|
24
|
-
log("block: #{block.object_id}")
|
25
|
-
log("storing: #{event.inspect}")
|
26
|
-
|
27
16
|
handlers[event] << block
|
28
17
|
end
|
29
18
|
|
30
19
|
def trigger(event, *args)
|
31
20
|
handlers[event].each do |handler|
|
32
|
-
log("self: #{self.object_id}")
|
33
|
-
log("handler: #{handler.object_id}")
|
34
|
-
log("running: #{event.inspect}")
|
35
|
-
|
36
21
|
handler.call(*args)
|
37
22
|
end
|
38
23
|
end
|
@@ -46,9 +31,5 @@ module Vedeu
|
|
46
31
|
private
|
47
32
|
|
48
33
|
attr_reader :handlers
|
49
|
-
|
50
|
-
def log(message)
|
51
|
-
Vedeu.log(sprintf("%42s%s", '', message)) if Vedeu.debug?
|
52
|
-
end
|
53
34
|
end
|
54
35
|
end
|
@@ -2,18 +2,13 @@ require 'vedeu/support/esc'
|
|
2
2
|
require 'vedeu/support/terminal'
|
3
3
|
|
4
4
|
module Vedeu
|
5
|
+
InvalidHeight = Class.new(StandardError)
|
6
|
+
InvalidWidth = Class.new(StandardError)
|
5
7
|
OutOfBoundsError = Class.new(StandardError)
|
6
8
|
|
7
9
|
class Geometry
|
8
10
|
def initialize(attrs = {})
|
9
|
-
@attrs
|
10
|
-
@height = attrs.fetch(:height)
|
11
|
-
@width = attrs.fetch(:width)
|
12
|
-
@terminal_height = attrs.fetch(:terminal_height, Terminal.height)
|
13
|
-
@terminal_width = attrs.fetch(:terminal_width, Terminal.width)
|
14
|
-
@y = attrs.fetch(:y, 1)
|
15
|
-
@x = attrs.fetch(:x, 1)
|
16
|
-
@centred = attrs.fetch(:centred, true)
|
11
|
+
@attrs = attrs
|
17
12
|
end
|
18
13
|
|
19
14
|
def origin(index = 0)
|
@@ -21,59 +16,31 @@ module Vedeu
|
|
21
16
|
end
|
22
17
|
|
23
18
|
def terminal_height
|
24
|
-
|
25
|
-
|
26
|
-
fail_if_out_of_bounds('terminal_height',
|
27
|
-
@terminal_height,
|
28
|
-
Terminal.height)
|
29
|
-
|
30
|
-
@terminal_height
|
19
|
+
@terminal_height ||= attrs_terminal_height
|
31
20
|
end
|
32
21
|
|
33
22
|
def height
|
34
|
-
|
35
|
-
|
36
|
-
fail_if_out_of_bounds('height', @height, terminal_height)
|
37
|
-
|
38
|
-
@height
|
23
|
+
@height ||= attrs_height
|
39
24
|
end
|
40
25
|
|
41
26
|
def y
|
42
|
-
|
43
|
-
|
44
|
-
fail_if_out_of_bounds('y', @y, terminal_height)
|
27
|
+
@y ||= attrs_y
|
28
|
+
end
|
45
29
|
|
46
|
-
|
30
|
+
def x
|
31
|
+
@x ||= attrs_x
|
47
32
|
end
|
48
33
|
|
49
34
|
def terminal_width
|
50
|
-
|
51
|
-
|
52
|
-
fail_if_out_of_bounds('terminal_width',
|
53
|
-
@terminal_width,
|
54
|
-
Terminal.width)
|
55
|
-
|
56
|
-
@terminal_width
|
35
|
+
@terminal_width ||= attrs_terminal_width
|
57
36
|
end
|
58
37
|
|
59
38
|
def width
|
60
|
-
|
61
|
-
|
62
|
-
fail_if_out_of_bounds('width', @width, terminal_width)
|
63
|
-
|
64
|
-
@width
|
65
|
-
end
|
66
|
-
|
67
|
-
def x
|
68
|
-
fail_if_less_than_one(@x)
|
69
|
-
|
70
|
-
fail_if_out_of_bounds('x', @x, terminal_width)
|
71
|
-
|
72
|
-
@x
|
39
|
+
@width ||= attrs_width
|
73
40
|
end
|
74
41
|
|
75
42
|
def centred
|
76
|
-
|
43
|
+
@centred ||= attrs_centred
|
77
44
|
end
|
78
45
|
|
79
46
|
def centre
|
@@ -128,6 +95,60 @@ module Vedeu
|
|
128
95
|
|
129
96
|
private
|
130
97
|
|
98
|
+
attr_reader :attrs
|
99
|
+
|
100
|
+
def attrs_height
|
101
|
+
height = attrs.fetch(:height)
|
102
|
+
fail_if_less_than_one(height)
|
103
|
+
fail_if_out_of_bounds('height', height, terminal_height)
|
104
|
+
height
|
105
|
+
rescue KeyError
|
106
|
+
fail InvalidHeight, 'An Interface must have a height attribute.'
|
107
|
+
end
|
108
|
+
|
109
|
+
def attrs_terminal_height
|
110
|
+
terminal_height = attrs.fetch(:terminal_height, Terminal.height)
|
111
|
+
fail_if_less_than_one(terminal_height)
|
112
|
+
fail_if_out_of_bounds('terminal_height', terminal_height, Terminal.height)
|
113
|
+
terminal_height
|
114
|
+
end
|
115
|
+
|
116
|
+
def attrs_y
|
117
|
+
y = attrs.fetch(:y, 1)
|
118
|
+
fail_if_less_than_one(y)
|
119
|
+
fail_if_out_of_bounds('y', y, terminal_height)
|
120
|
+
y
|
121
|
+
end
|
122
|
+
|
123
|
+
def attrs_x
|
124
|
+
x = attrs.fetch(:x, 1)
|
125
|
+
fail_if_less_than_one(x)
|
126
|
+
fail_if_out_of_bounds('x', x, terminal_width)
|
127
|
+
x
|
128
|
+
end
|
129
|
+
|
130
|
+
def attrs_terminal_width
|
131
|
+
terminal_width = attrs.fetch(:terminal_width, Terminal.width)
|
132
|
+
fail_if_less_than_one(terminal_width)
|
133
|
+
fail_if_out_of_bounds('terminal_width',
|
134
|
+
terminal_width,
|
135
|
+
Terminal.width)
|
136
|
+
terminal_width
|
137
|
+
end
|
138
|
+
|
139
|
+
def attrs_width
|
140
|
+
width = attrs.fetch(:width)
|
141
|
+
fail_if_less_than_one(width)
|
142
|
+
fail_if_out_of_bounds('width', width, terminal_width)
|
143
|
+
width
|
144
|
+
rescue KeyError
|
145
|
+
fail InvalidWidth, 'An Interface must have a width attribute.'
|
146
|
+
end
|
147
|
+
|
148
|
+
def attrs_centred
|
149
|
+
!!(attrs.fetch(:centred, true))
|
150
|
+
end
|
151
|
+
|
131
152
|
def fail_if_less_than_one(value)
|
132
153
|
fail OutOfBoundsError,
|
133
154
|
'Value must be greater than or equal to 1.' if value < 1
|
@@ -147,6 +168,5 @@ module Vedeu
|
|
147
168
|
def virtual_y(index = 0)
|
148
169
|
((top..bottom).to_a)[index]
|
149
170
|
end
|
150
|
-
|
151
171
|
end
|
152
172
|
end
|