sinatra-template 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +21 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +89 -0
- data/Rakefile +1 -0
- data/bin/sinatra +365 -0
- data/lib/sinatra/template.rb +7 -0
- data/lib/sinatra/template/version.rb +5 -0
- data/sinatra-template.gemspec +22 -0
- data/spec/sinatra/template_spec.rb +9 -0
- data/spec/spec_helper.rb +2 -0
- data/template/.gitignore +21 -0
- data/template/Gemfile +16 -0
- data/template/Gemfile.lock +85 -0
- data/template/Procfile +1 -0
- data/template/Procfile.development +1 -0
- data/template/README.md +38 -0
- data/template/Rakefile +3 -0
- data/template/apps/my_app.rb +10 -0
- data/template/apps/views/my_app/index.erb +1 -0
- data/template/apps/views/my_app/layout.erb +49 -0
- data/template/assets/javascripts/application.js.coffee +7 -0
- data/template/assets/stylesheets/application.css.scss +3 -0
- data/template/assets/templates/.git-keep +0 -0
- data/template/config.ru +19 -0
- data/template/models/.git-keep +0 -0
- data/template/mongoid.yml +28 -0
- data/template/public/.git-keep +0 -0
- data/template/setup.rb +19 -0
- data/template/spec/apps/my_app_spec.rb +15 -0
- data/template/spec/spec_helper.rb +10 -0
- data/template/vendor/assets/javascripts/backbone.js +42 -0
- data/template/vendor/assets/javascripts/jquery.js +2 -0
- data/template/vendor/assets/javascripts/json2.js +486 -0
- data/template/vendor/assets/javascripts/underscore.js +1 -0
- data/template/vendor/assets/stylesheets/.git-keep +0 -0
- metadata +102 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Mark Bates
|
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,89 @@
|
|
1
|
+
# Sinatra::Template
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'sinatra-template'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install sinatra-template
|
18
|
+
|
19
|
+
## Generating a New Project
|
20
|
+
|
21
|
+
```bash
|
22
|
+
$ sinatra new awesome_app
|
23
|
+
$ cd awesome_app
|
24
|
+
$ bundle
|
25
|
+
$ foreman start
|
26
|
+
```
|
27
|
+
|
28
|
+
## Testing
|
29
|
+
|
30
|
+
```bash
|
31
|
+
$ cd awesome_app
|
32
|
+
$ rake
|
33
|
+
```
|
34
|
+
|
35
|
+
## Starting
|
36
|
+
|
37
|
+
```bash
|
38
|
+
$ cd awesome_app
|
39
|
+
$ sinatra start [environment]
|
40
|
+
```
|
41
|
+
|
42
|
+
## Console
|
43
|
+
|
44
|
+
```bash
|
45
|
+
$ cd awesome_app
|
46
|
+
$ sinatra console [environment]
|
47
|
+
```
|
48
|
+
|
49
|
+
## Generating a New App
|
50
|
+
|
51
|
+
```bash
|
52
|
+
$ cd awesome_app
|
53
|
+
$ sinatra generate:app foo_app
|
54
|
+
```
|
55
|
+
|
56
|
+
### Destroying a New App
|
57
|
+
|
58
|
+
```bash
|
59
|
+
$ cd awesome_app
|
60
|
+
$ sinatra destroy:app foo_app
|
61
|
+
```
|
62
|
+
|
63
|
+
## Generating a New Model
|
64
|
+
|
65
|
+
```bash
|
66
|
+
$ cd awesome_app
|
67
|
+
$ sinatra generate:model user
|
68
|
+
```
|
69
|
+
|
70
|
+
### Destroying a New Model
|
71
|
+
|
72
|
+
```bash
|
73
|
+
$ cd awesome_app
|
74
|
+
$ sinatra destroy:model user
|
75
|
+
```
|
76
|
+
|
77
|
+
## Help
|
78
|
+
|
79
|
+
```bash
|
80
|
+
$ sinatra help
|
81
|
+
```
|
82
|
+
|
83
|
+
## Contributing
|
84
|
+
|
85
|
+
1. Fork it
|
86
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
87
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
88
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
89
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/sinatra
ADDED
@@ -0,0 +1,365 @@
|
|
1
|
+
require 'active_support/core_ext'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
$template_dir = File.expand_path(File.join("..", "template"), File.dirname(__FILE__))
|
5
|
+
|
6
|
+
command = ARGV[0]
|
7
|
+
|
8
|
+
class Command
|
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|
|
333
|
+
if klass.command == command
|
334
|
+
klass.new(ARGV).call
|
335
|
+
exit(0)
|
336
|
+
end
|
337
|
+
end
|
338
|
+
Command.commands.each do |klass|
|
339
|
+
if klass.respond_to?(:help)
|
340
|
+
puts "sinatra #{klass.command} #{klass.help}"
|
341
|
+
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
|