railties 3.0.20 → 3.1.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +36 -49
- data/README.rdoc +2 -1
- data/guides/assets/stylesheets/fixes.css +16 -0
- data/guides/rails_guides.rb +2 -2
- data/guides/rails_guides/generator.rb +8 -3
- data/guides/rails_guides/textile_extensions.rb +4 -2
- data/guides/source/2_2_release_notes.textile +3 -3
- data/guides/source/2_3_release_notes.textile +2 -2
- data/guides/source/3_0_release_notes.textile +14 -14
- data/guides/source/action_controller_overview.textile +54 -79
- data/guides/source/action_mailer_basics.textile +39 -9
- data/guides/source/action_view_overview.textile +257 -211
- data/guides/source/active_record_basics.textile +1 -1
- data/guides/source/active_record_querying.textile +217 -27
- data/guides/source/active_record_validations_callbacks.textile +94 -25
- data/guides/source/active_support_core_extensions.textile +109 -77
- data/guides/source/ajax_on_rails.textile +15 -150
- data/guides/source/api_documentation_guidelines.textile +12 -12
- data/guides/source/association_basics.textile +74 -60
- data/guides/source/caching_with_rails.textile +59 -60
- data/guides/source/command_line.textile +46 -47
- data/guides/source/configuring.textile +55 -37
- data/guides/source/contribute.textile +7 -7
- data/guides/source/contributing_to_ruby_on_rails.textile +14 -23
- data/guides/source/credits.html.erb +3 -3
- data/guides/source/debugging_rails_applications.textile +59 -46
- data/guides/source/form_helpers.textile +76 -31
- data/guides/source/generators.textile +39 -40
- data/guides/source/getting_started.textile +73 -94
- data/guides/source/i18n.textile +64 -58
- data/guides/source/index.html.erb +3 -3
- data/guides/source/initialization.textile +634 -3284
- data/guides/source/layout.html.erb +6 -7
- data/guides/source/layouts_and_rendering.textile +59 -60
- data/guides/source/migrations.textile +63 -59
- data/guides/source/nested_model_forms.textile +2 -2
- data/guides/source/performance_testing.textile +16 -16
- data/guides/source/plugins.textile +236 -1280
- data/guides/source/rails_application_templates.textile +37 -29
- data/guides/source/rails_on_rack.textile +4 -9
- data/guides/source/routing.textile +96 -75
- data/guides/source/ruby_on_rails_guides_guidelines.textile +19 -12
- data/guides/source/security.textile +57 -30
- data/guides/source/testing.textile +26 -24
- data/guides/w3c_validator.rb +2 -2
- data/lib/rails.rb +1 -7
- data/lib/rails/application.rb +46 -76
- data/lib/rails/application/bootstrap.rb +6 -11
- data/lib/rails/application/configuration.rb +43 -40
- data/lib/rails/application/finisher.rb +16 -4
- data/lib/rails/application/railties.rb +6 -24
- data/lib/rails/application/routes_reloader.rb +45 -0
- data/lib/rails/backtrace_cleaner.rb +1 -1
- data/lib/rails/cli.rb +7 -5
- data/lib/rails/commands.rb +27 -2
- data/lib/rails/commands/application.rb +14 -1
- data/lib/rails/commands/benchmarker.rb +3 -1
- data/lib/rails/commands/dbconsole.rb +2 -2
- data/lib/rails/commands/destroy.rb +3 -1
- data/lib/rails/commands/generate.rb +3 -1
- data/lib/rails/commands/plugin.rb +2 -7
- data/lib/rails/commands/plugin_new.rb +10 -0
- data/lib/rails/commands/profiler.rb +3 -1
- data/lib/rails/commands/server.rb +4 -0
- data/lib/rails/configuration.rb +8 -81
- data/lib/rails/console/app.rb +2 -2
- data/lib/rails/engine.rb +460 -78
- data/lib/rails/engine/configuration.rb +46 -49
- data/lib/rails/engine/railties.rb +33 -0
- data/lib/rails/generators.rb +11 -5
- data/lib/rails/generators/actions.rb +2 -27
- data/lib/rails/generators/app_base.rb +216 -0
- data/lib/rails/generators/base.rb +3 -2
- data/lib/rails/generators/erb/scaffold/templates/index.html.erb +1 -1
- data/lib/rails/generators/generated_attribute.rb +2 -1
- data/lib/rails/generators/migration.rb +6 -2
- data/lib/rails/generators/named_base.rb +79 -3
- data/lib/rails/generators/rails/app/app_generator.rb +44 -209
- data/lib/rails/generators/rails/app/templates/Gemfile +15 -31
- data/lib/rails/generators/rails/app/templates/README +2 -2
- data/lib/rails/generators/rails/app/templates/Rakefile +1 -1
- data/lib/rails/generators/rails/app/templates/{public → app/assets}/images/rails.png +0 -0
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +8 -0
- data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +5 -0
- data/lib/rails/generators/rails/app/templates/app/mailers/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/app/models/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +4 -4
- data/lib/rails/generators/rails/app/templates/config/application.rb +19 -3
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml +4 -4
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml +11 -6
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml +3 -3
- data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml +1 -1
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +1 -2
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +14 -11
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +5 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt +12 -0
- data/lib/rails/generators/rails/app/templates/config/locales/en.yml +1 -1
- data/lib/rails/generators/rails/app/templates/config/routes.rb +1 -1
- data/lib/rails/generators/rails/app/templates/db/{seeds.rb → seeds.rb.tt} +2 -2
- data/lib/rails/generators/rails/app/templates/public/index.html +10 -8
- data/lib/rails/generators/rails/app/templates/public/stylesheets/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/test/fixtures/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/test/functional/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/test/integration/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/test/{test_helper.rb.tt → test_helper.rb} +0 -0
- data/lib/rails/generators/rails/app/templates/test/unit/.empty_directory +0 -0
- data/lib/rails/generators/rails/assets/USAGE +20 -0
- data/lib/rails/generators/rails/assets/assets_generator.rb +39 -0
- data/lib/rails/generators/rails/assets/templates/javascript.js +2 -0
- data/lib/rails/generators/rails/assets/templates/javascript.js.coffee +3 -0
- data/lib/rails/generators/rails/assets/templates/stylesheet.css +4 -0
- data/lib/rails/generators/rails/assets/templates/stylesheet.css.scss +5 -0
- data/lib/rails/generators/rails/controller/controller_generator.rb +1 -1
- data/lib/rails/generators/rails/controller/templates/controller.rb +2 -0
- data/lib/rails/generators/rails/generator/generator_generator.rb +2 -2
- data/lib/rails/generators/rails/generator/templates/templates/.empty_directory +0 -0
- data/lib/rails/generators/rails/helper/templates/helper.rb +2 -0
- data/lib/rails/generators/rails/plugin/plugin_generator.rb +7 -0
- data/lib/rails/generators/rails/plugin/templates/Rakefile.tt +4 -4
- data/lib/rails/generators/rails/plugin_new/USAGE +10 -0
- data/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +303 -0
- data/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec +9 -0
- data/lib/rails/generators/rails/plugin_new/templates/Gemfile +11 -0
- data/lib/rails/generators/rails/plugin_new/templates/MIT-LICENSE +20 -0
- data/lib/rails/generators/rails/plugin_new/templates/README.rdoc +3 -0
- data/lib/rails/generators/rails/plugin_new/templates/Rakefile +21 -0
- data/lib/rails/generators/rails/plugin_new/templates/app/controllers/%name%/application_controller.rb.tt +4 -0
- data/lib/rails/generators/rails/plugin_new/templates/app/helpers/%name%/application_helper.rb.tt +4 -0
- data/lib/rails/generators/rails/plugin_new/templates/app/models/.empty_directory +0 -0
- data/lib/rails/generators/rails/plugin_new/templates/config/routes.rb +6 -0
- data/lib/rails/generators/rails/plugin_new/templates/gitignore +6 -0
- data/lib/rails/generators/rails/plugin_new/templates/lib/%name%.rb +6 -0
- data/lib/rails/generators/rails/plugin_new/templates/lib/%name%/engine.rb +7 -0
- data/lib/rails/generators/rails/plugin_new/templates/lib/tasks/%name%_tasks.rake +4 -0
- data/lib/rails/generators/rails/plugin_new/templates/rails/application.rb +16 -0
- data/lib/rails/generators/rails/plugin_new/templates/rails/boot.rb +10 -0
- data/lib/rails/generators/rails/plugin_new/templates/rails/routes.rb +4 -0
- data/lib/rails/generators/rails/plugin_new/templates/script/rails.tt +5 -0
- data/lib/rails/generators/rails/plugin_new/templates/test/%name%_test.rb +7 -0
- data/lib/rails/generators/rails/plugin_new/templates/test/integration/navigation_test.rb +12 -0
- data/lib/rails/generators/rails/plugin_new/templates/test/test_helper.rb +10 -0
- data/lib/rails/generators/rails/resource/resource_generator.rb +2 -2
- data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +20 -1
- data/lib/rails/generators/rails/{stylesheets → scaffold}/templates/scaffold.css +0 -0
- data/lib/rails/generators/rails/scaffold/templates/scaffold.css.scss +58 -0
- data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +21 -19
- data/lib/rails/generators/resource_helpers.rb +3 -3
- data/lib/rails/generators/test_case.rb +2 -20
- data/lib/rails/generators/test_unit/controller/templates/functional_test.rb +5 -4
- data/lib/rails/generators/test_unit/helper/templates/helper_test.rb +2 -0
- data/lib/rails/generators/test_unit/integration/templates/integration_test.rb +3 -4
- data/lib/rails/generators/test_unit/mailer/templates/functional_test.rb +5 -4
- data/lib/rails/generators/test_unit/model/templates/fixtures.yml +1 -1
- data/lib/rails/generators/test_unit/model/templates/unit_test.rb +5 -4
- data/lib/rails/generators/test_unit/observer/templates/unit_test.rb +5 -4
- data/lib/rails/generators/test_unit/plugin/templates/%file_name%_test.rb.tt +3 -4
- data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb +7 -5
- data/lib/rails/info.rb +0 -1
- data/lib/rails/paths.rb +119 -65
- data/lib/rails/plugin.rb +18 -19
- data/lib/rails/rack/log_tailer.rb +1 -1
- data/lib/rails/railtie.rb +50 -47
- data/lib/rails/railtie/configurable.rb +20 -10
- data/lib/rails/railtie/configuration.rb +20 -19
- data/lib/rails/source_annotation_extractor.rb +5 -5
- data/lib/rails/tasks.rb +1 -0
- data/lib/rails/tasks/assets.rake +10 -0
- data/lib/rails/tasks/documentation.rake +2 -8
- data/lib/rails/tasks/engine.rake +69 -0
- data/lib/rails/tasks/framework.rake +4 -21
- data/lib/rails/tasks/misc.rake +1 -1
- data/lib/rails/tasks/routes.rake +2 -1
- data/lib/rails/test_help.rb +17 -1
- data/lib/rails/test_unit/railtie.rb +1 -1
- data/lib/rails/test_unit/testing.rake +8 -3
- data/lib/rails/version.rb +3 -3
- metadata +128 -100
- checksums.yaml +0 -7
- data/lib/rails/application/configurable.rb +0 -19
- data/lib/rails/console/sandbox.rb +0 -6
- data/lib/rails/deprecation.rb +0 -41
- data/lib/rails/engine/configurable.rb +0 -25
- data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml +0 -62
- data/lib/rails/generators/rails/app/templates/public/javascripts/application.js +0 -2
- data/lib/rails/generators/rails/app/templates/public/javascripts/controls.js +0 -965
- data/lib/rails/generators/rails/app/templates/public/javascripts/dragdrop.js +0 -974
- data/lib/rails/generators/rails/app/templates/public/javascripts/effects.js +0 -1123
- data/lib/rails/generators/rails/app/templates/public/javascripts/prototype.js +0 -6001
- data/lib/rails/generators/rails/app/templates/public/javascripts/rails.js +0 -202
- data/lib/rails/generators/rails/stylesheets/USAGE +0 -5
- data/lib/rails/generators/rails/stylesheets/stylesheets_generator.rb +0 -9
- data/lib/rails/info_routes.rb +0 -3
@@ -3,11 +3,12 @@ begin
|
|
3
3
|
rescue LoadError
|
4
4
|
puts "Thor is not available.\nIf you ran this command from a git checkout " \
|
5
5
|
"of Rails, please make sure thor is installed,\nand run this command " \
|
6
|
-
"as `ruby #{$0} #{ARGV.join(" ")}
|
6
|
+
"as `ruby #{$0} #{(ARGV | ['--dev']).join(" ")}`"
|
7
7
|
exit
|
8
8
|
end
|
9
9
|
|
10
10
|
require 'rails/generators/actions'
|
11
|
+
require 'active_support/core_ext/object/inclusion'
|
11
12
|
|
12
13
|
module Rails
|
13
14
|
module Generators
|
@@ -164,7 +165,7 @@ module Rails
|
|
164
165
|
names.each do |name|
|
165
166
|
defaults = if options[:type] == :boolean
|
166
167
|
{ }
|
167
|
-
elsif
|
168
|
+
elsif default_value_for_option(name, options).in?([true, false])
|
168
169
|
{ :banner => "" }
|
169
170
|
else
|
170
171
|
{ :desc => "#{name.to_s.humanize} to be invoked", :banner => "NAME" }
|
@@ -17,7 +17,7 @@
|
|
17
17
|
<% end -%>
|
18
18
|
<td><%%= link_to 'Show', <%= singular_table_name %> %></td>
|
19
19
|
<td><%%= link_to 'Edit', edit_<%= singular_table_name %>_path(<%= singular_table_name %>) %></td>
|
20
|
-
<td><%%= link_to 'Destroy', <%= singular_table_name %>, :confirm
|
20
|
+
<td><%%= link_to 'Destroy', <%= singular_table_name %>, <%= key_value :confirm, "'Are you sure?'" %>, <%= key_value :method, ":delete" %> %></td>
|
21
21
|
</tr>
|
22
22
|
<%% end %>
|
23
23
|
</table>
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'active_support/time'
|
2
|
+
require 'active_support/core_ext/object/inclusion'
|
2
3
|
|
3
4
|
module Rails
|
4
5
|
module Generators
|
@@ -44,7 +45,7 @@ module Rails
|
|
44
45
|
end
|
45
46
|
|
46
47
|
def reference?
|
47
|
-
[
|
48
|
+
self.type.in?([:references, :belongs_to])
|
48
49
|
end
|
49
50
|
end
|
50
51
|
end
|
@@ -52,8 +52,12 @@ module Rails
|
|
52
52
|
|
53
53
|
destination = self.class.migration_exists?(migration_dir, @migration_file_name)
|
54
54
|
|
55
|
-
if behavior == :invoke
|
56
|
-
|
55
|
+
if !(destination && options[:skip]) && behavior == :invoke
|
56
|
+
if destination && options.force?
|
57
|
+
remove_file(destination)
|
58
|
+
elsif destination
|
59
|
+
raise Error, "Another migration is already named #{@migration_file_name}: #{destination}"
|
60
|
+
end
|
57
61
|
destination = File.join(migration_dir, "#{@migration_number}_#{@migration_file_name}.rb")
|
58
62
|
end
|
59
63
|
|
@@ -5,6 +5,11 @@ module Rails
|
|
5
5
|
module Generators
|
6
6
|
class NamedBase < Base
|
7
7
|
argument :name, :type => :string
|
8
|
+
class_option :skip_namespace, :type => :boolean, :default => false,
|
9
|
+
:desc => "Skip namespace (affects only isolated applications)"
|
10
|
+
|
11
|
+
class_option :old_style_hash, :type => :boolean, :default => false,
|
12
|
+
:desc => "Force using old style hash (:foo => 'bar') on Ruby >= 1.9"
|
8
13
|
|
9
14
|
def initialize(args, *options) #:nodoc:
|
10
15
|
# Unfreeze name in case it's given as a frozen string
|
@@ -14,17 +19,78 @@ module Rails
|
|
14
19
|
parse_attributes! if respond_to?(:attributes)
|
15
20
|
end
|
16
21
|
|
17
|
-
|
22
|
+
no_tasks do
|
23
|
+
def template(source, *args, &block)
|
24
|
+
inside_template do
|
25
|
+
super
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
18
29
|
|
19
|
-
|
30
|
+
protected
|
31
|
+
attr_reader :file_name
|
20
32
|
alias :singular_name :file_name
|
21
33
|
|
34
|
+
# Wrap block with namespace of current application
|
35
|
+
# if namespace exists and is not skipped
|
36
|
+
def module_namespacing(&block)
|
37
|
+
content = capture(&block)
|
38
|
+
content = wrap_with_namespace(content) if namespaced?
|
39
|
+
concat(content)
|
40
|
+
end
|
41
|
+
|
42
|
+
def indent(content, multiplier = 2)
|
43
|
+
spaces = " " * multiplier
|
44
|
+
content = content.each_line.map {|line| "#{spaces}#{line}" }.join
|
45
|
+
end
|
46
|
+
|
47
|
+
def wrap_with_namespace(content)
|
48
|
+
content = indent(content).chomp
|
49
|
+
"module #{namespace.name}\n#{content}\nend\n"
|
50
|
+
end
|
51
|
+
|
52
|
+
def inside_template
|
53
|
+
@inside_template = true
|
54
|
+
yield
|
55
|
+
ensure
|
56
|
+
@inside_template = false
|
57
|
+
end
|
58
|
+
|
59
|
+
def inside_template?
|
60
|
+
@inside_template
|
61
|
+
end
|
62
|
+
|
63
|
+
def namespace
|
64
|
+
@namespace ||= if defined?(Rails) && Rails.application
|
65
|
+
Rails.application.class.parents.detect { |n| n.respond_to?(:_railtie) }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def namespaced?
|
70
|
+
!options[:skip_namespace] && namespace
|
71
|
+
end
|
72
|
+
|
22
73
|
def file_path
|
23
74
|
@file_path ||= (class_path + [file_name]).join('/')
|
24
75
|
end
|
25
76
|
|
77
|
+
def class_path
|
78
|
+
inside_template? || !namespaced? ? regular_class_path : namespaced_class_path
|
79
|
+
end
|
80
|
+
|
81
|
+
def regular_class_path
|
82
|
+
@class_path
|
83
|
+
end
|
84
|
+
|
85
|
+
def namespaced_class_path
|
86
|
+
@namespaced_class_path ||= begin
|
87
|
+
namespace_path = namespace.name.split("::").map {|m| m.underscore }
|
88
|
+
namespace_path + @class_path
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
26
92
|
def class_name
|
27
|
-
|
93
|
+
(class_path + [file_name]).map!{ |m| m.camelize }.join('::')
|
28
94
|
end
|
29
95
|
|
30
96
|
def human_name
|
@@ -118,6 +184,16 @@ module Rails
|
|
118
184
|
class_collisions "#{options[:prefix]}#{name}#{options[:suffix]}"
|
119
185
|
end
|
120
186
|
end
|
187
|
+
|
188
|
+
# Returns Ruby 1.9 style key-value pair if current code is running on
|
189
|
+
# Ruby 1.9.x. Returns the old-style (with hash rocket) otherwise.
|
190
|
+
def key_value(key, value)
|
191
|
+
if options[:old_style_hash] || RUBY_VERSION < '1.9'
|
192
|
+
":#{key} => #{value}"
|
193
|
+
else
|
194
|
+
"#{key}: #{value}"
|
195
|
+
end
|
196
|
+
end
|
121
197
|
end
|
122
198
|
end
|
123
199
|
end
|
@@ -1,9 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
require 'active_support/secure_random'
|
3
|
-
require 'rails/version' unless defined?(Rails::VERSION)
|
4
|
-
require 'rbconfig'
|
5
|
-
require 'open-uri'
|
6
|
-
require 'uri'
|
1
|
+
require 'rails/generators/app_base'
|
7
2
|
|
8
3
|
module Rails
|
9
4
|
module ActionMethods
|
@@ -14,23 +9,20 @@ module Rails
|
|
14
9
|
@options = generator.options
|
15
10
|
end
|
16
11
|
|
17
|
-
|
18
|
-
%w(template copy_file directory empty_directory inside
|
19
|
-
empty_directory_with_gitkeep create_file chmod shebang).each do |method|
|
20
|
-
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
21
|
-
def #{method}(*args, &block)
|
22
|
-
@generator.send(:#{method}, *args, &block)
|
23
|
-
end
|
24
|
-
RUBY
|
25
|
-
end
|
12
|
+
private
|
26
13
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
@generator.send(meth, *args, &block)
|
31
|
-
end
|
14
|
+
def method_missing(meth, *args, &block)
|
15
|
+
@generator.send(meth, *args, &block)
|
16
|
+
end
|
32
17
|
end
|
33
18
|
|
19
|
+
# The application builder allows you to override elements of the application
|
20
|
+
# generator without being forced to reverse the operations of the default
|
21
|
+
# generator.
|
22
|
+
#
|
23
|
+
# This allows you to override entire operations, like the creation of the
|
24
|
+
# Gemfile, README, or javascript files, without needing to know exactly
|
25
|
+
# what those operations do so you can create another template action.
|
34
26
|
class AppBuilder
|
35
27
|
def rakefile
|
36
28
|
template "Rakefile"
|
@@ -54,6 +46,8 @@ module Rails
|
|
54
46
|
|
55
47
|
def app
|
56
48
|
directory 'app'
|
49
|
+
git_keep 'app/mailers'
|
50
|
+
git_keep 'app/models'
|
57
51
|
end
|
58
52
|
|
59
53
|
def config
|
@@ -71,7 +65,7 @@ module Rails
|
|
71
65
|
end
|
72
66
|
|
73
67
|
def database_yml
|
74
|
-
template "config/databases/#{
|
68
|
+
template "config/databases/#{options[:database]}.yml", "config/database.yml"
|
75
69
|
end
|
76
70
|
|
77
71
|
def db
|
@@ -88,37 +82,13 @@ module Rails
|
|
88
82
|
end
|
89
83
|
|
90
84
|
def log
|
91
|
-
|
92
|
-
|
93
|
-
inside "log" do
|
94
|
-
%w( server production development test ).each do |file|
|
95
|
-
create_file "#{file}.log"
|
96
|
-
chmod "#{file}.log", 0666, :verbose => false
|
97
|
-
end
|
98
|
-
end
|
85
|
+
empty_directory_with_gitkeep "log"
|
99
86
|
end
|
100
87
|
|
101
88
|
def public_directory
|
102
89
|
directory "public", "public", :recursive => false
|
103
90
|
end
|
104
91
|
|
105
|
-
def images
|
106
|
-
directory "public/images"
|
107
|
-
end
|
108
|
-
|
109
|
-
def stylesheets
|
110
|
-
empty_directory_with_gitkeep "public/stylesheets"
|
111
|
-
end
|
112
|
-
|
113
|
-
def javascripts
|
114
|
-
unless options[:skip_prototype]
|
115
|
-
directory "public/javascripts"
|
116
|
-
else
|
117
|
-
empty_directory_with_gitkeep "public/javascripts"
|
118
|
-
create_file "public/javascripts/application.js"
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
92
|
def script
|
123
93
|
directory "script" do |content|
|
124
94
|
"#{shebang}\n" + content
|
@@ -127,17 +97,26 @@ module Rails
|
|
127
97
|
end
|
128
98
|
|
129
99
|
def test
|
130
|
-
|
100
|
+
empty_directory_with_gitkeep "test/fixtures"
|
101
|
+
empty_directory_with_gitkeep "test/functional"
|
102
|
+
empty_directory_with_gitkeep "test/integration"
|
103
|
+
empty_directory_with_gitkeep "test/unit"
|
104
|
+
|
105
|
+
template "test/performance/browsing_test.rb"
|
106
|
+
template "test/test_helper.rb"
|
131
107
|
end
|
132
108
|
|
133
109
|
def tmp
|
134
|
-
|
110
|
+
empty_directory_with_gitkeep "tmp/cache"
|
111
|
+
end
|
135
112
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
113
|
+
def vendor
|
114
|
+
vendor_stylesheets
|
115
|
+
vendor_plugins
|
116
|
+
end
|
117
|
+
|
118
|
+
def vendor_stylesheets
|
119
|
+
empty_directory_with_gitkeep "vendor/assets/stylesheets"
|
141
120
|
end
|
142
121
|
|
143
122
|
def vendor_plugins
|
@@ -150,77 +129,26 @@ module Rails
|
|
150
129
|
# can change in Ruby 1.8.7 when we FileUtils.cd.
|
151
130
|
RAILS_DEV_PATH = File.expand_path("../../../../../..", File.dirname(__FILE__))
|
152
131
|
|
153
|
-
RESERVED_NAMES = %w[application destroy benchmarker profiler
|
154
|
-
plugin runner test]
|
155
|
-
|
156
|
-
class AppGenerator < Base
|
157
|
-
DATABASES = %w( mysql oracle postgresql sqlite3 frontbase ibm_db )
|
158
|
-
JDBC_DATABASES = %w( jdbcmysql jdbcsqlite3 jdbcpostgresql jdbc )
|
159
|
-
DATABASES.concat(JDBC_DATABASES)
|
160
|
-
|
161
|
-
attr_accessor :rails_template
|
162
|
-
add_shebang_option!
|
163
|
-
|
164
|
-
argument :app_path, :type => :string
|
165
|
-
|
166
|
-
class_option :database, :type => :string, :aliases => "-d", :default => "sqlite3",
|
167
|
-
:desc => "Preconfigure for selected database (options: #{DATABASES.join('/')})"
|
168
|
-
|
169
|
-
class_option :builder, :type => :string, :aliases => "-b",
|
170
|
-
:desc => "Path to an application builder (can be a filesystem path or URL)"
|
132
|
+
RESERVED_NAMES = %w[application destroy benchmarker profiler plugin runner test]
|
171
133
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
class_option :dev, :type => :boolean, :default => false,
|
176
|
-
:desc => "Setup the application with Gemfile pointing to your Rails checkout"
|
177
|
-
|
178
|
-
class_option :edge, :type => :boolean, :default => false,
|
179
|
-
:desc => "Setup the application with Gemfile pointing to Rails repository"
|
180
|
-
|
181
|
-
class_option :skip_gemfile, :type => :boolean, :default => false,
|
182
|
-
:desc => "Don't create a Gemfile"
|
183
|
-
|
184
|
-
class_option :skip_active_record, :type => :boolean, :aliases => "-O", :default => false,
|
185
|
-
:desc => "Skip Active Record files"
|
186
|
-
|
187
|
-
class_option :skip_test_unit, :type => :boolean, :aliases => "-T", :default => false,
|
188
|
-
:desc => "Skip Test::Unit files"
|
189
|
-
|
190
|
-
class_option :skip_prototype, :type => :boolean, :aliases => "-J", :default => false,
|
191
|
-
:desc => "Skip Prototype files"
|
192
|
-
|
193
|
-
class_option :skip_git, :type => :boolean, :aliases => "-G", :default => false,
|
194
|
-
:desc => "Skip Git ignores and keeps"
|
134
|
+
class AppGenerator < AppBase
|
135
|
+
add_shared_options_for "application"
|
195
136
|
|
196
137
|
# Add bin/rails options
|
197
|
-
class_option :version,
|
198
|
-
|
199
|
-
|
200
|
-
class_option :help, :type => :boolean, :aliases => "-h", :group => :rails,
|
201
|
-
:desc => "Show this help message and quit"
|
138
|
+
class_option :version, :type => :boolean, :aliases => "-v", :group => :rails,
|
139
|
+
:desc => "Show Rails version number and quit"
|
202
140
|
|
203
141
|
def initialize(*args)
|
204
142
|
raise Error, "Options should be given after the application name. For details run: rails --help" if args[0].blank?
|
205
143
|
|
206
|
-
@original_wd = Dir.pwd
|
207
|
-
|
208
144
|
super
|
209
|
-
convert_database_option_for_jruby
|
210
145
|
|
211
146
|
if !options[:skip_active_record] && !DATABASES.include?(options[:database])
|
212
147
|
raise Error, "Invalid value for --database option. Supported for preconfiguration are: #{DATABASES.join(", ")}."
|
213
148
|
end
|
214
149
|
end
|
215
150
|
|
216
|
-
|
217
|
-
self.destination_root = File.expand_path(app_path, destination_root)
|
218
|
-
valid_app_const?
|
219
|
-
|
220
|
-
empty_directory '.'
|
221
|
-
set_default_accessors!
|
222
|
-
FileUtils.cd(destination_root) unless options[:pretend]
|
223
|
-
end
|
151
|
+
public_task :create_root
|
224
152
|
|
225
153
|
def create_root_files
|
226
154
|
build(:readme)
|
@@ -267,18 +195,6 @@ module Rails
|
|
267
195
|
build(:public_directory)
|
268
196
|
end
|
269
197
|
|
270
|
-
def create_public_image_files
|
271
|
-
build(:images)
|
272
|
-
end
|
273
|
-
|
274
|
-
def create_public_stylesheets_files
|
275
|
-
build(:stylesheets)
|
276
|
-
end
|
277
|
-
|
278
|
-
def create_prototype_files
|
279
|
-
build(:javascripts)
|
280
|
-
end
|
281
|
-
|
282
198
|
def create_script_files
|
283
199
|
build(:script)
|
284
200
|
end
|
@@ -292,23 +208,14 @@ module Rails
|
|
292
208
|
end
|
293
209
|
|
294
210
|
def create_vendor_files
|
295
|
-
build(:
|
211
|
+
build(:vendor)
|
296
212
|
end
|
297
213
|
|
298
214
|
def finish_template
|
299
215
|
build(:leftovers)
|
300
216
|
end
|
301
217
|
|
302
|
-
|
303
|
-
apply rails_template if rails_template
|
304
|
-
rescue Thor::Error, LoadError, Errno::ENOENT => e
|
305
|
-
raise Error, "The template [#{rails_template}] could not be loaded. Error: #{e}"
|
306
|
-
end
|
307
|
-
|
308
|
-
def bundle_if_dev_or_edge
|
309
|
-
bundle_command = File.basename(Thor::Util.ruby_command).sub(/ruby/, 'bundle')
|
310
|
-
run "#{bundle_command} install" if dev_or_edge?
|
311
|
-
end
|
218
|
+
public_task :apply_rails_template, :bundle_if_dev_or_edge
|
312
219
|
|
313
220
|
protected
|
314
221
|
|
@@ -316,40 +223,6 @@ module Rails
|
|
316
223
|
"rails new #{self.arguments.map(&:usage).join(' ')} [options]"
|
317
224
|
end
|
318
225
|
|
319
|
-
def builder
|
320
|
-
@builder ||= begin
|
321
|
-
if path = options[:builder]
|
322
|
-
if URI(path).is_a?(URI::HTTP)
|
323
|
-
contents = open(path, "Accept" => "application/x-thor-template") {|io| io.read }
|
324
|
-
else
|
325
|
-
contents = open(File.expand_path(path, @original_wd)) {|io| io.read }
|
326
|
-
end
|
327
|
-
|
328
|
-
prok = eval("proc { #{contents} }", TOPLEVEL_BINDING, path, 1)
|
329
|
-
instance_eval(&prok)
|
330
|
-
end
|
331
|
-
|
332
|
-
builder_class = defined?(::AppBuilder) ? ::AppBuilder : Rails::AppBuilder
|
333
|
-
builder_class.send(:include, ActionMethods)
|
334
|
-
builder_class.new(self)
|
335
|
-
end
|
336
|
-
end
|
337
|
-
|
338
|
-
def build(meth, *args)
|
339
|
-
builder.send(meth, *args) if builder.respond_to?(meth)
|
340
|
-
end
|
341
|
-
|
342
|
-
def set_default_accessors!
|
343
|
-
self.rails_template = case options[:template]
|
344
|
-
when /^https?:\/\//
|
345
|
-
options[:template]
|
346
|
-
when String
|
347
|
-
File.expand_path(options[:template], Dir.pwd)
|
348
|
-
else
|
349
|
-
options[:template]
|
350
|
-
end
|
351
|
-
end
|
352
|
-
|
353
226
|
# Define file as an alias to create_file for backwards compatibility.
|
354
227
|
def file(*args, &block)
|
355
228
|
create_file(*args, &block)
|
@@ -373,12 +246,13 @@ module Rails
|
|
373
246
|
def app_const_base
|
374
247
|
@app_const_base ||= defined_app_const_base || app_name.gsub(/\W/, '_').squeeze('_').camelize
|
375
248
|
end
|
249
|
+
alias :camelized :app_const_base
|
376
250
|
|
377
251
|
def app_const
|
378
252
|
@app_const ||= "#{app_const_base}::Application"
|
379
253
|
end
|
380
254
|
|
381
|
-
def
|
255
|
+
def valid_const?
|
382
256
|
if app_const =~ /^\d/
|
383
257
|
raise Error, "Invalid application name #{app_name}. Please give a name which does not start with numbers."
|
384
258
|
elsif RESERVED_NAMES.include?(app_name)
|
@@ -392,44 +266,6 @@ module Rails
|
|
392
266
|
ActiveSupport::SecureRandom.hex(64)
|
393
267
|
end
|
394
268
|
|
395
|
-
def dev_or_edge?
|
396
|
-
options.dev? || options.edge?
|
397
|
-
end
|
398
|
-
|
399
|
-
def gem_for_database
|
400
|
-
# %w( mysql oracle postgresql sqlite3 frontbase ibm_db jdbcmysql jdbcsqlite3 jdbcpostgresql)
|
401
|
-
case options[:database]
|
402
|
-
when "oracle" then "ruby-oci8"
|
403
|
-
when "postgresql" then "pg"
|
404
|
-
when "sqlite3" then "sqlite3"
|
405
|
-
when "frontbase" then "ruby-frontbase"
|
406
|
-
when "mysql" then "mysql2"
|
407
|
-
when "jdbcmysql" then "activerecord-jdbcmysql-adapter"
|
408
|
-
when "jdbcsqlite3" then "activerecord-jdbcsqlite3-adapter"
|
409
|
-
when "jdbcpostgresql" then "activerecord-jdbcpostgresql-adapter"
|
410
|
-
when "jdbc" then "activerecord-jdbc-adapter"
|
411
|
-
else options[:database]
|
412
|
-
end
|
413
|
-
end
|
414
|
-
|
415
|
-
def convert_database_option_for_jruby
|
416
|
-
if defined?(JRUBY_VERSION)
|
417
|
-
case options[:database]
|
418
|
-
when "oracle" then options[:database].replace "jdbc"
|
419
|
-
when "postgresql" then options[:database].replace "jdbcpostgresql"
|
420
|
-
when "mysql" then options[:database].replace "jdbcmysql"
|
421
|
-
when "sqlite3" then options[:database].replace "jdbcsqlite3"
|
422
|
-
end
|
423
|
-
end
|
424
|
-
end
|
425
|
-
|
426
|
-
def version_constraint_for_database_gem
|
427
|
-
case options[:database]
|
428
|
-
when "mysql" then "~> 0.2.17"
|
429
|
-
else nil
|
430
|
-
end
|
431
|
-
end
|
432
|
-
|
433
269
|
def mysql_socket
|
434
270
|
@mysql_socket ||= [
|
435
271
|
"/tmp/mysql.sock", # default
|
@@ -444,9 +280,8 @@ module Rails
|
|
444
280
|
].find { |f| File.exist?(f) } unless RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
|
445
281
|
end
|
446
282
|
|
447
|
-
def
|
448
|
-
|
449
|
-
create_file("#{destination}/.gitkeep") unless options[:skip_git]
|
283
|
+
def get_builder_class
|
284
|
+
defined?(::AppBuilder) ? ::AppBuilder : Rails::AppBuilder
|
450
285
|
end
|
451
286
|
end
|
452
287
|
end
|