railties 6.1.4.1 → 7.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +113 -344
  3. data/MIT-LICENSE +1 -1
  4. data/RDOC_MAIN.rdoc +16 -16
  5. data/README.rdoc +0 -1
  6. data/lib/rails/all.rb +0 -1
  7. data/lib/rails/app_updater.rb +3 -5
  8. data/lib/rails/application/bootstrap.rb +21 -5
  9. data/lib/rails/application/configuration.rb +64 -28
  10. data/lib/rails/application/default_middleware_stack.rb +7 -3
  11. data/lib/rails/application/finisher.rb +42 -85
  12. data/lib/rails/application/routes_reloader.rb +8 -0
  13. data/lib/rails/application.rb +24 -50
  14. data/lib/rails/application_controller.rb +2 -2
  15. data/lib/rails/autoloaders/inflector.rb +21 -0
  16. data/lib/rails/autoloaders.rb +12 -16
  17. data/lib/rails/code_statistics.rb +2 -2
  18. data/lib/rails/code_statistics_calculator.rb +10 -1
  19. data/lib/rails/command/base.rb +26 -12
  20. data/lib/rails/command/behavior.rb +1 -1
  21. data/lib/rails/command/environment_argument.rb +1 -1
  22. data/lib/rails/command.rb +8 -5
  23. data/lib/rails/commands/credentials/USAGE +4 -2
  24. data/lib/rails/commands/credentials/credentials_command/diffing.rb +26 -16
  25. data/lib/rails/commands/credentials/credentials_command.rb +8 -3
  26. data/lib/rails/commands/dbconsole/dbconsole_command.rb +10 -11
  27. data/lib/rails/commands/help/USAGE +3 -2
  28. data/lib/rails/commands/runner/runner_command.rb +3 -2
  29. data/lib/rails/commands/server/server_command.rb +2 -5
  30. data/lib/rails/configuration.rb +18 -23
  31. data/lib/rails/engine/configuration.rb +3 -3
  32. data/lib/rails/engine.rb +18 -24
  33. data/lib/rails/gem_version.rb +4 -4
  34. data/lib/rails/generators/actions/create_migration.rb +2 -4
  35. data/lib/rails/generators/actions.rb +35 -13
  36. data/lib/rails/generators/app_base.rb +99 -105
  37. data/lib/rails/generators/app_name.rb +1 -1
  38. data/lib/rails/generators/base.rb +9 -13
  39. data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +2 -0
  40. data/lib/rails/generators/erb/scaffold/templates/_form.html.erb.tt +8 -8
  41. data/lib/rails/generators/erb/scaffold/templates/edit.html.erb.tt +8 -4
  42. data/lib/rails/generators/erb/scaffold/templates/index.html.erb.tt +6 -28
  43. data/lib/rails/generators/erb/scaffold/templates/new.html.erb.tt +7 -3
  44. data/lib/rails/generators/erb/scaffold/templates/partial.html.erb.tt +20 -0
  45. data/lib/rails/generators/erb/scaffold/templates/show.html.erb.tt +8 -17
  46. data/lib/rails/generators/erb.rb +1 -1
  47. data/lib/rails/generators/generated_attribute.rb +45 -9
  48. data/lib/rails/generators/migration.rb +2 -6
  49. data/lib/rails/generators/model_helpers.rb +1 -1
  50. data/lib/rails/generators/named_base.rb +1 -1
  51. data/lib/rails/generators/rails/app/app_generator.rb +53 -91
  52. data/lib/rails/generators/rails/app/templates/Gemfile.tt +44 -50
  53. data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css.tt +2 -2
  54. data/lib/rails/generators/rails/app/templates/app/mailers/application_mailer.rb.tt +2 -2
  55. data/lib/rails/generators/rails/app/templates/app/models/application_record.rb.tt +1 -1
  56. data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +3 -9
  57. data/lib/rails/generators/rails/app/templates/bin/rails.tt +1 -4
  58. data/lib/rails/generators/rails/app/templates/bin/rake.tt +0 -3
  59. data/lib/rails/generators/rails/app/templates/bin/setup.tt +9 -14
  60. data/lib/rails/generators/rails/app/templates/config/application.rb.tt +0 -1
  61. data/lib/rails/generators/rails/app/templates/config/boot.rb.tt +1 -1
  62. data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml.tt +2 -2
  63. data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml.tt +3 -3
  64. data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt +3 -3
  65. data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml.tt +2 -2
  66. data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +3 -3
  67. data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml.tt +2 -2
  68. data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +3 -3
  69. data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml.tt +1 -1
  70. data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml.tt +5 -5
  71. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +6 -12
  72. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +21 -17
  73. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +6 -11
  74. data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +1 -5
  75. data/lib/rails/generators/rails/app/templates/config/initializers/content_security_policy.rb.tt +19 -25
  76. data/lib/rails/generators/rails/app/templates/config/initializers/cors.rb.tt +2 -2
  77. data/lib/rails/generators/rails/app/templates/config/initializers/inflections.rb.tt +4 -4
  78. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_7_0.rb.tt +121 -0
  79. data/lib/rails/generators/rails/app/templates/config/locales/en.yml +3 -3
  80. data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +1 -1
  81. data/lib/rails/generators/rails/app/templates/config/routes.rb.tt +4 -1
  82. data/lib/rails/generators/rails/app/templates/config/storage.yml.tt +5 -5
  83. data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +2 -2
  84. data/lib/rails/generators/rails/app/templates/gitattributes.tt +0 -5
  85. data/lib/rails/generators/rails/app/templates/gitignore.tt +3 -1
  86. data/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +1 -1
  87. data/lib/rails/generators/rails/controller/controller_generator.rb +1 -2
  88. data/lib/rails/generators/rails/controller/templates/controller.rb.tt +0 -4
  89. data/lib/rails/generators/rails/db/system/change/change_generator.rb +1 -1
  90. data/lib/rails/generators/rails/generator/templates/%file_name%_generator.rb.tt +1 -1
  91. data/lib/rails/generators/rails/plugin/plugin_generator.rb +40 -15
  92. data/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt +7 -3
  93. data/lib/rails/generators/rails/plugin/templates/Gemfile.tt +9 -9
  94. data/lib/rails/generators/rails/plugin/templates/README.md.tt +1 -1
  95. data/lib/rails/generators/rails/plugin/templates/app/mailers/%namespaced_name%/application_mailer.rb.tt +2 -2
  96. data/lib/rails/generators/rails/plugin/templates/app/views/layouts/%namespaced_name%/application.html.erb.tt +0 -3
  97. data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +4 -5
  98. data/lib/rails/generators/rails/plugin/templates/gitignore.tt +0 -5
  99. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/engine.rb.tt +2 -2
  100. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/version.rb.tt +1 -1
  101. data/lib/rails/generators/rails/plugin/templates/rails/boot.rb.tt +2 -2
  102. data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb.tt +3 -3
  103. data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +0 -19
  104. data/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb.tt +1 -5
  105. data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt +6 -10
  106. data/lib/rails/generators/resource_helpers.rb +2 -2
  107. data/lib/rails/generators/test_unit/generator/templates/generator_test.rb.tt +1 -1
  108. data/lib/rails/generators/test_unit/model/templates/fixtures.yml.tt +2 -2
  109. data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +3 -3
  110. data/lib/rails/generators/test_unit/scaffold/templates/api_functional_test.rb.tt +5 -5
  111. data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb.tt +2 -2
  112. data/lib/rails/generators/test_unit/scaffold/templates/system_test.rb.tt +9 -11
  113. data/lib/rails/generators/testing/behaviour.rb +1 -2
  114. data/lib/rails/generators.rb +9 -22
  115. data/lib/rails/info.rb +1 -1
  116. data/lib/rails/info_controller.rb +1 -3
  117. data/lib/rails/initializable.rb +1 -1
  118. data/lib/rails/mailers_controller.rb +2 -4
  119. data/lib/rails/rack/logger.rb +0 -1
  120. data/lib/rails/railtie/configuration.rb +1 -2
  121. data/lib/rails/railtie.rb +27 -10
  122. data/lib/rails/ruby_version_check.rb +3 -3
  123. data/lib/rails/secrets.rb +4 -1
  124. data/lib/rails/tasks/framework.rake +2 -8
  125. data/lib/rails/tasks/statistics.rake +3 -1
  126. data/lib/rails/tasks/tmp.rake +8 -1
  127. data/lib/rails/tasks/yarn.rake +8 -9
  128. data/lib/rails/tasks/zeitwerk.rake +2 -10
  129. data/lib/rails/templates/layouts/application.html.erb +15 -0
  130. data/lib/rails/templates/rails/mailers/email.html.erb +13 -11
  131. data/lib/rails/templates/rails/welcome/index.html.erb +3 -0
  132. data/lib/rails/test_unit/railtie.rb +0 -4
  133. data/lib/rails/test_unit/runner.rb +16 -9
  134. data/lib/rails/test_unit/testing.rake +4 -9
  135. data/lib/rails/welcome_controller.rb +1 -0
  136. data/lib/rails.rb +5 -0
  137. metadata +34 -37
  138. data/lib/rails/command/spellchecker.rb +0 -57
  139. data/lib/rails/generators/css/assets/assets_generator.rb +0 -15
  140. data/lib/rails/generators/css/assets/templates/stylesheet.css +0 -4
  141. data/lib/rails/generators/css/scaffold/scaffold_generator.rb +0 -18
  142. data/lib/rails/generators/rails/app/templates/app/javascript/channels/consumer.js +0 -6
  143. data/lib/rails/generators/rails/app/templates/app/javascript/channels/index.js +0 -5
  144. data/lib/rails/generators/rails/app/templates/app/javascript/packs/application.js.tt +0 -23
  145. data/lib/rails/generators/rails/app/templates/bin/spring.tt +0 -13
  146. data/lib/rails/generators/rails/app/templates/bin/yarn.tt +0 -16
  147. data/lib/rails/generators/rails/app/templates/config/initializers/application_controller_renderer.rb.tt +0 -8
  148. data/lib/rails/generators/rails/app/templates/config/initializers/backtrace_silencers.rb.tt +0 -8
  149. data/lib/rails/generators/rails/app/templates/config/initializers/cookies_serializer.rb.tt +0 -5
  150. data/lib/rails/generators/rails/app/templates/config/initializers/mime_types.rb.tt +0 -4
  151. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_1.rb.tt +0 -67
  152. data/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt +0 -16
  153. data/lib/rails/generators/rails/app/templates/config/spring.rb.tt +0 -6
  154. data/lib/rails/generators/rails/app/templates/package.json.tt +0 -11
  155. data/lib/rails/generators/rails/assets/USAGE +0 -16
  156. data/lib/rails/generators/rails/assets/assets_generator.rb +0 -26
  157. data/lib/rails/generators/rails/assets/templates/stylesheet.css +0 -4
  158. data/lib/rails/generators/rails/scaffold/templates/scaffold.css +0 -80
@@ -7,6 +7,25 @@ module Rails
7
7
  class GeneratedAttribute # :nodoc:
8
8
  INDEX_OPTIONS = %w(index uniq)
9
9
  UNIQ_INDEX_OPTIONS = %w(uniq)
10
+ DEFAULT_TYPES = %w(
11
+ attachment
12
+ attachments
13
+ belongs_to
14
+ boolean
15
+ date
16
+ datetime
17
+ decimal
18
+ digest
19
+ float
20
+ integer
21
+ references
22
+ rich_text
23
+ string
24
+ text
25
+ time
26
+ timestamp
27
+ token
28
+ )
10
29
 
11
30
  attr_accessor :name, :type
12
31
  attr_reader :attr_options
@@ -14,23 +33,40 @@ module Rails
14
33
 
15
34
  class << self
16
35
  def parse(column_definition)
17
- name, type, has_index = column_definition.split(":")
36
+ name, type, index_type = column_definition.split(":")
18
37
 
19
38
  # if user provided "name:index" instead of "name:string:index"
20
39
  # type should be set blank so GeneratedAttribute's constructor
21
40
  # could set it to :string
22
- has_index, type = type, nil if INDEX_OPTIONS.include?(type)
41
+ index_type, type = type, nil if valid_index_type?(type)
23
42
 
24
43
  type, attr_options = *parse_type_and_options(type)
25
44
  type = type.to_sym if type
26
45
 
46
+ if type && !valid_type?(type)
47
+ raise Error, "Could not generate field '#{name}' with unknown type '#{type}'."
48
+ end
49
+
50
+ if index_type && !valid_index_type?(index_type)
51
+ raise Error, "Could not generate field '#{name}' with unknown index '#{index_type}'."
52
+ end
53
+
27
54
  if type && reference?(type)
28
- if UNIQ_INDEX_OPTIONS.include?(has_index)
55
+ if UNIQ_INDEX_OPTIONS.include?(index_type)
29
56
  attr_options[:index] = { unique: true }
30
57
  end
31
58
  end
32
59
 
33
- new(name, type, has_index, attr_options)
60
+ new(name, type, index_type, attr_options)
61
+ end
62
+
63
+ def valid_type?(type)
64
+ DEFAULT_TYPES.include?(type.to_s) ||
65
+ ActiveRecord::Base.connection.valid_type?(type)
66
+ end
67
+
68
+ def valid_index_type?(index_type)
69
+ INDEX_OPTIONS.include?(index_type.to_s)
34
70
  end
35
71
 
36
72
  def reference?(type)
@@ -70,9 +106,9 @@ module Rails
70
106
  @field_type ||= case type
71
107
  when :integer then :number_field
72
108
  when :float, :decimal then :text_field
73
- when :time then :time_select
74
- when :datetime, :timestamp then :datetime_select
75
- when :date then :date_select
109
+ when :time then :time_field
110
+ when :datetime, :timestamp then :datetime_field
111
+ when :date then :date_field
76
112
  when :text then :text_area
77
113
  when :rich_text then :rich_text_area
78
114
  when :boolean then :check_box
@@ -87,8 +123,8 @@ module Rails
87
123
  when :integer then 1
88
124
  when :float then 1.5
89
125
  when :decimal then "9.99"
90
- when :datetime, :timestamp, :time then Time.now.to_s(:db)
91
- when :date then Date.today.to_s(:db)
126
+ when :datetime, :timestamp, :time then Time.now.to_formatted_s(:db)
127
+ when :date then Date.today.to_formatted_s(:db)
92
128
  when :string then name == "type" ? "" : "MyString"
93
129
  when :text then "MyText"
94
130
  when :boolean then false
@@ -12,7 +12,7 @@ module Rails
12
12
  extend ActiveSupport::Concern
13
13
  attr_reader :migration_number, :migration_file_name, :migration_class_name
14
14
 
15
- module ClassMethods #:nodoc:
15
+ module ClassMethods # :nodoc:
16
16
  def migration_lookup_at(dirname)
17
17
  Dir.glob("#{dirname}/[0-9]*_*.rb")
18
18
  end
@@ -63,11 +63,7 @@ module Rails
63
63
  numbered_destination = File.join(dir, ["%migration_number%", base].join("_"))
64
64
 
65
65
  file = create_migration numbered_destination, nil, config do
66
- if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+
67
- ERB.new(::File.binread(source), trim_mode: "-", eoutvar: "@output_buffer").result(context)
68
- else
69
- ERB.new(::File.binread(source), nil, "-", "@output_buffer").result(context)
70
- end
66
+ ERB.new(::File.binread(source), trim_mode: "-", eoutvar: "@output_buffer").result(context)
71
67
  end
72
68
  Rails::Generators.add_generated_file(file)
73
69
  end
@@ -18,7 +18,7 @@ module Rails
18
18
  ERROR
19
19
  mattr_accessor :skip_warn
20
20
 
21
- def self.included(base) #:nodoc:
21
+ def self.included(base) # :nodoc:
22
22
  base.class_option :force_plural, type: :boolean, default: false, desc: "Forces the use of the given model name"
23
23
  end
24
24
 
@@ -8,7 +8,7 @@ module Rails
8
8
  class NamedBase < Base
9
9
  argument :name, type: :string
10
10
 
11
- def initialize(args, *options) #:nodoc:
11
+ def initialize(args, *options) # :nodoc:
12
12
  @inside_template = nil
13
13
  # Unfreeze name in case it's given as a frozen string
14
14
  args[0] = args[0].dup if args[0].is_a?(String) && args[0].frozen?
@@ -73,13 +73,12 @@ module Rails
73
73
  def version_control
74
74
  if !options[:skip_git] && !options[:pretend]
75
75
  run "git init", capture: options[:quiet], abort_on_failure: false
76
+ if user_default_branch.strip.empty?
77
+ `git symbolic-ref HEAD refs/heads/main`
78
+ end
76
79
  end
77
80
  end
78
81
 
79
- def package_json
80
- template "package.json"
81
- end
82
-
83
82
  def app
84
83
  directory "app"
85
84
 
@@ -94,58 +93,42 @@ module Rails
94
93
  "#{shebang}\n" + content
95
94
  end
96
95
  chmod "bin", 0755 & ~File.umask, verbose: false
97
-
98
- remove_file "bin/spring" unless spring_install?
99
- remove_file "bin/yarn" if options[:skip_javascript]
100
96
  end
101
97
 
102
98
  def bin_when_updating
103
99
  bin
104
100
  end
105
101
 
106
- def yarn_when_updating
107
- template "bin/yarn", force: true do |content|
108
- "#{shebang}\n" + content
109
- end
110
-
111
- chmod "bin", 0755 & ~File.umask, verbose: false
112
- end
113
-
114
102
  def config
115
103
  empty_directory "config"
116
104
 
117
105
  inside "config" do
118
- template "routes.rb"
106
+ template "routes.rb" unless options[:updating]
119
107
  template "application.rb"
120
108
  template "environment.rb"
121
- template "cable.yml" unless options[:skip_action_cable]
122
- template "puma.rb" unless options[:skip_puma]
123
- template "spring.rb" if spring_install?
124
- template "storage.yml" unless skip_active_storage?
109
+ template "cable.yml" unless options[:updating] || options[:skip_action_cable]
110
+ template "puma.rb" unless options[:updating]
111
+ template "storage.yml" unless options[:updating] || skip_active_storage?
125
112
 
126
113
  directory "environments"
127
114
  directory "initializers"
128
- directory "locales"
115
+ directory "locales" unless options[:updating]
129
116
  end
130
117
  end
131
118
 
132
119
  def config_when_updating
133
- cookie_serializer_config_exist = File.exist?("config/initializers/cookies_serializer.rb")
134
- action_cable_config_exist = File.exist?("config/cable.yml")
135
- active_storage_config_exist = File.exist?("config/storage.yml")
136
- rack_cors_config_exist = File.exist?("config/initializers/cors.rb")
137
- assets_config_exist = File.exist?("config/initializers/assets.rb")
138
- csp_config_exist = File.exist?("config/initializers/content_security_policy.rb")
120
+ action_cable_config_exist = File.exist?("config/cable.yml")
121
+ active_storage_config_exist = File.exist?("config/storage.yml")
122
+ rack_cors_config_exist = File.exist?("config/initializers/cors.rb")
123
+ assets_config_exist = File.exist?("config/initializers/assets.rb")
124
+ asset_manifest_exist = File.exist?("app/assets/config/manifest.js")
125
+ asset_app_stylesheet_exist = File.exist?("app/assets/stylesheets/application.css")
126
+ csp_config_exist = File.exist?("config/initializers/content_security_policy.rb")
139
127
  permissions_policy_config_exist = File.exist?("config/initializers/permissions_policy.rb")
140
128
 
141
129
  @config_target_version = Rails.application.config.loaded_config_version || "5.0"
142
130
 
143
131
  config
144
- configru
145
-
146
- unless cookie_serializer_config_exist
147
- gsub_file "config/initializers/cookies_serializer.rb", /json(?!,)/, "marshal"
148
- end
149
132
 
150
133
  if !options[:skip_action_cable] && !action_cable_config_exist
151
134
  template "config/cable.yml"
@@ -155,19 +138,23 @@ module Rails
155
138
  template "config/storage.yml"
156
139
  end
157
140
 
158
- if options[:skip_sprockets] && !assets_config_exist
141
+ if skip_sprockets? && !assets_config_exist
159
142
  remove_file "config/initializers/assets.rb"
160
143
  end
161
144
 
145
+ if skip_sprockets? && !asset_manifest_exist
146
+ remove_file "app/assets/config/manifest.js"
147
+ end
148
+
149
+ if skip_sprockets? && !asset_app_stylesheet_exist
150
+ remove_file "app/assets/stylesheets/application.css"
151
+ end
152
+
162
153
  unless rack_cors_config_exist
163
154
  remove_file "config/initializers/cors.rb"
164
155
  end
165
156
 
166
157
  if options[:api]
167
- unless cookie_serializer_config_exist
168
- remove_file "config/initializers/cookies_serializer.rb"
169
- end
170
-
171
158
  unless csp_config_exist
172
159
  remove_file "config/initializers/content_security_policy.rb"
173
160
  end
@@ -176,6 +163,10 @@ module Rails
176
163
  remove_file "config/initializers/permissions_policy.rb"
177
164
  end
178
165
  end
166
+
167
+ if !skip_sprockets?
168
+ insert_into_file "config/application.rb", %(require "sprockets/railtie"), after: /require\(["']rails\/all["']\)\n/
169
+ end
179
170
  end
180
171
 
181
172
  def master_key
@@ -253,6 +244,11 @@ module Rails
253
244
  def config_target_version
254
245
  defined?(@config_target_version) ? @config_target_version : Rails::VERSION::STRING.to_f
255
246
  end
247
+
248
+ private
249
+ def user_default_branch
250
+ @user_default_branch ||= `git config init.defaultbranch`
251
+ end
256
252
  end
257
253
 
258
254
  module Generators
@@ -263,28 +259,15 @@ module Rails
263
259
  class AppGenerator < AppBase
264
260
  # :stopdoc:
265
261
 
266
- WEBPACKS = %w( react vue angular elm stimulus )
267
-
268
262
  add_shared_options_for "application"
269
263
 
270
264
  # Add rails command options
271
- class_option :version, type: :boolean, aliases: "-v", group: :rails,
272
- desc: "Show Rails version number and quit"
273
-
274
- class_option :api, type: :boolean,
275
- desc: "Preconfigure smaller stack for API only apps"
276
-
277
- class_option :minimal, type: :boolean,
278
- desc: "Preconfigure a minimal rails app"
279
-
280
- class_option :skip_bundle, type: :boolean, aliases: "-B", default: false,
281
- desc: "Don't run bundle install"
282
-
283
- class_option :webpack, type: :string, aliases: "--webpacker", default: nil,
284
- desc: "Preconfigure Webpack with a particular framework (options: #{WEBPACKS.join(", ")})"
285
-
286
- class_option :skip_webpack_install, type: :boolean, default: false,
287
- desc: "Don't run Webpack install"
265
+ class_option :version, type: :boolean, aliases: "-v", group: :rails, desc: "Show Rails version number and quit"
266
+ class_option :api, type: :boolean, desc: "Preconfigure smaller stack for API only apps"
267
+ class_option :minimal, type: :boolean, desc: "Preconfigure a minimal rails app"
268
+ class_option :javascript, type: :string, aliases: "-j", default: "importmap", desc: "Choose JavaScript approach [options: importmap (default), webpack, esbuild, rollup]"
269
+ class_option :css, type: :string, aliases: "-c", desc: "Choose CSS processor [options: tailwind, bootstrap, bulma, postcss, sass... check https://github.com/rails/cssbundling-rails]"
270
+ class_option :skip_bundle, type: :boolean, aliases: "-B", default: false, desc: "Don't run bundle install"
288
271
 
289
272
  def initialize(*args)
290
273
  super
@@ -293,10 +276,10 @@ module Rails
293
276
  raise Error, "Invalid value for --database option. Supported preconfigurations are: #{DATABASES.join(", ")}."
294
277
  end
295
278
 
296
- # Force sprockets and yarn to be skipped when generating API only apps.
279
+ # Force sprockets and JavaScript to be skipped when generating API only apps.
297
280
  # Can't modify options hash as it's frozen by default.
298
281
  if options[:api]
299
- self.options = options.merge(skip_sprockets: true, skip_javascript: true).freeze
282
+ self.options = options.merge(skip_asset_pipeline: true, skip_javascript: true).freeze
300
283
  end
301
284
 
302
285
  if options[:minimal]
@@ -311,15 +294,8 @@ module Rails
311
294
  skip_dev_gems: true,
312
295
  skip_javascript: true,
313
296
  skip_jbuilder: true,
314
- skip_spring: true,
315
297
  skip_system_test: true,
316
- skip_webpack_install: true,
317
- skip_turbolinks: true).tap do |option|
318
- if option[:webpack]
319
- option[:skip_webpack_install] = false
320
- option[:skip_javascript] = false
321
- end
322
- end.freeze
298
+ skip_hotwire: true).freeze
323
299
  end
324
300
 
325
301
  @after_bundle_callbacks = []
@@ -339,9 +315,8 @@ module Rails
339
315
  build(:gitattributes)
340
316
  end
341
317
 
342
- build(:gemfile) unless options[:skip_gemfile]
318
+ build(:gemfile)
343
319
  build(:version_control)
344
- build(:package_json) unless options[:skip_javascript]
345
320
  end
346
321
 
347
322
  def create_app_files
@@ -357,11 +332,6 @@ module Rails
357
332
  end
358
333
  remove_task :update_bin_files
359
334
 
360
- def update_bin_yarn
361
- build(:yarn_when_updating)
362
- end
363
- remove_task :update_bin_yarn
364
-
365
335
  def update_active_storage
366
336
  unless skip_active_storage?
367
337
  rails_command "active_storage:update", inline: true
@@ -473,22 +443,13 @@ module Rails
473
443
  end
474
444
  end
475
445
 
476
- def delete_js_folder_skipping_javascript
477
- if options[:skip_javascript] && !options[:minimal]
478
- remove_dir "app/javascript"
479
- end
480
- end
481
-
482
- def delete_js_packs_when_minimal_skipping_webpack
483
- if options[:minimal] && options[:skip_webpack_install]
484
- remove_dir "app/javascript/packs"
485
- keep_file "app/javascript"
486
- end
487
- end
488
-
489
446
  def delete_assets_initializer_skipping_sprockets
490
- if options[:skip_sprockets]
447
+ if skip_sprockets?
491
448
  remove_file "config/initializers/assets.rb"
449
+ remove_file "app/assets/config/manifest.js"
450
+ remove_dir "app/assets/config"
451
+ remove_file "app/assets/stylesheets/application.css"
452
+ create_file "app/assets/stylesheets/application.css", "/* Application styles */\n" unless options[:api]
492
453
  end
493
454
  end
494
455
 
@@ -523,7 +484,6 @@ module Rails
523
484
 
524
485
  def delete_non_api_initializers_if_api_option
525
486
  if options[:api]
526
- remove_file "config/initializers/cookies_serializer.rb"
527
487
  remove_file "config/initializers/content_security_policy.rb"
528
488
  remove_file "config/initializers/permissions_policy.rb"
529
489
  end
@@ -537,7 +497,7 @@ module Rails
537
497
 
538
498
  def delete_new_framework_defaults
539
499
  unless options[:update]
540
- remove_file "config/initializers/new_framework_defaults_6_1.rb"
500
+ remove_file "config/initializers/new_framework_defaults_7_0.rb"
541
501
  end
542
502
  end
543
503
 
@@ -547,7 +507,9 @@ module Rails
547
507
 
548
508
  public_task :apply_rails_template, :run_bundle
549
509
  public_task :generate_bundler_binstub
550
- public_task :run_webpack
510
+ public_task :run_javascript
511
+ public_task :run_hotwire
512
+ public_task :run_css
551
513
 
552
514
  def run_after_bundle_callbacks
553
515
  @after_bundle_callbacks.each(&:call)
@@ -565,7 +527,7 @@ module Rails
565
527
  create_file(*args, &block)
566
528
  end
567
529
 
568
- # Registers a callback to be executed after bundle and spring binstubs
530
+ # Registers a callback to be executed after bundle binstubs
569
531
  # have run.
570
532
  #
571
533
  # after_bundle do
@@ -1,78 +1,72 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
  git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3
3
 
4
- ruby <%= "'#{RUBY_VERSION}'" -%>
5
-
6
- <% unless gemfile_entries.first&.comment -%>
7
-
8
- <% end -%>
4
+ ruby <%= "\"#{RUBY_VERSION}\"" -%>
9
5
  <% gemfile_entries.each do |gem| -%>
10
- <% if gem.comment -%>
6
+ <% if gem.comment %>
11
7
 
12
8
  # <%= gem.comment %>
13
9
  <% end -%>
14
- <%= gem.commented_out ? '# ' : '' %>gem '<%= gem.name %>'<%= %(, '#{gem.version}') if gem.version -%>
15
- <% if gem.options.any? -%>
16
- , <%= gem.options.map { |k,v|
17
- "#{k}: #{v.inspect.gsub('"', '\'')}" }.join(', ') %>
18
- <% end -%>
19
- <% end -%>
10
+ <%= gem.commented_out ? "# " : "" %>gem "<%= gem.name %>"<%= %(, "#{gem.version}") if gem.version -%>
11
+ <% if gem.options.any? -%>, <%= gem.options.map { |k,v| "#{k}: #{v.inspect}" }.join(", ") %><% end -%>
12
+ <% end %>
13
+ <% unless options.minimal? -%>
20
14
 
21
- # Use Active Model has_secure_password
22
- # gem 'bcrypt', '~> 3.1.7'
23
- <% unless skip_active_storage? -%>
15
+ # Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
16
+ # gem "kredis"
24
17
 
25
- # Use Active Storage variant
26
- # gem 'image_processing', '~> 1.2'
18
+ # Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
19
+ # gem "bcrypt", "~> 3.1.7"
27
20
  <% end -%>
28
21
 
22
+ # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
23
+ gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]
29
24
  <% if depend_on_bootsnap? -%>
25
+
30
26
  # Reduces boot times through caching; required in config/boot.rb
31
- gem 'bootsnap', '>= 1.4.4', require: false
27
+ gem "bootsnap", ">= 1.4.4", require: false
28
+ <% end -%>
29
+ <% unless skip_sprockets? || options.minimal? -%>
32
30
 
33
- <%- end -%>
31
+ # Use Sass to process CSS
32
+ # gem "sassc-rails", "~> 2.1"
33
+ <% end -%>
34
+ <% unless skip_active_storage? -%>
35
+
36
+ # Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
37
+ # gem "image_processing", "~> 1.2"
38
+ <% end -%>
34
39
  <%- if options.api? -%>
35
- # Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
36
- # gem 'rack-cors'
37
40
 
41
+ # Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
42
+ # gem "rack-cors"
38
43
  <%- end -%>
39
- <% if RUBY_ENGINE == 'ruby' -%>
44
+ <% if RUBY_ENGINE == "ruby" -%>
45
+
40
46
  group :development, :test do
41
- # Call 'byebug' anywhere in the code to stop execution and get a debugger console
42
- gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
47
+ # See https://edgeguides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
48
+ gem "debug", ">= 1.0.0", platforms: %i[ mri mingw x64_mingw ]
43
49
  end
44
-
45
50
  <% end -%>
51
+
46
52
  group :development do
47
53
  <%- unless options.api? || options.skip_dev_gems? -%>
48
- # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
49
- <%- if options.dev? || options.edge? || options.master? -%>
50
- gem 'web-console', github: 'rails/web-console'
51
- <%- else -%>
52
- gem 'web-console', '>= 4.1.0'
53
- <%- end -%>
54
- # Display performance information such as SQL time and flame graphs for each request in your browser.
55
- # Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md
56
- gem 'rack-mini-profiler', '~> 2.0'
54
+ # Use console on exceptions pages [https://github.com/rails/web-console]
55
+ gem "web-console", ">= 4.1.0"
56
+
57
+ # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
58
+ # gem "rack-mini-profiler", ">= 2.3.3"
59
+
57
60
  <%- end -%>
58
- <% if depend_on_listen? -%>
59
- gem 'listen', '~> 3.3'
60
- <% end -%>
61
- <% if spring_install? -%>
62
- # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
63
- gem 'spring'
64
- <% end -%>
61
+ # Speed up commands on slow machines / big apps [https://github.com/rails/spring]
62
+ # gem "spring"
65
63
  end
66
64
 
67
65
  <%- if depends_on_system_test? -%>
68
66
  group :test do
69
- # Adds support for Capybara system testing and selenium driver
70
- gem 'capybara', '>= 3.26'
71
- gem 'selenium-webdriver'
72
- # Easy installation and use of web drivers to run system tests with browsers
73
- gem 'webdrivers'
67
+ # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
68
+ gem "capybara", ">= 3.26"
69
+ gem "selenium-webdriver", ">= 4.0.0"
70
+ gem "webdrivers"
74
71
  end
75
-
76
72
  <%- end -%>
77
- # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
78
- gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
@@ -2,11 +2,11 @@
2
2
  * This is a manifest file that'll be compiled into application.css, which will include all the files
3
3
  * listed below.
4
4
  *
5
- * Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's
5
+ * Any CSS (and SCSS, if configured) file within this directory, lib/assets/stylesheets, or any plugin's
6
6
  * vendor/assets/stylesheets directory can be referenced here using a relative path.
7
7
  *
8
8
  * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
- * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS
10
10
  * files in this directory. Styles in this file should be added after the last require_* statement.
11
11
  * It is generally better to create a new file per style scope.
12
12
  *
@@ -1,4 +1,4 @@
1
1
  class ApplicationMailer < ActionMailer::Base
2
- default from: 'from@example.com'
3
- layout 'mailer'
2
+ default from: "from@example.com"
3
+ layout "mailer"
4
4
  end
@@ -1,3 +1,3 @@
1
1
  class ApplicationRecord < ActiveRecord::Base
2
- self.abstract_class = true
2
+ primary_abstract_class
3
3
  end
@@ -6,16 +6,10 @@
6
6
  <%%= csrf_meta_tags %>
7
7
  <%%= csp_meta_tag %>
8
8
 
9
- <%- if options[:skip_javascript] -%>
10
- <%%= stylesheet_link_tag 'application', media: 'all' %>
9
+ <%- if options[:skip_hotwire] || options[:skip_javascript] -%>
10
+ <%%= stylesheet_link_tag "application" %>
11
11
  <%- else -%>
12
- <%- unless options[:skip_turbolinks] -%>
13
- <%%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
14
- <%%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
15
- <%- else -%>
16
- <%%= stylesheet_link_tag 'application', media: 'all' %>
17
- <%%= javascript_pack_tag 'application' %>
18
- <%- end -%>
12
+ <%%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
19
13
  <%- end -%>
20
14
  </head>
21
15
 
@@ -1,6 +1,3 @@
1
- <% if spring_install? -%>
2
- load File.expand_path("spring", __dir__)
3
- <% end -%>
4
- APP_PATH = File.expand_path('../config/application', __dir__)
1
+ APP_PATH = File.expand_path("../config/application", __dir__)
5
2
  require_relative "../config/boot"
6
3
  require "rails/commands"
@@ -1,6 +1,3 @@
1
- <% if spring_install? -%>
2
- load File.expand_path("spring", __dir__)
3
- <% end -%>
4
1
  require_relative "../config/boot"
5
2
  require "rake"
6
3
  Rake.application.run
@@ -1,7 +1,7 @@
1
1
  require "fileutils"
2
2
 
3
3
  # path to your application root.
4
- APP_ROOT = File.expand_path('..', __dir__)
4
+ APP_ROOT = File.expand_path("..", __dir__)
5
5
 
6
6
  def system!(*args)
7
7
  system(*args) || abort("\n== Command #{args} failed ==")
@@ -12,28 +12,23 @@ FileUtils.chdir APP_ROOT do
12
12
  # This script is idempotent, so that you can run it at any time and get an expectable outcome.
13
13
  # Add necessary setup steps to this file.
14
14
 
15
- puts '== Installing dependencies =='
16
- system! 'gem install bundler --conservative'
17
- system('bundle check') || system!('bundle install')
18
- <% unless options.skip_javascript? -%>
19
-
20
- # Install JavaScript dependencies
21
- system! 'bin/yarn'
22
- <% end -%>
15
+ puts "== Installing dependencies =="
16
+ system! "gem install bundler --conservative"
17
+ system("bundle check") || system!("bundle install")
23
18
  <% unless options.skip_active_record? -%>
24
19
 
25
20
  # puts "\n== Copying sample files =="
26
- # unless File.exist?('config/database.yml')
27
- # FileUtils.cp 'config/database.yml.sample', 'config/database.yml'
21
+ # unless File.exist?("config/database.yml")
22
+ # FileUtils.cp "config/database.yml.sample", "config/database.yml"
28
23
  # end
29
24
 
30
25
  puts "\n== Preparing database =="
31
- system! 'bin/rails db:prepare'
26
+ system! "bin/rails db:prepare"
32
27
  <% end -%>
33
28
 
34
29
  puts "\n== Removing old logs and tempfiles =="
35
- system! 'bin/rails log:clear tmp:clear'
30
+ system! "bin/rails log:clear tmp:clear"
36
31
 
37
32
  puts "\n== Restarting application server =="
38
- system! 'bin/rails restart'
33
+ system! "bin/rails restart"
39
34
  end