Skip to content

Commit 5c27b46

Browse files
Remove deprecated CSS tooling. Introduce postcss. (#1113)
Remove obsolete CSS tooling such as bourbon in favor of postcss. This change requires us to use cssbundling-rails and jsbundling-rails. We needed to keep `sprockets` to prevent existing tests from failing when the app is generated in API only mode, but #1117 will explore a solution. Co-authored-by: Eric Milford <[email protected]>
1 parent ecb54e3 commit 5c27b46

File tree

10 files changed

+50
-84
lines changed

10 files changed

+50
-84
lines changed

lib/suspenders.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
require "suspenders/generators/advisories_generator"
55
require "suspenders/generators/app_generator"
66
require "suspenders/generators/static_generator"
7-
require "suspenders/generators/stylesheet_base_generator"
87
require "suspenders/generators/stylelint_generator"
98
require "suspenders/generators/forms_generator"
109
require "suspenders/generators/ci_generator"

lib/suspenders/generators/app_generator.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ class AppGenerator < Rails::Generators::AppGenerator
3131
class_option :skip_system_test,
3232
type: :boolean, default: true, desc: "Skip system test files"
3333

34+
class_option :css,
35+
type: :string, default: "postcss", aliases: "-c", desc: "Choose CSS processor"
36+
3437
def finish_template
3538
invoke :suspenders_customization
3639
super

lib/suspenders/generators/stylesheet_base_generator.rb

Lines changed: 0 additions & 30 deletions
This file was deleted.

lib/suspenders/generators/views_generator.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ def create_shared_flashes
1111
copy_file "flashes_helper.rb", "app/helpers/flashes_helper.rb"
1212
end
1313

14-
def create_shared_javascripts
15-
copy_file "_javascript.html.erb",
16-
"app/views/application/_javascript.html.erb"
17-
end
18-
1914
def create_shared_css_overrides
2015
copy_file "_css_overrides.html.erb",
2116
"app/views/application/_css_overrides.html.erb"

spec/features/new_project_spec.rb

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
expect(gemfile_file).to match(
1414
/^ruby "#{Suspenders::RUBY_VERSION}"$/o
1515
)
16-
expect(gemfile_file).to match(
17-
/^gem "autoprefixer-rails"$/
18-
)
1916
expect(gemfile_file).to match(
2017
/^gem "rails", "#{Suspenders::RAILS_VERSION}"$/o
2118
)
@@ -255,10 +252,6 @@
255252
expect(app_json_file).to match(/"name":\s*"#{app_name.dasherize}"/)
256253
end
257254

258-
def app_name
259-
TestPaths::APP_NAME
260-
end
261-
262255
it "adds high_voltage" do
263256
gemfile = IO.read("#{project_path}/Gemfile")
264257
expect(gemfile).to match(/high_voltage/)
@@ -270,22 +263,43 @@ def app_name
270263
expect(gemfile).to match(/sassc-rails/)
271264
end
272265

273-
it "adds and configures bourbon" do
266+
it "configures Timecop safe mode" do
267+
spec_helper = read_project_file(%w[spec spec_helper.rb])
268+
expect(spec_helper).to match(/Timecop.safe_mode = true/)
269+
end
270+
271+
it "adds and configures a bundler strategy for css and js" do
274272
gemfile = read_project_file("Gemfile")
275273

276-
expect(gemfile).to match(/bourbon/)
274+
expect(gemfile).to match(/cssbundling-rails/)
275+
expect(gemfile).to match(/jsbundling-rails/)
276+
expect(File).to exist("#{project_path}/postcss.config.js")
277+
expect(File).to exist("#{project_path}/package.json")
278+
expect(File).to exist("#{project_path}/bin/dev")
279+
expect(File).to exist("#{project_path}/app/assets/stylesheets/application.postcss.css")
280+
expect(File).to exist("#{project_path}/app/javascript/application.js")
277281
end
278282

279-
it "configures bourbon, and bitters" do
280-
app_css = read_project_file(%w[app assets stylesheets application.scss])
281-
expect(app_css).to match(
282-
/normalize\.css\/normalize.*bourbon.*base/m
283-
)
283+
it "imports css and js" do
284+
layout = read_project_file %w[app views layouts application.html.erb]
285+
286+
expect(layout)
287+
.to include(%(<%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>))
288+
expect(layout)
289+
.to include(%(<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>))
284290
end
285291

286-
it "configures Timecop safe mode" do
287-
spec_helper = read_project_file(%w[spec spec_helper.rb])
288-
expect(spec_helper).to match(/Timecop.safe_mode = true/)
292+
it "loads security helpers" do
293+
layout = read_project_file %w[app views layouts application.html.erb]
294+
295+
expect(layout)
296+
.to include(%(<%= csp_meta_tag %>))
297+
expect(layout)
298+
.to include(%(<%= csrf_meta_tags %>))
299+
end
300+
301+
def app_name
302+
TestPaths::APP_NAME
289303
end
290304

291305
def development_config

spec/support/fixtures/dummy_app/config/environments/development.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
config.action_controller.perform_caching = true
88
config.action_controller.enable_fragment_cache_logging = true
99
config.cache_store = :memory_store
10-
config.public_file_server.headers = {
11-
}
10+
config.public_file_server.headers = {}
1211
else
1312
config.action_controller.perform_caching = false
1413
config.cache_store = :null_store

templates/Gemfile.erb

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,27 @@ end
77

88
ruby "<%= Suspenders::RUBY_VERSION %>"
99

10-
<% unless options[:api] %>
11-
gem "autoprefixer-rails"
10+
<% if options[:api] %>
11+
gem "sprockets", "< 4"
1212
<% end %>
13+
1314
gem "bootsnap", require: false
15+
gem "cssbundling-rails"
1416
gem "honeybadger"
17+
gem "jsbundling-rails"
1518
gem "pg"
1619
gem "puma"
1720
gem "rack-canonical-host"
1821
gem "rails", "<%= Suspenders::RAILS_VERSION %>"
1922
gem "recipient_interceptor"
2023
gem "sassc-rails"
2124
gem "skylight"
22-
gem "sprockets", "< 4"
23-
gem "title"
24-
gem "tzinfo-data", platforms: [:mingw, :x64_mingw, :mswin, :jruby]
25-
<%# TODO: Remove this, and consider passing an option to the `rails new` command for esbuild %>
26-
<%# TODO: Maybe this is how we conditionally handle dependencies that need a bundler %>
27-
<%# unless options[:javascript] %>
28-
<%# gem "webpacker" %>
29-
# Rails 7
3025
gem "sprockets-rails"
31-
gem "importmap-rails"
32-
gem "turbo-rails"
3326
gem "stimulus-rails"
27+
gem "title"
28+
gem "turbo-rails"
29+
gem "tzinfo-data", platforms: [:mingw, :x64_mingw, :mswin, :jruby]
30+
3431
group :development do
3532
gem "listen"
3633
gem "web-console"

templates/_javascript.html.erb

Lines changed: 0 additions & 5 deletions
This file was deleted.

templates/application.scss

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
<!DOCTYPE html>
22
<html lang="<%= I18n.locale %>">
33
<head>
4-
<meta charset="utf-8" />
5-
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
64
<%%#
75
Configure default and controller-, and view-specific titles in
86
config/locales/en.yml. For more see:
97
https://github.com/calebthompson/title#usage
108
%>
119
<title><%%= title %></title>
12-
<%%= stylesheet_link_tag :application, media: "all" %>
10+
<meta charset="utf-8" />
11+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
1312
<%%= csrf_meta_tags %>
13+
<%%= csp_meta_tag %>
14+
15+
<%%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
16+
<%%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>
1417
</head>
1518
<body>
1619
<%%= render "flashes" -%>
1720
<%%= yield %>
18-
<%%= render "javascript" %>
1921
<%%= render "css_overrides" %>
2022
</body>
2123
</html>

0 commit comments

Comments
 (0)