gloo 0.4.0 → 0.5.0
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/.DS_Store +0 -0
- data/.rubocop.yml +1 -1
- data/Gemfile.lock +80 -81
- data/Rakefile +1 -0
- data/gloo.gemspec +2 -1
- data/lib/gloo/app/engine.rb +48 -3
- data/lib/gloo/app/info.rb +1 -1
- data/lib/gloo/app/settings.rb +12 -5
- data/lib/gloo/convert/string_to_datetime.rb +21 -0
- data/lib/gloo/convert/string_to_decimal.rb +20 -0
- data/lib/gloo/convert/string_to_integer.rb +20 -0
- data/lib/gloo/core/event_manager.rb +2 -6
- data/lib/gloo/core/factory.rb +58 -1
- data/lib/gloo/core/gloo_system.rb +72 -0
- data/lib/gloo/core/obj.rb +50 -1
- data/lib/gloo/core/parser.rb +3 -1
- data/lib/gloo/core/pn.rb +3 -2
- data/lib/gloo/exec/dispatch.rb +30 -0
- data/lib/gloo/exec/runner.rb +43 -0
- data/lib/gloo/expr/expression.rb +1 -0
- data/lib/gloo/expr/l_decimal.rb +34 -0
- data/lib/gloo/expr/op_div.rb +2 -0
- data/lib/gloo/expr/op_minus.rb +2 -0
- data/lib/gloo/expr/op_mult.rb +2 -0
- data/lib/gloo/expr/op_plus.rb +2 -0
- data/lib/gloo/objs/basic/alias.rb +111 -0
- data/lib/gloo/objs/basic/container.rb +11 -1
- data/lib/gloo/objs/basic/decimal.rb +96 -0
- data/lib/gloo/objs/basic/integer.rb +5 -0
- data/lib/gloo/objs/basic/string.rb +9 -1
- data/lib/gloo/objs/basic/text.rb +27 -2
- data/lib/gloo/objs/cli/banner.rb +137 -0
- data/lib/gloo/objs/cli/bar.rb +141 -0
- data/lib/gloo/objs/cli/colorize.rb +1 -1
- data/lib/gloo/objs/cli/menu.rb +236 -0
- data/lib/gloo/objs/cli/menu_item.rb +128 -0
- data/lib/gloo/objs/cli/pastel.rb +120 -0
- data/lib/gloo/objs/cli/prompt.rb +19 -11
- data/lib/gloo/objs/cli/select.rb +153 -0
- data/lib/gloo/objs/ctrl/each.rb +45 -16
- data/lib/gloo/objs/ctrl/repeat.rb +129 -0
- data/lib/gloo/objs/data/markdown.rb +109 -0
- data/lib/gloo/objs/data/table.rb +168 -0
- data/lib/gloo/objs/dt/date.rb +72 -0
- data/lib/gloo/objs/dt/datetime.rb +84 -0
- data/lib/gloo/objs/dt/time.rb +72 -0
- data/lib/gloo/objs/ror/erb.rb +1 -0
- data/lib/gloo/objs/system/file_handle.rb +50 -1
- data/lib/gloo/objs/web/http_get.rb +24 -4
- data/lib/gloo/objs/web/http_post.rb +1 -0
- data/lib/gloo/objs/web/json.rb +155 -0
- data/lib/gloo/objs/web/uri.rb +160 -0
- data/lib/gloo/persist/file_loader.rb +17 -6
- data/lib/gloo/persist/line_splitter.rb +7 -2
- data/lib/gloo/persist/persist_man.rb +37 -13
- data/lib/gloo/verbs/cls.rb +67 -0
- data/lib/gloo/verbs/help.rb +9 -0
- data/lib/gloo/verbs/if.rb +1 -0
- data/lib/gloo/verbs/load.rb +3 -2
- data/lib/gloo/verbs/move.rb +128 -0
- data/lib/gloo/verbs/run.rb +21 -7
- data/lib/gloo/verbs/tell.rb +1 -1
- data/lib/gloo/verbs/unless.rb +1 -0
- data/lib/gloo/verbs/wait.rb +73 -0
- metadata +36 -5
- data/lib/gloo/core/runner.rb +0 -26
@@ -10,6 +10,7 @@ module Gloo
|
|
10
10
|
|
11
11
|
BEGIN_BLOCK = 'BEGIN'.freeze
|
12
12
|
END_BLOCK = 'END'.freeze
|
13
|
+
SPACE_CNT = 2
|
13
14
|
|
14
15
|
attr_reader :obj
|
15
16
|
|
@@ -85,10 +86,9 @@ module Gloo
|
|
85
86
|
@tabs = tabs
|
86
87
|
@indent = 1
|
87
88
|
elsif tabs < @tabs # outdent
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
end
|
89
|
+
diff = @tabs - tabs
|
90
|
+
@tabs -= diff
|
91
|
+
@indent -= diff
|
92
92
|
end
|
93
93
|
puts "tabs: #{@tabs}, indent: #{@indent}, line: #{line}" if @debug
|
94
94
|
end
|
@@ -116,7 +116,10 @@ module Gloo
|
|
116
116
|
def setup_process_obj_line
|
117
117
|
if @exiting_multiline
|
118
118
|
@exiting_multiline = false
|
119
|
-
|
119
|
+
@indent += 1
|
120
|
+
end
|
121
|
+
|
122
|
+
if @indent.positive?
|
120
123
|
@parent = @last
|
121
124
|
@parent_stack.push @parent
|
122
125
|
elsif @indent.negative?
|
@@ -139,7 +142,7 @@ module Gloo
|
|
139
142
|
params = { name: name, type: type, value: value, parent: @parent }
|
140
143
|
@last = $engine.factory.create( params )
|
141
144
|
|
142
|
-
if @last&.multiline_value?
|
145
|
+
if value.empty? && @last&.multiline_value?
|
143
146
|
@multi_indent = 0
|
144
147
|
@in_multiline = true
|
145
148
|
puts "*** Start multiline. multi_indent: #{@multi_indent}" if @debug
|
@@ -153,6 +156,14 @@ module Gloo
|
|
153
156
|
#
|
154
157
|
def tab_count( line )
|
155
158
|
i = 0
|
159
|
+
|
160
|
+
if line[ i ] == ' '
|
161
|
+
i += 1 while line[ i ] == ' '
|
162
|
+
tab_equiv = ( i / SPACE_CNT ).to_i
|
163
|
+
puts "Found #{i} spaces => #{tab_equiv}" if @debug
|
164
|
+
return tab_equiv
|
165
|
+
end
|
166
|
+
|
156
167
|
i += 1 while line[ i ] == "\t"
|
157
168
|
return i
|
158
169
|
end
|
@@ -35,8 +35,7 @@ module Gloo
|
|
35
35
|
# Detect the object name.
|
36
36
|
#
|
37
37
|
def detect_name
|
38
|
-
@line = @line
|
39
|
-
@line = @line[ 0..-2 ] if @line[ -1 ] == "\n"
|
38
|
+
@line = @line.strip
|
40
39
|
@idx = @line.index( ' ' )
|
41
40
|
@name = @line[ 0..@idx - 1 ]
|
42
41
|
end
|
@@ -47,6 +46,12 @@ module Gloo
|
|
47
46
|
def detect_type
|
48
47
|
@line = @line[ @idx + 1..-1 ]
|
49
48
|
@idx = @line.index( ' ' )
|
49
|
+
|
50
|
+
if @line[ 0 ] == ':'
|
51
|
+
@type = 'untyped'
|
52
|
+
return
|
53
|
+
end
|
54
|
+
|
50
55
|
@type = @line[ 0..( @idx ? @idx - 1 : -1 ) ]
|
51
56
|
@type = @type[ 1..-1 ] if @type[ 0 ] == '['
|
52
57
|
@type = @type[ 0..-2 ] if @type[ -1 ] == ']'
|
@@ -50,26 +50,50 @@ module Gloo
|
|
50
50
|
# Load the object from the file.
|
51
51
|
#
|
52
52
|
def load( name )
|
53
|
-
|
54
|
-
return unless
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
53
|
+
pns = get_full_path_names name
|
54
|
+
return unless pns
|
55
|
+
|
56
|
+
pns.each do |pn|
|
57
|
+
$log.debug "Load file(s) at: #{pn}"
|
58
|
+
fs = Gloo::Persist::FileStorage.new( pn )
|
59
|
+
fs.load
|
60
|
+
@maps << fs
|
61
|
+
$engine.event_manager.on_load fs.obj
|
62
|
+
end
|
62
63
|
end
|
63
64
|
|
64
65
|
#
|
65
66
|
# Get the full path and name of the file.
|
66
67
|
#
|
67
|
-
def
|
68
|
+
def get_full_path_names( name )
|
68
69
|
return nil if name.strip.empty?
|
69
70
|
|
70
|
-
|
71
|
-
|
72
|
-
|
71
|
+
if name.strip[ -1 ] == '*'
|
72
|
+
pns = []
|
73
|
+
dir = File.join( $settings.project_path, name[ 0..-2 ] )
|
74
|
+
Dir.glob( "#{dir}*.gloo" ).each do |f|
|
75
|
+
pns << f
|
76
|
+
end
|
77
|
+
return pns
|
78
|
+
else
|
79
|
+
ext_path = File.expand_path( name )
|
80
|
+
return [ ext_path ] if self.gloo_file?( ext_path )
|
81
|
+
|
82
|
+
full_name = "#{name}#{file_ext}"
|
83
|
+
return [ File.join( $settings.project_path, full_name ) ]
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
#
|
88
|
+
# Check to see if a given path name refers to a gloo object file.
|
89
|
+
#
|
90
|
+
def gloo_file?( name )
|
91
|
+
return false unless name
|
92
|
+
return false unless File.exist?( name )
|
93
|
+
return false unless File.file?( name )
|
94
|
+
return false unless name.end_with?( self.file_ext )
|
95
|
+
|
96
|
+
return true
|
73
97
|
end
|
74
98
|
|
75
99
|
# Get the default file extention.
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# Clear the screen.
|
5
|
+
#
|
6
|
+
|
7
|
+
module Gloo
|
8
|
+
module Verbs
|
9
|
+
class Cls < Gloo::Core::Verb
|
10
|
+
|
11
|
+
KEYWORD = 'cls'.freeze
|
12
|
+
KEYWORD_SHORT = 'cls'.freeze
|
13
|
+
|
14
|
+
#
|
15
|
+
# Run the verb.
|
16
|
+
#
|
17
|
+
def run
|
18
|
+
$engine&.clear_screen
|
19
|
+
end
|
20
|
+
|
21
|
+
#
|
22
|
+
# Get the Verb's keyword.
|
23
|
+
#
|
24
|
+
def self.keyword
|
25
|
+
return KEYWORD
|
26
|
+
end
|
27
|
+
|
28
|
+
#
|
29
|
+
# Get the Verb's keyword shortcut.
|
30
|
+
#
|
31
|
+
def self.keyword_shortcut
|
32
|
+
return KEYWORD_SHORT
|
33
|
+
end
|
34
|
+
|
35
|
+
# ---------------------------------------------------------------------
|
36
|
+
# Help
|
37
|
+
# ---------------------------------------------------------------------
|
38
|
+
|
39
|
+
#
|
40
|
+
# Get help for this verb.
|
41
|
+
#
|
42
|
+
def self.help
|
43
|
+
return <<~TEXT
|
44
|
+
CLS VERB
|
45
|
+
NAME: cls
|
46
|
+
SHORTCUT: cls
|
47
|
+
|
48
|
+
DESCRIPTION
|
49
|
+
Clear the console screen.
|
50
|
+
|
51
|
+
SYNTAX
|
52
|
+
cls
|
53
|
+
|
54
|
+
PARAMETERS
|
55
|
+
None
|
56
|
+
|
57
|
+
RESULT
|
58
|
+
The screen is cleared and cursor set to the top.
|
59
|
+
|
60
|
+
ERRORS
|
61
|
+
None
|
62
|
+
TEXT
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/gloo/verbs/help.rb
CHANGED
@@ -12,6 +12,7 @@ module Gloo
|
|
12
12
|
KEYWORD_SHORT = '?'.freeze
|
13
13
|
|
14
14
|
DISPATCH = {
|
15
|
+
settings: 'show_settings',
|
15
16
|
verb: 'show_verbs',
|
16
17
|
verbs: 'show_verbs',
|
17
18
|
v: 'show_verbs',
|
@@ -113,6 +114,13 @@ module Gloo
|
|
113
114
|
$engine.run_help( true )
|
114
115
|
end
|
115
116
|
|
117
|
+
#
|
118
|
+
# Show application settings.
|
119
|
+
#
|
120
|
+
def show_settings
|
121
|
+
$settings.show
|
122
|
+
end
|
123
|
+
|
116
124
|
#
|
117
125
|
# List the verbs
|
118
126
|
#
|
@@ -199,6 +207,7 @@ module Gloo
|
|
199
207
|
PARAMETERS
|
200
208
|
about - Optional parameter.
|
201
209
|
If no parameter is given, shows the default help screen
|
210
|
+
settings - Show application settings
|
202
211
|
verbs - List available verbs
|
203
212
|
objects - List available objects
|
204
213
|
<verb> - Look up detail about a verb
|
data/lib/gloo/verbs/if.rb
CHANGED
data/lib/gloo/verbs/load.rb
CHANGED
@@ -49,8 +49,9 @@ module Gloo
|
|
49
49
|
|
50
50
|
DESCRIPTION
|
51
51
|
Load an object file.
|
52
|
-
|
53
|
-
|
52
|
+
There are two ways to specify the file. Give either the full path and file name or use a relative path from the gloo project folder. For the latter, the extension is not needed. For the former, the
|
53
|
+
file extension is necessary.
|
54
|
+
Using * instead of a file name will load all gloo files in the folder.
|
54
55
|
|
55
56
|
SYNTAX
|
56
57
|
load <file_name>
|
@@ -0,0 +1,128 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# Move an object to a new parent.
|
5
|
+
#
|
6
|
+
|
7
|
+
module Gloo
|
8
|
+
module Verbs
|
9
|
+
class Move < Gloo::Core::Verb
|
10
|
+
|
11
|
+
KEYWORD = 'move'.freeze
|
12
|
+
KEYWORD_SHORT = 'mv'.freeze
|
13
|
+
TO = 'to'.freeze
|
14
|
+
|
15
|
+
#
|
16
|
+
# Run the verb.
|
17
|
+
#
|
18
|
+
def run
|
19
|
+
dst = lookup_dst
|
20
|
+
return if dst.nil?
|
21
|
+
|
22
|
+
o = lookup_obj
|
23
|
+
return unless o
|
24
|
+
|
25
|
+
o.parent.remove_child o
|
26
|
+
dst.add_child o
|
27
|
+
end
|
28
|
+
|
29
|
+
#
|
30
|
+
# Get the Verb's keyword.
|
31
|
+
#
|
32
|
+
def self.keyword
|
33
|
+
return KEYWORD
|
34
|
+
end
|
35
|
+
|
36
|
+
#
|
37
|
+
# Get the Verb's keyword shortcut.
|
38
|
+
#
|
39
|
+
def self.keyword_shortcut
|
40
|
+
return KEYWORD_SHORT
|
41
|
+
end
|
42
|
+
|
43
|
+
# ---------------------------------------------------------------------
|
44
|
+
# Helper functions
|
45
|
+
# ---------------------------------------------------------------------
|
46
|
+
|
47
|
+
#
|
48
|
+
# Lookup the object that we're moving.
|
49
|
+
#
|
50
|
+
def lookup_obj
|
51
|
+
arr = @tokens.before_token( TO )
|
52
|
+
if arr.count == 1
|
53
|
+
msg = 'object to move was not specified'
|
54
|
+
$log.error msg, nil, $engine
|
55
|
+
end
|
56
|
+
|
57
|
+
name = arr[ 1 ]
|
58
|
+
pn = Gloo::Core::Pn.new name
|
59
|
+
o = pn.resolve
|
60
|
+
|
61
|
+
unless o
|
62
|
+
msg = "could not find object to move: #{name}"
|
63
|
+
$log.error msg, nil, $engine
|
64
|
+
end
|
65
|
+
|
66
|
+
return o
|
67
|
+
end
|
68
|
+
|
69
|
+
#
|
70
|
+
# Lookup destination, the new parent object.
|
71
|
+
#
|
72
|
+
def lookup_dst
|
73
|
+
dst = @tokens.after_token( TO )
|
74
|
+
unless dst
|
75
|
+
msg = "'move' must include 'to' parent object"
|
76
|
+
$log.error msg, nil, $engine
|
77
|
+
return nil
|
78
|
+
end
|
79
|
+
|
80
|
+
pn = Gloo::Core::Pn.new dst
|
81
|
+
o = pn.resolve
|
82
|
+
unless o
|
83
|
+
msg = "could not resolve '#{dst}'"
|
84
|
+
$log.error msg, nil, $engine
|
85
|
+
return nil
|
86
|
+
end
|
87
|
+
|
88
|
+
return o
|
89
|
+
end
|
90
|
+
|
91
|
+
# ---------------------------------------------------------------------
|
92
|
+
# Help
|
93
|
+
# ---------------------------------------------------------------------
|
94
|
+
|
95
|
+
#
|
96
|
+
# Get help for this verb.
|
97
|
+
#
|
98
|
+
def self.help
|
99
|
+
return <<~TEXT
|
100
|
+
MOVE VERB
|
101
|
+
NAME: move
|
102
|
+
SHORTCUT: mv
|
103
|
+
|
104
|
+
DESCRIPTION
|
105
|
+
Move an object to a new parent.
|
106
|
+
|
107
|
+
SYNTAX
|
108
|
+
move <path.to.object> to <new.parent>
|
109
|
+
|
110
|
+
PARAMETERS
|
111
|
+
path.to.object - The object that we want to move.
|
112
|
+
new.parent - The new location for the object.
|
113
|
+
|
114
|
+
RESULT
|
115
|
+
The object will now be in the new location.
|
116
|
+
|
117
|
+
ERRORS
|
118
|
+
The <path.to.object> is not specified.
|
119
|
+
The <path.to.object> cannot be resolved.
|
120
|
+
The <new.parent> is not specified.
|
121
|
+
The <new.parent> cannot be resolved.
|
122
|
+
The 'to' keyword is missing.
|
123
|
+
TEXT
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
data/lib/gloo/verbs/run.rb
CHANGED
@@ -11,22 +11,36 @@ module Gloo
|
|
11
11
|
|
12
12
|
KEYWORD = 'run'.freeze
|
13
13
|
KEYWORD_SHORT = 'r'.freeze
|
14
|
+
EVALUATE_RUN = '~>'.freeze
|
14
15
|
|
15
16
|
#
|
16
17
|
# Run the verb.
|
17
18
|
#
|
18
19
|
def run
|
19
|
-
|
20
|
-
|
21
|
-
o = pn.resolve
|
22
|
-
|
23
|
-
if o
|
24
|
-
o.send_message 'run'
|
20
|
+
if @tokens.second == EVALUATE_RUN
|
21
|
+
run_expression
|
25
22
|
else
|
26
|
-
|
23
|
+
run_script
|
27
24
|
end
|
28
25
|
end
|
29
26
|
|
27
|
+
#
|
28
|
+
# Run a script specified by pathname
|
29
|
+
#
|
30
|
+
def run_script
|
31
|
+
Gloo::Exec::Runner.run @tokens.second
|
32
|
+
end
|
33
|
+
|
34
|
+
#
|
35
|
+
# Evaluate an expression and run that.
|
36
|
+
#
|
37
|
+
def run_expression
|
38
|
+
return unless @tokens.token_count > 2
|
39
|
+
|
40
|
+
expr = Gloo::Expr::Expression.new( @tokens.params[ 1..-1 ] )
|
41
|
+
$engine.parser.run expr.evaluate
|
42
|
+
end
|
43
|
+
|
30
44
|
#
|
31
45
|
# Get the Verb's keyword.
|
32
46
|
#
|
data/lib/gloo/verbs/tell.rb
CHANGED
data/lib/gloo/verbs/unless.rb
CHANGED