sinatra-template 1.0.0 → 1.1.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.
- data/bin/sinatra +5 -351
- data/lib/sinatra/commands.rb +6 -0
- data/lib/sinatra/commands/app_destroyer_command.rb +51 -0
- data/lib/sinatra/commands/app_generator_command.rb +59 -0
- data/lib/sinatra/commands/command.rb +27 -0
- data/lib/sinatra/commands/console_command.rb +18 -0
- data/lib/sinatra/commands/env_command.rb +19 -0
- data/lib/sinatra/commands/model_destroyer_command.rb +31 -0
- data/lib/sinatra/commands/model_generator_command.rb +46 -0
- data/lib/sinatra/commands/name_command.rb +29 -0
- data/lib/sinatra/commands/new_project_generator_command.rb +36 -0
- data/lib/sinatra/commands/start_command.rb +23 -0
- data/lib/sinatra/template/version.rb +1 -1
- data/{template → template_app}/.gitignore +0 -0
- data/{template → template_app}/Gemfile +0 -0
- data/{template → template_app}/Gemfile.lock +0 -0
- data/{template → template_app}/Procfile +0 -0
- data/{template → template_app}/Procfile.development +0 -0
- data/{template → template_app}/README.md +0 -0
- data/{template → template_app}/Rakefile +0 -0
- data/{template → template_app}/apps/my_app.rb +0 -0
- data/{template → template_app}/apps/views/my_app/index.erb +0 -0
- data/{template → template_app}/apps/views/my_app/layout.erb +0 -0
- data/{template → template_app}/assets/javascripts/application.js.coffee +0 -0
- data/{template → template_app}/assets/stylesheets/application.css.scss +0 -0
- data/{template → template_app}/assets/templates/.git-keep +0 -0
- data/{template → template_app}/config.ru +0 -0
- data/{template → template_app}/models/.git-keep +0 -0
- data/{template → template_app}/mongoid.yml +0 -0
- data/{template → template_app}/public/.git-keep +0 -0
- data/{template → template_app}/setup.rb +0 -0
- data/{template → template_app}/spec/apps/my_app_spec.rb +0 -0
- data/{template → template_app}/spec/spec_helper.rb +0 -0
- data/{template → template_app}/vendor/assets/javascripts/backbone.js +0 -0
- data/{template → template_app}/vendor/assets/javascripts/jquery.js +0 -0
- data/{template → template_app}/vendor/assets/javascripts/json2.js +0 -0
- data/{template → template_app}/vendor/assets/javascripts/underscore.js +0 -0
- data/{template → template_app}/vendor/assets/stylesheets/.git-keep +0 -0
- metadata +37 -26
data/bin/sinatra
CHANGED
@@ -1,365 +1,19 @@
|
|
1
1
|
require 'active_support/core_ext'
|
2
2
|
require 'fileutils'
|
3
3
|
|
4
|
-
|
4
|
+
$:.unshift File.expand_path(File.join("..", "lib", "sinatra"), File.dirname(__FILE__))
|
5
|
+
require 'commands'
|
5
6
|
|
6
7
|
command = ARGV[0]
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
def self.command
|
11
|
-
nil
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.commands
|
15
|
-
@commands ||= []
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.inherited(klass)
|
19
|
-
self.commands << klass
|
20
|
-
end
|
21
|
-
|
22
|
-
def cmd(command)
|
23
|
-
puts command
|
24
|
-
system command
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
class NameCommand < Command
|
30
|
-
include FileUtils
|
31
|
-
|
32
|
-
attr_accessor :args, :name
|
33
|
-
|
34
|
-
def self.inherited(klass)
|
35
|
-
Command.inherited(klass)
|
36
|
-
end
|
37
|
-
|
38
|
-
def underscored
|
39
|
-
self.name.underscore
|
40
|
-
end
|
41
|
-
|
42
|
-
def classified
|
43
|
-
self.name.classify
|
44
|
-
end
|
45
|
-
|
46
|
-
def initialize(args)
|
47
|
-
self.args = args
|
48
|
-
self.name = ARGV[1]
|
49
|
-
end
|
50
|
-
|
51
|
-
def clean_string(f)
|
52
|
-
f.gsub($template_dir, @app_dir).gsub("my_app", self.underscored).gsub("MyApp", self.classified)
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
class NewProjectGenerator < NameCommand
|
58
|
-
|
59
|
-
def self.command
|
60
|
-
"new"
|
61
|
-
end
|
62
|
-
|
63
|
-
def self.help
|
64
|
-
"name"
|
65
|
-
end
|
66
|
-
|
67
|
-
def initialize(*args)
|
68
|
-
super
|
69
|
-
@app_dir = File.expand_path(File.join(pwd, self.underscored))
|
70
|
-
end
|
71
|
-
|
72
|
-
def classified
|
73
|
-
"#{self.name.classify}App"
|
74
|
-
end
|
75
|
-
|
76
|
-
def call
|
77
|
-
mkdir self.underscored, verbose: true
|
78
|
-
Dir[File.expand_path(File.join("**", "*"), $template_dir)].each do |f|
|
79
|
-
if File.directory?(f)
|
80
|
-
mkdir_p clean_string(f), verbose: true
|
81
|
-
else
|
82
|
-
mkdir_p clean_string(File.dirname(f)), verbose: true
|
83
|
-
File.open(clean_string(f), 'w') do |file|
|
84
|
-
file.puts clean_string(File.read(f))
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
end
|
91
|
-
|
92
|
-
class AppGenerator < NameCommand
|
93
|
-
|
94
|
-
def self.command
|
95
|
-
"generate:app"
|
96
|
-
end
|
97
|
-
|
98
|
-
def self.help
|
99
|
-
"app_name"
|
100
|
-
end
|
101
|
-
|
102
|
-
def initialize(*args)
|
103
|
-
super
|
104
|
-
@app_dir = File.expand_path(pwd)
|
105
|
-
end
|
106
|
-
|
107
|
-
def classified
|
108
|
-
"#{self.name.classify}App"
|
109
|
-
end
|
110
|
-
|
111
|
-
def call
|
112
|
-
# mkdir self.underscored, verbose: true
|
113
|
-
%w{apps spec/apps}.each do |dir|
|
114
|
-
Dir[File.expand_path(File.join(dir, "**", "*"), $template_dir)].each do |f|
|
115
|
-
if File.directory?(f)
|
116
|
-
mkdir_p clean_string(f), verbose: true
|
117
|
-
else
|
118
|
-
mkdir_p clean_string(File.dirname(f)), verbose: true
|
119
|
-
File.open(clean_string(f), 'w') do |file|
|
120
|
-
file.puts clean_string(File.read(f))
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
File.open(File.expand_path(File.join(@app_dir, "config.ru")), "a") do |file|
|
126
|
-
file.puts <<-EOF
|
127
|
-
map "/#{self.underscored}" do
|
128
|
-
run #{self.classified}
|
129
|
-
end
|
130
|
-
EOF
|
131
|
-
end
|
132
|
-
|
133
|
-
path = File.expand_path(File.join(@app_dir, "spec", "apps", "#{self.underscored}_spec.rb"))
|
134
|
-
mkdir_p File.dirname(path), verbose: true
|
135
|
-
File.open(path, 'w') do |file|
|
136
|
-
file.puts <<-EOF
|
137
|
-
require 'spec_helper'
|
138
|
-
|
139
|
-
describe #{self.classified} do
|
140
|
-
|
141
|
-
it "does something"
|
142
|
-
|
143
|
-
end
|
144
|
-
EOF
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
end
|
149
|
-
|
150
|
-
class AppDestroyer < NameCommand
|
151
|
-
|
152
|
-
def self.command
|
153
|
-
"destroy:app"
|
154
|
-
end
|
155
|
-
|
156
|
-
def self.help
|
157
|
-
"app_name"
|
158
|
-
end
|
159
|
-
|
160
|
-
def initialize(*args)
|
161
|
-
super
|
162
|
-
@app_dir = File.expand_path(pwd)
|
163
|
-
end
|
164
|
-
|
165
|
-
def classified
|
166
|
-
"#{self.name.classify}App"
|
167
|
-
end
|
168
|
-
|
169
|
-
def call
|
170
|
-
path = File.expand_path(File.join(@app_dir, "apps", "#{self.underscored}.rb"))
|
171
|
-
begin
|
172
|
-
rm path, verbose: true
|
173
|
-
rescue Errno::ENOENT => e
|
174
|
-
end
|
175
|
-
path = File.expand_path(File.join(@app_dir, "apps", "views", self.underscored))
|
176
|
-
begin
|
177
|
-
rm_r path, verbose: true
|
178
|
-
rescue Errno::ENOENT => e
|
179
|
-
end
|
180
|
-
path = File.expand_path(File.join(@app_dir, "spec", "apps", "#{self.underscored}_spec.rb"))
|
181
|
-
begin
|
182
|
-
rm path, verbose: true
|
183
|
-
rescue Errno::ENOENT => e
|
184
|
-
end
|
185
|
-
|
186
|
-
path = File.expand_path(File.join(@app_dir, "config.ru"))
|
187
|
-
old = File.read(path)
|
188
|
-
File.open(path, "w") do |file|
|
189
|
-
map = <<-EOF
|
190
|
-
map "/#{self.underscored}" do
|
191
|
-
run #{self.classified}
|
192
|
-
end
|
193
|
-
EOF
|
194
|
-
file.puts old.gsub(map, "")
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
end
|
199
|
-
|
200
|
-
class ModelGenerator < NameCommand
|
201
|
-
|
202
|
-
def self.command
|
203
|
-
"generate:model"
|
204
|
-
end
|
205
|
-
|
206
|
-
def self.help
|
207
|
-
"model_name"
|
208
|
-
end
|
209
|
-
|
210
|
-
def initialize(*args)
|
211
|
-
super
|
212
|
-
@app_dir = File.expand_path(pwd)
|
213
|
-
end
|
214
|
-
|
215
|
-
def call
|
216
|
-
path = File.expand_path(File.join(@app_dir, "models", "#{self.underscored}.rb"))
|
217
|
-
mkdir_p File.dirname(path), verbose: true
|
218
|
-
File.open(path, 'w') do |file|
|
219
|
-
file.puts <<-EOF
|
220
|
-
class #{self.classified}
|
221
|
-
include Mongoid::Document
|
222
|
-
include Mongoid::Timestamps
|
223
|
-
|
224
|
-
end
|
225
|
-
EOF
|
226
|
-
end
|
227
|
-
|
228
|
-
path = File.expand_path(File.join(@app_dir, "spec", "models", "#{self.underscored}_spec.rb"))
|
229
|
-
mkdir_p File.dirname(path), verbose: true
|
230
|
-
File.open(path, 'w') do |file|
|
231
|
-
file.puts <<-EOF
|
232
|
-
require 'spec_helper'
|
233
|
-
|
234
|
-
describe #{self.classified} do
|
235
|
-
|
236
|
-
it "does something"
|
237
|
-
|
238
|
-
end
|
239
|
-
EOF
|
240
|
-
end
|
241
|
-
end
|
242
|
-
|
243
|
-
end
|
244
|
-
|
245
|
-
class ModelDestroyer < NameCommand
|
246
|
-
|
247
|
-
def self.command
|
248
|
-
"destroy:model"
|
249
|
-
end
|
250
|
-
|
251
|
-
def self.help
|
252
|
-
"model_name"
|
253
|
-
end
|
254
|
-
|
255
|
-
def initialize(*args)
|
256
|
-
super
|
257
|
-
@app_dir = File.expand_path(pwd)
|
258
|
-
end
|
259
|
-
|
260
|
-
def call
|
261
|
-
path = File.expand_path(File.join(@app_dir, "models", "#{self.underscored}.rb"))
|
262
|
-
begin
|
263
|
-
rm path, verbose: true
|
264
|
-
rescue Errno::ENOENT => e
|
265
|
-
end
|
266
|
-
path = File.expand_path(File.join(@app_dir, "spec", "models", "#{self.underscored}_spec.rb"))
|
267
|
-
begin
|
268
|
-
rm path, verbose: true
|
269
|
-
rescue Errno::ENOENT => e
|
270
|
-
end
|
271
|
-
end
|
272
|
-
|
273
|
-
end
|
274
|
-
|
275
|
-
class EnvCommand < Command
|
276
|
-
include FileUtils
|
277
|
-
|
278
|
-
attr_accessor :args, :env
|
279
|
-
|
280
|
-
def self.inherited(klass)
|
281
|
-
Command.inherited(klass)
|
282
|
-
end
|
283
|
-
|
284
|
-
def initialize(args)
|
285
|
-
self.args = args
|
286
|
-
@app_dir = File.expand_path(pwd)
|
287
|
-
self.env = args[1] || "development"
|
288
|
-
ENV["RACK_ENV"] = self.env
|
289
|
-
end
|
290
|
-
|
291
|
-
end
|
292
|
-
|
293
|
-
class ConsoleCommand < EnvCommand
|
294
|
-
|
295
|
-
def self.command
|
296
|
-
"console"
|
297
|
-
end
|
298
|
-
|
299
|
-
def self.help
|
300
|
-
"[environment]\t\t# default: development"
|
301
|
-
end
|
302
|
-
|
303
|
-
def call
|
304
|
-
path = File.expand_path(File.join(@app_dir, "setup.rb"))
|
305
|
-
cmd "pry -r #{path}"
|
306
|
-
end
|
307
|
-
|
308
|
-
end
|
309
|
-
|
310
|
-
class StartCommand < EnvCommand
|
311
|
-
|
312
|
-
def self.command
|
313
|
-
"start"
|
314
|
-
end
|
315
|
-
|
316
|
-
def self.help
|
317
|
-
"[environment]\t\t# default: development"
|
318
|
-
end
|
319
|
-
|
320
|
-
def call
|
321
|
-
path = File.expand_path(File.join(@app_dir, "Procfile.#{self.env}"))
|
322
|
-
if File.exists?(path)
|
323
|
-
cmd "bundle exec foreman start -f #{path}"
|
324
|
-
else
|
325
|
-
path = File.expand_path(File.join(@app_dir, "Procfile"))
|
326
|
-
cmd "bundle exec foreman start -f #{path}"
|
327
|
-
end
|
328
|
-
end
|
329
|
-
|
330
|
-
end
|
331
|
-
|
332
|
-
Command.commands.each do |klass|
|
9
|
+
Sinatra::Command.commands.each do |klass|
|
333
10
|
if klass.command == command
|
334
11
|
klass.new(ARGV).call
|
335
12
|
exit(0)
|
336
13
|
end
|
337
14
|
end
|
338
|
-
Command.commands.each do |klass|
|
15
|
+
Sinatra::Command.commands.each do |klass|
|
339
16
|
if klass.respond_to?(:help)
|
340
17
|
puts "sinatra #{klass.command} #{klass.help}"
|
341
18
|
end
|
342
|
-
end
|
343
|
-
|
344
|
-
# case command
|
345
|
-
# when 'help'
|
346
|
-
# Command.commands.each do |klass|
|
347
|
-
# if klass.respond_to?(:help)
|
348
|
-
# puts "sinatra #{klass.command} #{klass.help}"
|
349
|
-
# end
|
350
|
-
# end
|
351
|
-
# when 'new'
|
352
|
-
# NewProjectGenerator.new(ARGV).call
|
353
|
-
# when 'generate:app'
|
354
|
-
# AppGenerator.new(ARGV).call
|
355
|
-
# when 'destroy:app'
|
356
|
-
# AppDestroyer.new(ARGV).call
|
357
|
-
# when 'generate:model'
|
358
|
-
# ModelGenerator.new(ARGV).call
|
359
|
-
# when 'destroy:model'
|
360
|
-
# ModelDestroyer.new(ARGV).call
|
361
|
-
# when 'console'
|
362
|
-
# ConsoleCommand.new(ARGV).call
|
363
|
-
# when 'start'
|
364
|
-
# StartCommand.new(ARGV).call
|
365
|
-
# end
|
19
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Sinatra
|
2
|
+
class AppDestroyer < Sinatra::NameCommand
|
3
|
+
|
4
|
+
def self.command
|
5
|
+
"destroy:app"
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.help
|
9
|
+
"app_name"
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(*args)
|
13
|
+
super
|
14
|
+
@app_dir = File.expand_path(pwd)
|
15
|
+
end
|
16
|
+
|
17
|
+
def classified
|
18
|
+
"#{self.name.classify}App"
|
19
|
+
end
|
20
|
+
|
21
|
+
def call
|
22
|
+
path = File.expand_path(File.join(@app_dir, "apps", "#{self.underscored}.rb"))
|
23
|
+
begin
|
24
|
+
rm path, verbose: true
|
25
|
+
rescue Errno::ENOENT => e
|
26
|
+
end
|
27
|
+
path = File.expand_path(File.join(@app_dir, "apps", "views", self.underscored))
|
28
|
+
begin
|
29
|
+
rm_r path, verbose: true
|
30
|
+
rescue Errno::ENOENT => e
|
31
|
+
end
|
32
|
+
path = File.expand_path(File.join(@app_dir, "spec", "apps", "#{self.underscored}_spec.rb"))
|
33
|
+
begin
|
34
|
+
rm path, verbose: true
|
35
|
+
rescue Errno::ENOENT => e
|
36
|
+
end
|
37
|
+
|
38
|
+
path = File.expand_path(File.join(@app_dir, "config.ru"))
|
39
|
+
old = File.read(path)
|
40
|
+
File.open(path, "w") do |file|
|
41
|
+
map = <<-EOF
|
42
|
+
map "/#{self.underscored}" do
|
43
|
+
run #{self.classified}
|
44
|
+
end
|
45
|
+
EOF
|
46
|
+
file.puts old.gsub(map, "")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Sinatra
|
2
|
+
class AppGenerator < Sinatra::NameCommand
|
3
|
+
|
4
|
+
def self.command
|
5
|
+
"generate:app"
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.help
|
9
|
+
"app_name"
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(*args)
|
13
|
+
super
|
14
|
+
@app_dir = File.expand_path(pwd)
|
15
|
+
end
|
16
|
+
|
17
|
+
def classified
|
18
|
+
"#{self.name.classify}App"
|
19
|
+
end
|
20
|
+
|
21
|
+
def call
|
22
|
+
# mkdir self.underscored, verbose: true
|
23
|
+
%w{apps spec/apps}.each do |dir|
|
24
|
+
Dir[File.expand_path(File.join(dir, "**", "*"), Sinatra.template_dir)].each do |f|
|
25
|
+
if File.directory?(f)
|
26
|
+
mkdir_p clean_string(f), verbose: true
|
27
|
+
else
|
28
|
+
mkdir_p clean_string(File.dirname(f)), verbose: true
|
29
|
+
File.open(clean_string(f), 'w') do |file|
|
30
|
+
file.puts clean_string(File.read(f))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
File.open(File.expand_path(File.join(@app_dir, "config.ru")), "a") do |file|
|
36
|
+
file.puts <<-EOF
|
37
|
+
map "/#{self.underscored}" do
|
38
|
+
run #{self.classified}
|
39
|
+
end
|
40
|
+
EOF
|
41
|
+
end
|
42
|
+
|
43
|
+
path = File.expand_path(File.join(@app_dir, "spec", "apps", "#{self.underscored}_spec.rb"))
|
44
|
+
mkdir_p File.dirname(path), verbose: true
|
45
|
+
File.open(path, 'w') do |file|
|
46
|
+
file.puts <<-EOF
|
47
|
+
require 'spec_helper'
|
48
|
+
|
49
|
+
describe #{self.classified} do
|
50
|
+
|
51
|
+
it "does something"
|
52
|
+
|
53
|
+
end
|
54
|
+
EOF
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Sinatra
|
2
|
+
|
3
|
+
def self.template_dir
|
4
|
+
File.expand_path(File.join("..", "..", "..", "template_app"), File.dirname(__FILE__))
|
5
|
+
end
|
6
|
+
|
7
|
+
class Command
|
8
|
+
|
9
|
+
def self.command
|
10
|
+
nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.commands
|
14
|
+
@commands ||= []
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.inherited(klass)
|
18
|
+
self.commands << klass
|
19
|
+
end
|
20
|
+
|
21
|
+
def cmd(command)
|
22
|
+
puts command
|
23
|
+
system command
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Sinatra
|
2
|
+
class ConsoleCommand < Sinatra::EnvCommand
|
3
|
+
|
4
|
+
def self.command
|
5
|
+
"console"
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.help
|
9
|
+
"[environment]\t\t# default: development"
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
path = File.expand_path(File.join(@app_dir, "setup.rb"))
|
14
|
+
cmd "pry -r #{path}"
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Sinatra
|
2
|
+
class EnvCommand < Sinatra::Command
|
3
|
+
include FileUtils
|
4
|
+
|
5
|
+
attr_accessor :args, :env
|
6
|
+
|
7
|
+
def self.inherited(klass)
|
8
|
+
Command.inherited(klass)
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(args)
|
12
|
+
self.args = args
|
13
|
+
@app_dir = File.expand_path(pwd)
|
14
|
+
self.env = args[1] || "development"
|
15
|
+
ENV["RACK_ENV"] = self.env
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Sinatra
|
2
|
+
class ModelDestroyer < Sinatra::NameCommand
|
3
|
+
|
4
|
+
def self.command
|
5
|
+
"destroy:model"
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.help
|
9
|
+
"model_name"
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(*args)
|
13
|
+
super
|
14
|
+
@app_dir = File.expand_path(pwd)
|
15
|
+
end
|
16
|
+
|
17
|
+
def call
|
18
|
+
path = File.expand_path(File.join(@app_dir, "models", "#{self.underscored}.rb"))
|
19
|
+
begin
|
20
|
+
rm path, verbose: true
|
21
|
+
rescue Errno::ENOENT => e
|
22
|
+
end
|
23
|
+
path = File.expand_path(File.join(@app_dir, "spec", "models", "#{self.underscored}_spec.rb"))
|
24
|
+
begin
|
25
|
+
rm path, verbose: true
|
26
|
+
rescue Errno::ENOENT => e
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Sinatra
|
2
|
+
class ModelGenerator < Sinatra::NameCommand
|
3
|
+
|
4
|
+
def self.command
|
5
|
+
"generate:model"
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.help
|
9
|
+
"model_name"
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(*args)
|
13
|
+
super
|
14
|
+
@app_dir = File.expand_path(pwd)
|
15
|
+
end
|
16
|
+
|
17
|
+
def call
|
18
|
+
path = File.expand_path(File.join(@app_dir, "models", "#{self.underscored}.rb"))
|
19
|
+
mkdir_p File.dirname(path), verbose: true
|
20
|
+
File.open(path, 'w') do |file|
|
21
|
+
file.puts <<-EOF
|
22
|
+
class #{self.classified}
|
23
|
+
include Mongoid::Document
|
24
|
+
include Mongoid::Timestamps
|
25
|
+
|
26
|
+
end
|
27
|
+
EOF
|
28
|
+
end
|
29
|
+
|
30
|
+
path = File.expand_path(File.join(@app_dir, "spec", "models", "#{self.underscored}_spec.rb"))
|
31
|
+
mkdir_p File.dirname(path), verbose: true
|
32
|
+
File.open(path, 'w') do |file|
|
33
|
+
file.puts <<-EOF
|
34
|
+
require 'spec_helper'
|
35
|
+
|
36
|
+
describe #{self.classified} do
|
37
|
+
|
38
|
+
it "does something"
|
39
|
+
|
40
|
+
end
|
41
|
+
EOF
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Sinatra
|
2
|
+
class NameCommand < Sinatra::Command
|
3
|
+
include FileUtils
|
4
|
+
|
5
|
+
attr_accessor :args, :name
|
6
|
+
|
7
|
+
def self.inherited(klass)
|
8
|
+
Command.inherited(klass)
|
9
|
+
end
|
10
|
+
|
11
|
+
def underscored
|
12
|
+
self.name.underscore
|
13
|
+
end
|
14
|
+
|
15
|
+
def classified
|
16
|
+
self.name.classify
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(args)
|
20
|
+
self.args = args
|
21
|
+
self.name = ARGV[1]
|
22
|
+
end
|
23
|
+
|
24
|
+
def clean_string(f)
|
25
|
+
f.gsub(Sinatra.template_dir, @app_dir).gsub("my_app", self.underscored).gsub("MyApp", self.classified)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Sinatra
|
2
|
+
class NewProjectGenerator < Sinatra::NameCommand
|
3
|
+
|
4
|
+
def self.command
|
5
|
+
"new"
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.help
|
9
|
+
"name"
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(*args)
|
13
|
+
super
|
14
|
+
@app_dir = File.expand_path(File.join(pwd, self.underscored))
|
15
|
+
end
|
16
|
+
|
17
|
+
def classified
|
18
|
+
"#{self.name.classify}App"
|
19
|
+
end
|
20
|
+
|
21
|
+
def call
|
22
|
+
mkdir self.underscored, verbose: true
|
23
|
+
Dir[File.expand_path(File.join("**", "*"), Sinatra.template_dir)].each do |f|
|
24
|
+
if File.directory?(f)
|
25
|
+
mkdir_p clean_string(f), verbose: true
|
26
|
+
else
|
27
|
+
mkdir_p clean_string(File.dirname(f)), verbose: true
|
28
|
+
File.open(clean_string(f), 'w') do |file|
|
29
|
+
file.puts clean_string(File.read(f))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Sinatra
|
2
|
+
class StartCommand < Sinatra::EnvCommand
|
3
|
+
|
4
|
+
def self.command
|
5
|
+
"start"
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.help
|
9
|
+
"[environment]\t\t# default: development"
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
path = File.expand_path(File.join(@app_dir, "Procfile.#{self.env}"))
|
14
|
+
if File.exists?(path)
|
15
|
+
cmd "bundle exec foreman start -f #{path}"
|
16
|
+
else
|
17
|
+
path = File.expand_path(File.join(@app_dir, "Procfile"))
|
18
|
+
cmd "bundle exec foreman start -f #{path}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-template
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -42,36 +42,47 @@ files:
|
|
42
42
|
- README.md
|
43
43
|
- Rakefile
|
44
44
|
- bin/sinatra
|
45
|
+
- lib/sinatra/commands.rb
|
46
|
+
- lib/sinatra/commands/app_destroyer_command.rb
|
47
|
+
- lib/sinatra/commands/app_generator_command.rb
|
48
|
+
- lib/sinatra/commands/command.rb
|
49
|
+
- lib/sinatra/commands/console_command.rb
|
50
|
+
- lib/sinatra/commands/env_command.rb
|
51
|
+
- lib/sinatra/commands/model_destroyer_command.rb
|
52
|
+
- lib/sinatra/commands/model_generator_command.rb
|
53
|
+
- lib/sinatra/commands/name_command.rb
|
54
|
+
- lib/sinatra/commands/new_project_generator_command.rb
|
55
|
+
- lib/sinatra/commands/start_command.rb
|
45
56
|
- lib/sinatra/template.rb
|
46
57
|
- lib/sinatra/template/version.rb
|
47
58
|
- sinatra-template.gemspec
|
48
59
|
- spec/sinatra/template_spec.rb
|
49
60
|
- spec/spec_helper.rb
|
50
|
-
-
|
51
|
-
-
|
52
|
-
-
|
53
|
-
-
|
54
|
-
-
|
55
|
-
-
|
56
|
-
-
|
57
|
-
-
|
58
|
-
-
|
59
|
-
-
|
60
|
-
-
|
61
|
-
-
|
62
|
-
-
|
63
|
-
-
|
64
|
-
-
|
65
|
-
-
|
66
|
-
-
|
67
|
-
-
|
68
|
-
-
|
69
|
-
-
|
70
|
-
-
|
71
|
-
-
|
72
|
-
-
|
73
|
-
-
|
74
|
-
-
|
61
|
+
- template_app/.gitignore
|
62
|
+
- template_app/Gemfile
|
63
|
+
- template_app/Gemfile.lock
|
64
|
+
- template_app/Procfile
|
65
|
+
- template_app/Procfile.development
|
66
|
+
- template_app/README.md
|
67
|
+
- template_app/Rakefile
|
68
|
+
- template_app/apps/my_app.rb
|
69
|
+
- template_app/apps/views/my_app/index.erb
|
70
|
+
- template_app/apps/views/my_app/layout.erb
|
71
|
+
- template_app/assets/javascripts/application.js.coffee
|
72
|
+
- template_app/assets/stylesheets/application.css.scss
|
73
|
+
- template_app/assets/templates/.git-keep
|
74
|
+
- template_app/config.ru
|
75
|
+
- template_app/models/.git-keep
|
76
|
+
- template_app/mongoid.yml
|
77
|
+
- template_app/public/.git-keep
|
78
|
+
- template_app/setup.rb
|
79
|
+
- template_app/spec/apps/my_app_spec.rb
|
80
|
+
- template_app/spec/spec_helper.rb
|
81
|
+
- template_app/vendor/assets/javascripts/backbone.js
|
82
|
+
- template_app/vendor/assets/javascripts/jquery.js
|
83
|
+
- template_app/vendor/assets/javascripts/json2.js
|
84
|
+
- template_app/vendor/assets/javascripts/underscore.js
|
85
|
+
- template_app/vendor/assets/stylesheets/.git-keep
|
75
86
|
homepage: ''
|
76
87
|
licenses:
|
77
88
|
- MIT
|