padrino-gen 0.7.9 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +42 -13
- data/Rakefile +7 -6
- data/VERSION +1 -1
- data/lib/padrino-gen/generators/actions.rb +25 -3
- data/lib/padrino-gen/generators/app/{app/app.rb.tt → app.rb.tt} +0 -0
- data/lib/padrino-gen/generators/app/{app → controllers}/.empty_directory +0 -0
- data/lib/padrino-gen/generators/app/{app/controllers → helpers}/.empty_directory +0 -0
- data/lib/padrino-gen/generators/app/{app/helpers → views}/.empty_directory +0 -0
- data/lib/padrino-gen/generators/app.rb +28 -36
- data/lib/padrino-gen/generators/components/actions.rb +4 -22
- data/lib/padrino-gen/generators/components/mocks/rr_gen.rb +8 -4
- data/lib/padrino-gen/generators/controller.rb +7 -4
- data/lib/padrino-gen/generators/mailer.rb +5 -2
- data/lib/padrino-gen/generators/model.rb +1 -1
- data/lib/padrino-gen/generators/{app → project}/.gitignore +0 -0
- data/lib/padrino-gen/generators/{app/app/views → project/app}/.empty_directory +0 -0
- data/lib/padrino-gen/generators/project/app/app.rb.tt +37 -0
- data/lib/padrino-gen/generators/{app/config/initializers → project/app/controllers}/.empty_directory +0 -0
- data/lib/padrino-gen/generators/{app/public/images → project/app/helpers}/.empty_directory +0 -0
- data/lib/padrino-gen/generators/{app/public/javascripts → project/app/views}/.empty_directory +0 -0
- data/lib/padrino-gen/generators/{app → project}/config/apps.rb.tt +0 -0
- data/lib/padrino-gen/generators/{app → project}/config/boot.rb +1 -1
- data/lib/padrino-gen/generators/{app/public/stylesheets → project/config/initializers}/.empty_directory +0 -0
- data/lib/padrino-gen/generators/{app → project}/config/initializers/example.rb +0 -0
- data/lib/padrino-gen/generators/{app → project}/config.ru +0 -0
- data/lib/padrino-gen/generators/{app/tmp → project/public/images}/.empty_directory +0 -0
- data/lib/padrino-gen/generators/project/public/javascripts/.empty_directory +0 -0
- data/lib/padrino-gen/generators/project/public/stylesheets/.empty_directory +0 -0
- data/lib/padrino-gen/generators/project/tmp/.empty_directory +0 -0
- data/lib/padrino-gen/generators/project.rb +64 -0
- data/lib/padrino-gen/generators/templates/Gemfile.tt +0 -1
- data/lib/padrino-gen/generators.rb +7 -3
- data/lib/padrino-gen/padrino-tasks/activerecord.rb +1 -1
- data/padrino-gen.gemspec +31 -24
- data/test/helper.rb +7 -7
- data/test/test_app_generator.rb +35 -199
- data/test/test_cli.rb +25 -0
- data/test/test_controller_generator.rb +45 -45
- data/test/test_generator.rb +0 -3
- data/test/test_mailer_generator.rb +25 -26
- data/test/test_migration_generator.rb +61 -62
- data/test/test_model_generator.rb +119 -114
- data/test/test_project_generator.rb +222 -0
- metadata +26 -19
data/README.rdoc
CHANGED
@@ -23,42 +23,42 @@ This means that Padrino generators do *not* lock you into using any particular d
|
|
23
23
|
templating engine or javascript library. In fact, when generating an application you can actually tell
|
24
24
|
Padrino which components you would like to use!
|
25
25
|
|
26
|
-
The usage for the
|
26
|
+
The usage for the project generator is quite simple:
|
27
27
|
|
28
|
-
$ padrino-gen
|
28
|
+
$ padrino-gen project <the_app_name> </path/to/create/app> --<component-name> <value>
|
29
29
|
|
30
30
|
The simplest possible command to generate a base application would be:
|
31
31
|
|
32
|
-
$ padrino-gen
|
32
|
+
$ padrino-gen project demo_project
|
33
33
|
|
34
34
|
This would construct a Padrino application DemoApp (which extends from Padrino::Application)
|
35
|
-
inside the folder '
|
35
|
+
inside the folder 'demo_project' at our current path. Inside the application there would be configuration and
|
36
36
|
setup performed for the default components.
|
37
37
|
|
38
38
|
You can also define specific components to be used:
|
39
39
|
|
40
|
-
$ padrino-gen
|
40
|
+
$ padrino-gen project demo_project --test rspec --renderer haml --mock rr --script jquery --orm datamapper
|
41
41
|
|
42
42
|
There is also support for aliases for each component within the command:
|
43
43
|
|
44
|
-
$ padrino-gen
|
44
|
+
$ padrino-gen project demo_project -t rspec -r haml -m rr -s jquery -d datamapper
|
45
45
|
|
46
46
|
You can also instruct the generator to skip a certain component to avoid using one at all (or to use your own):
|
47
47
|
|
48
|
-
$ padrino-gen
|
48
|
+
$ padrino-gen project demo_project --test none --renderer none
|
49
49
|
|
50
50
|
The available components and their default options are listed below:
|
51
51
|
|
52
|
-
* test: <tt>bacon</tt>
|
53
|
-
* renderer: <tt>
|
54
|
-
* mock: <tt>mocha</tt>
|
55
|
-
* script: <tt>jquery</tt>
|
52
|
+
* test: <tt>bacon</tt> (default), <tt>shoulda</tt>, <tt>rspec</tt>, <tt>testspec</tt>, <tt>riot</tt>
|
53
|
+
* renderer: <tt>haml</tt> (default), <tt>erb</tt>
|
54
|
+
* mock: <tt>mocha</tt> (default), <tt>rr</tt>
|
55
|
+
* script: <tt>jquery</tt> (default), <tt>prototype</tt>, <tt>rightjs</tt>
|
56
56
|
* orm: <tt>datamapper</tt> (default), <tt>mongomapper</tt>, <tt>activerecord</tt>, <tt>sequel</tt>, <tt>couchrest</tt>
|
57
57
|
|
58
58
|
The generator uses the <tt>bundler</tt> gem to resolve any application dependencies when the application is newly created.
|
59
59
|
The necessary bundler command can be executed automatically through the generator with
|
60
60
|
|
61
|
-
$ padrino-gen
|
61
|
+
$ padrino-gen project demo_project --run_bundler # alias -b
|
62
62
|
|
63
63
|
or this can be done manually through executing command <tt>gem bundle</tt> in the terminal at the root of the generated application.
|
64
64
|
If not executed manually, the bundling will be performed automatically the first time the application attempts to boot.
|
@@ -69,6 +69,27 @@ This would be achieved through forking our project and reading through the code
|
|
69
69
|
the setup instructions inside the relevant files within <tt>lib/generators/components/</tt>. We are happy to accept pull requests
|
70
70
|
for additional component types not originally included (although helping us maintain them would also be appreciated).
|
71
71
|
|
72
|
+
=== Sub App Generator
|
73
|
+
|
74
|
+
Unlike other ruby frameworks Padrino is principally designed for mounting multiple apps at the same time.
|
75
|
+
|
76
|
+
First you need to create a project
|
77
|
+
|
78
|
+
$ padrino-gen project demo_project
|
79
|
+
$ cd demo_project
|
80
|
+
|
81
|
+
Now you are in demo_project and you can create your apps:
|
82
|
+
|
83
|
+
$ padrino-gen app one
|
84
|
+
$ padrino-gen app two
|
85
|
+
|
86
|
+
By default these apps are mounted under:
|
87
|
+
|
88
|
+
* /one
|
89
|
+
* /two
|
90
|
+
|
91
|
+
but you can edit config/apps.rb and change it.
|
92
|
+
|
72
93
|
=== Model Generator
|
73
94
|
|
74
95
|
Padrino provides generator support for quickly creating new models within your Padrino application. Note that
|
@@ -142,6 +163,10 @@ created through the Padrino application generator and that follow Padrino conven
|
|
142
163
|
Using the controller generator is as simple as:
|
143
164
|
|
144
165
|
$ padrino-gen controller Admin
|
166
|
+
|
167
|
+
If you want create a controller for a specified sub app you can:
|
168
|
+
|
169
|
+
$ padrino-gen controller Admin -a my_sub_app
|
145
170
|
|
146
171
|
You can also specify desired actions to be added to your controller:
|
147
172
|
|
@@ -170,7 +195,11 @@ created through the Padrino application generator and that follow Padrino conven
|
|
170
195
|
Using the mailer generator is as simple as:
|
171
196
|
|
172
197
|
$ padrino-gen mailer UserNotifier
|
173
|
-
|
198
|
+
|
199
|
+
If you want create a mailer for a specified sub app you can:
|
200
|
+
|
201
|
+
$ padrino-gen mailer UserNotifier -a my_sub_app
|
202
|
+
|
174
203
|
You can also specify desired delivery actions to be added to the mailer:
|
175
204
|
|
176
205
|
$ padrino-gen mailer UserNotifier confirm_account welcome inactive_account
|
data/Rakefile
CHANGED
@@ -20,7 +20,7 @@ begin
|
|
20
20
|
gem.add_runtime_dependency "thor", ">= 0.13.0"
|
21
21
|
gem.add_runtime_dependency "bundler", ">= 0.9.3"
|
22
22
|
gem.add_development_dependency "haml", ">= 2.2.1"
|
23
|
-
gem.add_development_dependency "shoulda", ">=
|
23
|
+
gem.add_development_dependency "shoulda", ">= 2.10.3"
|
24
24
|
gem.add_development_dependency "mocha", ">= 0.9.7"
|
25
25
|
gem.add_development_dependency "rack-test", ">= 0.5.0"
|
26
26
|
gem.add_development_dependency "webrat", ">= 0.5.1"
|
@@ -42,14 +42,15 @@ end
|
|
42
42
|
|
43
43
|
begin
|
44
44
|
require 'rcov/rcovtask'
|
45
|
-
Rcov::RcovTask.new do |
|
46
|
-
|
47
|
-
|
48
|
-
|
45
|
+
Rcov::RcovTask.new do |rcov|
|
46
|
+
rcov.libs << 'test'
|
47
|
+
rcov.pattern = 'test/**/test_*.rb'
|
48
|
+
rcov.verbose = true
|
49
|
+
rcov.rcov_opts << ['--exclude /Gems/1.8/gems/,/tmp/,padrino-admin,padrino-cache,padrino-core,padrino-helpers,padrino-mailer']
|
49
50
|
end
|
50
51
|
rescue LoadError
|
51
52
|
task :rcov do
|
52
|
-
abort "RCov is not available. In order to run rcov, you must: sudo gem install
|
53
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install relevance-rcov"
|
53
54
|
end
|
54
55
|
end
|
55
56
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.8.0
|
@@ -28,6 +28,7 @@ module Padrino
|
|
28
28
|
# include_component_module_for(:mock, 'rr')
|
29
29
|
def include_component_module_for(component, choice=nil)
|
30
30
|
choice = fetch_component_choice(component) unless choice
|
31
|
+
return if choice.to_s == 'none'
|
31
32
|
self.class.send(:include, generator_module_for(choice, component))
|
32
33
|
end
|
33
34
|
|
@@ -107,16 +108,37 @@ module Padrino
|
|
107
108
|
inject_into_file('Gemfile', options[:content], :after => options[:after])
|
108
109
|
end
|
109
110
|
|
111
|
+
## Return true if our project has test component
|
112
|
+
def test?
|
113
|
+
fetch_component_choice(:test).to_s != 'none'
|
114
|
+
end
|
115
|
+
|
116
|
+
## Raise SystemExit if the app is inexistent
|
117
|
+
def check_app_existence(app)
|
118
|
+
unless File.exist?(destination_root(app))
|
119
|
+
say
|
120
|
+
say "================================================================="
|
121
|
+
say "We didn't found #{app.underscore.classify}! Available apps are:"
|
122
|
+
say "================================================================="
|
123
|
+
Padrino.mounted_apps.each do |app|
|
124
|
+
say " - #{app.app_object}"
|
125
|
+
end
|
126
|
+
say "================================================================="
|
127
|
+
say
|
128
|
+
raise SystemExit
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
110
132
|
module ClassMethods
|
111
133
|
|
112
134
|
# Defines a class option to allow a component to be chosen and add to component type list
|
113
135
|
# Also builds the available_choices hash of which component choices are supported
|
114
136
|
# component_option :test, "Testing framework", :aliases => '-t', :choices => [:bacon, :shoulda]
|
115
137
|
def component_option(name, caption, options = {})
|
116
|
-
(@component_types
|
117
|
-
(@available_choices ||= Hash.new
|
138
|
+
(@component_types ||= []) << name # TODO use ordered hash and combine with choices below
|
139
|
+
(@available_choices ||= Hash.new)[name] = options[:choices]
|
118
140
|
description = "The #{caption} component (#{options[:choices].join(', ')}, none)"
|
119
|
-
class_option name, :default => options[:choices].first, :aliases => options[:aliases], :desc => description
|
141
|
+
class_option name, :default => options[:default] || options[:choices].first, :aliases => options[:aliases], :desc => description
|
120
142
|
end
|
121
143
|
|
122
144
|
# Returns the compiled list of component types which can be specified
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,33 +1,25 @@
|
|
1
1
|
module Padrino
|
2
2
|
module Generators
|
3
|
+
|
3
4
|
class App < Thor::Group
|
4
5
|
|
5
6
|
# Add this generator to our padrino-gen
|
6
7
|
Padrino::Generators.add_generator(:app, self)
|
7
8
|
|
8
9
|
# Define the source template root
|
9
|
-
def self.source_root; File.dirname(__FILE__); end
|
10
|
-
def self.banner; "padrino-gen project [name]
|
10
|
+
def self.source_root; File.expand_path(File.dirname(__FILE__)); end
|
11
|
+
def self.banner; "padrino-gen project [name]"; end
|
11
12
|
|
12
13
|
# Include related modules
|
13
14
|
include Thor::Actions
|
14
15
|
include Padrino::Generators::Actions
|
15
|
-
include Padrino::Generators::Components::Actions
|
16
|
-
|
17
|
-
desc "Description:\n\n\tpadrino-gen project generates a new Padrino project"
|
18
16
|
|
19
|
-
|
17
|
+
desc "Description:\n\n\tpadrino-gen project generate a new Padrino application"
|
20
18
|
|
21
|
-
|
22
|
-
class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
|
23
|
-
class_option :dev, :desc => "Use padrino from a git checkout", :default => false, :type => :boolean
|
19
|
+
argument :name, :desc => "The name of your padrino application"
|
24
20
|
|
25
|
-
|
26
|
-
|
27
|
-
component_option :test, "testing framework", :aliases => '-t', :choices => [:bacon, :shoulda, :rspec, :testspec, :riot]
|
28
|
-
component_option :mock, "mocking library", :aliases => '-m', :choices => [:mocha, :rr]
|
29
|
-
component_option :script, "javascript library", :aliases => '-s', :choices => [:jquery, :prototype, :rightjs]
|
30
|
-
component_option :renderer, "template engine", :aliases => '-e', :choices => [:erb, :haml]
|
21
|
+
class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
|
22
|
+
class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
|
31
23
|
|
32
24
|
# Show help if no argv given
|
33
25
|
def self.start(given_args=ARGV, config={})
|
@@ -35,30 +27,30 @@ module Padrino
|
|
35
27
|
super
|
36
28
|
end
|
37
29
|
|
38
|
-
# Copies over the Padrino base application
|
39
|
-
def
|
30
|
+
# Copies over the Padrino base admin application
|
31
|
+
def create_app
|
32
|
+
self.destination_root = options[:root]
|
40
33
|
@class_name = name.underscore.classify
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
34
|
+
if in_app_root?
|
35
|
+
directory("app/", destination_root(name))
|
36
|
+
append_file destination_root("config/apps.rb"), "\nPadrino.mount(\"#{@class_name}\").to(\"/#{name.underscore}\")"
|
37
|
+
|
38
|
+
return if self.behavior == :revoke
|
39
|
+
say (<<-TEXT).gsub(/ {10}/,'')
|
40
|
+
|
41
|
+
=================================================================
|
42
|
+
Your #{@class_name} Application now is installed.
|
43
|
+
It's available on /#{name.underscore}
|
44
|
+
You can setup a new path editing config/apps.rb
|
45
|
+
=================================================================
|
46
|
+
|
47
|
+
TEXT
|
48
|
+
else
|
49
|
+
say "You are not at the root of a Padrino application! (config/boot.rb not found)" and exit unless in_app_root?
|
52
50
|
end
|
53
51
|
end
|
54
52
|
|
55
|
-
# Bundle all required components using bundler and Gemfile
|
56
|
-
def bundle_dependencies
|
57
|
-
if options[:run_bundle]
|
58
|
-
say "Bundling application dependencies using bundler..."
|
59
|
-
in_root { run 'bundle install' }
|
60
|
-
end
|
61
|
-
end
|
62
53
|
end
|
54
|
+
|
63
55
|
end
|
64
|
-
end
|
56
|
+
end
|
@@ -72,12 +72,6 @@ module Padrino
|
|
72
72
|
Dir[destination_root("db/migrate/*_#{filename.underscore}.rb")].size > 0
|
73
73
|
end
|
74
74
|
|
75
|
-
# For model destroy option
|
76
|
-
# removes the initial migration file of model
|
77
|
-
def remove_model_migration(name)
|
78
|
-
remove_migration "Create" + name
|
79
|
-
end
|
80
|
-
|
81
75
|
# For the removal of migration files
|
82
76
|
# removes the migration file based on the migration name
|
83
77
|
def remove_migration(name)
|
@@ -85,10 +79,8 @@ module Padrino
|
|
85
79
|
File.basename(f) =~ /#{name.to_s.underscore}/
|
86
80
|
end
|
87
81
|
return unless migration_path
|
88
|
-
if behavior == :revoke
|
89
|
-
create_file migration_path
|
90
|
-
else
|
91
|
-
remove_file migration_path
|
82
|
+
if behavior == :revoke
|
83
|
+
create_file migration_path # we use create to reverse the operation of a revoke
|
92
84
|
end
|
93
85
|
end
|
94
86
|
|
@@ -125,19 +117,9 @@ module Padrino
|
|
125
117
|
field_tuples = fields.collect { |value| value.split(":") }
|
126
118
|
action_declarations = field_tuples.collect do |request, name|
|
127
119
|
"#{request} :#{name} do\n end\n"
|
128
|
-
end
|
129
|
-
|
130
|
-
|
131
|
-
# For controller route generation
|
132
|
-
# Takes in the fields and maps out an appropriate default route.
|
133
|
-
# where controller is user and route is get:test, will add map(:test).to("/user/test")
|
134
|
-
def controller_routes(name,fields)
|
135
|
-
field_tuples = fields.collect { |value| value.split(":") }
|
136
|
-
routes = "\n" + field_tuples.collect do |request, route|
|
137
|
-
" map(:#{route}).to(\"/#{name}/#{route}\")"
|
138
|
-
end.join("\n") + "\n"
|
120
|
+
end
|
121
|
+
action_declarations.join("\n ")
|
139
122
|
end
|
140
|
-
|
141
123
|
end
|
142
124
|
end
|
143
125
|
end
|
@@ -2,15 +2,19 @@ module Padrino
|
|
2
2
|
module Generators
|
3
3
|
module Components
|
4
4
|
module Mocks
|
5
|
-
|
5
|
+
|
6
6
|
module RrGen
|
7
7
|
def setup_mock
|
8
8
|
require_dependencies 'rr', :group => 'test'
|
9
|
-
|
9
|
+
if options[:test] == 'riot'
|
10
|
+
inject_into_file "test/test_config.rb"," Riot.rr\n", :after => "class Riot::Situation\n"
|
11
|
+
else
|
12
|
+
insert_mocking_include "RR::Adapters::RRMethods", :path => "test/test_config.rb"
|
13
|
+
end
|
10
14
|
end
|
11
15
|
end
|
12
|
-
|
16
|
+
|
13
17
|
end
|
14
18
|
end
|
15
19
|
end
|
16
|
-
end
|
20
|
+
end
|
@@ -20,6 +20,7 @@ module Padrino
|
|
20
20
|
argument :name, :desc => "The name of your padrino controller"
|
21
21
|
argument :fields, :desc => "The fields for the controller", :type => :array, :default => []
|
22
22
|
class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
|
23
|
+
class_option :app, :desc => "The application destination", :aliases => '-a', :default => "/app", :type => :string
|
23
24
|
class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
|
24
25
|
|
25
26
|
# Show help if no argv given
|
@@ -31,15 +32,17 @@ module Padrino
|
|
31
32
|
def create_controller
|
32
33
|
self.destination_root = options[:root]
|
33
34
|
if in_app_root?
|
35
|
+
app = options[:app].underscore
|
36
|
+
check_app_existence(app)
|
34
37
|
@app_name = fetch_app_name(options[:root])
|
35
38
|
@actions = controller_actions(fields)
|
36
39
|
@controller = name
|
37
40
|
self.behavior = :revoke if options[:destroy]
|
38
|
-
template "templates/controller.rb.tt", destination_root("
|
39
|
-
template "templates/helper.rb.tt", destination_root("
|
40
|
-
empty_directory destination_root("
|
41
|
+
template "templates/controller.rb.tt", destination_root(app, "controllers", "#{name}.rb")
|
42
|
+
template "templates/helper.rb.tt", destination_root(app, "helpers", "#{name}_helper.rb")
|
43
|
+
empty_directory destination_root(app, "/views/#{name}")
|
41
44
|
include_component_module_for(:test)
|
42
|
-
generate_controller_test(name)
|
45
|
+
generate_controller_test(name) if test?
|
43
46
|
else
|
44
47
|
say "You are not at the root of a Padrino application! (config/boot.rb not found)" and return unless in_app_root?
|
45
48
|
end
|
@@ -19,6 +19,7 @@ module Padrino
|
|
19
19
|
|
20
20
|
argument :name, :desc => "The name of your padrino mailer"
|
21
21
|
class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
|
22
|
+
class_option :app, :desc => "The application destination", :aliases => '-a', :default => "/app", :type => :string
|
22
23
|
class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
|
23
24
|
|
24
25
|
# Show help if no argv given
|
@@ -30,13 +31,15 @@ module Padrino
|
|
30
31
|
def create_mailer
|
31
32
|
self.destination_root = options[:root]
|
32
33
|
if in_app_root?
|
34
|
+
app = options[:app].underscore
|
35
|
+
check_app_existence(app)
|
33
36
|
self.behavior = :revoke if options[:destroy]
|
34
37
|
simple_name = name.to_s.gsub(/mailer/i, '')
|
35
38
|
@mailer_basename = "#{simple_name.downcase.underscore}_mailer"
|
36
39
|
@mailer_klass = "#{simple_name.downcase.camelize}Mailer"
|
37
40
|
template "templates/mailer_initializer.rb.tt", destination_root("config/initializers/mailer.rb"), :skip => true
|
38
|
-
template "templates/mailer.rb.tt", destination_root("
|
39
|
-
empty_directory destination_root('
|
41
|
+
template "templates/mailer.rb.tt", destination_root(app, "mailers", "#{@mailer_basename}.rb")
|
42
|
+
empty_directory destination_root(app, 'views', @mailer_basename)
|
40
43
|
else
|
41
44
|
say "You are not at the root of a Padrino application! (config/boot.rb not found)" and return unless in_app_root?
|
42
45
|
end
|
@@ -37,7 +37,7 @@ module Padrino
|
|
37
37
|
include_component_module_for(:test)
|
38
38
|
migration_name = "create_#{name.pluralize.underscore}"
|
39
39
|
create_model_file(name, fields)
|
40
|
-
generate_model_test(name)
|
40
|
+
generate_model_test(name) if test?
|
41
41
|
create_model_migration(migration_name, name, fields) unless options[:skip_migration]
|
42
42
|
else
|
43
43
|
say "You are not at the root of a Padrino application! (config/boot.rb not found)" and return unless in_app_root?
|
File without changes
|
File without changes
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class <%= @class_name %> < Padrino::Application
|
2
|
+
configure do
|
3
|
+
##
|
4
|
+
# Application-specific configuration options
|
5
|
+
#
|
6
|
+
# set :raise_errors, true # Show exceptions (default for development)
|
7
|
+
# set :public, "foo/bar" # Location for static assets (default root/public)
|
8
|
+
# set :sessions, false # Enabled by default
|
9
|
+
# set :reload, false # Reload application files (default in development)
|
10
|
+
# set :default_builder, "foo" # Set a custom form builder (default 'StandardFormBuilder')
|
11
|
+
# set :locale_path, "bar" # Set path for I18n translations (default your_app/locales)
|
12
|
+
# enable :autolocale # Auto Set locale if url match /:lang/foo/bar (disabled by default)
|
13
|
+
# disable :padrino_helpers # Disables padrino markup helpers (enabled by default if present)
|
14
|
+
# disable :padrino_mailer # Disables padrino mailer (enabled by default if present)
|
15
|
+
# disable :flash # Disables rack-flash (enabled by default)
|
16
|
+
# enable :authentication # Enable padrino-admin authentication (disabled by default)
|
17
|
+
# layout :foo # Layout can be in views/layouts/foo.ext or views/foo.ext (:application is default)
|
18
|
+
#
|
19
|
+
end
|
20
|
+
|
21
|
+
##
|
22
|
+
# You can configure for a specified environment like:
|
23
|
+
#
|
24
|
+
# configure :development do
|
25
|
+
# set :foo, :bar
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
|
29
|
+
##
|
30
|
+
# You can manage errors like:
|
31
|
+
#
|
32
|
+
# errors 404 do
|
33
|
+
# render 'errors/404'
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
|
37
|
+
end
|
data/lib/padrino-gen/generators/{app/config/initializers → project/app/controllers}/.empty_directory
RENAMED
File without changes
|
File without changes
|
data/lib/padrino-gen/generators/{app/public/javascripts → project/app/views}/.empty_directory
RENAMED
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
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Padrino
|
2
|
+
module Generators
|
3
|
+
class Project < Thor::Group
|
4
|
+
|
5
|
+
# Add this generator to our padrino-gen
|
6
|
+
Padrino::Generators.add_generator(:project, self)
|
7
|
+
|
8
|
+
# Define the source template root
|
9
|
+
def self.source_root; File.dirname(__FILE__); end
|
10
|
+
def self.banner; "padrino-gen project [name] [options]"; end
|
11
|
+
|
12
|
+
# Include related modules
|
13
|
+
include Thor::Actions
|
14
|
+
include Padrino::Generators::Actions
|
15
|
+
include Padrino::Generators::Components::Actions
|
16
|
+
|
17
|
+
desc "Description:\n\n\tpadrino-gen project generates a new Padrino project"
|
18
|
+
|
19
|
+
argument :name, :desc => "The name of your padrino project"
|
20
|
+
|
21
|
+
class_option :run_bundler, :desc => "Run 'bundle install'", :aliases => '-b', :default => false, :type => :boolean
|
22
|
+
class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
|
23
|
+
class_option :dev, :desc => "Use padrino from a git checkout", :default => false, :type => :boolean
|
24
|
+
|
25
|
+
# Definitions for the available customizable components
|
26
|
+
component_option :orm, "database engine", :aliases => '-d', :choices => [:datamapper, :mongomapper, :activerecord, :sequel, :couchrest], :default => :none
|
27
|
+
component_option :test, "testing framework", :aliases => '-t', :choices => [:bacon, :shoulda, :rspec, :testspec, :riot]
|
28
|
+
component_option :mock, "mocking library", :aliases => '-m', :choices => [:mocha, :rr]
|
29
|
+
component_option :script, "javascript library", :aliases => '-s', :choices => [:jquery, :prototype, :rightjs], :default => :none
|
30
|
+
component_option :renderer, "template engine", :aliases => '-e', :choices => [:haml, :erb]
|
31
|
+
|
32
|
+
# Show help if no argv given
|
33
|
+
def self.start(given_args=ARGV, config={})
|
34
|
+
given_args = ["-h"] if given_args.empty?
|
35
|
+
super
|
36
|
+
end
|
37
|
+
|
38
|
+
# Copies over the Padrino base application App
|
39
|
+
def setup_project
|
40
|
+
@class_name = name.underscore.classify
|
41
|
+
self.destination_root = File.join(options[:root], name)
|
42
|
+
directory("project/", destination_root)
|
43
|
+
store_component_config('.components')
|
44
|
+
template "templates/Gemfile.tt", destination_root("Gemfile")
|
45
|
+
end
|
46
|
+
|
47
|
+
# For each component, retrieve a valid choice and then execute the associated generator
|
48
|
+
def setup_components
|
49
|
+
self.class.component_types.each do |comp|
|
50
|
+
choice = resolve_valid_choice(comp)
|
51
|
+
execute_component_setup(comp, choice)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# Bundle all required components using bundler and Gemfile
|
56
|
+
def bundle_dependencies
|
57
|
+
if options[:run_bundle]
|
58
|
+
say "Bundling application dependencies using bundler..."
|
59
|
+
in_root { run 'bundle install' }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -5,7 +5,7 @@ module Padrino
|
|
5
5
|
|
6
6
|
class << self
|
7
7
|
def load_paths
|
8
|
-
@load_paths ||= Dir[File.dirname(__FILE__) + '/generators/{app,mailer,controller,model,migration}.rb']
|
8
|
+
@load_paths ||= Dir[File.dirname(__FILE__) + '/generators/{project,app,mailer,controller,model,migration}.rb']
|
9
9
|
end
|
10
10
|
|
11
11
|
def mappings
|
@@ -16,6 +16,11 @@ module Padrino
|
|
16
16
|
mappings[name] = klass
|
17
17
|
end
|
18
18
|
|
19
|
+
def setup!
|
20
|
+
require 'padrino-gen/generators/actions'
|
21
|
+
Dir[File.dirname(__FILE__) + '/generators/{components}/**/*.rb'].each { |lib| require lib }
|
22
|
+
end
|
23
|
+
|
19
24
|
def lockup!
|
20
25
|
load_paths.each { |lib| require lib }
|
21
26
|
end
|
@@ -31,8 +36,7 @@ module Padrino
|
|
31
36
|
# We need to TRY to load boot because some of our app dependencies maybe have
|
32
37
|
# custom generators, so is necessary know who are.
|
33
38
|
def load_boot
|
34
|
-
|
35
|
-
Dir[File.dirname(__FILE__) + '/generators/{components}/**/*.rb'].each { |lib| require lib }
|
39
|
+
Padrino::Generators.setup!
|
36
40
|
|
37
41
|
begin
|
38
42
|
ENV['PADRINO_LOG_LEVEL'] ||= "test"
|
@@ -35,7 +35,7 @@ if defined?(ActiveRecord)
|
|
35
35
|
else
|
36
36
|
begin
|
37
37
|
# Create the SQLite database
|
38
|
-
Dir.mkdir File.dirname(config[:database])
|
38
|
+
Dir.mkdir File.dirname(config[:database]) unless File.exist?(File.dirname(config[:database]))
|
39
39
|
ActiveRecord::Base.establish_connection(config)
|
40
40
|
ActiveRecord::Base.connection
|
41
41
|
rescue
|