railties 4.1.0 → 4.2.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +229 -197
  3. data/RDOC_MAIN.rdoc +1 -1
  4. data/README.rdoc +6 -2
  5. data/lib/rails/all.rb +1 -0
  6. data/lib/rails/api/task.rb +7 -0
  7. data/lib/rails/app_rails_loader.rb +5 -3
  8. data/lib/rails/application/bootstrap.rb +15 -1
  9. data/lib/rails/application/configuration.rb +65 -8
  10. data/lib/rails/application/default_middleware_stack.rb +6 -2
  11. data/lib/rails/application/finisher.rb +0 -2
  12. data/lib/rails/application.rb +119 -24
  13. data/lib/rails/backtrace_cleaner.rb +9 -4
  14. data/lib/rails/code_statistics.rb +3 -4
  15. data/lib/rails/commands/commands_tasks.rb +2 -7
  16. data/lib/rails/commands/console.rb +24 -12
  17. data/lib/rails/commands/dbconsole.rb +20 -5
  18. data/lib/rails/commands/destroy.rb +2 -0
  19. data/lib/rails/commands/generate.rb +2 -0
  20. data/lib/rails/commands/plugin.rb +1 -1
  21. data/lib/rails/commands/server.rb +32 -21
  22. data/lib/rails/configuration.rb +2 -2
  23. data/lib/rails/engine/configuration.rb +1 -1
  24. data/lib/rails/engine.rb +15 -12
  25. data/lib/rails/gem_version.rb +2 -2
  26. data/lib/rails/generators/actions/create_migration.rb +4 -3
  27. data/lib/rails/generators/actions.rb +33 -12
  28. data/lib/rails/generators/app_base.rb +63 -55
  29. data/lib/rails/generators/base.rb +2 -2
  30. data/lib/rails/generators/erb/mailer/mailer_generator.rb +25 -2
  31. data/lib/rails/generators/erb/mailer/templates/layout.html.erb +5 -0
  32. data/lib/rails/generators/erb/mailer/templates/layout.text.erb +1 -0
  33. data/lib/rails/generators/erb/scaffold/templates/_form.html.erb +1 -6
  34. data/lib/rails/generators/erb/scaffold/templates/edit.html.erb +1 -1
  35. data/lib/rails/generators/erb/scaffold/templates/index.html.erb +3 -1
  36. data/lib/rails/generators/erb/scaffold/templates/new.html.erb +1 -1
  37. data/lib/rails/generators/generated_attribute.rb +28 -4
  38. data/lib/rails/generators/model_helpers.rb +28 -0
  39. data/lib/rails/generators/named_base.rb +10 -1
  40. data/lib/rails/generators/rails/app/app_generator.rb +34 -2
  41. data/lib/rails/generators/rails/app/templates/Gemfile +22 -7
  42. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +2 -2
  43. data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +1 -1
  44. data/lib/rails/generators/rails/app/templates/bin/rails +1 -1
  45. data/lib/rails/generators/rails/app/templates/bin/setup +28 -0
  46. data/lib/rails/generators/rails/app/templates/config/application.rb +8 -1
  47. data/lib/rails/generators/rails/app/templates/config/boot.rb +1 -2
  48. data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml +1 -3
  49. data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml +1 -1
  50. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +4 -0
  51. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +14 -20
  52. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +5 -2
  53. data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +11 -0
  54. data/lib/rails/generators/rails/app/templates/config/initializers/cookies_serializer.rb +1 -1
  55. data/lib/rails/generators/rails/app/templates/config/initializers/to_time_preserves_timezone.rb +10 -0
  56. data/lib/rails/generators/rails/app/templates/config.ru +1 -1
  57. data/lib/rails/generators/rails/app/templates/gitignore +4 -1
  58. data/lib/rails/generators/rails/app/templates/test/test_helper.rb +0 -3
  59. data/lib/rails/generators/rails/controller/USAGE +0 -1
  60. data/lib/rails/generators/rails/controller/controller_generator.rb +8 -4
  61. data/lib/rails/generators/rails/helper/USAGE +0 -4
  62. data/lib/rails/generators/rails/model/USAGE +12 -3
  63. data/lib/rails/generators/rails/model/model_generator.rb +4 -0
  64. data/lib/rails/generators/rails/plugin/plugin_generator.rb +23 -1
  65. data/lib/rails/generators/rails/plugin/templates/%name%.gemspec +3 -3
  66. data/lib/rails/generators/rails/plugin/templates/Gemfile +14 -6
  67. data/lib/rails/generators/rails/plugin/templates/MIT-LICENSE +1 -1
  68. data/lib/rails/generators/rails/plugin/templates/Rakefile +4 -0
  69. data/lib/rails/generators/rails/plugin/templates/app/controllers/%name%/application_controller.rb.tt +1 -0
  70. data/lib/rails/generators/rails/plugin/templates/rails/application.rb +1 -1
  71. data/lib/rails/generators/rails/plugin/templates/rails/javascripts.js +2 -2
  72. data/lib/rails/generators/rails/plugin/templates/rails/stylesheets.css +1 -1
  73. data/lib/rails/generators/rails/plugin/templates/test/integration/navigation_test.rb +0 -4
  74. data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb +13 -3
  75. data/lib/rails/generators/rails/resource_route/resource_route_generator.rb +4 -2
  76. data/lib/rails/generators/rails/scaffold/USAGE +7 -1
  77. data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +1 -0
  78. data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +1 -1
  79. data/lib/rails/generators/resource_helpers.rb +2 -11
  80. data/lib/rails/generators/test_unit/controller/templates/functional_test.rb +6 -0
  81. data/lib/rails/generators/test_unit/helper/helper_generator.rb +1 -5
  82. data/lib/rails/generators/test_unit/job/job_generator.rb +13 -0
  83. data/lib/rails/generators/test_unit/job/templates/unit_test.rb.erb +9 -0
  84. data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +9 -0
  85. data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb +4 -1
  86. data/lib/rails/generators/testing/assertions.rb +3 -1
  87. data/lib/rails/generators/testing/behaviour.rb +18 -1
  88. data/lib/rails/generators.rb +66 -15
  89. data/lib/rails/info.rb +8 -24
  90. data/lib/rails/info_controller.rb +1 -1
  91. data/lib/rails/mailers_controller.rb +20 -14
  92. data/lib/rails/paths.rb +3 -3
  93. data/lib/rails/rack/log_tailer.rb +4 -0
  94. data/lib/rails/rack/logger.rb +1 -1
  95. data/lib/rails/rack.rb +1 -1
  96. data/lib/rails/railtie.rb +3 -3
  97. data/lib/rails/ruby_version_check.rb +1 -1
  98. data/lib/rails/source_annotation_extractor.rb +25 -19
  99. data/lib/rails/tasks/framework.rake +2 -2
  100. data/lib/rails/tasks/statistics.rake +9 -2
  101. data/lib/rails/tasks.rb +3 -2
  102. data/lib/rails/templates/rails/mailers/email.html.erb +22 -4
  103. data/lib/rails/templates/rails/mailers/index.html.erb +2 -2
  104. data/lib/rails/templates/rails/mailers/mailer.html.erb +1 -1
  105. data/lib/rails/templates/rails/welcome/index.html.erb +23 -7
  106. data/lib/rails/test_help.rb +1 -0
  107. data/lib/rails/test_unit/sub_test_task.rb +2 -2
  108. data/lib/rails/test_unit/testing.rake +23 -5
  109. data/lib/rails.rb +7 -1
  110. metadata +17 -12
  111. data/lib/rails/commands/update.rb +0 -9
  112. data/lib/rails/generators/test_unit/helper/templates/helper_test.rb +0 -6
  113. data/lib/rails/rubyprof_ext.rb +0 -35
@@ -1,5 +1,7 @@
1
1
  require 'rails/generators'
2
2
 
3
+ #if no argument/-h/--help is passed to rails destroy command, then
4
+ #it generates the help associated.
3
5
  if [nil, "-h", "--help"].include?(ARGV.first)
4
6
  Rails::Generators.help 'destroy'
5
7
  exit
@@ -1,5 +1,7 @@
1
1
  require 'rails/generators'
2
2
 
3
+ #if no argument/-h/--help is passed to rails generate command, then
4
+ #it generates the help associated.
3
5
  if [nil, "-h", "--help"].include?(ARGV.first)
4
6
  Rails::Generators.help 'generate'
5
7
  exit
@@ -11,7 +11,7 @@ else
11
11
  end
12
12
  if File.exist?(railsrc)
13
13
  extra_args_string = File.read(railsrc)
14
- extra_args = extra_args_string.split(/\n+/).map {|l| l.split}.flatten
14
+ extra_args = extra_args_string.split(/\n+/).flat_map {|l| l.split}
15
15
  puts "Using #{extra_args.join(" ")} from #{railsrc}"
16
16
  ARGV.insert(1, *extra_args)
17
17
  end
@@ -9,16 +9,33 @@ module Rails
9
9
  def parse!(args)
10
10
  args, options = args.dup, {}
11
11
 
12
- opt_parser = OptionParser.new do |opts|
13
- opts.banner = "Usage: rails server [mongrel, thin, etc] [options]"
12
+ option_parser(options).parse! args
13
+
14
+ options[:log_stdout] = options[:daemonize].blank? && (options[:environment] || Rails.env) == "development"
15
+ options[:server] = args.shift
16
+ options
17
+ end
18
+
19
+ private
20
+
21
+ def option_parser(options)
22
+ OptionParser.new do |opts|
23
+ opts.banner = "Usage: rails server [mongrel, thin etc] [options]"
14
24
  opts.on("-p", "--port=port", Integer,
15
25
  "Runs Rails on the specified port.", "Default: 3000") { |v| options[:Port] = v }
16
- opts.on("-b", "--binding=ip", String,
17
- "Binds Rails to the specified ip.", "Default: 0.0.0.0") { |v| options[:Host] = v }
26
+ opts.on("-b", "--binding=IP", String,
27
+ "Binds Rails to the specified IP.", "Default: localhost") { |v| options[:Host] = v }
18
28
  opts.on("-c", "--config=file", String,
19
- "Use custom rackup configuration file") { |v| options[:config] = v }
20
- opts.on("-d", "--daemon", "Make server run as a Daemon.") { options[:daemonize] = true }
21
- opts.on("-u", "--debugger", "Enable the debugger") { options[:debugger] = true }
29
+ "Uses a custom rackup configuration.") { |v| options[:config] = v }
30
+ opts.on("-d", "--daemon", "Runs server as a Daemon.") { options[:daemonize] = true }
31
+ opts.on("-u", "--debugger", "Enables the debugger.") do
32
+ if RUBY_VERSION < '2.0.0'
33
+ options[:debugger] = true
34
+ else
35
+ puts "=> Notice: debugger option is ignored since Ruby 2.0 and " \
36
+ "it will be removed in future versions."
37
+ end
38
+ end
22
39
  opts.on("-e", "--environment=name", String,
23
40
  "Specifies the environment to run this server under (test/development/production).",
24
41
  "Default: development") { |v| options[:environment] = v }
@@ -28,14 +45,8 @@ module Rails
28
45
 
29
46
  opts.separator ""
30
47
 
31
- opts.on("-h", "--help", "Show this help message.") { puts opts; exit }
48
+ opts.on("-h", "--help", "Shows this help message.") { puts opts; exit }
32
49
  end
33
-
34
- opt_parser.parse! args
35
-
36
- options[:log_stdout] = options[:daemonize].blank? && (options[:environment] || Rails.env) == "development"
37
- options[:server] = args.shift
38
- options
39
50
  end
40
51
  end
41
52
 
@@ -75,7 +86,9 @@ module Rails
75
86
 
76
87
  def middleware
77
88
  middlewares = []
78
- middlewares << [Rails::Rack::Debugger] if options[:debugger]
89
+ if RUBY_VERSION < '2.0.0'
90
+ middlewares << [Rails::Rack::Debugger] if options[:debugger]
91
+ end
79
92
  middlewares << [::Rack::ContentLength]
80
93
 
81
94
  # FIXME: add Rack::Lock in the case people are using webrick.
@@ -113,10 +126,6 @@ module Rails
113
126
  puts "=> Rails #{Rails.version} application starting in #{Rails.env} on #{url}"
114
127
  puts "=> Run `rails server -h` for more startup options"
115
128
 
116
- if options[:Host].to_s.match(/0\.0\.0\.0/)
117
- puts "=> Notice: server is listening on all interfaces (#{options[:Host]}). Consider using 127.0.0.1 (--binding option)"
118
- end
119
-
120
129
  puts "=> Ctrl-C to shutdown server" unless options[:daemonize]
121
130
  end
122
131
 
@@ -129,11 +138,13 @@ module Rails
129
138
  def log_to_stdout
130
139
  wrapped_app # touch the app so the logger is set up
131
140
 
132
- console = ActiveSupport::Logger.new($stdout)
141
+ console = ActiveSupport::Logger.new(STDOUT)
133
142
  console.formatter = Rails.logger.formatter
134
143
  console.level = Rails.logger.level
135
144
 
136
- Rails.logger.extend(ActiveSupport::Logger.broadcast(console))
145
+ unless ActiveSupport::Logger.logger_outputs_to?(Rails.logger, STDOUT)
146
+ Rails.logger.extend(ActiveSupport::Logger.broadcast(console))
147
+ end
137
148
  end
138
149
  end
139
150
  end
@@ -18,11 +18,11 @@ module Rails
18
18
  # This will put the <tt>Magical::Unicorns</tt> middleware on the end of the stack.
19
19
  # You can use +insert_before+ if you wish to add a middleware before another:
20
20
  #
21
- # config.middleware.insert_before ActionDispatch::Head, Magical::Unicorns
21
+ # config.middleware.insert_before Rack::Head, Magical::Unicorns
22
22
  #
23
23
  # There's also +insert_after+ which will insert a middleware after another:
24
24
  #
25
- # config.middleware.insert_after ActionDispatch::Head, Magical::Unicorns
25
+ # config.middleware.insert_after Rack::Head, Magical::Unicorns
26
26
  #
27
27
  # Middlewares can also be completely swapped out and replaced with others:
28
28
  #
@@ -29,7 +29,7 @@ module Rails
29
29
  #
30
30
  # config.generators.colorize_logging = false
31
31
  #
32
- def generators #:nodoc:
32
+ def generators
33
33
  @generators ||= Rails::Configuration::Generators.new
34
34
  yield(@generators) if block_given?
35
35
  @generators
data/lib/rails/engine.rb CHANGED
@@ -110,8 +110,8 @@ module Rails
110
110
  #
111
111
  # == Endpoint
112
112
  #
113
- # An engine can be also a rack application. It can be useful if you have a rack application that
114
- # you would like to wrap with +Engine+ and provide some of the +Engine+'s features.
113
+ # An engine can also be a rack application. It can be useful if you have a rack application that
114
+ # you would like to wrap with +Engine+ and provide with some of the +Engine+'s features.
115
115
  #
116
116
  # To do that, use the +endpoint+ method:
117
117
  #
@@ -351,7 +351,7 @@ module Rails
351
351
 
352
352
  base.called_from = begin
353
353
  call_stack = if Kernel.respond_to?(:caller_locations)
354
- caller_locations.map(&:path)
354
+ caller_locations.map { |l| l.absolute_path || l.path }
355
355
  else
356
356
  # Remove the line number from backtraces making sure we don't leave anything behind
357
357
  caller.map { |p| p.sub(/:\d+.*/, '') }
@@ -364,6 +364,10 @@ module Rails
364
364
  super
365
365
  end
366
366
 
367
+ def find_root(from)
368
+ find_root_with_flag "lib", from
369
+ end
370
+
367
371
  def endpoint(endpoint = nil)
368
372
  @endpoint ||= nil
369
373
  @endpoint = endpoint if endpoint
@@ -371,7 +375,7 @@ module Rails
371
375
  end
372
376
 
373
377
  def isolate_namespace(mod)
374
- engine_name(generate_railtie_name(mod))
378
+ engine_name(generate_railtie_name(mod.name))
375
379
 
376
380
  self.routes.default_scope = { module: ActiveSupport::Inflector.underscore(mod.name) }
377
381
  self.isolated = true
@@ -395,7 +399,7 @@ module Rails
395
399
  end
396
400
 
397
401
  unless mod.respond_to?(:railtie_routes_url_helpers)
398
- define_method(:railtie_routes_url_helpers) { railtie.routes.url_helpers }
402
+ define_method(:railtie_routes_url_helpers) {|include_path_helpers = true| railtie.routes.url_helpers(include_path_helpers) }
399
403
  end
400
404
  end
401
405
  end
@@ -509,7 +513,7 @@ module Rails
509
513
  def call(env)
510
514
  env.merge!(env_config)
511
515
  if env['SCRIPT_NAME']
512
- env.merge! "ROUTES_#{routes.object_id}_SCRIPT_NAME" => env['SCRIPT_NAME'].dup
516
+ env["ROUTES_#{routes.object_id}_SCRIPT_NAME"] = env['SCRIPT_NAME'].dup
513
517
  end
514
518
  app.call(env)
515
519
  end
@@ -531,7 +535,7 @@ module Rails
531
535
 
532
536
  # Define the configuration object for the engine.
533
537
  def config
534
- @config ||= Engine::Configuration.new(find_root_with_flag("lib"))
538
+ @config ||= Engine::Configuration.new(self.class.find_root(self.class.called_from))
535
539
  end
536
540
 
537
541
  # Load data from db/seeds.rb file. It can be used in to load engines'
@@ -567,10 +571,10 @@ module Rails
567
571
  end
568
572
 
569
573
  initializer :add_routing_paths do |app|
570
- paths = self.paths["config/routes.rb"].existent
574
+ routing_paths = self.paths["config/routes.rb"].existent
571
575
 
572
- if routes? || paths.any?
573
- app.routes_reloader.paths.unshift(*paths)
576
+ if routes? || routing_paths.any?
577
+ app.routes_reloader.paths.unshift(*routing_paths)
574
578
  app.routes_reloader.route_sets << routes
575
579
  end
576
580
  end
@@ -658,8 +662,7 @@ module Rails
658
662
  paths["db/migrate"].existent.any?
659
663
  end
660
664
 
661
- def find_root_with_flag(flag, default=nil) #:nodoc:
662
- root_path = self.class.called_from
665
+ def self.find_root_with_flag(flag, root_path, default=nil) #:nodoc:
663
666
 
664
667
  while root_path && File.directory?(root_path) && !File.exist?("#{root_path}/#{flag}")
665
668
  parent = File.dirname(root_path)
@@ -6,8 +6,8 @@ module Rails
6
6
 
7
7
  module VERSION
8
8
  MAJOR = 4
9
- MINOR = 1
10
- TINY = 0
9
+ MINOR = 2
10
+ TINY = 10
11
11
  PRE = nil
12
12
 
13
13
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
@@ -39,7 +39,7 @@ module Rails
39
39
 
40
40
  protected
41
41
 
42
- def on_conflict_behavior(&block)
42
+ def on_conflict_behavior
43
43
  options = base.options.merge(config)
44
44
  if identical?
45
45
  say_status :identical, :blue, relative_existing_migration
@@ -48,14 +48,15 @@ module Rails
48
48
  say_status :create, :green
49
49
  unless pretend?
50
50
  ::FileUtils.rm_rf(existing_migration)
51
- block.call
51
+ yield
52
52
  end
53
53
  elsif options[:skip]
54
54
  say_status :skip, :yellow
55
55
  else
56
56
  say_status :conflict, :red
57
57
  raise Error, "Another migration is already named #{migration_file_name}: " +
58
- "#{existing_migration}. Use --force to replace this migration file."
58
+ "#{existing_migration}. Use --force to replace this migration " +
59
+ "or --skip to ignore conflicted file."
59
60
  end
60
61
  end
61
62
 
@@ -1,4 +1,3 @@
1
- require 'open-uri'
2
1
  require 'rbconfig'
3
2
 
4
3
  module Rails
@@ -7,6 +6,7 @@ module Rails
7
6
  def initialize(*) # :nodoc:
8
7
  super
9
8
  @in_group = nil
9
+ @after_bundle_callbacks = []
10
10
  end
11
11
 
12
12
  # Adds an entry into +Gemfile+ for the supplied gem.
@@ -20,9 +20,9 @@ module Rails
20
20
 
21
21
  # Set the message to be shown in logs. Uses the git repo if one is given,
22
22
  # otherwise use name (version).
23
- parts, message = [ name.inspect ], name
23
+ parts, message = [ quote(name) ], name
24
24
  if version ||= options.delete(:version)
25
- parts << version.inspect
25
+ parts << quote(version)
26
26
  message << " (#{version})"
27
27
  end
28
28
  message = options[:git] if options[:git]
@@ -30,7 +30,7 @@ module Rails
30
30
  log :gemfile, message
31
31
 
32
32
  options.each do |option, value|
33
- parts << "#{option}: #{value.inspect}"
33
+ parts << "#{option}: #{quote(value)}"
34
34
  end
35
35
 
36
36
  in_root do
@@ -68,7 +68,7 @@ module Rails
68
68
  log :source, source
69
69
 
70
70
  in_root do
71
- prepend_file "Gemfile", "source #{source.inspect}\n", verbose: false
71
+ prepend_file "Gemfile", "source #{quote(source)}\n", verbose: false
72
72
  end
73
73
  end
74
74
 
@@ -78,16 +78,16 @@ module Rails
78
78
  # file in <tt>config/environments</tt>.
79
79
  #
80
80
  # environment do
81
- # "config.autoload_paths += %W(#{config.root}/extras)"
81
+ # "config.action_controller.asset_host = 'cdn.provider.com'"
82
82
  # end
83
83
  #
84
84
  # environment(nil, env: "development") do
85
- # "config.autoload_paths += %W(#{config.root}/extras)"
85
+ # "config.action_controller.asset_host = 'localhost:3000'"
86
86
  # end
87
- def environment(data=nil, options={}, &block)
87
+ def environment(data=nil, options={})
88
88
  sentinel = /class [a-z_:]+ < Rails::Application/i
89
89
  env_file_sentinel = /Rails\.application\.configure do/
90
- data = block.call if !data && block_given?
90
+ data = yield if !data && block_given?
91
91
 
92
92
  in_root do
93
93
  if options[:env].nil?
@@ -188,7 +188,7 @@ module Rails
188
188
  # generate(:authenticated, "user session")
189
189
  def generate(what, *args)
190
190
  log :generate, what
191
- argument = args.map {|arg| arg.to_s }.flatten.join(" ")
191
+ argument = args.flat_map {|arg| arg.to_s }.join(" ")
192
192
 
193
193
  in_root { run_ruby_script("bin/rails generate #{what} #{argument}", verbose: false) }
194
194
  end
@@ -218,10 +218,10 @@ module Rails
218
218
  # route "root 'welcome#index'"
219
219
  def route(routing_code)
220
220
  log :route, routing_code
221
- sentinel = /\.routes\.draw do\s*$/
221
+ sentinel = /\.routes\.draw do\s*\n/m
222
222
 
223
223
  in_root do
224
- inject_into_file 'config/routes.rb', "\n #{routing_code}", { after: sentinel, verbose: false }
224
+ inject_into_file 'config/routes.rb', " #{routing_code}\n", { after: sentinel, verbose: false, force: true }
225
225
  end
226
226
  end
227
227
 
@@ -232,6 +232,16 @@ module Rails
232
232
  log File.read(find_in_source_paths(path))
233
233
  end
234
234
 
235
+ # Registers a callback to be executed after bundle and spring binstubs
236
+ # have run.
237
+ #
238
+ # after_bundle do
239
+ # git add: '.'
240
+ # end
241
+ def after_bundle(&block)
242
+ @after_bundle_callbacks << block
243
+ end
244
+
235
245
  protected
236
246
 
237
247
  # Define log for backwards compatibility. If just one argument is sent,
@@ -255,6 +265,17 @@ module Rails
255
265
  end
256
266
  end
257
267
 
268
+ # Surround string with single quotes if there is no quotes.
269
+ # Otherwise fall back to double quotes
270
+ def quote(value)
271
+ return value.inspect unless value.is_a? String
272
+
273
+ if value.include?("'")
274
+ value.inspect
275
+ else
276
+ "'#{value}'"
277
+ end
278
+ end
258
279
  end
259
280
  end
260
281
  end
@@ -41,9 +41,6 @@ module Rails
41
41
  class_option :skip_active_record, type: :boolean, aliases: '-O', default: false,
42
42
  desc: 'Skip Active Record files'
43
43
 
44
- class_option :skip_action_view, type: :boolean, aliases: '-V', default: false,
45
- desc: 'Skip Action View files'
46
-
47
44
  class_option :skip_sprockets, type: :boolean, aliases: '-S', default: false,
48
45
  desc: 'Skip Sprockets files'
49
46
 
@@ -65,10 +62,13 @@ module Rails
65
62
  class_option :edge, type: :boolean, default: false,
66
63
  desc: "Setup the #{name} with Gemfile pointing to Rails repository"
67
64
 
65
+ class_option :skip_turbolinks, type: :boolean, default: false,
66
+ desc: 'Skip turbolinks gem'
67
+
68
68
  class_option :skip_test_unit, type: :boolean, aliases: '-T', default: false,
69
69
  desc: 'Skip Test::Unit files'
70
70
 
71
- class_option :rc, type: :string, default: false,
71
+ class_option :rc, type: :string, default: nil,
72
72
  desc: "Path to file containing extra configuration options for rails command"
73
73
 
74
74
  class_option :no_rc, type: :boolean, default: false,
@@ -79,7 +79,6 @@ module Rails
79
79
  end
80
80
 
81
81
  def initialize(*args)
82
- @original_wd = Dir.pwd
83
82
  @gem_filter = lambda { |gem| true }
84
83
  @extra_entries = []
85
84
  super
@@ -105,14 +104,15 @@ module Rails
105
104
  end
106
105
 
107
106
  def gemfile_entries
108
- [ rails_gemfile_entry,
109
- database_gemfile_entry,
110
- assets_gemfile_entry,
111
- javascript_gemfile_entry,
112
- jbuilder_gemfile_entry,
113
- sdoc_gemfile_entry,
114
- spring_gemfile_entry,
115
- @extra_entries].flatten.find_all(&@gem_filter)
107
+ [rails_gemfile_entry,
108
+ database_gemfile_entry,
109
+ assets_gemfile_entry,
110
+ javascript_gemfile_entry,
111
+ jbuilder_gemfile_entry,
112
+ sdoc_gemfile_entry,
113
+ psych_gemfile_entry,
114
+ mime_type_gemfile_entry,
115
+ @extra_entries].flatten.find_all(&@gem_filter)
116
116
  end
117
117
 
118
118
  def add_gem_entry_filter
@@ -160,18 +160,23 @@ module Rails
160
160
 
161
161
  def database_gemfile_entry
162
162
  return [] if options[:skip_active_record]
163
- GemfileEntry.version gem_for_database, nil,
163
+ gem_name, gem_version = gem_for_database
164
+ GemfileEntry.version gem_name, gem_version,
164
165
  "Use #{options[:database]} as the database for Active Record"
165
166
  end
166
167
 
167
168
  def include_all_railties?
168
- !options[:skip_active_record] && !options[:skip_action_view] && !options[:skip_test_unit] && !options[:skip_sprockets]
169
+ !options[:skip_active_record] && !options[:skip_test_unit] && !options[:skip_sprockets]
169
170
  end
170
171
 
171
172
  def comment_if(value)
172
173
  options[value] ? '# ' : ''
173
174
  end
174
175
 
176
+ def sqlite3?
177
+ !options[:skip_active_record] && options[:database] == 'sqlite3'
178
+ end
179
+
175
180
  class GemfileEntry < Struct.new(:name, :version, :comment, :options, :commented_out)
176
181
  def initialize(name, version, comment, options = {}, commented_out = false)
177
182
  super
@@ -193,18 +198,22 @@ module Rails
193
198
  new(name, nil, comment, path: path)
194
199
  end
195
200
 
196
- def padding(max_width)
197
- ' ' * (max_width - name.length + 2)
201
+ def version
202
+ version = super
203
+
204
+ if version.is_a?(Array)
205
+ version.join("', '")
206
+ else
207
+ version
208
+ end
198
209
  end
199
210
  end
200
211
 
201
212
  def rails_gemfile_entry
202
213
  if options.dev?
203
- [GemfileEntry.path('rails', Rails::Generators::RAILS_DEV_PATH),
204
- GemfileEntry.github('arel', 'rails/arel', '5-0-stable')]
214
+ [GemfileEntry.path('rails', Rails::Generators::RAILS_DEV_PATH)]
205
215
  elsif options.edge?
206
- [GemfileEntry.github('rails', 'rails/rails', '4-1-stable'),
207
- GemfileEntry.github('arel', 'rails/arel', '5-0-stable')]
216
+ [GemfileEntry.github('rails', 'rails/rails', '4-2-stable')]
208
217
  else
209
218
  [GemfileEntry.version('rails',
210
219
  Rails::VERSION::STRING,
@@ -215,16 +224,16 @@ module Rails
215
224
  def gem_for_database
216
225
  # %w( mysql oracle postgresql sqlite3 frontbase ibm_db sqlserver jdbcmysql jdbcsqlite3 jdbcpostgresql )
217
226
  case options[:database]
218
- when "oracle" then "ruby-oci8"
219
- when "postgresql" then "pg"
220
- when "frontbase" then "ruby-frontbase"
221
- when "mysql" then "mysql2"
222
- when "sqlserver" then "activerecord-sqlserver-adapter"
223
- when "jdbcmysql" then "activerecord-jdbcmysql-adapter"
224
- when "jdbcsqlite3" then "activerecord-jdbcsqlite3-adapter"
225
- when "jdbcpostgresql" then "activerecord-jdbcpostgresql-adapter"
226
- when "jdbc" then "activerecord-jdbc-adapter"
227
- else options[:database]
227
+ when "oracle" then ["ruby-oci8", nil]
228
+ when "postgresql" then ["pg", ["~> 0.15"]]
229
+ when "frontbase" then ["ruby-frontbase", nil]
230
+ when "mysql" then ["mysql2", [">= 0.3.13", "< 0.5"]]
231
+ when "sqlserver" then ["activerecord-sqlserver-adapter", nil]
232
+ when "jdbcmysql" then ["activerecord-jdbcmysql-adapter", nil]
233
+ when "jdbcsqlite3" then ["activerecord-jdbcsqlite3-adapter", nil]
234
+ when "jdbcpostgresql" then ["activerecord-jdbcpostgresql-adapter", nil]
235
+ when "jdbc" then ["activerecord-jdbc-adapter", nil]
236
+ else [options[:database], nil]
228
237
  end
229
238
  end
230
239
 
@@ -243,16 +252,8 @@ module Rails
243
252
  return [] if options[:skip_sprockets]
244
253
 
245
254
  gems = []
246
- if options.dev? || options.edge?
247
- gems << GemfileEntry.github('sprockets-rails', 'rails/sprockets-rails', nil,
248
- 'Use edge version of sprockets-rails')
249
- gems << GemfileEntry.github('sass-rails', 'rails/sass-rails', nil,
250
- 'Use SCSS for stylesheets')
251
- else
252
- gems << GemfileEntry.version('sass-rails',
253
- '~> 4.0.3',
255
+ gems << GemfileEntry.version('sass-rails', '~> 5.0',
254
256
  'Use SCSS for stylesheets')
255
- end
256
257
 
257
258
  gems << GemfileEntry.version('uglifier',
258
259
  '>= 1.3.0',
@@ -272,12 +273,8 @@ module Rails
272
273
  end
273
274
 
274
275
  def coffee_gemfile_entry
275
- comment = 'Use CoffeeScript for .js.coffee assets and views'
276
- if options.dev? || options.edge?
277
- GemfileEntry.github 'coffee-rails', 'rails/coffee-rails', nil, comment
278
- else
279
- GemfileEntry.version 'coffee-rails', '~> 4.0.0', comment
280
- end
276
+ comment = 'Use CoffeeScript for .coffee assets and views'
277
+ GemfileEntry.version 'coffee-rails', '~> 4.1.0', comment
281
278
  end
282
279
 
283
280
  def javascript_gemfile_entry
@@ -286,16 +283,19 @@ module Rails
286
283
  else
287
284
  gems = [coffee_gemfile_entry, javascript_runtime_gemfile_entry]
288
285
  gems << GemfileEntry.version("#{options[:javascript]}-rails", nil,
289
- "Use #{options[:javascript]} as the JavaScript library")
286
+ "Use #{options[:javascript]} as the JavaScript library")
287
+
288
+ unless options[:skip_turbolinks]
289
+ gems << GemfileEntry.version("turbolinks", nil,
290
+ "Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks")
291
+ end
290
292
 
291
- gems << GemfileEntry.version("turbolinks", nil,
292
- "Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks")
293
293
  gems
294
294
  end
295
295
  end
296
296
 
297
297
  def javascript_runtime_gemfile_entry
298
- comment = 'See https://github.com/sstephenson/execjs#readme for more supported runtimes'
298
+ comment = 'See https://github.com/rails/execjs#readme for more supported runtimes'
299
299
  if defined?(JRUBY_VERSION)
300
300
  GemfileEntry.version 'therubyrhino', nil, comment
301
301
  else
@@ -303,10 +303,18 @@ module Rails
303
303
  end
304
304
  end
305
305
 
306
- def spring_gemfile_entry
307
- return [] unless spring_install?
308
- comment = 'Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring'
309
- GemfileEntry.new('spring', nil, comment, group: :development)
306
+ def psych_gemfile_entry
307
+ return [] unless defined?(Rubinius)
308
+
309
+ comment = 'Use Psych as the YAML engine, instead of Syck, so serialized ' \
310
+ 'data can be read safely from different rubies (see http://git.io/uuLVag)'
311
+ GemfileEntry.new('psych', '~> 2.0', comment, platforms: :rbx)
312
+ end
313
+
314
+ def mime_type_gemfile_entry
315
+ return [] unless RUBY_VERSION < '2'
316
+
317
+ GemfileEntry.new('mime-types', '< 3', nil, require: false)
310
318
  end
311
319
 
312
320
  def bundle_command(command)
@@ -338,7 +346,7 @@ module Rails
338
346
  end
339
347
 
340
348
  def spring_install?
341
- !options[:skip_spring] && Process.respond_to?(:fork)
349
+ !options[:skip_spring] && Process.respond_to?(:fork) && !RUBY_PLATFORM.include?("cygwin")
342
350
  end
343
351
 
344
352
  def run_bundle
@@ -83,7 +83,7 @@ module Rails
83
83
  #
84
84
  # The first and last part used to find the generator to be invoked are
85
85
  # guessed based on class invokes hook_for, as noticed in the example above.
86
- # This can be customized with two options: :base and :as.
86
+ # This can be customized with two options: :in and :as.
87
87
  #
88
88
  # Let's suppose you are creating a generator that needs to invoke the
89
89
  # controller generator from test unit. Your first attempt is:
@@ -108,7 +108,7 @@ module Rails
108
108
  # "test_unit:controller", "test_unit"
109
109
  #
110
110
  # Similarly, if you want it to also lookup in the rails namespace, you just
111
- # need to provide the :base value:
111
+ # need to provide the :in value:
112
112
  #
113
113
  # class AwesomeGenerator < Rails::Generators::Base
114
114
  # hook_for :test_framework, in: :rails, as: :controller
@@ -1,8 +1,31 @@
1
- require 'rails/generators/erb/controller/controller_generator'
1
+ require 'rails/generators/erb'
2
2
 
3
3
  module Erb # :nodoc:
4
4
  module Generators # :nodoc:
5
- class MailerGenerator < ControllerGenerator # :nodoc:
5
+ class MailerGenerator < Base # :nodoc:
6
+ argument :actions, type: :array, default: [], banner: "method method"
7
+
8
+ def copy_view_files
9
+ view_base_path = File.join("app/views", class_path, file_name)
10
+ empty_directory view_base_path
11
+
12
+ if self.behavior == :invoke
13
+ formats.each do |format|
14
+ layout_path = File.join("app/views/layouts", filename_with_extensions("mailer", format))
15
+ template filename_with_extensions(:layout, format), layout_path
16
+ end
17
+ end
18
+
19
+ actions.each do |action|
20
+ @action = action
21
+
22
+ formats.each do |format|
23
+ @path = File.join(view_base_path, filename_with_extensions(action, format))
24
+ template filename_with_extensions(:view, format), @path
25
+ end
26
+ end
27
+ end
28
+
6
29
  protected
7
30
 
8
31
  def formats