simrb 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/3s +3 -0
- data/bin/simrb +2 -1
- data/lib/simrb/comd.rb +185 -0
- data/lib/simrb/config.rb +212 -0
- data/lib/simrb/docs.rb +207 -0
- data/lib/simrb/help.rb +33 -0
- data/lib/simrb/hook.rb +38 -0
- data/lib/simrb/info.rb +5 -1
- data/lib/simrb/init.rb +53 -0
- data/lib/simrb/thin_start.rb +26 -0
- data/lib/simrb/tool_start.rb +61 -0
- data/lib/simrb.rb +8 -3
- metadata +68 -3
- data/lib/simrb/command.rb +0 -57
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 08d0b17242e8c909cfb0bf359a32384261911518
|
4
|
+
data.tar.gz: d933bcb7a53af6c263580ae9102ffc531ad5783e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8f309668d5e1f668c3a9d6c6f93bbc6f7f173e58c5d7fd51d45509914258b0ad9c8cf7cf8a2df3f493ad2a2bb32e376c4feda16235a86d8d74d76966218f5f5
|
7
|
+
data.tar.gz: 6b6f9a11dd06d04b141bcd59b7fe4bb7ad2fea8aa57339d6942284d9969f62db65cf78d4229f90e6cacb89bec1e706cacf48ccb1eaaba8fc8bde7f2568e6b62c
|
data/bin/3s
ADDED
data/bin/simrb
CHANGED
data/lib/simrb/comd.rb
ADDED
@@ -0,0 +1,185 @@
|
|
1
|
+
#
|
2
|
+
# the file defines the base functionality of commands
|
3
|
+
# that let you initializing a project, create an empty directory of module, or clone
|
4
|
+
# from remote repository, show the info of this software version, help document, and so on
|
5
|
+
#
|
6
|
+
|
7
|
+
module Simrb
|
8
|
+
class Scommand
|
9
|
+
|
10
|
+
def run args = []
|
11
|
+
@output = []
|
12
|
+
cmd = args.empty? ? '' : args.shift
|
13
|
+
if Scommand.private_method_defined? cmd
|
14
|
+
self.send(cmd, args)
|
15
|
+
else
|
16
|
+
@output << ">> WARNING: No #{cmd} command found >>"
|
17
|
+
help
|
18
|
+
end
|
19
|
+
Simrb.p(@output.empty? ? 'Implemented complete' : @output)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
# initialize a project directory
|
25
|
+
#
|
26
|
+
# == Example
|
27
|
+
#
|
28
|
+
# $ simrb init myapp
|
29
|
+
#
|
30
|
+
# or, initialize directory and module at the same time with more arguments,
|
31
|
+
# the simrb/system is from remote, the blog is generated by local,
|
32
|
+
# details see the new and clone method
|
33
|
+
#
|
34
|
+
# $ simrb init myapp simrb/system blog
|
35
|
+
#
|
36
|
+
def init args
|
37
|
+
app_name = args.empty? ? 'myapp' : args.shift
|
38
|
+
|
39
|
+
# generate module directories and files
|
40
|
+
Dir.mkdir app_name
|
41
|
+
Dir.chdir app_name
|
42
|
+
|
43
|
+
Scfg[:init_root_path].each do | item |
|
44
|
+
path = "#{Spath[item]}"
|
45
|
+
Simrb::path_init path
|
46
|
+
end
|
47
|
+
|
48
|
+
# initialize scfg file
|
49
|
+
data = {}
|
50
|
+
Scfg[:init_scfg_item].each do | item |
|
51
|
+
data[item] = Scfg[item]
|
52
|
+
end
|
53
|
+
Simrb.yaml_write('scfg', data)
|
54
|
+
|
55
|
+
# create module if it is given,
|
56
|
+
# get module from remote repository if it has the backslash,
|
57
|
+
# other is created at local
|
58
|
+
unless args.empty?
|
59
|
+
args.each do | name |
|
60
|
+
name.index("/") ? clone(args) : new(args)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# initialize rubygem bundled
|
65
|
+
# mode = "develpment"
|
66
|
+
# if @args.include? '--dev'
|
67
|
+
# mode = "production"
|
68
|
+
# end
|
69
|
+
# system("bundle install --gemfile=#{@app_name}/apps/#{@module_name}#{@gemfile_path} --without=#{mode}")
|
70
|
+
|
71
|
+
@output << "Initialized project complete"
|
72
|
+
end
|
73
|
+
|
74
|
+
# create a module, initialize default paths of file and directory
|
75
|
+
#
|
76
|
+
# == Example
|
77
|
+
#
|
78
|
+
# $ simrb new blog
|
79
|
+
#
|
80
|
+
# or, more than one at same time
|
81
|
+
#
|
82
|
+
# $ simrb new blog cms test
|
83
|
+
#
|
84
|
+
def new args
|
85
|
+
Simrb.root_dir_force
|
86
|
+
|
87
|
+
args.each do | name |
|
88
|
+
if Smodules.include? name
|
89
|
+
@output << "The module #{name} is existing, not new it"
|
90
|
+
else
|
91
|
+
# create root dir of module
|
92
|
+
Simrb::path_init "#{Spath[:module]}#{name}/"
|
93
|
+
|
94
|
+
Dir.chdir "."
|
95
|
+
|
96
|
+
# create sub dir of module
|
97
|
+
Scfg[:init_module_path].each do | item |
|
98
|
+
path = "#{Spath[:module]}#{name}#{Spath[item]}"
|
99
|
+
Simrb::path_init path
|
100
|
+
end
|
101
|
+
|
102
|
+
# write the content of module info
|
103
|
+
text = [{ 'name' => name, 'author' => 'unknown', 'version' => '1.0.0' }]
|
104
|
+
Simrb.yaml_write "#{Spath[:module]}#{name}#{Spath[:modinfo]}", text
|
105
|
+
|
106
|
+
# write the content of .gitignore
|
107
|
+
path = "#{Spath[:module]}#{name}#{Spath[:gitignore]}"
|
108
|
+
File.open(path, "w+") do | f |
|
109
|
+
f.write "*.swp\n*.gem\n*~"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
@output << "Initialized module complete"
|
115
|
+
end
|
116
|
+
|
117
|
+
# clone a module from remote repository to local
|
118
|
+
#
|
119
|
+
# == Example
|
120
|
+
#
|
121
|
+
# $ simrb clone simrb/system
|
122
|
+
#
|
123
|
+
# or, more than one at same time
|
124
|
+
#
|
125
|
+
# $ simrb clone simrb/system simrb/test
|
126
|
+
#
|
127
|
+
def clone args
|
128
|
+
Simrb.root_dir_force
|
129
|
+
|
130
|
+
args.each do | name |
|
131
|
+
if Smodules.include? name
|
132
|
+
@output << "The module #{name} is existing, not clone from remote"
|
133
|
+
else
|
134
|
+
path = "#{Scfg[:repo_source]}#{name[0]}.git"
|
135
|
+
name = "#{Spath[:module]}#{name[0].split('/').last}"
|
136
|
+
system("git clone #{path} #{name}")
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
@output << "Cloned module complete"
|
141
|
+
end
|
142
|
+
|
143
|
+
# kill the current process of Simrb of that is running in background
|
144
|
+
#
|
145
|
+
# == Example
|
146
|
+
#
|
147
|
+
# $ simrb kill
|
148
|
+
#
|
149
|
+
def kill args = []
|
150
|
+
s = `ps -ax | grep 'simrb start'`
|
151
|
+
s = s.split("\n")[0].split(" ")[0]
|
152
|
+
# s = `cat #{Spath[:tmp_dir]}pid`.split("\n")[0]
|
153
|
+
# `rm #{Spath[:tmp_dir]}pid`
|
154
|
+
|
155
|
+
system("kill #{s}")
|
156
|
+
@output << "Killed the process #{s} of Simrb"
|
157
|
+
end
|
158
|
+
|
159
|
+
# display the basic inforamtion of current version of Simrb
|
160
|
+
#
|
161
|
+
# == Example
|
162
|
+
#
|
163
|
+
# $ simrb info
|
164
|
+
#
|
165
|
+
def info args = []
|
166
|
+
require 'simrb/info'
|
167
|
+
@output << Simrb::Info
|
168
|
+
end
|
169
|
+
|
170
|
+
# the help document
|
171
|
+
#
|
172
|
+
# == Example
|
173
|
+
#
|
174
|
+
# $ simrb help
|
175
|
+
# $ simrb help 0
|
176
|
+
#
|
177
|
+
def help args = []
|
178
|
+
require 'simrb/help'
|
179
|
+
require 'simrb/docs'
|
180
|
+
@output << Simrb.help(args)
|
181
|
+
end
|
182
|
+
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
data/lib/simrb/config.rb
ADDED
@@ -0,0 +1,212 @@
|
|
1
|
+
#
|
2
|
+
# definition to the base methods, and default configuration options
|
3
|
+
# and the modules that would be loaded
|
4
|
+
#
|
5
|
+
|
6
|
+
Sroot = Dir.pwd + '/'
|
7
|
+
module Simrb
|
8
|
+
|
9
|
+
# common methods
|
10
|
+
class << self
|
11
|
+
|
12
|
+
def yaml_read path
|
13
|
+
require 'yaml'
|
14
|
+
YAML.load_file path
|
15
|
+
rescue
|
16
|
+
[]
|
17
|
+
end
|
18
|
+
|
19
|
+
def yaml_write path, data
|
20
|
+
require "yaml"
|
21
|
+
File.open(path, 'w+') do | f |
|
22
|
+
f.write data.to_yaml
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def p args
|
27
|
+
res = ""
|
28
|
+
|
29
|
+
if args.class.to_s == 'Array'
|
30
|
+
res = args.join("\n")
|
31
|
+
elsif args.class.to_s == 'Hash'
|
32
|
+
args.each do | k, v |
|
33
|
+
res << "#{k.to_s.ljust(15)} => #{v}\n"
|
34
|
+
end
|
35
|
+
res = res.chomp "\n"
|
36
|
+
else
|
37
|
+
res = args.to_s
|
38
|
+
end
|
39
|
+
|
40
|
+
puts "="*30 + "\n" + res + "\n" + "="*30
|
41
|
+
end
|
42
|
+
|
43
|
+
def module_load
|
44
|
+
dirs = []
|
45
|
+
module_ds = {}
|
46
|
+
|
47
|
+
# get the path of module
|
48
|
+
if Scfg[:only_enable_modules].empty?
|
49
|
+
dirs = Dir["#{Spath[:module]}*"]
|
50
|
+
else
|
51
|
+
Scfg[:only_enable_modules].each do | name |
|
52
|
+
path = "#{Spath[:module]}#{name}"
|
53
|
+
dirs << path if File.exist?(path)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# load the info of module
|
58
|
+
dirs.each do | path |
|
59
|
+
path = "#{path}#{Spath[:modinfo]}"
|
60
|
+
content = Simrb.yaml_read path
|
61
|
+
name = content[0]["name"]
|
62
|
+
order = (content[0]["order"] || 99)
|
63
|
+
module_ds[name] = order unless Scfg[:disable_modules].include?(name.to_s)
|
64
|
+
end
|
65
|
+
|
66
|
+
# sort the module by order field
|
67
|
+
res = []
|
68
|
+
module_ds = module_ds.sort_by { |k, v| v }
|
69
|
+
module_ds.each do | item |
|
70
|
+
res << item[0]
|
71
|
+
end
|
72
|
+
res
|
73
|
+
end
|
74
|
+
|
75
|
+
def path_init path, content = ""
|
76
|
+
unless File.exist?(path)
|
77
|
+
path[-1] == '/' ? Dir.mkdir(path) : File.open(path, 'w+') {|f| f.write content}
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def root_dir_force
|
82
|
+
unless File.exist? 'scfg'
|
83
|
+
Simrb.p "Current command only allow to be used under root directory of project"
|
84
|
+
exit
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# format the input argument from an array to two item,
|
89
|
+
# first item is orgin array, last is an hash option
|
90
|
+
#
|
91
|
+
# == Example
|
92
|
+
#
|
93
|
+
# args, opts = Simrb.input_format ["test", "test2", "--test", "--name=test2", "-n=test3"]
|
94
|
+
#
|
95
|
+
# the above is same as
|
96
|
+
#
|
97
|
+
# args, opts = Simrb.input_format ["--test", "test", "test2", "--name=test2", "-n=test3"]
|
98
|
+
#
|
99
|
+
# the options that starts with "-" you can write any positions of argument
|
100
|
+
#
|
101
|
+
# output
|
102
|
+
#
|
103
|
+
# args = ["test", "test2"]
|
104
|
+
# opts = {test: true, name: test2, n:test3}
|
105
|
+
#
|
106
|
+
def input_format args = []
|
107
|
+
resa = [] # return an array
|
108
|
+
resh = {} # return an hash
|
109
|
+
unless args.empty?
|
110
|
+
args.each do | item |
|
111
|
+
|
112
|
+
if item[0] == "-"
|
113
|
+
new_item = item.split("-").uniq.last
|
114
|
+
if new_item.index "="
|
115
|
+
key, val = new_item.split "="
|
116
|
+
resh[key.to_sym] = val
|
117
|
+
else
|
118
|
+
resh[new_item.to_sym] = true
|
119
|
+
end
|
120
|
+
else
|
121
|
+
resa << item
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
end
|
126
|
+
[resa, resh]
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
# basic path definition
|
132
|
+
Spath = {
|
133
|
+
# root path of project
|
134
|
+
:module => 'modules/',
|
135
|
+
:public => 'public/',
|
136
|
+
:db_dir => 'db/',
|
137
|
+
:upload_dir => 'db/upload/',
|
138
|
+
:backup_dir => 'db/backup/',
|
139
|
+
:tmp_dir => 'tmp/',
|
140
|
+
:cache_dir => 'tmp/cache/simrb/',
|
141
|
+
:install_lock_file => 'tmp/install.lock',
|
142
|
+
:log_dir => 'log/',
|
143
|
+
:server_log => 'log/thin.log',
|
144
|
+
:command_log => 'log/command_error_log.html',
|
145
|
+
|
146
|
+
# sub path under module directory of project
|
147
|
+
:tool => '/tool/',
|
148
|
+
:logic => '/logic/',
|
149
|
+
:store => '/boxes/',
|
150
|
+
:lang => '/boxes/langs/',
|
151
|
+
:doc => '/boxes/docs/',
|
152
|
+
:schema => '/boxes/migrations/',
|
153
|
+
:install => '/boxes/installs/',
|
154
|
+
:modinfo => '/boxes/installs/_mods',
|
155
|
+
:vars => '/boxes/installs/_vars',
|
156
|
+
:menu => '/boxes/installs/_menu',
|
157
|
+
:tpl => '/boxes/tpls/',
|
158
|
+
:layout_css => '/boxes/tpls/layout.css',
|
159
|
+
:common_css => '/boxes/tpls/common.css',
|
160
|
+
:misc => '/boxes/misc/',
|
161
|
+
:gemfile => '/boxes/misc/Gemfile',
|
162
|
+
:view => '/views/',
|
163
|
+
:assets => '/views/assets/',
|
164
|
+
:gitignore => '/.gitignore',
|
165
|
+
:route => '/routes.rb',
|
166
|
+
:readme => '/README.md',
|
167
|
+
}
|
168
|
+
|
169
|
+
# default settings of scfg file
|
170
|
+
Scfg = {
|
171
|
+
:time_types => ['created', 'changed'],
|
172
|
+
:fixnum_types => ['order', 'level'],
|
173
|
+
:number_types => ['Fixnum', 'Integer', 'Float'],
|
174
|
+
:field_alias => {int:'Fixnum', str:'String', text:'Text', time:'Time', big:'Bignum', fl:'Float'},
|
175
|
+
:init_module_path => [:store, :lang, :schema, :install, :modinfo, :misc, :gemfile, :view, :assets, :readme, :route],
|
176
|
+
:init_root_path => [:db_dir, :upload_dir, :backup_dir, :tmp_dir, :log_dir, :module],
|
177
|
+
:environment => 'development', # or production, test
|
178
|
+
:only_enable_modules => [],
|
179
|
+
:disable_modules => [],
|
180
|
+
:encoding => 'utf-8',
|
181
|
+
:lang => 'en',
|
182
|
+
:install_lock => 'yes',
|
183
|
+
:db_connection => 'sqlite://db/data.db',
|
184
|
+
:server_log_mode => 'file',
|
185
|
+
:repo_source => 'https://github.com/',
|
186
|
+
:server => 'thin',
|
187
|
+
:bind => '0.0.0.0',
|
188
|
+
:port => 3000,
|
189
|
+
:init_scfg_item => [:lang, :db_connection, :environment, :bind, :port],
|
190
|
+
}
|
191
|
+
|
192
|
+
end
|
193
|
+
|
194
|
+
# load config file in shortcut pipe
|
195
|
+
Scfg = Simrb::Scfg
|
196
|
+
if File.exist? 'scfg'
|
197
|
+
Simrb.yaml_read('scfg').each do | k, v |
|
198
|
+
Scfg[k.to_sym] = v
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
# load path in shortcut pipe
|
203
|
+
Spath = Simrb::Spath
|
204
|
+
if File.exist? 'spath'
|
205
|
+
Simrb.yaml_read('spath').each do | k, v |
|
206
|
+
Spath[k.to_sym] = v
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
# load modules
|
211
|
+
Smodules = Simrb.module_load
|
212
|
+
|
data/lib/simrb/docs.rb
ADDED
@@ -0,0 +1,207 @@
|
|
1
|
+
#
|
2
|
+
# all of help documents is wrote here
|
3
|
+
#
|
4
|
+
|
5
|
+
Sdocs['Preface'] =<<Doc
|
6
|
+
|
7
|
+
=== What about the Simrb ?
|
8
|
+
|
9
|
+
Simrb is a framework for building server application. Many years ago, i had tried to find an application to do work of that i want to build something that could be used to run at server, and support the web service, web page, json data, xml data, and varied formats of data.
|
10
|
+
|
11
|
+
The importance things in using is need to be simple, flexible, comfortable. I couldn't find it, So this is the reason why would i build this software called Simrb.
|
12
|
+
|
13
|
+
|
14
|
+
=== What responsibility Simrb does ?
|
15
|
+
|
16
|
+
Defining the directory architecture, basic command-line, configuration option, initialize loading workflow, that is all.
|
17
|
+
Doc
|
18
|
+
|
19
|
+
|
20
|
+
Sdocs['Directory'] =<<Doc
|
21
|
+
|
22
|
+
/home/project
|
23
|
+
├── modules
|
24
|
+
│ ├── module_name1
|
25
|
+
│ │ ├── boxes ───│ ---- DATA LAYER ----
|
26
|
+
│ │ │ ├── docs │ stores the documents
|
27
|
+
│ │ │ ├── tpls │ stores the templates, like *.erb
|
28
|
+
│ │ │ ├── migrations │ stores the migration records
|
29
|
+
│ │ │ ├── langs │ stores the language file, *.en, *.de, *.cn, etc
|
30
|
+
│ │ │ │ ├── name.en │
|
31
|
+
│ │ │ │ └── name.cn │
|
32
|
+
│ │ │ ├── misc │ stores the Gemfile, Gemfile.lock, and others
|
33
|
+
│ │ │ │ └── Gemfile │
|
34
|
+
│ │ │ ├── installs │ stores the installing file that will be write into database, by
|
35
|
+
│ │ │ │ └── _mods │ the file name as the table name
|
36
|
+
│ │ │ ├── tool.rb │ these files will be loaded in command `$ 3s`
|
37
|
+
│ │ │ └── ... │
|
38
|
+
│ │ ├── views ───│ ---- VIEW LAYER ----
|
39
|
+
│ │ │ ├── assets │ assets dir stores the file *.js, *.css, *.jpg, *.png, etc
|
40
|
+
│ │ │ │ ├── jqeury.js │
|
41
|
+
│ │ │ │ └── style.css │
|
42
|
+
│ │ │ ├── temp.slim │ here is stored the template files that will be loaded
|
43
|
+
│ │ │ ├── demo.slim │ when the route file need it
|
44
|
+
│ │ │ ├── demo2.slim │
|
45
|
+
│ │ │ └── ... │
|
46
|
+
│ │ ├── README.md ───│ ---- LOGIC LAYER ----
|
47
|
+
│ │ ├── .gitignore │
|
48
|
+
│ │ ├── routes.rb │ any files with suffix `rb`, like routes.rb, all will be loaded in
|
49
|
+
│ │ ├── demo.rb │ startup of web server
|
50
|
+
│ │ ├── demo2.rb │
|
51
|
+
│ │ └── ... ───│
|
52
|
+
│ │
|
53
|
+
│ ├── module_name2 ───│ other modules, you add it according to the requirement
|
54
|
+
│ ├── module_name3 │
|
55
|
+
│ └── ... │
|
56
|
+
│
|
57
|
+
├── db
|
58
|
+
│ ├── backup
|
59
|
+
│ ├── upload
|
60
|
+
│ └── data.db
|
61
|
+
├── log
|
62
|
+
│ ├── thin.log
|
63
|
+
│ └── command_error_log.html
|
64
|
+
├── tmp
|
65
|
+
│ └── install.lock
|
66
|
+
└── scfg put any options of static configuration here with an hash form
|
67
|
+
Doc
|
68
|
+
|
69
|
+
|
70
|
+
Sdocs['Configuration'] =<<Doc
|
71
|
+
|
72
|
+
Simrb has two configuration files that is scfg and spath under the root directory, spath stores all of paths of default directory and file, and the scfg file is for setting options to your project application.
|
73
|
+
Doc
|
74
|
+
|
75
|
+
|
76
|
+
Sdocs['Modularization'] =<<Doc
|
77
|
+
|
78
|
+
In Simrb, any functionalities that should be packed into module, whatever you want to do, three ways is there for you: new a module, or clone a module that has the requirement you want from remote repository, modify existed module at local.
|
79
|
+
|
80
|
+
Here is a core [system](https://github.com/simrb/system) module for common application.
|
81
|
+
Doc
|
82
|
+
|
83
|
+
|
84
|
+
Sdocs['Command-line'] =<<Doc
|
85
|
+
|
86
|
+
=== Overview
|
87
|
+
|
88
|
+
Simrb includes two commands, `simrb`, `3s`. `simrb` is ran at global, except the `new` and `clone`. The `3s` is only allowed to run under root directory of project. And the functionality of `3s` command could be extended by that file *.rb under the boxes dir
|
89
|
+
|
90
|
+
|
91
|
+
=== Description of command simrb
|
92
|
+
|
93
|
+
init - initialize a project directory
|
94
|
+
new - create a new module
|
95
|
+
clone - clone a module from remote repository
|
96
|
+
help - show the help documentation
|
97
|
+
info - show the information of current version of Simrb
|
98
|
+
start - boot Simrb up via web server mode
|
99
|
+
kill - kill the process of that web server you have booted up
|
100
|
+
|
101
|
+
|
102
|
+
init
|
103
|
+
==================
|
104
|
+
Command format:
|
105
|
+
|
106
|
+
$ simrb init [project_name] [module_name] [module_name2] ...
|
107
|
+
|
108
|
+
Example 1, initial a project
|
109
|
+
|
110
|
+
$ simrb init project_name
|
111
|
+
|
112
|
+
Example 2, with creating a new module when initializing the project
|
113
|
+
|
114
|
+
$ simrb init project_name module_name module_name2
|
115
|
+
|
116
|
+
Example 3, or, the module could be came from remote repository
|
117
|
+
|
118
|
+
$ simrb init project_name module_name repo_name/module_name2
|
119
|
+
|
120
|
+
|
121
|
+
new
|
122
|
+
==================
|
123
|
+
Command format:
|
124
|
+
|
125
|
+
$ simrb new [module_name] [module_name2] [module_name3] ...
|
126
|
+
|
127
|
+
note that this command only be used in root directory that includes the scfg file
|
128
|
+
|
129
|
+
Example 1,
|
130
|
+
|
131
|
+
$ simrb new blog
|
132
|
+
|
133
|
+
Example 2, new module more than one at the same time
|
134
|
+
|
135
|
+
$ simrb new test test2 test3
|
136
|
+
|
137
|
+
|
138
|
+
clone
|
139
|
+
==================
|
140
|
+
Command format:
|
141
|
+
|
142
|
+
$ simrb clone [repo_name/module_name] [repo_name/module_name2] [repo_name/module_name3] ...
|
143
|
+
|
144
|
+
its usage is as same as the new command, but just get the module from remote repository.
|
145
|
+
|
146
|
+
Example 1
|
147
|
+
|
148
|
+
$ simrb clone repos_name/module_name repos_name2/module_name2
|
149
|
+
|
150
|
+
|
151
|
+
help
|
152
|
+
==================
|
153
|
+
Command format:
|
154
|
+
|
155
|
+
$ simrb help
|
156
|
+
|
157
|
+
Example 1, if plus a number at the end, that will show the detail
|
158
|
+
|
159
|
+
$ simrb help
|
160
|
+
$ simrb help 1
|
161
|
+
|
162
|
+
|
163
|
+
info
|
164
|
+
==================
|
165
|
+
Command format:
|
166
|
+
|
167
|
+
$ simrb info
|
168
|
+
|
169
|
+
|
170
|
+
start
|
171
|
+
==================
|
172
|
+
Command format:
|
173
|
+
|
174
|
+
$ simrb start
|
175
|
+
|
176
|
+
|
177
|
+
kill
|
178
|
+
==================
|
179
|
+
Command format:
|
180
|
+
|
181
|
+
$ simrb kill
|
182
|
+
Doc
|
183
|
+
|
184
|
+
|
185
|
+
Sdocs['Hello World'] =<<Doc
|
186
|
+
|
187
|
+
When it finished installing at once, you can cook yourself by a `Hello World` demo.
|
188
|
+
|
189
|
+
Step 01, create a project directory called myapp
|
190
|
+
|
191
|
+
$ simrb init myapp
|
192
|
+
|
193
|
+
Step 02, new a module called demo
|
194
|
+
|
195
|
+
$ cd myapp && simrb new demo
|
196
|
+
|
197
|
+
Step 03, add content to file
|
198
|
+
|
199
|
+
$ echo 'get "/" do "Hello world" end' > modules/demo/routes.rb
|
200
|
+
|
201
|
+
Step 04, start up by web server to see what we have done
|
202
|
+
|
203
|
+
$ simrb start
|
204
|
+
|
205
|
+
So, open browser and type the link http://0.0.0.0:3000 to address bar,
|
206
|
+
yup, if you see the Hello world is there, welcome you fall in Simrb.
|
207
|
+
Doc
|
data/lib/simrb/help.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
#
|
2
|
+
# a help interface for document
|
3
|
+
#
|
4
|
+
|
5
|
+
Sdocs = {}
|
6
|
+
|
7
|
+
module Simrb
|
8
|
+
|
9
|
+
def self.help args = []
|
10
|
+
res = []
|
11
|
+
i = 0
|
12
|
+
docs_key = {}
|
13
|
+
docs_val = {}
|
14
|
+
Sdocs.each do | key, val |
|
15
|
+
docs_key[i] = key
|
16
|
+
docs_val[i] = val
|
17
|
+
i = i + 1
|
18
|
+
end
|
19
|
+
|
20
|
+
if args.empty?
|
21
|
+
res << 'please select the number before the list to see detials'
|
22
|
+
docs_key.each do | i, key |
|
23
|
+
res << "#{i.to_s}, #{key}"
|
24
|
+
end
|
25
|
+
else
|
26
|
+
args.each do | i |
|
27
|
+
res << (docs_val.include?(i.to_i) ? docs_val[i.to_i] : 'no document')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
res
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/lib/simrb/hook.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#
|
2
|
+
# a hooking file that determines what middleware to use
|
3
|
+
#
|
4
|
+
|
5
|
+
require 'sinatra'
|
6
|
+
require 'sequel'
|
7
|
+
require 'slim'
|
8
|
+
|
9
|
+
Svalid = {}
|
10
|
+
Sdata = {}
|
11
|
+
|
12
|
+
# increase data and valid block
|
13
|
+
module Sinatra
|
14
|
+
class Application < Base
|
15
|
+
def self.data name = '', &block
|
16
|
+
(Sdata[name] ||= []) << block
|
17
|
+
end
|
18
|
+
def self.valid name = '', &block
|
19
|
+
(Svalid[name] ||= []) << block
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module Delegator
|
24
|
+
delegate :data, :valid
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# default environment and db configuration setting
|
29
|
+
set :environment, Scfg[:environment].to_sym
|
30
|
+
|
31
|
+
# alter the path of template customized
|
32
|
+
set :views, Sload[:view]
|
33
|
+
helpers do
|
34
|
+
def find_template(views, name, engine, &block)
|
35
|
+
Array(views).each { |v| super(v, name, engine, &block) }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
data/lib/simrb/info.rb
CHANGED
@@ -1,10 +1,14 @@
|
|
1
|
+
#
|
2
|
+
# this file stores the base info of this project of the software
|
3
|
+
#
|
4
|
+
|
1
5
|
module Simrb
|
2
6
|
|
3
7
|
Info = {
|
4
8
|
:name => 'simrb',
|
5
9
|
:created => '2014-01-01',
|
6
10
|
:alias_name => '3s',
|
7
|
-
:version => '1.0.
|
11
|
+
:version => '1.0.4',
|
8
12
|
:author => 'Linyu Deng',
|
9
13
|
:email => 'coolesting@gmail.com',
|
10
14
|
:homepage => 'https://github.com/simrb/simrb-gem',
|
data/lib/simrb/init.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
#
|
2
|
+
# this is a configuration file and loading workflow of application
|
3
|
+
#
|
4
|
+
|
5
|
+
require 'simrb/config'
|
6
|
+
|
7
|
+
Simrb.root_dir_force
|
8
|
+
|
9
|
+
# increase language block
|
10
|
+
class Sl
|
11
|
+
@@options = {}
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def [] key
|
15
|
+
key = key.to_s
|
16
|
+
@@options.include?(key) ? @@options[key] : key
|
17
|
+
end
|
18
|
+
|
19
|
+
def << h
|
20
|
+
@@options.merge!(h)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# scan file path
|
26
|
+
Sload = {}
|
27
|
+
Sload[:lang] = []
|
28
|
+
Sload[:main] = []
|
29
|
+
Sload[:tool] = []
|
30
|
+
Sload[:view] = []
|
31
|
+
|
32
|
+
Smodules.each do | name |
|
33
|
+
Sload[:lang] += Dir["#{Sroot}#{Spath[:module]}#{name}#{Spath[:lang]}*.#{Scfg[:lang]}"]
|
34
|
+
Sload[:tool] += Dir["#{Sroot}#{Spath[:module]}#{name}#{Spath[:store]}*.rb"]
|
35
|
+
Sload[:tool] += Dir["#{Sroot}#{Spath[:module]}#{name}#{Spath[:tool]}*.rb"]
|
36
|
+
Sload[:main] += Dir["#{Sroot}#{Spath[:module]}#{name}/*.rb"]
|
37
|
+
Sload[:main] += Dir["#{Sroot}#{Spath[:module]}#{name}#{Spath[:logic]}*.rb"]
|
38
|
+
Sload[:view] << "#{Sroot}#{Spath[:module]}#{name}#{Spath[:view]}".chomp("/")
|
39
|
+
end
|
40
|
+
|
41
|
+
# cache label statement of language
|
42
|
+
Sload[:lang].each do | lang |
|
43
|
+
Sl << Simrb.yaml_read(lang)
|
44
|
+
end
|
45
|
+
|
46
|
+
# lood the hook of default configure
|
47
|
+
require "simrb/hook"
|
48
|
+
|
49
|
+
# load main files that will be run later
|
50
|
+
Sload[:main].each do | path |
|
51
|
+
require path
|
52
|
+
end
|
53
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#
|
2
|
+
# this is an entrance to start the web server
|
3
|
+
#
|
4
|
+
|
5
|
+
require 'simrb/init'
|
6
|
+
|
7
|
+
set :run, true
|
8
|
+
set :server, Scfg[:server]
|
9
|
+
set :bind, Scfg[:bind]
|
10
|
+
set :port, Scfg[:port]
|
11
|
+
|
12
|
+
if Scfg[:environment] == 'production'
|
13
|
+
|
14
|
+
Process.daemon Sroot
|
15
|
+
# system("echo #{Process.pid} > #{Spath[:tmp_dir]}pid")
|
16
|
+
|
17
|
+
if Scfg[:server_log_mode] == 'file'
|
18
|
+
log = File.new(Spath[:server_log], "a+")
|
19
|
+
$stdout.reopen(log)
|
20
|
+
$stderr.reopen(log)
|
21
|
+
|
22
|
+
$stderr.sync = true
|
23
|
+
$stdout.sync = true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,61 @@
|
|
1
|
+
#
|
2
|
+
# this is an entrance for running the task command in tool box
|
3
|
+
#
|
4
|
+
|
5
|
+
require 'simrb/init'
|
6
|
+
|
7
|
+
module Simrb
|
8
|
+
module Stool
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
Sload[:tool].each do | path |
|
13
|
+
require path
|
14
|
+
end
|
15
|
+
argv = ARGV.clone
|
16
|
+
output = []
|
17
|
+
|
18
|
+
# command mode
|
19
|
+
if argv.count > 0 and Simrb::Stool.method_defined?(argv[0])
|
20
|
+
|
21
|
+
helpers do
|
22
|
+
include Simrb::Stool
|
23
|
+
end
|
24
|
+
|
25
|
+
get '/_tools' do
|
26
|
+
method = argv.shift(1)[0]
|
27
|
+
argv.empty? ? eval(method).to_s : eval("#{method} #{argv}").to_s
|
28
|
+
end
|
29
|
+
|
30
|
+
env = {'PATH_INFO' => "/_tools", 'REQUEST_METHOD' => 'GET', 'rack.input' => ''}
|
31
|
+
status, type, body = Sinatra::Application.call env
|
32
|
+
if status == 200
|
33
|
+
body.each do | line |
|
34
|
+
output << line
|
35
|
+
end
|
36
|
+
else
|
37
|
+
File.open(Spath[:command_log], 'a+') do | f |
|
38
|
+
f.write "\n#{'='*10}#{Time.now.to_s}\n#{'='*10}\n"
|
39
|
+
# f.write body
|
40
|
+
f.write (Sinatra::ShowExceptions.new(self).call(env.merge("HTTP_USER_AGENT" => "curl"))[2][0].to_s + "\n")
|
41
|
+
end
|
42
|
+
output << env["sinatra.error"]
|
43
|
+
end
|
44
|
+
|
45
|
+
# document mode
|
46
|
+
else
|
47
|
+
|
48
|
+
require 'simrb/help'
|
49
|
+
|
50
|
+
Smodules.each do | name |
|
51
|
+
Dir["#{Spath[:module]}#{name}#{Spath[:doc]}*.#{Scfg[:lang]}.rb"].each do | path |
|
52
|
+
require(Sroot + path)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
argv.shift 1
|
57
|
+
output << Simrb.help(argv)
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
Simrb.p output
|
data/lib/simrb.rb
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
-
|
1
|
+
#
|
2
|
+
# this is an entrance to base command operated
|
3
|
+
#
|
4
|
+
|
5
|
+
require 'simrb/config'
|
6
|
+
require 'simrb/comd'
|
7
|
+
simrb_app = Simrb::Scommand.new
|
8
|
+
simrb_app.run ARGV
|
2
9
|
|
3
|
-
require 'simrb/command'
|
4
|
-
Simrb::Scommand.run ARGV
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Linyu Deng
|
@@ -9,18 +9,83 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2014-01-01 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sinatra
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.4.5
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.4.5
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sequel
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 4.10.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 4.10.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: slim
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.0.2
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.0.2
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: thin
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.6.2
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.6.2
|
13
69
|
description: This is a command helper for simrb
|
14
70
|
email: coolesting@gmail.com
|
15
71
|
executables:
|
72
|
+
- 3s
|
16
73
|
- simrb
|
17
74
|
extensions: []
|
18
75
|
extra_rdoc_files: []
|
19
76
|
files:
|
77
|
+
- bin/3s
|
20
78
|
- bin/simrb
|
21
79
|
- lib/simrb.rb
|
22
|
-
- lib/simrb/
|
80
|
+
- lib/simrb/comd.rb
|
81
|
+
- lib/simrb/config.rb
|
82
|
+
- lib/simrb/docs.rb
|
83
|
+
- lib/simrb/help.rb
|
84
|
+
- lib/simrb/hook.rb
|
23
85
|
- lib/simrb/info.rb
|
86
|
+
- lib/simrb/init.rb
|
87
|
+
- lib/simrb/thin_start.rb
|
88
|
+
- lib/simrb/tool_start.rb
|
24
89
|
homepage: https://github.com/simrb/simrb-gem
|
25
90
|
licenses:
|
26
91
|
- MIT
|
data/lib/simrb/command.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
require 'simrb/info'
|
2
|
-
|
3
|
-
module Simrb
|
4
|
-
|
5
|
-
class Scommand
|
6
|
-
|
7
|
-
# pull the simrb
|
8
|
-
#
|
9
|
-
# == Example
|
10
|
-
#
|
11
|
-
# $ simrb init myapp
|
12
|
-
#
|
13
|
-
def self.init
|
14
|
-
# get the copy from remote repository
|
15
|
-
@appname = @args[0] ? @args[0] : 'simrb'
|
16
|
-
system("git clone https://github.com/simrb/simrb.git #{@appname}")
|
17
|
-
|
18
|
-
# initializes detected the running environment
|
19
|
-
init_env
|
20
|
-
end
|
21
|
-
|
22
|
-
# initialize environment
|
23
|
-
def self.init_env
|
24
|
-
# bash command
|
25
|
-
if `which 3s`.empty?
|
26
|
-
`echo 'alias 3s="ruby cmd.rb"' >> ~/.bashrc && source`
|
27
|
-
end
|
28
|
-
|
29
|
-
# basic gem bundling
|
30
|
-
if @args.include? '--dev'
|
31
|
-
system("bundle install --gemfile=#{@appname}/modules/system/stores/Gemfile --without=production")
|
32
|
-
elsif @args.include? '--pro'
|
33
|
-
system("bundle install --gemfile=#{@appname}/modules/system/stores/Gemfile --without=develpment")
|
34
|
-
else
|
35
|
-
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def self.run argv
|
40
|
-
if argv.count > 0
|
41
|
-
@cmd = argv.shift
|
42
|
-
@args = argv ? argv : []
|
43
|
-
end
|
44
|
-
|
45
|
-
case @cmd
|
46
|
-
when 'init'
|
47
|
-
init
|
48
|
-
puts "Successfully initialized"
|
49
|
-
else
|
50
|
-
puts "No #{@cmd} command found in simrb"
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
57
|
-
|