Skip to content

Commit ecbd92c

Browse files
author
David Heinemeier Hansson
authored
Clearer default gemfile (rails#43212)
* More succinct Gemfile comments * Use double plings * Separate gems with comments * Correct separation at the top * Style * Use comments for all rails options * Clearer still * Clear invocation pointer * Move tzinfo-data up to all the other gems that are available everywhere * More succinct * Better order and spacing * Add similar read more link style * No Sass recommendation on minimal
1 parent 366c8f0 commit ecbd92c

File tree

3 files changed

+40
-49
lines changed

3 files changed

+40
-49
lines changed

railties/lib/rails/generators/app_base.rb

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,11 @@ def database_gemfile_entry # :doc:
158158
return [] if options[:skip_active_record]
159159
gem_name, gem_version = gem_for_database
160160
GemfileEntry.version gem_name, gem_version,
161-
"Use #{options[:database]} as the database for Active Record"
161+
"Use #{options[:database]} as the database for Active Record"
162162
end
163163

164164
def web_server_gemfile_entry # :doc:
165-
comment = "Use Puma as the app server"
166-
GemfileEntry.new("puma", "~> 5.0", comment)
165+
GemfileEntry.new "puma", "~> 5.0", "Use the Puma web server [https://github.com/puma/puma]"
167166
end
168167

169168
def include_all_railties? # :doc:
@@ -254,21 +253,21 @@ def version
254253
def rails_gemfile_entry
255254
if options.dev?
256255
[
257-
GemfileEntry.path("rails", Rails::Generators::RAILS_DEV_PATH)
256+
GemfileEntry.path("rails", Rails::Generators::RAILS_DEV_PATH, "Use local checkout of Rails")
258257
]
259258
elsif options.edge?
260259
edge_branch = Rails.gem_version.prerelease? ? "main" : [*Rails.gem_version.segments.first(2), "stable"].join("-")
261260
[
262-
GemfileEntry.github("rails", "rails/rails", edge_branch)
261+
GemfileEntry.github("rails", "rails/rails", edge_branch, "Use specific branch of Rails")
263262
]
264263
elsif options.main?
265264
[
266-
GemfileEntry.github("rails", "rails/rails", "main")
265+
GemfileEntry.github("rails", "rails/rails", "main", "Use main development branch of Rails")
267266
]
268267
else
269268
[GemfileEntry.version("rails",
270269
rails_version_specifier,
271-
"Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'")]
270+
%(Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"))]
272271
end
273272
end
274273

@@ -287,28 +286,28 @@ def rails_version_specifier(gem_version = Rails.gem_version)
287286

288287
def jbuilder_gemfile_entry
289288
return [] if options[:skip_jbuilder]
290-
comment = "Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder"
289+
comment = "Build JSON APIs with ease [https://github.com/rails/jbuilder]"
291290
GemfileEntry.new "jbuilder", "~> 2.7", comment, {}, options[:api]
292291
end
293292

294293
def javascript_gemfile_entry
295294
return [] if options[:skip_javascript]
296295

297296
if options[:javascript] == "importmap"
298-
GemfileEntry.version("importmap-rails", ">= 0.3.4", "Manage modern JavaScript using ESM without transpiling or bundling")
297+
GemfileEntry.version("importmap-rails", ">= 0.3.4", "Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]")
299298
else
300-
GemfileEntry.version "jsbundling-rails", "~> 0.1.0", "Bundle and transpile JavaScript with a JavaScript bundler. Read more: https://github.com/rails/jsbundling-rails"
299+
GemfileEntry.version "jsbundling-rails", "~> 0.1.0", "Bundle and transpile JavaScript [https://github.com/rails/jsbundling-rails]"
301300
end
302301
end
303302

304303
def hotwire_gemfile_entry
305304
return [] if options[:skip_javascript] || options[:skip_hotwire]
306305

307306
turbo_rails_entry =
308-
GemfileEntry.version("turbo-rails", ">= 0.7.11", "Hotwire's SPA-like page accelerator. Read more: https://turbo.hotwired.dev")
307+
GemfileEntry.version("turbo-rails", ">= 0.7.11", "Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]")
309308

310309
stimulus_rails_entry =
311-
GemfileEntry.version("stimulus-rails", ">= 0.4.0", "Hotwire's modest JavaScript framework for the HTML you already have. Read more: https://stimulus.hotwired.dev")
310+
GemfileEntry.version("stimulus-rails", ">= 0.4.0", "Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]")
312311

313312
[ turbo_rails_entry, stimulus_rails_entry ]
314313
end
@@ -321,9 +320,9 @@ def css_gemfile_entry
321320
return [] unless options[:css]
322321

323322
if !using_node? && options[:css] == "tailwind"
324-
GemfileEntry.version("tailwindcss-rails", ">= 0.4.3", "Use Tailwind CSS. See: https://github.com/rails/tailwindcss-rails")
323+
GemfileEntry.version("tailwindcss-rails", ">= 0.4.3", "Use Tailwind CSS [https://github.com/rails/tailwindcss-rails]")
325324
else
326-
GemfileEntry.version("cssbundling-rails", ">= 0.1.0", "Bundle and process CSS with Tailwind, PostCSS, or Sass. Read more: https://github.com/rails/cssbundling-rails")
325+
GemfileEntry.version("cssbundling-rails", ">= 0.1.0", "Bundle and process CSS [https://github.com/rails/cssbundling-rails]")
327326
end
328327
end
329328

railties/lib/rails/generators/rails/app/templates/Gemfile.tt

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,74 +2,66 @@ source "https://rubygems.org"
22
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
33

44
ruby <%= "\"#{RUBY_VERSION}\"" -%>
5-
6-
<% unless gemfile_entries.first&.comment -%>
7-
8-
<% end -%>
95
<% gemfile_entries.each do |gem| -%>
10-
<% if gem.comment -%>
6+
<% if gem.comment %>
117

128
# <%= gem.comment %>
139
<% end -%>
1410
<%= 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 -%>
20-
<% unless options.skip_sprockets? %>
11+
<% if gem.options.any? -%>, <%= gem.options.map { |k,v| "#{k}: #{v.inspect}" }.join(", ") %><% end -%>
12+
<% end %>
13+
14+
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
15+
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]
16+
17+
<% if depend_on_bootsnap? -%>
18+
# Reduces boot times through caching; required in config/boot.rb
19+
gem "bootsnap", ">= 1.4.4", require: false
20+
21+
<%- end -%>
22+
# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
23+
# gem "bcrypt", "~> 3.1.7"
24+
<% unless options.skip_sprockets? || options.minimal? -%>
2125

2226
# Use Sass to process CSS
2327
# gem "sassc-rails", "~> 2.1"
2428
<% end -%>
25-
26-
# Use Active Model has_secure_password
27-
# gem "bcrypt", "~> 3.1.7"
2829
<% unless skip_active_storage? -%>
2930

30-
# Use Active Storage variant
31+
# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
3132
# gem "image_processing", "~> 1.2"
3233
<% end -%>
33-
34-
<% if depend_on_bootsnap? -%>
35-
# Reduces boot times through caching; required in config/boot.rb
36-
gem "bootsnap", ">= 1.4.4", require: false
37-
38-
<%- end -%>
3934
<%- if options.api? -%>
35+
4036
# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
4137
# gem "rack-cors"
42-
4338
<%- end -%>
4439
<% if RUBY_ENGINE == "ruby" -%>
40+
4541
group :development, :test do
46-
# See https://github.com/ruby/debug for usage
42+
# Start debugger with binding.b [https://github.com/ruby/debug]
4743
gem "debug", ">= 1.0.0", platforms: %i[ mri mingw x64_mingw ]
4844
end
49-
5045
<% end -%>
46+
5147
group :development do
5248
<%- unless options.api? || options.skip_dev_gems? -%>
53-
# Access an interactive console on exception pages or by calling "console" anywhere in the code.
49+
# Use console on exceptions pages [https://github.com/rails/web-console]
5450
gem "web-console", ">= 4.1.0"
5551

56-
# Display speed badge on every html page with SQL times and flame graphs.
57-
# Note: Interferes with etag cache testing. Can be configured to work on production: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md
52+
# Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
5853
# gem "rack-mini-profiler", "~> 2.0"
54+
5955
<%- end -%>
60-
# Speed up rails commands in dev on slow machines / big apps. See: https://github.com/rails/spring
56+
# Speed up commands on slow machines / big apps [https://github.com/rails/spring]
6157
# gem "spring"
6258
end
6359

6460
<%- if depends_on_system_test? -%>
6561
group :test do
66-
# Adds support for Capybara system testing and selenium driver
62+
# Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
6763
gem "capybara", ">= 3.26"
6864
gem "selenium-webdriver"
69-
# Easy installation and use of web drivers to run system tests with browsers
7065
gem "webdrivers"
7166
end
72-
73-
<%- end -%>
74-
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
75-
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]
67+
<%- end -%>

railties/lib/rails/generators/rails/plugin/templates/Gemfile.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ end
3232

3333
<% end -%>
3434
<% if RUBY_ENGINE == "ruby" -%>
35-
# See https://github.com/ruby/debug for usage
35+
# Start debugger with binding.b -- Read more: https://github.com/ruby/debug
3636
# gem "debug", ">= 1.0.0", group: %i[ development test ]
3737
<% end -%>
3838
<% if RUBY_PLATFORM.match(/bccwin|cygwin|emx|mingw|mswin|wince|java/) -%>

0 commit comments

Comments
 (0)