railties 6.1.0 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +121 -276
- data/MIT-LICENSE +1 -1
- data/RDOC_MAIN.rdoc +16 -16
- data/README.rdoc +1 -2
- data/lib/rails/all.rb +0 -1
- data/lib/rails/api/task.rb +1 -1
- data/lib/rails/app_updater.rb +3 -5
- data/lib/rails/application/bootstrap.rb +21 -5
- data/lib/rails/application/configuration.rb +79 -33
- data/lib/rails/application/default_middleware_stack.rb +7 -3
- data/lib/rails/application/finisher.rb +42 -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 -11
- data/lib/rails/commands/help/USAGE +3 -2
- data/lib/rails/commands/notes/notes_command.rb +2 -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 +3 -3
- data/lib/rails/engine.rb +18 -24
- data/lib/rails/gem_version.rb +2 -2
- 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 +140 -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/_form.html.erb.tt +8 -8
- data/lib/rails/generators/erb/scaffold/templates/edit.html.erb.tt +8 -4
- data/lib/rails/generators/erb/scaffold/templates/index.html.erb.tt +11 -28
- data/lib/rails/generators/erb/scaffold/templates/new.html.erb.tt +7 -3
- data/lib/rails/generators/erb/scaffold/templates/partial.html.erb.tt +17 -0
- data/lib/rails/generators/erb/scaffold/templates/show.html.erb.tt +8 -17
- data/lib/rails/generators/erb.rb +1 -1
- data/lib/rails/generators/generated_attribute.rb +45 -9
- data/lib/rails/generators/migration.rb +2 -6
- data/lib/rails/generators/model_helpers.rb +1 -1
- data/lib/rails/generators/named_base.rb +11 -11
- data/lib/rails/generators/rails/app/app_generator.rb +54 -93
- data/lib/rails/generators/rails/app/templates/Gemfile.tt +42 -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 -9
- 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/application.rb.tt +0 -1
- 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 +6 -12
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +11 -38
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +6 -11
- 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 +19 -25
- 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 +117 -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 +4 -1
- 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 +3 -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 +42 -24
- data/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt +7 -3
- data/lib/rails/generators/rails/plugin/templates/Gemfile.tt +11 -20
- 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/views/layouts/%namespaced_name%/application.html.erb.tt +0 -3
- data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +4 -5
- 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 +2 -7
- 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 +7 -7
- data/lib/rails/generators/test_unit/scaffold/templates/system_test.rb.tt +9 -11
- data/lib/rails/generators/testing/behaviour.rb +3 -4
- 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 +31 -14
- data/lib/rails/ruby_version_check.rb +3 -3
- data/lib/rails/secrets.rb +4 -1
- data/lib/rails/source_annotation_extractor.rb +1 -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 +10 -7
- 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 +13 -11
- data/lib/rails/templates/rails/welcome/index.html.erb +62 -47
- data/lib/rails/test_unit/railtie.rb +0 -4
- data/lib/rails/test_unit/runner.rb +16 -9
- data/lib/rails/test_unit/testing.rake +4 -9
- data/lib/rails/welcome_controller.rb +1 -0
- data/lib/rails.rb +5 -0
- metadata +33 -36
- 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 -9
- data/lib/rails/generators/rails/app/templates/bin/yarn.tt +0 -18
- 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/backtrace_silencers.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/mime_types.rb.tt +0 -4
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_1.rb.tt +0 -63
- data/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt +0 -16
- 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
@@ -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)
|
@@ -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 :
|
74
|
-
when :datetime, :timestamp then :
|
75
|
-
when :date then :
|
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.
|
91
|
-
when :date then Date.today.
|
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
|
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?
|
@@ -94,20 +94,20 @@ module Rails
|
|
94
94
|
singular_name == plural_name
|
95
95
|
end
|
96
96
|
|
97
|
-
def index_helper # :doc:
|
98
|
-
uncountable?
|
97
|
+
def index_helper(type: nil) # :doc:
|
98
|
+
[plural_route_name, ("index" if uncountable?), type].compact.join("_")
|
99
99
|
end
|
100
100
|
|
101
|
-
def show_helper # :doc:
|
102
|
-
"#{singular_route_name}
|
101
|
+
def show_helper(arg = "@#{singular_table_name}", type: :url) # :doc:
|
102
|
+
"#{singular_route_name}_#{type}(#{arg})"
|
103
103
|
end
|
104
104
|
|
105
|
-
def edit_helper # :doc:
|
106
|
-
"edit_#{show_helper}"
|
105
|
+
def edit_helper(...) # :doc:
|
106
|
+
"edit_#{show_helper(...)}"
|
107
107
|
end
|
108
108
|
|
109
|
-
def new_helper # :doc:
|
110
|
-
"new_#{singular_route_name}
|
109
|
+
def new_helper(type: :url) # :doc:
|
110
|
+
"new_#{singular_route_name}_#{type}"
|
111
111
|
end
|
112
112
|
|
113
113
|
def singular_table_name # :doc:
|
@@ -147,8 +147,8 @@ module Rails
|
|
147
147
|
model_resource_name(prefix: "@")
|
148
148
|
end
|
149
149
|
|
150
|
-
def model_resource_name(prefix: "") # :doc:
|
151
|
-
resource_name = "#{prefix}#{
|
150
|
+
def model_resource_name(base_name = singular_table_name, prefix: "") # :doc:
|
151
|
+
resource_name = "#{prefix}#{base_name}"
|
152
152
|
if options[:model_name]
|
153
153
|
"[#{controller_class_path.map { |name| ":" + name }.join(", ")}, #{resource_name}]"
|
154
154
|
else
|
@@ -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,60 +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
|
-
return if File.exist?("bin/yarn")
|
108
|
-
|
109
|
-
template "bin/yarn" do |content|
|
110
|
-
"#{shebang}\n" + content
|
111
|
-
end
|
112
|
-
|
113
|
-
chmod "bin", 0755 & ~File.umask, verbose: false
|
114
|
-
end
|
115
|
-
|
116
102
|
def config
|
117
103
|
empty_directory "config"
|
118
104
|
|
119
105
|
inside "config" do
|
120
|
-
template "routes.rb"
|
106
|
+
template "routes.rb" unless options[:updating]
|
121
107
|
template "application.rb"
|
122
108
|
template "environment.rb"
|
123
|
-
template "cable.yml" unless options[:skip_action_cable]
|
124
|
-
template "puma.rb" unless options[:
|
125
|
-
template "
|
126
|
-
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?
|
127
112
|
|
128
113
|
directory "environments"
|
129
114
|
directory "initializers"
|
130
|
-
directory "locales"
|
115
|
+
directory "locales" unless options[:updating]
|
131
116
|
end
|
132
117
|
end
|
133
118
|
|
134
119
|
def config_when_updating
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
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")
|
141
127
|
permissions_policy_config_exist = File.exist?("config/initializers/permissions_policy.rb")
|
142
128
|
|
143
129
|
@config_target_version = Rails.application.config.loaded_config_version || "5.0"
|
144
130
|
|
145
131
|
config
|
146
|
-
configru
|
147
|
-
|
148
|
-
unless cookie_serializer_config_exist
|
149
|
-
gsub_file "config/initializers/cookies_serializer.rb", /json(?!,)/, "marshal"
|
150
|
-
end
|
151
132
|
|
152
133
|
if !options[:skip_action_cable] && !action_cable_config_exist
|
153
134
|
template "config/cable.yml"
|
@@ -157,19 +138,23 @@ module Rails
|
|
157
138
|
template "config/storage.yml"
|
158
139
|
end
|
159
140
|
|
160
|
-
if
|
141
|
+
if skip_sprockets? && !assets_config_exist
|
161
142
|
remove_file "config/initializers/assets.rb"
|
162
143
|
end
|
163
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
|
+
|
164
153
|
unless rack_cors_config_exist
|
165
154
|
remove_file "config/initializers/cors.rb"
|
166
155
|
end
|
167
156
|
|
168
157
|
if options[:api]
|
169
|
-
unless cookie_serializer_config_exist
|
170
|
-
remove_file "config/initializers/cookies_serializer.rb"
|
171
|
-
end
|
172
|
-
|
173
158
|
unless csp_config_exist
|
174
159
|
remove_file "config/initializers/content_security_policy.rb"
|
175
160
|
end
|
@@ -178,6 +163,10 @@ module Rails
|
|
178
163
|
remove_file "config/initializers/permissions_policy.rb"
|
179
164
|
end
|
180
165
|
end
|
166
|
+
|
167
|
+
if !skip_sprockets?
|
168
|
+
insert_into_file "config/application.rb", %(require "sprockets/railtie"), after: /require\(["']rails\/all["']\)\n/
|
169
|
+
end
|
181
170
|
end
|
182
171
|
|
183
172
|
def master_key
|
@@ -255,6 +244,11 @@ module Rails
|
|
255
244
|
def config_target_version
|
256
245
|
defined?(@config_target_version) ? @config_target_version : Rails::VERSION::STRING.to_f
|
257
246
|
end
|
247
|
+
|
248
|
+
private
|
249
|
+
def user_default_branch
|
250
|
+
@user_default_branch ||= `git config init.defaultbranch`
|
251
|
+
end
|
258
252
|
end
|
259
253
|
|
260
254
|
module Generators
|
@@ -265,28 +259,15 @@ module Rails
|
|
265
259
|
class AppGenerator < AppBase
|
266
260
|
# :stopdoc:
|
267
261
|
|
268
|
-
WEBPACKS = %w( react vue angular elm stimulus )
|
269
|
-
|
270
262
|
add_shared_options_for "application"
|
271
263
|
|
272
264
|
# Add rails command options
|
273
|
-
class_option :version, type: :boolean, aliases: "-v", group: :rails,
|
274
|
-
|
275
|
-
|
276
|
-
class_option :
|
277
|
-
|
278
|
-
|
279
|
-
class_option :minimal, type: :boolean,
|
280
|
-
desc: "Preconfigure a minimal rails app"
|
281
|
-
|
282
|
-
class_option :skip_bundle, type: :boolean, aliases: "-B", default: false,
|
283
|
-
desc: "Don't run bundle install"
|
284
|
-
|
285
|
-
class_option :webpack, type: :string, aliases: "--webpacker", default: nil,
|
286
|
-
desc: "Preconfigure Webpack with a particular framework (options: #{WEBPACKS.join(", ")})"
|
287
|
-
|
288
|
-
class_option :skip_webpack_install, type: :boolean, default: false,
|
289
|
-
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"
|
290
271
|
|
291
272
|
def initialize(*args)
|
292
273
|
super
|
@@ -295,10 +276,10 @@ module Rails
|
|
295
276
|
raise Error, "Invalid value for --database option. Supported preconfigurations are: #{DATABASES.join(", ")}."
|
296
277
|
end
|
297
278
|
|
298
|
-
# Force sprockets and
|
279
|
+
# Force sprockets and JavaScript to be skipped when generating API only apps.
|
299
280
|
# Can't modify options hash as it's frozen by default.
|
300
281
|
if options[:api]
|
301
|
-
self.options = options.merge(
|
282
|
+
self.options = options.merge(skip_asset_pipeline: true, skip_javascript: true).freeze
|
302
283
|
end
|
303
284
|
|
304
285
|
if options[:minimal]
|
@@ -313,15 +294,8 @@ module Rails
|
|
313
294
|
skip_dev_gems: true,
|
314
295
|
skip_javascript: true,
|
315
296
|
skip_jbuilder: true,
|
316
|
-
skip_spring: true,
|
317
297
|
skip_system_test: true,
|
318
|
-
|
319
|
-
skip_turbolinks: true).tap do |option|
|
320
|
-
if option[:webpack]
|
321
|
-
option[:skip_webpack_install] = false
|
322
|
-
option[:skip_javascript] = false
|
323
|
-
end
|
324
|
-
end.freeze
|
298
|
+
skip_hotwire: true).freeze
|
325
299
|
end
|
326
300
|
|
327
301
|
@after_bundle_callbacks = []
|
@@ -329,6 +303,7 @@ module Rails
|
|
329
303
|
|
330
304
|
public_task :set_default_accessors!
|
331
305
|
public_task :create_root
|
306
|
+
public_task :target_rails_prerelease
|
332
307
|
|
333
308
|
def create_root_files
|
334
309
|
build(:readme)
|
@@ -341,9 +316,8 @@ module Rails
|
|
341
316
|
build(:gitattributes)
|
342
317
|
end
|
343
318
|
|
344
|
-
build(:gemfile)
|
319
|
+
build(:gemfile)
|
345
320
|
build(:version_control)
|
346
|
-
build(:package_json) unless options[:skip_javascript]
|
347
321
|
end
|
348
322
|
|
349
323
|
def create_app_files
|
@@ -359,11 +333,6 @@ module Rails
|
|
359
333
|
end
|
360
334
|
remove_task :update_bin_files
|
361
335
|
|
362
|
-
def update_bin_yarn
|
363
|
-
build(:yarn_when_updating)
|
364
|
-
end
|
365
|
-
remove_task :update_bin_yarn
|
366
|
-
|
367
336
|
def update_active_storage
|
368
337
|
unless skip_active_storage?
|
369
338
|
rails_command "active_storage:update", inline: true
|
@@ -475,22 +444,13 @@ module Rails
|
|
475
444
|
end
|
476
445
|
end
|
477
446
|
|
478
|
-
def delete_js_folder_skipping_javascript
|
479
|
-
if options[:skip_javascript] && !options[:minimal]
|
480
|
-
remove_dir "app/javascript"
|
481
|
-
end
|
482
|
-
end
|
483
|
-
|
484
|
-
def delete_js_packs_when_minimal_skipping_webpack
|
485
|
-
if options[:minimal] && options[:skip_webpack_install]
|
486
|
-
remove_dir "app/javascript/packs"
|
487
|
-
keep_file "app/javascript"
|
488
|
-
end
|
489
|
-
end
|
490
|
-
|
491
447
|
def delete_assets_initializer_skipping_sprockets
|
492
|
-
if
|
448
|
+
if skip_sprockets?
|
493
449
|
remove_file "config/initializers/assets.rb"
|
450
|
+
remove_file "app/assets/config/manifest.js"
|
451
|
+
remove_dir "app/assets/config"
|
452
|
+
remove_file "app/assets/stylesheets/application.css"
|
453
|
+
create_file "app/assets/stylesheets/application.css", "/* Application styles */\n" unless options[:api]
|
494
454
|
end
|
495
455
|
end
|
496
456
|
|
@@ -525,7 +485,6 @@ module Rails
|
|
525
485
|
|
526
486
|
def delete_non_api_initializers_if_api_option
|
527
487
|
if options[:api]
|
528
|
-
remove_file "config/initializers/cookies_serializer.rb"
|
529
488
|
remove_file "config/initializers/content_security_policy.rb"
|
530
489
|
remove_file "config/initializers/permissions_policy.rb"
|
531
490
|
end
|
@@ -539,7 +498,7 @@ module Rails
|
|
539
498
|
|
540
499
|
def delete_new_framework_defaults
|
541
500
|
unless options[:update]
|
542
|
-
remove_file "config/initializers/
|
501
|
+
remove_file "config/initializers/new_framework_defaults_7_0.rb"
|
543
502
|
end
|
544
503
|
end
|
545
504
|
|
@@ -549,7 +508,9 @@ module Rails
|
|
549
508
|
|
550
509
|
public_task :apply_rails_template, :run_bundle
|
551
510
|
public_task :generate_bundler_binstub
|
552
|
-
public_task :
|
511
|
+
public_task :run_javascript
|
512
|
+
public_task :run_hotwire
|
513
|
+
public_task :run_css
|
553
514
|
|
554
515
|
def run_after_bundle_callbacks
|
555
516
|
@after_bundle_callbacks.each(&:call)
|
@@ -567,7 +528,7 @@ module Rails
|
|
567
528
|
create_file(*args, &block)
|
568
529
|
end
|
569
530
|
|
570
|
-
# Registers a callback to be executed after bundle
|
531
|
+
# Registers a callback to be executed after bundle binstubs
|
571
532
|
# have run.
|
572
533
|
#
|
573
534
|
# after_bundle do
|
@@ -1,78 +1,68 @@
|
|
1
|
-
source
|
1
|
+
source "https://rubygems.org"
|
2
2
|
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
3
3
|
|
4
|
-
ruby <%= "
|
5
|
-
|
6
|
-
<% unless gemfile_entries.first&.comment -%>
|
4
|
+
ruby <%= "\"#{RUBY_VERSION}\"" -%>
|
7
5
|
|
6
|
+
<% gemfile_entries.each do |gemfile_entry| %>
|
7
|
+
<%= gemfile_entry %>
|
8
8
|
<% end -%>
|
9
|
-
<%
|
10
|
-
<% if gem.comment -%>
|
9
|
+
<% unless options.minimal? -%>
|
11
10
|
|
12
|
-
#
|
13
|
-
|
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 -%>
|
11
|
+
# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
|
12
|
+
# gem "kredis"
|
20
13
|
|
21
|
-
# Use Active Model has_secure_password
|
22
|
-
# gem
|
23
|
-
<% unless skip_active_storage? -%>
|
24
|
-
|
25
|
-
# Use Active Storage variant
|
26
|
-
# gem 'image_processing', '~> 1.2'
|
14
|
+
# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
|
15
|
+
# gem "bcrypt", "~> 3.1.7"
|
27
16
|
<% end -%>
|
28
17
|
|
18
|
+
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
|
19
|
+
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]
|
29
20
|
<% if depend_on_bootsnap? -%>
|
21
|
+
|
30
22
|
# Reduces boot times through caching; required in config/boot.rb
|
31
|
-
gem
|
23
|
+
gem "bootsnap", require: false
|
24
|
+
<% end -%>
|
25
|
+
<% unless skip_sprockets? || options.minimal? -%>
|
32
26
|
|
33
|
-
|
27
|
+
# Use Sass to process CSS
|
28
|
+
# gem "sassc-rails"
|
29
|
+
<% end -%>
|
30
|
+
<% unless skip_active_storage? -%>
|
31
|
+
|
32
|
+
# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
|
33
|
+
# gem "image_processing", "~> 1.2"
|
34
|
+
<% end -%>
|
34
35
|
<%- if options.api? -%>
|
35
|
-
# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
|
36
|
-
# gem 'rack-cors'
|
37
36
|
|
37
|
+
# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
|
38
|
+
# gem "rack-cors"
|
38
39
|
<%- end -%>
|
39
|
-
<% if RUBY_ENGINE ==
|
40
|
+
<% if RUBY_ENGINE == "ruby" -%>
|
41
|
+
|
40
42
|
group :development, :test do
|
41
|
-
#
|
42
|
-
gem
|
43
|
+
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
|
44
|
+
gem "debug", platforms: %i[ mri mingw x64_mingw ]
|
43
45
|
end
|
44
|
-
|
45
46
|
<% end -%>
|
47
|
+
|
46
48
|
group :development do
|
47
49
|
<%- unless options.api? || options.skip_dev_gems? -%>
|
48
|
-
#
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
gem
|
53
|
-
|
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'
|
50
|
+
# Use console on exceptions pages [https://github.com/rails/web-console]
|
51
|
+
gem "web-console"
|
52
|
+
|
53
|
+
# Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
|
54
|
+
# gem "rack-mini-profiler"
|
55
|
+
|
57
56
|
<%- end -%>
|
58
|
-
|
59
|
-
gem
|
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 -%>
|
57
|
+
# Speed up commands on slow machines / big apps [https://github.com/rails/spring]
|
58
|
+
# gem "spring"
|
65
59
|
end
|
66
60
|
|
67
61
|
<%- if depends_on_system_test? -%>
|
68
62
|
group :test do
|
69
|
-
#
|
70
|
-
gem
|
71
|
-
gem
|
72
|
-
|
73
|
-
gem 'webdrivers'
|
63
|
+
# Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
|
64
|
+
gem "capybara"
|
65
|
+
gem "selenium-webdriver"
|
66
|
+
gem "webdrivers"
|
74
67
|
end
|
75
|
-
|
76
68
|
<%- 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
|
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
|
*
|
@@ -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
|
9
|
+
<%- if options[:skip_hotwire] || options[:skip_javascript] -%>
|
10
|
+
<%%= stylesheet_link_tag "application" %>
|
11
11
|
<%- else -%>
|
12
|
-
|
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
|
-
|
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"
|