railties 6.1.3.2 → 7.0.0.alpha2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +96 -334
- data/MIT-LICENSE +1 -1
- data/RDOC_MAIN.rdoc +16 -16
- data/README.rdoc +0 -1
- data/lib/rails/app_updater.rb +2 -4
- data/lib/rails/application/bootstrap.rb +16 -4
- data/lib/rails/application/configuration.rb +57 -29
- data/lib/rails/application/default_middleware_stack.rb +5 -2
- data/lib/rails/application/finisher.rb +43 -85
- data/lib/rails/application/routes_reloader.rb +8 -0
- data/lib/rails/application.rb +32 -51
- data/lib/rails/application_controller.rb +2 -2
- data/lib/rails/autoloaders/inflector.rb +21 -0
- data/lib/rails/autoloaders.rb +12 -16
- data/lib/rails/code_statistics.rb +2 -2
- data/lib/rails/code_statistics_calculator.rb +10 -1
- data/lib/rails/command/base.rb +26 -12
- data/lib/rails/command/behavior.rb +1 -1
- data/lib/rails/command/environment_argument.rb +1 -1
- data/lib/rails/command.rb +11 -10
- data/lib/rails/commands/credentials/USAGE +4 -2
- data/lib/rails/commands/credentials/credentials_command/diffing.rb +26 -16
- data/lib/rails/commands/credentials/credentials_command.rb +8 -3
- data/lib/rails/commands/dbconsole/dbconsole_command.rb +10 -6
- data/lib/rails/commands/help/USAGE +3 -2
- data/lib/rails/commands/runner/runner_command.rb +3 -2
- data/lib/rails/commands/server/server_command.rb +2 -5
- data/lib/rails/configuration.rb +18 -23
- data/lib/rails/engine/configuration.rb +2 -2
- data/lib/rails/engine.rb +23 -27
- data/lib/rails/gem_version.rb +4 -4
- data/lib/rails/generators/actions/create_migration.rb +4 -4
- data/lib/rails/generators/actions.rb +35 -13
- data/lib/rails/generators/app_base.rb +66 -102
- data/lib/rails/generators/app_name.rb +1 -1
- data/lib/rails/generators/base.rb +9 -13
- data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +2 -0
- data/lib/rails/generators/erb/scaffold/templates/edit.html.erb.tt +8 -4
- data/lib/rails/generators/erb/scaffold/templates/index.html.erb.tt +5 -27
- data/lib/rails/generators/erb/scaffold/templates/new.html.erb.tt +7 -3
- data/lib/rails/generators/erb/scaffold/templates/partial.html.erb.tt +20 -0
- data/lib/rails/generators/erb/scaffold/templates/show.html.erb.tt +7 -16
- data/lib/rails/generators/erb.rb +1 -1
- data/lib/rails/generators/generated_attribute.rb +40 -4
- data/lib/rails/generators/migration.rb +2 -6
- data/lib/rails/generators/model_helpers.rb +1 -1
- data/lib/rails/generators/named_base.rb +1 -1
- data/lib/rails/generators/rails/app/app_generator.rb +44 -88
- data/lib/rails/generators/rails/app/templates/Gemfile.tt +41 -52
- data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css.tt +2 -2
- data/lib/rails/generators/rails/app/templates/app/mailers/application_mailer.rb.tt +2 -2
- data/lib/rails/generators/rails/app/templates/app/models/application_record.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +3 -10
- data/lib/rails/generators/rails/app/templates/bin/rails.tt +1 -4
- data/lib/rails/generators/rails/app/templates/bin/rake.tt +0 -3
- data/lib/rails/generators/rails/app/templates/bin/setup.tt +9 -14
- data/lib/rails/generators/rails/app/templates/config/boot.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml.tt +3 -3
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt +3 -3
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +3 -3
- data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +3 -3
- data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml.tt +5 -5
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +2 -11
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +9 -15
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +2 -7
- data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +1 -5
- data/lib/rails/generators/rails/app/templates/config/initializers/content_security_policy.rb.tt +0 -5
- data/lib/rails/generators/rails/app/templates/config/initializers/cors.rb.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/initializers/inflections.rb.tt +4 -4
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_7_0.rb.tt +85 -0
- data/lib/rails/generators/rails/app/templates/config/locales/en.yml +3 -3
- data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/routes.rb.tt +3 -0
- data/lib/rails/generators/rails/app/templates/config/storage.yml.tt +5 -5
- data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +2 -2
- data/lib/rails/generators/rails/app/templates/gitattributes.tt +0 -5
- data/lib/rails/generators/rails/app/templates/gitignore.tt +0 -1
- data/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +1 -1
- data/lib/rails/generators/rails/controller/controller_generator.rb +1 -2
- data/lib/rails/generators/rails/controller/templates/controller.rb.tt +0 -4
- data/lib/rails/generators/rails/db/system/change/change_generator.rb +1 -1
- data/lib/rails/generators/rails/generator/templates/%file_name%_generator.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/plugin_generator.rb +40 -15
- data/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt +4 -2
- data/lib/rails/generators/rails/plugin/templates/Gemfile.tt +9 -9
- data/lib/rails/generators/rails/plugin/templates/README.md.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/app/mailers/%namespaced_name%/application_mailer.rb.tt +2 -2
- data/lib/rails/generators/rails/plugin/templates/app/models/%namespaced_name%/application_record.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/app/views/layouts/%namespaced_name%/application.html.erb.tt +0 -3
- data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +4 -4
- data/lib/rails/generators/rails/plugin/templates/gitignore.tt +0 -5
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/engine.rb.tt +2 -2
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/version.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/rails/boot.rb.tt +2 -2
- data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb.tt +3 -3
- data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +0 -19
- data/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb.tt +1 -5
- data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt +6 -10
- data/lib/rails/generators/resource_helpers.rb +2 -2
- data/lib/rails/generators/test_unit/generator/templates/generator_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/model/templates/fixtures.yml.tt +2 -2
- data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +3 -3
- data/lib/rails/generators/test_unit/scaffold/templates/api_functional_test.rb.tt +5 -5
- data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb.tt +2 -2
- data/lib/rails/generators/test_unit/scaffold/templates/system_test.rb.tt +3 -3
- data/lib/rails/generators/testing/behaviour.rb +1 -2
- data/lib/rails/generators.rb +9 -22
- data/lib/rails/info.rb +1 -1
- data/lib/rails/info_controller.rb +1 -3
- data/lib/rails/initializable.rb +1 -1
- data/lib/rails/mailers_controller.rb +2 -4
- data/lib/rails/rack/logger.rb +0 -1
- data/lib/rails/railtie/configuration.rb +1 -2
- data/lib/rails/railtie.rb +9 -9
- data/lib/rails/ruby_version_check.rb +3 -3
- data/lib/rails/secrets.rb +4 -1
- data/lib/rails/tasks/framework.rake +2 -8
- data/lib/rails/tasks/statistics.rake +3 -1
- data/lib/rails/tasks/tmp.rake +8 -1
- data/lib/rails/tasks/yarn.rake +6 -2
- data/lib/rails/tasks/zeitwerk.rake +2 -10
- data/lib/rails/templates/layouts/application.html.erb +15 -0
- data/lib/rails/templates/rails/mailers/email.html.erb +12 -10
- data/lib/rails/templates/rails/welcome/index.html.erb +3 -0
- data/lib/rails/test_unit/railtie.rb +0 -4
- data/lib/rails/test_unit/runner.rb +7 -5
- data/lib/rails/test_unit/testing.rake +4 -9
- data/lib/rails.rb +1 -0
- metadata +37 -38
- data/lib/rails/command/spellchecker.rb +0 -57
- data/lib/rails/generators/css/assets/assets_generator.rb +0 -15
- data/lib/rails/generators/css/assets/templates/stylesheet.css +0 -4
- data/lib/rails/generators/css/scaffold/scaffold_generator.rb +0 -18
- data/lib/rails/generators/rails/app/templates/app/javascript/channels/consumer.js +0 -6
- data/lib/rails/generators/rails/app/templates/app/javascript/channels/index.js +0 -5
- data/lib/rails/generators/rails/app/templates/app/javascript/packs/application.js.tt +0 -23
- data/lib/rails/generators/rails/app/templates/bin/spring.tt +0 -13
- data/lib/rails/generators/rails/app/templates/bin/yarn.tt +0 -16
- data/lib/rails/generators/rails/app/templates/config/initializers/application_controller_renderer.rb.tt +0 -8
- data/lib/rails/generators/rails/app/templates/config/initializers/cookies_serializer.rb.tt +0 -5
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_1.rb.tt +0 -67
- data/lib/rails/generators/rails/app/templates/config/spring.rb.tt +0 -6
- data/lib/rails/generators/rails/app/templates/package.json.tt +0 -11
- data/lib/rails/generators/rails/assets/USAGE +0 -16
- data/lib/rails/generators/rails/assets/assets_generator.rb +0 -26
- data/lib/rails/generators/rails/assets/templates/stylesheet.css +0 -4
- data/lib/rails/generators/rails/scaffold/templates/scaffold.css +0 -80
@@ -206,7 +206,7 @@ module Rails
|
|
206
206
|
end
|
207
207
|
|
208
208
|
# Make class option aware of Rails::Generators.options and Rails::Generators.aliases.
|
209
|
-
def self.class_option(name, options = {})
|
209
|
+
def self.class_option(name, options = {}) # :nodoc:
|
210
210
|
options[:desc] = "Indicates when to generate #{name.to_s.humanize.downcase}" unless options.key?(:desc)
|
211
211
|
options[:aliases] = default_aliases_for_option(name, options)
|
212
212
|
options[:default] = default_value_for_option(name, options)
|
@@ -231,7 +231,7 @@ module Rails
|
|
231
231
|
|
232
232
|
# Cache source root and add lib/generators/base/generator/templates to
|
233
233
|
# source paths.
|
234
|
-
def self.inherited(base)
|
234
|
+
def self.inherited(base) # :nodoc:
|
235
235
|
super
|
236
236
|
|
237
237
|
# Invoke source_root so the default_source_root is set.
|
@@ -324,21 +324,17 @@ module Rails
|
|
324
324
|
|
325
325
|
# Sets the base_name taking into account the current class namespace.
|
326
326
|
def self.base_name # :doc:
|
327
|
-
@base_name ||=
|
328
|
-
|
329
|
-
base.underscore
|
330
|
-
end
|
327
|
+
@base_name ||= if base = name.to_s.split("::").first
|
328
|
+
base.underscore
|
331
329
|
end
|
332
330
|
end
|
333
331
|
|
334
332
|
# Removes the namespaces and get the generator name. For example,
|
335
333
|
# Rails::Generators::ModelGenerator will return "model" as generator name.
|
336
334
|
def self.generator_name # :doc:
|
337
|
-
@generator_name ||=
|
338
|
-
|
339
|
-
|
340
|
-
generator.underscore
|
341
|
-
end
|
335
|
+
@generator_name ||= if generator = name.to_s.split("::").last
|
336
|
+
generator.delete_suffix!("Generator")
|
337
|
+
generator.underscore
|
342
338
|
end
|
343
339
|
end
|
344
340
|
|
@@ -368,13 +364,13 @@ module Rails
|
|
368
364
|
end
|
369
365
|
|
370
366
|
# Keep hooks configuration that are used on prepare_for_invocation.
|
371
|
-
def self.hooks
|
367
|
+
def self.hooks # :nodoc:
|
372
368
|
@hooks ||= from_superclass(:hooks, {})
|
373
369
|
end
|
374
370
|
|
375
371
|
# Prepare class invocation to search on Rails namespace if a previous
|
376
372
|
# added hook is being used.
|
377
|
-
def self.prepare_for_invocation(name, value)
|
373
|
+
def self.prepare_for_invocation(name, value) # :nodoc:
|
378
374
|
return super unless value.is_a?(String) || value.is_a?(Symbol)
|
379
375
|
|
380
376
|
if value && constants = hooks[name]
|
@@ -1,6 +1,10 @@
|
|
1
|
-
<h1>Editing <%=
|
1
|
+
<h1>Editing <%= human_name.downcase %></h1>
|
2
2
|
|
3
|
-
<%%= render
|
3
|
+
<%%= render "form", <%= singular_table_name %>: @<%= singular_table_name %> %>
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
<br>
|
6
|
+
|
7
|
+
<div>
|
8
|
+
<%%= link_to "Show this <%= human_name.downcase %>", @<%= singular_table_name %> %> |
|
9
|
+
<%%= link_to "Back to <%= human_name.pluralize.downcase %>", <%= index_helper %>_path %>
|
10
|
+
</div>
|
@@ -1,31 +1,9 @@
|
|
1
1
|
<p id="notice"><%%= notice %></p>
|
2
2
|
|
3
|
-
<h1><%=
|
3
|
+
<h1><%= human_name %></h1>
|
4
4
|
|
5
|
-
<
|
6
|
-
|
7
|
-
|
8
|
-
<% attributes.reject(&:password_digest?).each do |attribute| -%>
|
9
|
-
<th><%= attribute.human_name %></th>
|
10
|
-
<% end -%>
|
11
|
-
<th colspan="3"></th>
|
12
|
-
</tr>
|
13
|
-
</thead>
|
5
|
+
<div id="<%= plural_table_name %>">
|
6
|
+
<%%= render @<%= plural_table_name %> %>
|
7
|
+
</div>
|
14
8
|
|
15
|
-
|
16
|
-
<%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
|
17
|
-
<tr>
|
18
|
-
<% attributes.reject(&:password_digest?).each do |attribute| -%>
|
19
|
-
<td><%%= <%= singular_table_name %>.<%= attribute.column_name %> %></td>
|
20
|
-
<% end -%>
|
21
|
-
<td><%%= link_to 'Show', <%= model_resource_name %> %></td>
|
22
|
-
<td><%%= link_to 'Edit', edit_<%= singular_route_name %>_path(<%= singular_table_name %>) %></td>
|
23
|
-
<td><%%= link_to 'Destroy', <%= model_resource_name %>, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
24
|
-
</tr>
|
25
|
-
<%% end %>
|
26
|
-
</tbody>
|
27
|
-
</table>
|
28
|
-
|
29
|
-
<br>
|
30
|
-
|
31
|
-
<%%= link_to 'New <%= singular_table_name.titleize %>', new_<%= singular_route_name %>_path %>
|
9
|
+
<%%= link_to "New <%= human_name.downcase %>", new_<%= singular_route_name %>_path %>
|
@@ -1,5 +1,9 @@
|
|
1
|
-
<h1>New <%=
|
1
|
+
<h1>New <%= human_name.downcase %></h1>
|
2
2
|
|
3
|
-
<%%= render
|
3
|
+
<%%= render "form", <%= singular_table_name %>: @<%= singular_table_name %> %>
|
4
4
|
|
5
|
-
|
5
|
+
<br>
|
6
|
+
|
7
|
+
<div>
|
8
|
+
<%%= link_to "Back to <%= human_name.pluralize.downcase %>", <%= index_helper %>_path %>
|
9
|
+
</div>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<div id="<%%= dom_id <%= singular_table_name %> %>" class="scaffold_record">
|
2
|
+
<% attributes.reject(&:password_digest?).each do |attribute| -%>
|
3
|
+
<p>
|
4
|
+
<strong><%= attribute.human_name %>:</strong>
|
5
|
+
<% if attribute.attachment? -%>
|
6
|
+
<%%= link_to <%= singular_table_name %>.<%= attribute.column_name %>.filename, <%= singular_table_name %>.<%= attribute.column_name %> if <%= singular_table_name %>.<%= attribute.column_name %>.attached? %>
|
7
|
+
<% elsif attribute.attachments? -%>
|
8
|
+
<%% <%= singular_table_name %>.<%= attribute.column_name %>.each do |<%= attribute.singular_name %>| %>
|
9
|
+
<div><%%= link_to <%= attribute.singular_name %>.filename, <%= attribute.singular_name %> %></div>
|
10
|
+
<%% end %>
|
11
|
+
<% else -%>
|
12
|
+
<%%= <%= singular_table_name %>.<%= attribute.column_name %> %>
|
13
|
+
<% end -%>
|
14
|
+
</p>
|
15
|
+
|
16
|
+
<% end -%>
|
17
|
+
<p>
|
18
|
+
<%%= link_to "Show this <%= human_name.downcase %>", <%= singular_table_name %> %>
|
19
|
+
</p>
|
20
|
+
</div>
|
@@ -1,19 +1,10 @@
|
|
1
1
|
<p id="notice"><%%= notice %></p>
|
2
2
|
|
3
|
-
|
4
|
-
<p>
|
5
|
-
<strong><%= attribute.human_name %>:</strong>
|
6
|
-
<% if attribute.attachment? -%>
|
7
|
-
<%%= link_to @<%= singular_table_name %>.<%= attribute.column_name %>.filename, @<%= singular_table_name %>.<%= attribute.column_name %> if @<%= singular_table_name %>.<%= attribute.column_name %>.attached? %>
|
8
|
-
<% elsif attribute.attachments? -%>
|
9
|
-
<%% @<%= singular_table_name %>.<%= attribute.column_name %>.each do |<%= attribute.singular_name %>| %>
|
10
|
-
<div><%%= link_to <%= attribute.singular_name %>.filename, <%= attribute.singular_name %> %></div>
|
11
|
-
<%% end %>
|
12
|
-
<% else -%>
|
13
|
-
<%%= @<%= singular_table_name %>.<%= attribute.column_name %> %>
|
14
|
-
<% end -%>
|
15
|
-
</p>
|
3
|
+
<%%= render @<%= singular_table_name %> %>
|
16
4
|
|
17
|
-
|
18
|
-
<%%= link_to
|
19
|
-
<%%= link_to
|
5
|
+
<div>
|
6
|
+
<%%= link_to "Edit this <%= human_name.downcase %>", edit_<%= singular_table_name %>_path(@<%= singular_table_name %>) %> |
|
7
|
+
<%%= link_to "Back to <%= human_name.pluralize.downcase %>", <%= index_helper %>_path %>
|
8
|
+
|
9
|
+
<%%= button_to "Destroy this <%= human_name.downcase %>", <%= singular_table_name %>_path(@<%= singular_table_name %>), method: :delete %>
|
10
|
+
</div>
|
data/lib/rails/generators/erb.rb
CHANGED
@@ -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,
|
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
|
-
|
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?(
|
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,
|
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)
|
@@ -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
|
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
|
-
|
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
|
@@ -8,7 +8,7 @@ module Rails
|
|
8
8
|
class NamedBase < Base
|
9
9
|
argument :name, type: :string
|
10
10
|
|
11
|
-
def initialize(args, *options)
|
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[:
|
123
|
-
template "
|
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
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
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"
|
@@ -159,15 +142,19 @@ module Rails
|
|
159
142
|
remove_file "config/initializers/assets.rb"
|
160
143
|
end
|
161
144
|
|
145
|
+
if options[:skip_sprockets] && !asset_manifest_exist
|
146
|
+
remove_file "app/assets/config/manifest.js"
|
147
|
+
end
|
148
|
+
|
149
|
+
if options[: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
|
@@ -253,6 +240,11 @@ module Rails
|
|
253
240
|
def config_target_version
|
254
241
|
defined?(@config_target_version) ? @config_target_version : Rails::VERSION::STRING.to_f
|
255
242
|
end
|
243
|
+
|
244
|
+
private
|
245
|
+
def user_default_branch
|
246
|
+
@user_default_branch ||= `git config init.defaultbranch`
|
247
|
+
end
|
256
248
|
end
|
257
249
|
|
258
250
|
module Generators
|
@@ -263,28 +255,15 @@ module Rails
|
|
263
255
|
class AppGenerator < AppBase
|
264
256
|
# :stopdoc:
|
265
257
|
|
266
|
-
WEBPACKS = %w( react vue angular elm stimulus )
|
267
|
-
|
268
258
|
add_shared_options_for "application"
|
269
259
|
|
270
260
|
# Add rails command options
|
271
|
-
class_option :version, type: :boolean, aliases: "-v", group: :rails,
|
272
|
-
|
273
|
-
|
274
|
-
class_option :
|
275
|
-
|
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"
|
261
|
+
class_option :version, type: :boolean, aliases: "-v", group: :rails, desc: "Show Rails version number and quit"
|
262
|
+
class_option :api, type: :boolean, desc: "Preconfigure smaller stack for API only apps"
|
263
|
+
class_option :minimal, type: :boolean, desc: "Preconfigure a minimal rails app"
|
264
|
+
class_option :javascript, type: :string, aliases: "-j", default: "importmap", desc: "Choose JavaScript approach [options: importmap (default), webpack, esbuild, rollup]"
|
265
|
+
class_option :css, type: :string, desc: "Choose CSS processor [options: tailwind, postcss, sass]"
|
266
|
+
class_option :skip_bundle, type: :boolean, aliases: "-B", default: false, desc: "Don't run bundle install"
|
288
267
|
|
289
268
|
def initialize(*args)
|
290
269
|
super
|
@@ -293,7 +272,7 @@ module Rails
|
|
293
272
|
raise Error, "Invalid value for --database option. Supported preconfigurations are: #{DATABASES.join(", ")}."
|
294
273
|
end
|
295
274
|
|
296
|
-
# Force sprockets and
|
275
|
+
# Force sprockets and JavaScript to be skipped when generating API only apps.
|
297
276
|
# Can't modify options hash as it's frozen by default.
|
298
277
|
if options[:api]
|
299
278
|
self.options = options.merge(skip_sprockets: true, skip_javascript: true).freeze
|
@@ -311,15 +290,8 @@ module Rails
|
|
311
290
|
skip_dev_gems: true,
|
312
291
|
skip_javascript: true,
|
313
292
|
skip_jbuilder: true,
|
314
|
-
skip_spring: true,
|
315
293
|
skip_system_test: true,
|
316
|
-
|
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
|
294
|
+
skip_hotwire: true).freeze
|
323
295
|
end
|
324
296
|
|
325
297
|
@after_bundle_callbacks = []
|
@@ -339,9 +311,8 @@ module Rails
|
|
339
311
|
build(:gitattributes)
|
340
312
|
end
|
341
313
|
|
342
|
-
build(:gemfile)
|
314
|
+
build(:gemfile)
|
343
315
|
build(:version_control)
|
344
|
-
build(:package_json) unless options[:skip_javascript]
|
345
316
|
end
|
346
317
|
|
347
318
|
def create_app_files
|
@@ -357,11 +328,6 @@ module Rails
|
|
357
328
|
end
|
358
329
|
remove_task :update_bin_files
|
359
330
|
|
360
|
-
def update_bin_yarn
|
361
|
-
build(:yarn_when_updating)
|
362
|
-
end
|
363
|
-
remove_task :update_bin_yarn
|
364
|
-
|
365
331
|
def update_active_storage
|
366
332
|
unless skip_active_storage?
|
367
333
|
rails_command "active_storage:update", inline: true
|
@@ -473,22 +439,11 @@ module Rails
|
|
473
439
|
end
|
474
440
|
end
|
475
441
|
|
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
442
|
def delete_assets_initializer_skipping_sprockets
|
490
443
|
if options[:skip_sprockets]
|
491
444
|
remove_file "config/initializers/assets.rb"
|
445
|
+
remove_file "app/assets/config/manifest.js"
|
446
|
+
remove_file "app/assets/stylesheets/application.css"
|
492
447
|
end
|
493
448
|
end
|
494
449
|
|
@@ -523,7 +478,6 @@ module Rails
|
|
523
478
|
|
524
479
|
def delete_non_api_initializers_if_api_option
|
525
480
|
if options[:api]
|
526
|
-
remove_file "config/initializers/cookies_serializer.rb"
|
527
481
|
remove_file "config/initializers/content_security_policy.rb"
|
528
482
|
remove_file "config/initializers/permissions_policy.rb"
|
529
483
|
end
|
@@ -537,7 +491,7 @@ module Rails
|
|
537
491
|
|
538
492
|
def delete_new_framework_defaults
|
539
493
|
unless options[:update]
|
540
|
-
remove_file "config/initializers/
|
494
|
+
remove_file "config/initializers/new_framework_defaults_7_0.rb"
|
541
495
|
end
|
542
496
|
end
|
543
497
|
|
@@ -547,7 +501,9 @@ module Rails
|
|
547
501
|
|
548
502
|
public_task :apply_rails_template, :run_bundle
|
549
503
|
public_task :generate_bundler_binstub
|
550
|
-
public_task :
|
504
|
+
public_task :run_javascript
|
505
|
+
public_task :run_hotwire
|
506
|
+
public_task :run_css
|
551
507
|
|
552
508
|
def run_after_bundle_callbacks
|
553
509
|
@after_bundle_callbacks.each(&:call)
|
@@ -565,7 +521,7 @@ module Rails
|
|
565
521
|
create_file(*args, &block)
|
566
522
|
end
|
567
523
|
|
568
|
-
# Registers a callback to be executed after bundle
|
524
|
+
# Registers a callback to be executed after bundle binstubs
|
569
525
|
# have run.
|
570
526
|
#
|
571
527
|
# after_bundle do
|