modularize_sinatra 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +5 -0
- data/{LICENSE → LICENSE.txt} +2 -2
- data/README.md +13 -63
- data/Rakefile +1 -2
- data/bin/modularize_sinatra +3 -37
- data/lib/modularize_sinatra.rb +7 -1
- data/lib/modularize_sinatra/app_generator.rb +104 -0
- data/lib/modularize_sinatra/cli.rb +14 -0
- data/lib/modularize_sinatra/helper_methods.rb +0 -0
- data/lib/modularize_sinatra/templates/config.ru +1 -1
- data/lib/modularize_sinatra/templates/spec/controllers/controller_spec.rb +1 -1
- data/lib/modularize_sinatra/templates/spec/controllers/ping_spec.rb +2 -2
- data/lib/modularize_sinatra/templates/spec/spec_helper.rb +2 -2
- data/lib/modularize_sinatra/version.rb +1 -1
- data/modularize_sinatra.gemspec +22 -18
- metadata +20 -24
- data/lib/modularize_sinatra/USAGE +0 -5
- data/lib/modularize_sinatra/modularize_sinatra_generator.rb +0 -89
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d12e2c1d1380144ecf1b80e01cec41ca48802d70
|
4
|
+
data.tar.gz: 1b89c821801ed22a8e8b8c15569ed3796e852b5a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 696eaa9d1f7623b806c038c5f4c68337f629600b541f454fe475d6dea9324215acd4f02450dd40239b54cefb7a0aeabf1d1a762a9b6d567b0a43570d9035b9b2
|
7
|
+
data.tar.gz: 13eba011f55b9cab8b8fd030a5dd1bf0108fe3785086b389bea27e642a17eca281b25be211247375a9cd43707333ddb2fa636da5d7cbbca6a0e709254be93925
|
data/.gitignore
CHANGED
data/{LICENSE → LICENSE.txt}
RENAMED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c)
|
1
|
+
Copyright (c) 2014 Ankit Goyal
|
2
2
|
|
3
3
|
MIT License
|
4
4
|
|
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
19
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
20
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
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.
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,79 +1,29 @@
|
|
1
|
-
#
|
1
|
+
# ModularizeSinatra
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
Modularized Code Generator for Sinatra. Gem available on [rubygems](https://rubygems.org/gems/modularize_sinatra)
|
6
|
-
More information at: http://goyalankit.com/blog/2013/07/23/modularize-sinatra/
|
3
|
+
TODO: Write a gem description
|
7
4
|
|
8
5
|
## Installation
|
9
6
|
|
10
|
-
|
11
|
-
|
12
|
-
## Usage
|
13
|
-
|
14
|
-
To generate the skeleton structure with custom controller:
|
15
|
-
|
16
|
-
modularize_sinatra myapp -C user
|
17
|
-
|
18
|
-
To Start the app:
|
19
|
-
|
20
|
-
rackup -p 9292
|
7
|
+
Add this line to your application's Gemfile:
|
21
8
|
|
22
|
-
|
23
|
-
|
24
|
-
http://localhost:9292/
|
9
|
+
gem 'modularize_sinatra'
|
25
10
|
|
26
|
-
|
11
|
+
And then execute:
|
27
12
|
|
28
|
-
|
29
|
-
|-- Gemfile
|
30
|
-
|-- Rakefile
|
31
|
-
|-- config
|
32
|
-
| `-- environment.rb
|
33
|
-
|-- config.ru
|
34
|
-
|-- lib
|
35
|
-
| |-- app.rb
|
36
|
-
| |-- controllers
|
37
|
-
| | `-- user.rb
|
38
|
-
| `-- views
|
39
|
-
| `-- users
|
40
|
-
| `-- index.erb
|
41
|
-
|-- myapp.rb
|
42
|
-
|-- public
|
43
|
-
|-- script
|
44
|
-
|-- spec
|
45
|
-
| |-- controllers
|
46
|
-
| | `-- user_spec.rb
|
47
|
-
| |-- spec_helper.rb
|
48
|
-
| `-- support
|
49
|
-
`-- tmp
|
13
|
+
$ bundle
|
50
14
|
|
51
|
-
|
15
|
+
Or install it yourself as:
|
52
16
|
|
53
|
-
|
54
|
-
> Ahoy! from Myapp 2013-04-07 00:33:58 +0530
|
55
|
-
|
56
|
-
Currently `rspec` is configured by default. Hope to release support for other frameworks in future versions.
|
57
|
-
|
58
|
-
To Run specs:
|
59
|
-
|
60
|
-
bundle exec rake
|
61
|
-
|
62
|
-
## TODO
|
17
|
+
$ gem install modularize_sinatra
|
63
18
|
|
64
|
-
|
65
|
-
2. More testing frameworks.
|
66
|
-
|
67
|
-
## Authors
|
19
|
+
## Usage
|
68
20
|
|
69
|
-
|
70
|
-
* [more projects](http://goyalankit.com/labs)
|
21
|
+
TODO: Write usage instructions here
|
71
22
|
|
72
23
|
## Contributing
|
73
24
|
|
74
|
-
1. Fork it
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/modularize_sinatra/fork )
|
75
26
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
76
|
-
3. Commit your changes (`git commit -am '
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
77
28
|
4. Push to the branch (`git push origin my-new-feature`)
|
78
|
-
5. Create new Pull Request
|
79
|
-
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
CHANGED
data/bin/modularize_sinatra
CHANGED
@@ -1,39 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
require '
|
5
|
-
|
6
|
-
#Monkey patching for source_index deprecation
|
7
|
-
unless Gem.respond_to?(:source_index)
|
8
|
-
module Gem
|
9
|
-
def self.source_index
|
10
|
-
sources
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.cache
|
14
|
-
sources
|
15
|
-
end
|
16
|
-
|
17
|
-
SourceIndex = Specification
|
18
|
-
|
19
|
-
class SourceList
|
20
|
-
# If you want vendor gems, this is where to start writing code.
|
21
|
-
def search( *args ); []; end
|
22
|
-
def each( &block ); end
|
23
|
-
include Enumerable
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
if %w(-v --version).include? ARGV.first
|
29
|
-
require 'modularize_sinatra'
|
30
|
-
puts "#{File.basename($0)} #{ModularizeSinatra::VERSION}"
|
31
|
-
exit(0)
|
32
|
-
end
|
33
|
-
|
34
|
-
require 'rubigen/scripts/generate'
|
35
|
-
source = RubiGen::PathSource.new(:application,
|
36
|
-
File.join(File.dirname(__FILE__), "../lib"))
|
37
|
-
RubiGen::Base.reset_sources
|
38
|
-
RubiGen::Base.append_sources source
|
39
|
-
RubiGen::Scripts::Generate.new.run(ARGV, :generator => 'modularize_sinatra')
|
3
|
+
$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")))
|
4
|
+
require 'modularize_sinatra/cli'
|
5
|
+
ModularizeSinatra::CLI.start
|
data/lib/modularize_sinatra.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
|
+
require "active_support/inflector"
|
1
2
|
require "modularize_sinatra/version"
|
3
|
+
require "modularize_sinatra/helper_methods"
|
4
|
+
require "modularize_sinatra/app_generator"
|
2
5
|
|
3
6
|
module ModularizeSinatra
|
4
|
-
#
|
7
|
+
# root of the gem
|
8
|
+
def self.root
|
9
|
+
File.expand_path '../..', __FILE__
|
10
|
+
end
|
5
11
|
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
module ModularizeSinatra
|
2
|
+
require 'erubis'
|
3
|
+
class AppGenerator
|
4
|
+
attr_accessor :app_name, :controller_name, :controller_module_name, :module_name, :app_root, :test_framework
|
5
|
+
def initialize app_name, controller_name
|
6
|
+
@app_name = app_name
|
7
|
+
@controller_name = controller_name
|
8
|
+
@controller_module_name = controller_name.camelize
|
9
|
+
@module_name = app_name.camelize
|
10
|
+
@templates_path = File.join(File.expand_path(File.dirname(__FILE__)), 'templates')
|
11
|
+
@test_framework = "rspec"
|
12
|
+
end
|
13
|
+
|
14
|
+
def full_path destination
|
15
|
+
File.join(@app_root, destination)
|
16
|
+
end
|
17
|
+
|
18
|
+
def add_file source, destination
|
19
|
+
destination_path = full_path(destination)
|
20
|
+
input = File.read(File.join(@templates_path, source))
|
21
|
+
eruby = Erubis::Eruby.new(input)
|
22
|
+
|
23
|
+
already_exists = false
|
24
|
+
overwrite = true
|
25
|
+
|
26
|
+
if File.exists?(destination_path)
|
27
|
+
print "File #{destination_path} already exists. Overwrite(Y/n)? "
|
28
|
+
user_says = STDIN.gets.chomp
|
29
|
+
overwrite = false unless user_says.downcase == 'y'
|
30
|
+
already_exists = true
|
31
|
+
end
|
32
|
+
|
33
|
+
if overwrite
|
34
|
+
puts "#{already_exists ? 'overwriting' : 'creating'}" << " #{destination_path}"
|
35
|
+
File.open(destination_path, 'w') { |file| file.write(eruby.result(binding())) }
|
36
|
+
else
|
37
|
+
puts "skipping #{destination_path}"
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
# this method adds directory w.r.t root path of the app
|
43
|
+
def add_dir destination
|
44
|
+
destination_path = full_path(destination)
|
45
|
+
Dir.mkdir(destination_path) unless Dir.exists?(destination_path)
|
46
|
+
puts "creating directory #{@app_name}/#{destination}"
|
47
|
+
end
|
48
|
+
|
49
|
+
def create_app_dir
|
50
|
+
Dir.mkdir(@app_name) unless Dir.exists?(@app_name)
|
51
|
+
@app_root = File.join(Dir.pwd, @app_name)
|
52
|
+
end
|
53
|
+
|
54
|
+
def generate
|
55
|
+
# generate root directory
|
56
|
+
create_app_dir
|
57
|
+
|
58
|
+
# create all directories
|
59
|
+
# order is important here
|
60
|
+
dirs = [
|
61
|
+
"config",
|
62
|
+
"lib",
|
63
|
+
"lib/controllers",
|
64
|
+
"lib/views",
|
65
|
+
"spec",
|
66
|
+
"spec/controllers"
|
67
|
+
]
|
68
|
+
|
69
|
+
# if controller is not default
|
70
|
+
if @controller_name != "ping"
|
71
|
+
dirs << "lib/views/#{@controller_name.pluralize}"
|
72
|
+
end
|
73
|
+
|
74
|
+
dirs.each do |dir|
|
75
|
+
add_dir(dir)
|
76
|
+
end
|
77
|
+
|
78
|
+
# create all files
|
79
|
+
files = {
|
80
|
+
"config/environment.rb" => "config/environment.rb",
|
81
|
+
"lib/app.rb" => "lib/app.rb",
|
82
|
+
"spec/spec_helper.rb" => "spec/spec_helper.rb",
|
83
|
+
"config.ru" => "config.ru",
|
84
|
+
"Gemfile" => "Gemfile",
|
85
|
+
"module.rb" => "#{@app_name}.rb",
|
86
|
+
"Rakefile" => "Rakefile"
|
87
|
+
}
|
88
|
+
|
89
|
+
# add default ping controller
|
90
|
+
if @controller_name == "ping"
|
91
|
+
files["lib/controllers/ping.rb"] = "lib/controllers/ping.rb"
|
92
|
+
files["spec/controllers/ping_spec.rb"] = "spec/controllers/ping_spec.rb"
|
93
|
+
else
|
94
|
+
files["lib/controllers/controller.rb"] = "lib/controllers/#{@controller_name}.rb"
|
95
|
+
files["lib/views/index.erb"] = "lib/views/#{@controller_name.pluralize}/index.erb"
|
96
|
+
files["spec/controllers/controller_spec.rb"] = "spec/controllers/#{@controller_name}_spec.rb"
|
97
|
+
end
|
98
|
+
|
99
|
+
files.each do |src, dest|
|
100
|
+
add_file src, dest
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'modularize_sinatra'
|
3
|
+
module ModularizeSinatra
|
4
|
+
class CLI < Thor
|
5
|
+
desc "new", "Create a new app"
|
6
|
+
option :c, :default => "ping", :aliases => :C
|
7
|
+
def new(app_name)
|
8
|
+
app_generator = AppGenerator.new(app_name, options[:c])
|
9
|
+
app_generator.generate
|
10
|
+
end
|
11
|
+
|
12
|
+
default_task :new
|
13
|
+
end
|
14
|
+
end
|
File without changes
|
@@ -8,8 +8,8 @@ describe <%= module_name %>::Controllers::Ping do
|
|
8
8
|
describe "get /ping" do
|
9
9
|
it "should return 200" do
|
10
10
|
get :ping
|
11
|
-
last_response.body.
|
12
|
-
last_response.status.
|
11
|
+
expect(last_response.body).to eq("Ahoy! from <%= module_name %> #{Time.now}")
|
12
|
+
expect(last_response.status).to eq(200)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -9,11 +9,11 @@ $: << spec_root
|
|
9
9
|
$: << File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
10
10
|
|
11
11
|
Sinatra::Base.set :environment, :test
|
12
|
-
require File.join(File.dirname(__FILE__), '..', '<%=
|
12
|
+
require File.join(File.dirname(__FILE__), '..', '<%= app_name %>')
|
13
13
|
Dir[File.join(spec_root, "support/**/*.rb")].each { |f| require f }
|
14
14
|
|
15
15
|
RSpec.configure do |config|
|
16
|
-
config.
|
16
|
+
config.color = true
|
17
17
|
config.include Sinatra::TestHelpers
|
18
18
|
end
|
19
19
|
|
data/modularize_sinatra.gemspec
CHANGED
@@ -1,21 +1,25 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'modularize_sinatra/version'
|
3
5
|
|
4
|
-
Gem::Specification.new do |
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "modularize_sinatra"
|
8
|
+
spec.version = ModularizeSinatra::VERSION
|
9
|
+
spec.authors = ["Ankit Goyal"]
|
10
|
+
spec.email = ["ankit3goyal@gmail.com"]
|
11
|
+
spec.summary = %q{Creates a modular skeleton for Sinatra application.}
|
12
|
+
spec.description = %q{Code Generator for Sinatra}
|
13
|
+
spec.homepage = "https://github.com/goyalankit/modularize_sinatra"
|
14
|
+
spec.license = "MIT"
|
10
15
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
gem.add_dependency 'activesupport', '>= 2.3.5', "< 3.2.0"
|
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.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_dependency "thor"
|
24
|
+
spec.add_dependency "erubis"
|
21
25
|
end
|
metadata
CHANGED
@@ -1,37 +1,37 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: modularize_sinatra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ankit Goyal
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '1.6'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '1.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
|
-
type: :
|
34
|
+
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: thor
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -53,25 +53,19 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: erubis
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
62
|
-
- - "<"
|
63
|
-
- !ruby/object:Gem::Version
|
64
|
-
version: 3.2.0
|
61
|
+
version: '0'
|
65
62
|
type: :runtime
|
66
63
|
prerelease: false
|
67
64
|
version_requirements: !ruby/object:Gem::Requirement
|
68
65
|
requirements:
|
69
66
|
- - ">="
|
70
67
|
- !ruby/object:Gem::Version
|
71
|
-
version:
|
72
|
-
- - "<"
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
version: 3.2.0
|
68
|
+
version: '0'
|
75
69
|
description: Code Generator for Sinatra
|
76
70
|
email:
|
77
71
|
- ankit3goyal@gmail.com
|
@@ -82,13 +76,14 @@ extra_rdoc_files: []
|
|
82
76
|
files:
|
83
77
|
- ".gitignore"
|
84
78
|
- Gemfile
|
85
|
-
- LICENSE
|
79
|
+
- LICENSE.txt
|
86
80
|
- README.md
|
87
81
|
- Rakefile
|
88
82
|
- bin/modularize_sinatra
|
89
83
|
- lib/modularize_sinatra.rb
|
90
|
-
- lib/modularize_sinatra/
|
91
|
-
- lib/modularize_sinatra/
|
84
|
+
- lib/modularize_sinatra/app_generator.rb
|
85
|
+
- lib/modularize_sinatra/cli.rb
|
86
|
+
- lib/modularize_sinatra/helper_methods.rb
|
92
87
|
- lib/modularize_sinatra/templates/Gemfile
|
93
88
|
- lib/modularize_sinatra/templates/Rakefile
|
94
89
|
- lib/modularize_sinatra/templates/config.ru
|
@@ -104,7 +99,8 @@ files:
|
|
104
99
|
- lib/modularize_sinatra/version.rb
|
105
100
|
- modularize_sinatra.gemspec
|
106
101
|
homepage: https://github.com/goyalankit/modularize_sinatra
|
107
|
-
licenses:
|
102
|
+
licenses:
|
103
|
+
- MIT
|
108
104
|
metadata: {}
|
109
105
|
post_install_message:
|
110
106
|
rdoc_options: []
|
@@ -122,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
118
|
version: '0'
|
123
119
|
requirements: []
|
124
120
|
rubyforge_project:
|
125
|
-
rubygems_version: 2.
|
121
|
+
rubygems_version: 2.2.2
|
126
122
|
signing_key:
|
127
123
|
specification_version: 4
|
128
124
|
summary: Creates a modular skeleton for Sinatra application.
|
@@ -1,89 +0,0 @@
|
|
1
|
-
class ModularizeSinatraGenerator < RubiGen::Base
|
2
|
-
|
3
|
-
DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
|
4
|
-
Config::CONFIG['ruby_install_name'])
|
5
|
-
|
6
|
-
default_options :shebang => DEFAULT_SHEBANG,
|
7
|
-
:version => '0.0.1',
|
8
|
-
:controller_name => 'Ping'
|
9
|
-
|
10
|
-
attr_reader :name, :module_name, :project_name
|
11
|
-
attr_reader :controller_name, :controller_module_name
|
12
|
-
|
13
|
-
# extensions/option
|
14
|
-
attr_reader :test_framework
|
15
|
-
|
16
|
-
|
17
|
-
def initialize(runtime_args, runtime_options = {})
|
18
|
-
super
|
19
|
-
usage if args.empty?
|
20
|
-
@destination_root = File.expand_path(args.shift)
|
21
|
-
@name = base_name
|
22
|
-
@project_name = @name
|
23
|
-
@module_name = name.gsub('-','_').camelize
|
24
|
-
extract_options
|
25
|
-
end
|
26
|
-
|
27
|
-
def manifest
|
28
|
-
record do |m|
|
29
|
-
m.directory ''
|
30
|
-
BASEDIRS.each { |path| m.directory path }
|
31
|
-
|
32
|
-
m.template_copy_each %w( Gemfile config.ru Rakefile)
|
33
|
-
m.template "module.rb", "#{project_name}.rb"
|
34
|
-
m.template "lib/app.rb", "lib/app.rb"
|
35
|
-
m.template "config/environment.rb", "config/environment.rb"
|
36
|
-
m.template "spec/spec_helper.rb", "spec/spec_helper.rb"
|
37
|
-
|
38
|
-
#controller for app
|
39
|
-
case controller_name
|
40
|
-
when 'Ping'
|
41
|
-
m.template "lib/controllers/ping.rb", "lib/controllers/ping.rb"
|
42
|
-
m.template "spec/controllers/ping_spec.rb", "spec/controllers/ping_spec.rb"
|
43
|
-
else
|
44
|
-
m.template "lib/controllers/controller.rb", "lib/controllers/#{controller_name}.rb"
|
45
|
-
m.template "spec/controllers/controller_spec.rb", "spec/controllers/#{controller_name}_spec.rb"
|
46
|
-
m.directory "lib/views/#{controller_name.pluralize}"
|
47
|
-
m.template "lib/views/index.erb", "lib/views/#{controller_name.pluralize}/index.erb"
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
protected
|
53
|
-
def banner
|
54
|
-
<<-EOS
|
55
|
-
Creates a skeltan for modularized Sinatra Applications
|
56
|
-
|
57
|
-
USAGE: #{spec.name} name
|
58
|
-
EOS
|
59
|
-
end
|
60
|
-
|
61
|
-
def add_options!(opts)
|
62
|
-
opts.separator ''
|
63
|
-
opts.separator 'Options:'
|
64
|
-
opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
|
65
|
-
opts.on("-T", "--test-with=TEST_FRAMEWORK", String,
|
66
|
-
"Select your preferred testing framework.",
|
67
|
-
"Options: rspec (default), test_unit.") { |x| options[:test_framework] = x }
|
68
|
-
opts.on("-C", "--controller=CONTROLLER_NAME", String,
|
69
|
-
"Give name of your initial controller",
|
70
|
-
"default name give is Ping.") { |x| options[:controller_name] = x }
|
71
|
-
end
|
72
|
-
|
73
|
-
def extract_options
|
74
|
-
@test_framework = "rspec"
|
75
|
-
@controller_name = options[:controller_name] || "Ping"
|
76
|
-
@controller_module_name = controller_name.gsub('-','_').camelize
|
77
|
-
end
|
78
|
-
|
79
|
-
BASEDIRS = %w(
|
80
|
-
config
|
81
|
-
lib/controllers
|
82
|
-
lib/views
|
83
|
-
public
|
84
|
-
spec/controllers
|
85
|
-
spec/support
|
86
|
-
script
|
87
|
-
tmp
|
88
|
-
)
|
89
|
-
end
|