tony 0.0.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/tony/generator.rb +3 -7
- data/lib/tony/generators/heroku/heroku_generator.rb +10 -0
- data/lib/tony/generators/rspec/Rakefile +6 -0
- data/lib/tony/generators/{rspec_generator.rb → rspec/rspec_generator.rb} +2 -8
- data/lib/tony/generators/rspec/spec/helper.rb +3 -0
- data/lib/tony/generators/sinatra/config.ru +2 -0
- data/lib/tony/generators/sinatra/lib/application.rb +9 -0
- data/lib/tony/generators/sinatra/lib/configuration.rb +19 -0
- data/lib/tony/generators/sinatra/public/scripts/main.js +1 -0
- data/lib/tony/generators/sinatra/public/styles/main.css +1 -0
- data/lib/tony/generators/sinatra/sinatra_generator.rb +17 -0
- data/lib/tony/generators/sinatra/views/index.erb +2 -0
- data/lib/tony/generators/sinatra/views/layout.erb +14 -0
- data/lib/tony/generators/sinatra_rspec/sinatra_rspec_generator.rb +8 -0
- data/lib/tony/generators/sinatra_rspec/spec/application_spec.rb +21 -0
- data/lib/tony/tony.rb +20 -3
- data/lib/tony/version.rb +1 -1
- data/lib/tony.rb +7 -3
- data/spec/generator_spec.rb +11 -7
- data/spec/tony_spec.rb +38 -0
- metadata +17 -4
data/lib/tony/generator.rb
CHANGED
@@ -1,15 +1,11 @@
|
|
1
|
-
require 'ostruct'
|
2
1
|
require 'fileutils'
|
3
2
|
|
4
3
|
module Tony
|
5
4
|
class Generator
|
6
|
-
|
5
|
+
attr_accessor :name, :description, :files, :gems, :combination
|
6
|
+
|
7
7
|
def initialize(&block)
|
8
|
-
|
9
|
-
yield options
|
10
|
-
@name = options.name
|
11
|
-
@description = options.description
|
12
|
-
@files = options.files
|
8
|
+
yield self
|
13
9
|
end
|
14
10
|
|
15
11
|
def generate
|
@@ -2,13 +2,7 @@ Tony::generators << Tony::Generator.new do |options|
|
|
2
2
|
options.name = "rspec"
|
3
3
|
options.description = "Generates rspec rake tasks, spec directories and a spec_helper"
|
4
4
|
options.files = {
|
5
|
-
'Rakefile'
|
6
|
-
|
7
|
-
|
8
|
-
desc "Run specs"
|
9
|
-
RSpec::Core::RakeTask.new do |t|
|
10
|
-
t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
|
11
|
-
end
|
12
|
-
FILE
|
5
|
+
'Rakefile' => File.read(File.join(File.dirname(__FILE__), 'Rakefile')),
|
6
|
+
'spec/helper.rb' => File.read(File.join(File.dirname(__FILE__), 'spec/helper.rb'))
|
13
7
|
}
|
14
8
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class Application < Sinatra::Base
|
2
|
+
configure do
|
3
|
+
set :app_file, File.join(File.dirname(__FILE__), 'application.rb')
|
4
|
+
set :public, File.join(File.dirname(__FILE__), '..', 'public')
|
5
|
+
set :views, File.join(File.dirname(__FILE__) , '..', 'views')
|
6
|
+
end
|
7
|
+
|
8
|
+
configure :production do
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
configure :development do
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
configure :test do
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
//scripts
|
@@ -0,0 +1 @@
|
|
1
|
+
/* styles */
|
@@ -0,0 +1,17 @@
|
|
1
|
+
Tony::generators << Tony::Generator.new do |options|
|
2
|
+
options.name = "sinatra"
|
3
|
+
options.description = "Generates a Sinatra application"
|
4
|
+
options.files = {}
|
5
|
+
[
|
6
|
+
'config.ru',
|
7
|
+
'lib/application.rb',
|
8
|
+
'lib/configuration.rb',
|
9
|
+
'public/scripts/main.js',
|
10
|
+
'public/styles/main.css',
|
11
|
+
'views/index.erb',
|
12
|
+
'views/layout.erb'
|
13
|
+
].each do |path|
|
14
|
+
options.files[path] = File.read(File.join(File.dirname(__FILE__), path))
|
15
|
+
end
|
16
|
+
options.gems = ['sinatra']
|
17
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
2
|
+
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
6
|
+
<link rel="stylesheet" type="text/css" href="/styles/main.css" />
|
7
|
+
<script type="text/javascript" src="/scripts/main.js"></script>
|
8
|
+
<title>Sinatra Template</title>
|
9
|
+
</head>
|
10
|
+
|
11
|
+
<body>
|
12
|
+
<%= yield %>
|
13
|
+
</body>
|
14
|
+
</html>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
Tony::generators << Tony::Generator.new do |options|
|
2
|
+
options.name = "sinatra and rspec"
|
3
|
+
options.description = "sinatra and rspec"
|
4
|
+
options.combination = ["sinatra", "rspec"]
|
5
|
+
options.files = {
|
6
|
+
'spec/application_spec.rb' => File.read(File.join(File.dirname(__FILE__), 'spec', 'application_spec.rb'))
|
7
|
+
}
|
8
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
ENV['RACK_ENV'] = 'test'
|
2
|
+
|
3
|
+
require 'application'
|
4
|
+
require 'rspec'
|
5
|
+
require 'rack/test'
|
6
|
+
|
7
|
+
describe Application do
|
8
|
+
include Rack::Test::Methods
|
9
|
+
|
10
|
+
def app
|
11
|
+
Application
|
12
|
+
end
|
13
|
+
|
14
|
+
context "GET /" do
|
15
|
+
it "should not 404" do
|
16
|
+
get "/"
|
17
|
+
last_response.ok?.should == true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
data/lib/tony/tony.rb
CHANGED
@@ -3,10 +3,27 @@ module Tony
|
|
3
3
|
@@generators = [] unless defined? @@generators
|
4
4
|
@@generators
|
5
5
|
end
|
6
|
+
|
7
|
+
def self.used_generators
|
8
|
+
used_generators = []
|
9
|
+
generators.each do |generator|
|
10
|
+
used_generators << generator if ARGV.include?(generator.name)
|
11
|
+
if generator.combination
|
12
|
+
used_generators << generator if (ARGV - generator.combination).size == (ARGV.size - generator.combination.size)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
used_generators
|
16
|
+
end
|
17
|
+
|
6
18
|
def self.generate
|
7
|
-
ARGV.
|
8
|
-
|
9
|
-
generator
|
19
|
+
if ARGV.size == 0
|
20
|
+
puts 'Supported Generators'
|
21
|
+
generators.each do |generator|
|
22
|
+
puts generator.name
|
23
|
+
end
|
24
|
+
end
|
25
|
+
used_generators.each do |used_generator|
|
26
|
+
used_generator.generate
|
10
27
|
end
|
11
28
|
end
|
12
29
|
end
|
data/lib/tony/version.rb
CHANGED
data/lib/tony.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'tony'))
|
2
|
+
require 'tony'
|
3
|
+
require 'generator'
|
4
|
+
|
5
|
+
Dir.glob(File.join(File.dirname(__FILE__), '**/*_generator.rb')).each do |generator|
|
6
|
+
require generator
|
7
|
+
end
|
data/spec/generator_spec.rb
CHANGED
@@ -17,16 +17,20 @@ describe Tony::Generator do
|
|
17
17
|
generator.name.should == "name"
|
18
18
|
end
|
19
19
|
|
20
|
-
it "
|
21
|
-
ARGV = ['test_generator']
|
20
|
+
it "takes a combination" do
|
22
21
|
generator = Tony::Generator.new do |options|
|
23
|
-
options.
|
22
|
+
options.combination = ['generator1', 'generator2']
|
24
23
|
end
|
25
|
-
|
26
|
-
generator.should_receive(:generate)
|
27
|
-
Tony::generate
|
24
|
+
generator.combination.should == ['generator1', 'generator2']
|
28
25
|
end
|
29
|
-
|
26
|
+
|
27
|
+
it "stores gems" do
|
28
|
+
generator = Tony::Generator.new do |options|
|
29
|
+
options.gems = ["rspec", "sinatra"]
|
30
|
+
end
|
31
|
+
generator.gems.should == ["rspec", "sinatra"]
|
32
|
+
end
|
33
|
+
|
30
34
|
it "takes a description" do
|
31
35
|
generator = Tony::Generator.new do |options|
|
32
36
|
options.description = "description"
|
data/spec/tony_spec.rb
CHANGED
@@ -1,4 +1,42 @@
|
|
1
1
|
require_relative 'helper'
|
2
2
|
|
3
3
|
describe Tony do
|
4
|
+
def mock_generator(name, combination = nil)
|
5
|
+
mock_generator = mock
|
6
|
+
mock_generator.stub!(:name).and_return(name)
|
7
|
+
mock_generator.stub!(:combination).and_return(combination)
|
8
|
+
mock_generator
|
9
|
+
end
|
10
|
+
|
11
|
+
it "stores a list of used generators" do
|
12
|
+
ARGV = ['generator']
|
13
|
+
generator = mock_generator('generator')
|
14
|
+
Tony.stub!(:generators).and_return([generator])
|
15
|
+
Tony.used_generators.should == [generator]
|
16
|
+
end
|
17
|
+
|
18
|
+
it "stores a list of combination generators if all combinations are used" do
|
19
|
+
ARGV = ['generator1', 'generator2']
|
20
|
+
generator1 = mock_generator('generator1')
|
21
|
+
generator2 = mock_generator('generator2')
|
22
|
+
combination_generator = mock_generator('combination_generator', ['generator1', 'generator2'])
|
23
|
+
Tony.stub!(:generators).and_return([generator1, generator2, combination_generator])
|
24
|
+
Tony.used_generators.should == [generator1, generator2, combination_generator]
|
25
|
+
end
|
26
|
+
|
27
|
+
it "sends generate to all generators" do
|
28
|
+
generator = mock_generator('test_generator')
|
29
|
+
Tony.stub(:used_generators).and_return([generator])
|
30
|
+
generator.should_receive(:generate).once
|
31
|
+
Tony.generate
|
32
|
+
end
|
33
|
+
|
34
|
+
it "outputs a list of generators if there are no arguments" do
|
35
|
+
ARGV = []
|
36
|
+
generator = mock_generator('generator')
|
37
|
+
Tony.stub!(:generators).and_return([generator])
|
38
|
+
Tony.should_receive(:puts).with('Supported Generators')
|
39
|
+
Tony.should_receive(:puts).with('generator')
|
40
|
+
Tony.generate
|
41
|
+
end
|
4
42
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
+
- 2
|
7
8
|
- 0
|
8
|
-
|
9
|
-
version: 0.0.1
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Andrew Vos
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-05-
|
17
|
+
date: 2011-05-10 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -48,7 +48,20 @@ files:
|
|
48
48
|
- bin/tony
|
49
49
|
- lib/tony.rb
|
50
50
|
- lib/tony/generator.rb
|
51
|
-
- lib/tony/generators/
|
51
|
+
- lib/tony/generators/heroku/heroku_generator.rb
|
52
|
+
- lib/tony/generators/rspec/Rakefile
|
53
|
+
- lib/tony/generators/rspec/rspec_generator.rb
|
54
|
+
- lib/tony/generators/rspec/spec/helper.rb
|
55
|
+
- lib/tony/generators/sinatra/config.ru
|
56
|
+
- lib/tony/generators/sinatra/lib/application.rb
|
57
|
+
- lib/tony/generators/sinatra/lib/configuration.rb
|
58
|
+
- lib/tony/generators/sinatra/public/scripts/main.js
|
59
|
+
- lib/tony/generators/sinatra/public/styles/main.css
|
60
|
+
- lib/tony/generators/sinatra/sinatra_generator.rb
|
61
|
+
- lib/tony/generators/sinatra/views/index.erb
|
62
|
+
- lib/tony/generators/sinatra/views/layout.erb
|
63
|
+
- lib/tony/generators/sinatra_rspec/sinatra_rspec_generator.rb
|
64
|
+
- lib/tony/generators/sinatra_rspec/spec/application_spec.rb
|
52
65
|
- lib/tony/tony.rb
|
53
66
|
- lib/tony/version.rb
|
54
67
|
- spec/generator_spec.rb
|