girls_bar 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +34 -0
- data/Rakefile +2 -0
- data/bin/girls_bar +52 -0
- data/girls_bar.gemspec +24 -0
- data/lib/girls_bar/app.rb +28 -0
- data/lib/girls_bar/command.rb +130 -0
- data/lib/girls_bar/config.rb +36 -0
- data/lib/girls_bar/constants.rb +94 -0
- data/lib/girls_bar/controller.rb +92 -0
- data/lib/girls_bar/filter.rb +33 -0
- data/lib/girls_bar/helper.rb +21 -0
- data/lib/girls_bar/model.rb +63 -0
- data/lib/girls_bar/version.rb +4 -0
- data/lib/girls_bar.rb +55 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 942c884b813e73a9ce88301768e06c12156401e8
|
4
|
+
data.tar.gz: 7bca2fa0474f6517a3deda228abad4fe6a917880
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d3e623d1a43eb14d54bc37a1de42ed5a9cc475645d64c42cf1e9362a82ed521888c8709c63a383b1c50840b07daacd082958a27a653a49025b74b671c01dbd38
|
7
|
+
data.tar.gz: ef9962e64c4b4eb5613d89643aa06ff5898025c74f10a30bdd28e01cb662c96f1cfc2df039333a9a487eb4843c0c102e845d03a0055e113237992442e19c0ef8
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Yoshiyuki Hirano
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# GirlsBar
|
2
|
+
|
3
|
+
Create interactive CLI program from YAML or JSON.
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
Write Features
|
8
|
+
|
9
|
+
## Supported versions
|
10
|
+
|
11
|
+
Write Supported versions
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
install it yourself as:
|
16
|
+
|
17
|
+
% gem install girls_bar
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Write Usage
|
22
|
+
|
23
|
+
## Contributing to GirlsBar
|
24
|
+
|
25
|
+
Fork, fix, then send a pull request.
|
26
|
+
|
27
|
+
To run the test suite locally against all supported frameworks:
|
28
|
+
|
29
|
+
% bundle install
|
30
|
+
% rake spec:all
|
31
|
+
|
32
|
+
## Copyright
|
33
|
+
|
34
|
+
Copyright © 2015 Yoshiyuki Hirano. See MIT-LICENSE for further details.
|
data/Rakefile
ADDED
data/bin/girls_bar
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'optparse'
|
4
|
+
require 'girls_bar'
|
5
|
+
|
6
|
+
opts = OptionParser.new do |opts|
|
7
|
+
opts.banner = "Girls Bar:"
|
8
|
+
opts.define_head "Easy to Create a Interactive CLI Program by Yaml or JSON"
|
9
|
+
opts.separator ""
|
10
|
+
opts.separator "Usage:"
|
11
|
+
opts.separator " $ girls_bar open <path:yaml|json>"
|
12
|
+
opts.separator " $ girls_bar generate --format <yaml(default)|json>"
|
13
|
+
opts.separator ""
|
14
|
+
opts.separator "Options:"
|
15
|
+
|
16
|
+
opts.on("-f", "--format <yaml|json>", "Set format you want") do |v|
|
17
|
+
format = v.strip.downcase
|
18
|
+
if %(yml yaml json).include?(format)
|
19
|
+
@format = format
|
20
|
+
else
|
21
|
+
GirlsBar::Helper.set_color(:red) do
|
22
|
+
puts "Invalid Format: Available Format YAML or JSON"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
opts.on_tail("-v", "--version", "Show version") do
|
28
|
+
GirlsBar::Helper.set_color(:yellow) do
|
29
|
+
puts "GirlsBar version #{GirlsBar::VERSION} on Ruby #{RUBY_VERSION}"
|
30
|
+
end
|
31
|
+
exit
|
32
|
+
end
|
33
|
+
end
|
34
|
+
opts.parse!
|
35
|
+
|
36
|
+
mode = ARGV.shift
|
37
|
+
|
38
|
+
if mode.to_s.strip.empty?
|
39
|
+
puts opts
|
40
|
+
exit 1
|
41
|
+
end
|
42
|
+
|
43
|
+
case mode
|
44
|
+
when "generate", "g"
|
45
|
+
GirlsBar.generate(@format)
|
46
|
+
when "open", "run", "serve", "start", "init", "boot", "s"
|
47
|
+
path = ARGV.shift.strip
|
48
|
+
GirlsBar.boot(path)
|
49
|
+
else
|
50
|
+
puts opts
|
51
|
+
exit 1
|
52
|
+
end
|
data/girls_bar.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'girls_bar/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "girls_bar"
|
8
|
+
spec.version = GirlsBar::VERSION
|
9
|
+
spec.authors = ["Yoshiyuki Hirano"]
|
10
|
+
spec.email = ["yoshiyuki.hirano@henteco-labs.com"]
|
11
|
+
spec.summary = %q{ Create interactive CLI program from YAML or JSON. }
|
12
|
+
spec.description = %q{ Create interactive CLI program from YAML or JSON. }
|
13
|
+
spec.homepage = "https://github.com/YoshiyukiHirano/girls_bar"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "pry", '~> 0.10', '>= 0.10.1'
|
24
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module GirlsBar
|
3
|
+
class App
|
4
|
+
attr_reader :controller, :config, :girls
|
5
|
+
attr_accessor :data
|
6
|
+
|
7
|
+
def self.boot(resource)
|
8
|
+
app = self.new(resource)
|
9
|
+
app.controller.start
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(resource)
|
13
|
+
@controller = GirlsBar::Controller.new(self)
|
14
|
+
@config = GirlsBar::Config.new(resource['config'])
|
15
|
+
@girls = []
|
16
|
+
@data = {}
|
17
|
+
register_girls resource['girls']
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def register_girls(resource)
|
23
|
+
resource.each_pair do |res|
|
24
|
+
girls << GirlsBar::Model::Girl.new(res)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module GirlsBar
|
3
|
+
module Command
|
4
|
+
class Input
|
5
|
+
def initialize(resource)
|
6
|
+
@subject = resource['subject']
|
7
|
+
@id = GirlsBar::Filter.to_id resource['id']
|
8
|
+
@link = GirlsBar::Filter.to_id resource['link']
|
9
|
+
end
|
10
|
+
|
11
|
+
def execute(app)
|
12
|
+
while true
|
13
|
+
show_subject(app)
|
14
|
+
raw_data = gets
|
15
|
+
key = GirlsBar::Filter.to_id raw_data
|
16
|
+
case key
|
17
|
+
when 'exit', 'quit'
|
18
|
+
app.controller.quit
|
19
|
+
when 'help'
|
20
|
+
app.controller.help
|
21
|
+
else
|
22
|
+
unless "#{key}".empty?
|
23
|
+
app.data[@id] = raw_data.strip
|
24
|
+
app.controller.move(@link)
|
25
|
+
return true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
app.controller.retry
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def show_subject(app)
|
35
|
+
GirlsBar::Helper.set_color(:white) do
|
36
|
+
print "\n"
|
37
|
+
puts GirlsBar::Filter.to_subject(@subject, app.data)
|
38
|
+
puts app.config.delimiter
|
39
|
+
end
|
40
|
+
print app.config.prompt
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class Confirm
|
45
|
+
def initialize(resource)
|
46
|
+
@subject = resource['subject']
|
47
|
+
@selections = []
|
48
|
+
register_selections resource['select']
|
49
|
+
end
|
50
|
+
|
51
|
+
def execute(app)
|
52
|
+
while true
|
53
|
+
show_subject_and_selections(app)
|
54
|
+
key = GirlsBar::Filter.to_id gets
|
55
|
+
case key
|
56
|
+
when 'exit', 'quit'
|
57
|
+
app.controller.quit
|
58
|
+
when 'help'
|
59
|
+
app.controller.help
|
60
|
+
else
|
61
|
+
if selected = find_selection_by_key(key)
|
62
|
+
app.controller.move(selected.link)
|
63
|
+
return true
|
64
|
+
end
|
65
|
+
end
|
66
|
+
app.controller.retry
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def register_selections(resource)
|
73
|
+
resource.each do |id, content|
|
74
|
+
@selections << GirlsBar::Model::Selection.new(id, content['label'], content['link'])
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def show_subject_and_selections(app)
|
79
|
+
GirlsBar::Helper.set_color(:white) do
|
80
|
+
print "\n"
|
81
|
+
puts GirlsBar::Filter.to_subject(@subject, app.data)
|
82
|
+
puts app.config.delimiter
|
83
|
+
@selections.each do |selection|
|
84
|
+
puts " #{selection.key}: " + GirlsBar::Filter.to_selection(selection.label, app.data)
|
85
|
+
end
|
86
|
+
puts app.config.delimiter
|
87
|
+
end
|
88
|
+
print app.config.prompt
|
89
|
+
end
|
90
|
+
|
91
|
+
def find_selection_by_key(key)
|
92
|
+
@selections.find {|x| x.key == key }
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
class Redirect
|
97
|
+
def initialize(resource)
|
98
|
+
@key = GirlsBar::Filter.to_id resource
|
99
|
+
end
|
100
|
+
|
101
|
+
def execute(app)
|
102
|
+
app.controller.move(@key)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
class Restart
|
107
|
+
def execute(app)
|
108
|
+
app.controller.restart
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
class Script
|
113
|
+
def initialize(resource)
|
114
|
+
@script = resource
|
115
|
+
end
|
116
|
+
|
117
|
+
def execute(app)
|
118
|
+
script = GirlsBar::Filter.to_script(@script, app.data)
|
119
|
+
GirlsBar::Helper.set_color(:green) do
|
120
|
+
print "\n"
|
121
|
+
puts "=> run #{script}"
|
122
|
+
end
|
123
|
+
res = %x( #{script} )
|
124
|
+
GirlsBar::Helper.set_color(:blue) do
|
125
|
+
puts res
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module GirlsBar
|
3
|
+
class Config
|
4
|
+
attr :title,
|
5
|
+
:description,
|
6
|
+
:delimiter,
|
7
|
+
:prompt,
|
8
|
+
:boot_message,
|
9
|
+
:quit_message,
|
10
|
+
:help_message,
|
11
|
+
:retry_message,
|
12
|
+
:invalid_link_message
|
13
|
+
|
14
|
+
def initialize(resource=nil)
|
15
|
+
resource ||= {}
|
16
|
+
@title = resource['title']
|
17
|
+
@description = resource['description']
|
18
|
+
@delimiter = set_delimiter(resource['delimiter'])
|
19
|
+
@prompt = resource['prompt'] || GirlsBar::DEFAULT_SETTINGS[:prompt]
|
20
|
+
@boot_message = GirlsBar::DEFAULT_SETTINGS[:messages][:boot]
|
21
|
+
@quit_message = GirlsBar::DEFAULT_SETTINGS[:messages][:quit]
|
22
|
+
@help_message = resource['help_message'] || @boot_message
|
23
|
+
@retry_message = GirlsBar::DEFAULT_SETTINGS[:messages][:retry]
|
24
|
+
@invalid_link_message = GirlsBar::DEFAULT_SETTINGS[:messages][:invalid_link]
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def set_delimiter(resource=nil)
|
30
|
+
resource ||= {}
|
31
|
+
string = resource['character'] || GirlsBar::DEFAULT_SETTINGS[:delimiter][:character]
|
32
|
+
count = resource['count'] || GirlsBar::DEFAULT_SETTINGS[:delimiter][:count]
|
33
|
+
string * count
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# -*- utf-8 -*-
|
2
|
+
module GirlsBar
|
3
|
+
DEFAULT_SETTINGS = {
|
4
|
+
delimiter: {
|
5
|
+
character: "-",
|
6
|
+
count: 45
|
7
|
+
},
|
8
|
+
prompt: "[GirlsBar] > ",
|
9
|
+
messages: {
|
10
|
+
boot: "Type 'help' for help. Type 'exit' or 'quit' to quit.",
|
11
|
+
quit: "...Quit",
|
12
|
+
retry: "Please try again.",
|
13
|
+
invalid_link: "Link is invalid. Return to first section."
|
14
|
+
}
|
15
|
+
}
|
16
|
+
DISPLAY_COLORS = {
|
17
|
+
clear: 0, bold: 1, black: 30, red: 31, green: 32, yellow: 33, blue: 34, magenda: 35, cyan: 36, white: 37,
|
18
|
+
on_black: 40, on_red: 41, on_green: 42, on_yellow: 43, on_blue: 44, on_magenda: 45, on_cyan: 46, on_white: 47
|
19
|
+
}
|
20
|
+
TEMPLATE = <<EOF
|
21
|
+
config:
|
22
|
+
title: GirlsBar Title (Optional)
|
23
|
+
description: |+
|
24
|
+
Hello, girls_bar.
|
25
|
+
This is description (Optional)
|
26
|
+
prompt: "[Hello:girls_bar] > "
|
27
|
+
delimiter:
|
28
|
+
character: "-"
|
29
|
+
count: 45
|
30
|
+
help_message: |+
|
31
|
+
Show something... when you type 'help'.
|
32
|
+
[Default] Type 'help' for help. Type 'exit' or 'quit' to quit.
|
33
|
+
girls:
|
34
|
+
input_your_name:
|
35
|
+
input:
|
36
|
+
subject: |
|
37
|
+
[SECTION 0]
|
38
|
+
Input Your Name
|
39
|
+
id: your_name
|
40
|
+
link: done
|
41
|
+
done:
|
42
|
+
confirm:
|
43
|
+
subject: |
|
44
|
+
Hello {% your_name %}!!
|
45
|
+
select:
|
46
|
+
1:
|
47
|
+
label: OK, I am {% your_name %}.
|
48
|
+
link: section_1
|
49
|
+
section_1:
|
50
|
+
confirm:
|
51
|
+
subject: |+
|
52
|
+
[SECTION 1]
|
53
|
+
You can create a interactive CLI program.
|
54
|
+
select:
|
55
|
+
1:
|
56
|
+
label: Next
|
57
|
+
link: second
|
58
|
+
2:
|
59
|
+
label: Jump
|
60
|
+
link: third
|
61
|
+
second:
|
62
|
+
confirm:
|
63
|
+
subject: |+
|
64
|
+
[SECTION 2]
|
65
|
+
You can set ShellScript.
|
66
|
+
select:
|
67
|
+
1:
|
68
|
+
label: Run command A
|
69
|
+
link: command_a
|
70
|
+
2:
|
71
|
+
label: Run command B
|
72
|
+
link: command_b
|
73
|
+
third:
|
74
|
+
confirm:
|
75
|
+
subject: |+
|
76
|
+
[SECTION 3]
|
77
|
+
You can exit this program, please input 'exit' or 'quit'.
|
78
|
+
select:
|
79
|
+
1:
|
80
|
+
label: Return to SECTION 1
|
81
|
+
link: section_1
|
82
|
+
2:
|
83
|
+
label: Return to SECTION 2
|
84
|
+
link: second
|
85
|
+
command_a:
|
86
|
+
script: |+
|
87
|
+
echo "command_a"
|
88
|
+
redirect_to: second
|
89
|
+
command_b:
|
90
|
+
script: |+
|
91
|
+
echo "command_b"
|
92
|
+
redirect_to: third
|
93
|
+
EOF
|
94
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module GirlsBar
|
3
|
+
class Controller
|
4
|
+
def initialize(app)
|
5
|
+
@app = app
|
6
|
+
end
|
7
|
+
|
8
|
+
def start
|
9
|
+
show_boot_message
|
10
|
+
show_banner unless @app.config.title.nil?
|
11
|
+
execute_start
|
12
|
+
end
|
13
|
+
|
14
|
+
def restart
|
15
|
+
execute_start
|
16
|
+
end
|
17
|
+
|
18
|
+
def quit
|
19
|
+
show_quit_message
|
20
|
+
exit
|
21
|
+
end
|
22
|
+
|
23
|
+
def help
|
24
|
+
show_help_message
|
25
|
+
end
|
26
|
+
|
27
|
+
def retry
|
28
|
+
show_retry_message
|
29
|
+
end
|
30
|
+
|
31
|
+
def move(id)
|
32
|
+
if next_girl = @app.girls.find {|g| g.id == id }
|
33
|
+
next_girl.execute(@app)
|
34
|
+
else
|
35
|
+
show_invalid_link_message
|
36
|
+
execute_start
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def execute_start
|
43
|
+
@app.girls.first.execute(@app)
|
44
|
+
end
|
45
|
+
|
46
|
+
def show_boot_message
|
47
|
+
GirlsBar::Helper.set_color(:red) do
|
48
|
+
puts @app.config.boot_message
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def show_quit_message
|
53
|
+
GirlsBar::Helper.set_color(:green) do
|
54
|
+
print "\n"
|
55
|
+
puts @app.config.quit_message
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def show_help_message
|
60
|
+
GirlsBar::Helper.set_color(:green) do
|
61
|
+
print "\n"
|
62
|
+
puts @app.config.help_message
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def show_retry_message
|
67
|
+
GirlsBar::Helper.set_color(:red) do
|
68
|
+
print "\n"
|
69
|
+
puts @app.config.retry_message
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def show_invalid_link_message
|
74
|
+
GirlsBar::Helper.set_color(:red) do
|
75
|
+
print "\n"
|
76
|
+
puts @app.config.invalid_link_message
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def show_banner
|
81
|
+
GirlsBar::Helper.set_color(:yellow) do
|
82
|
+
print [
|
83
|
+
nil,
|
84
|
+
@app.config.delimiter,
|
85
|
+
@app.config.title,
|
86
|
+
@app.config.delimiter,
|
87
|
+
@app.config.description
|
88
|
+
].join("\n")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module GirlsBar
|
3
|
+
module Filter
|
4
|
+
def self.to_id(param)
|
5
|
+
return param if param.is_a?(Fixnum)
|
6
|
+
/^\d/ =~ param ? param.to_i : param.downcase.strip
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.to_subject(str, data)
|
10
|
+
return replace_vars_from_data(str, data)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.to_selection(str, data)
|
14
|
+
return replace_vars_from_data(str, data)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.to_script(str, data)
|
18
|
+
script = replace_vars_from_data(str, data)
|
19
|
+
script.split("\n").join(" && ")
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def self.replace_vars_from_data(str, data)
|
25
|
+
unless data.empty?
|
26
|
+
str.scan(/\{%(.+)?%\}/).flatten.map do |x|
|
27
|
+
str.gsub!(/\{%#{x}%\}/, data[x.strip])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
return str
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- utf-8 -*-
|
2
|
+
module GirlsBar
|
3
|
+
module Helper
|
4
|
+
def self.set_color(*arg)
|
5
|
+
print color_codes(arg)
|
6
|
+
yield
|
7
|
+
print color_code(:clear)
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def self.color_code(key)
|
13
|
+
"\e[#{GirlsBar::DISPLAY_COLORS[key]}m"
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.color_codes(keys)
|
17
|
+
codes = keys.map {|k| GirlsBar::DISPLAY_COLORS[k] }.compact.join(";")
|
18
|
+
"\e[#{codes}m"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module GirlsBar
|
3
|
+
module Model
|
4
|
+
class Girl
|
5
|
+
attr :id
|
6
|
+
|
7
|
+
def initialize(resource)
|
8
|
+
@id = GirlsBar::Filter.to_id resource[0]
|
9
|
+
@commands = []
|
10
|
+
register_commands resource[1]
|
11
|
+
end
|
12
|
+
|
13
|
+
def execute(app)
|
14
|
+
@commands.map {|x| x.execute(app) }
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def register_commands(resource)
|
20
|
+
add_command_script resource
|
21
|
+
add_command_input resource
|
22
|
+
add_command_confirm resource
|
23
|
+
add_command_redirect resource
|
24
|
+
add_command_restart resource
|
25
|
+
end
|
26
|
+
|
27
|
+
def add_command_script(resource)
|
28
|
+
return if resource['script'].nil?
|
29
|
+
@commands << GirlsBar::Command::Script.new(resource['script'])
|
30
|
+
end
|
31
|
+
|
32
|
+
def add_command_input(resource)
|
33
|
+
return if resource['input'].nil?
|
34
|
+
@commands << GirlsBar::Command::Input.new(resource['input'])
|
35
|
+
end
|
36
|
+
|
37
|
+
def add_command_confirm(resource)
|
38
|
+
return if resource['confirm'].nil? || !resource['input'].nil?
|
39
|
+
@commands << GirlsBar::Command::Confirm.new(resource['confirm'])
|
40
|
+
end
|
41
|
+
|
42
|
+
def add_command_redirect(resource)
|
43
|
+
return if resource['redirect_to'].nil?
|
44
|
+
@commands << GirlsBar::Command::Redirect.new(resource['redirect_to'])
|
45
|
+
end
|
46
|
+
|
47
|
+
def add_command_restart(resource)
|
48
|
+
return unless resource['input'].nil? && resource['confirm'].nil?
|
49
|
+
@commands << GirlsBar::Command::Restart.new
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class Selection
|
54
|
+
attr :key, :label, :link
|
55
|
+
|
56
|
+
def initialize(key, label, link)
|
57
|
+
@key = GirlsBar::Filter.to_id key
|
58
|
+
@label = label
|
59
|
+
@link = GirlsBar::Filter.to_id link
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/girls_bar.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require "yaml"
|
3
|
+
require "json"
|
4
|
+
|
5
|
+
require "girls_bar/version"
|
6
|
+
require "girls_bar/constants"
|
7
|
+
require "girls_bar/config"
|
8
|
+
require "girls_bar/model"
|
9
|
+
require "girls_bar/command"
|
10
|
+
require "girls_bar/controller"
|
11
|
+
require "girls_bar/helper"
|
12
|
+
require "girls_bar/filter"
|
13
|
+
require "girls_bar/app"
|
14
|
+
|
15
|
+
module GirlsBar
|
16
|
+
class << self
|
17
|
+
def boot(path)
|
18
|
+
begin
|
19
|
+
raise "File Does Not Exist" unless FileTest.exist?(path)
|
20
|
+
case File.extname(path)
|
21
|
+
when '.yml'
|
22
|
+
data = YAML.load_file path
|
23
|
+
when '.json'
|
24
|
+
data = JSON.load open(path)
|
25
|
+
else
|
26
|
+
raise 'Invalid File Extension'
|
27
|
+
end
|
28
|
+
GirlsBar::App.boot(data)
|
29
|
+
rescue => e
|
30
|
+
GirlsBar::Helper.set_color(:white, :on_red) do
|
31
|
+
puts e.message
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def generate(format=nil)
|
37
|
+
data = YAML.load GirlsBar::TEMPLATE
|
38
|
+
if format == "json"
|
39
|
+
filename = "tequila.json"
|
40
|
+
open(filename, "w") {|io|
|
41
|
+
io.write JSON.pretty_generate data
|
42
|
+
}
|
43
|
+
else
|
44
|
+
filename = "tequila.yml"
|
45
|
+
open(filename, "w") {|io|
|
46
|
+
io.write YAML.dump data
|
47
|
+
}
|
48
|
+
end
|
49
|
+
GirlsBar::Helper.set_color(:blue) do
|
50
|
+
puts "...Generated #{filename}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: girls_bar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yoshiyuki Hirano
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.10'
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 0.10.1
|
51
|
+
type: :development
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0.10'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 0.10.1
|
61
|
+
description: " Create interactive CLI program from YAML or JSON. "
|
62
|
+
email:
|
63
|
+
- yoshiyuki.hirano@henteco-labs.com
|
64
|
+
executables:
|
65
|
+
- girls_bar
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- ".gitignore"
|
70
|
+
- Gemfile
|
71
|
+
- LICENSE.txt
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- bin/girls_bar
|
75
|
+
- girls_bar.gemspec
|
76
|
+
- lib/girls_bar.rb
|
77
|
+
- lib/girls_bar/app.rb
|
78
|
+
- lib/girls_bar/command.rb
|
79
|
+
- lib/girls_bar/config.rb
|
80
|
+
- lib/girls_bar/constants.rb
|
81
|
+
- lib/girls_bar/controller.rb
|
82
|
+
- lib/girls_bar/filter.rb
|
83
|
+
- lib/girls_bar/helper.rb
|
84
|
+
- lib/girls_bar/model.rb
|
85
|
+
- lib/girls_bar/version.rb
|
86
|
+
homepage: https://github.com/YoshiyukiHirano/girls_bar
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.2.2
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: Create interactive CLI program from YAML or JSON.
|
110
|
+
test_files: []
|
111
|
+
has_rdoc:
|