Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated CSS tooling. Introduce postcss. #1113

Merged
merged 7 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/suspenders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
require "suspenders/generators/advisories_generator"
require "suspenders/generators/app_generator"
require "suspenders/generators/static_generator"
require "suspenders/generators/stylesheet_base_generator"
require "suspenders/generators/stylelint_generator"
require "suspenders/generators/forms_generator"
require "suspenders/generators/ci_generator"
Expand Down
3 changes: 3 additions & 0 deletions lib/suspenders/generators/app_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class AppGenerator < Rails::Generators::AppGenerator
class_option :skip_system_test,
type: :boolean, default: true, desc: "Skip system test files"

class_option :css,
stevepolitodesign marked this conversation as resolved.
Show resolved Hide resolved
type: :string, default: "postcss", aliases: "-c", desc: "Choose CSS processor"

def finish_template
invoke :suspenders_customization
super
Expand Down
30 changes: 0 additions & 30 deletions lib/suspenders/generators/stylesheet_base_generator.rb

This file was deleted.

5 changes: 0 additions & 5 deletions lib/suspenders/generators/views_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ def create_shared_flashes
copy_file "flashes_helper.rb", "app/helpers/flashes_helper.rb"
end

def create_shared_javascripts
copy_file "_javascript.html.erb",
"app/views/application/_javascript.html.erb"
end

def create_shared_css_overrides
copy_file "_css_overrides.html.erb",
"app/views/application/_css_overrides.html.erb"
Expand Down
48 changes: 31 additions & 17 deletions spec/features/new_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
expect(gemfile_file).to match(
/^ruby "#{Suspenders::RUBY_VERSION}"$/o
)
expect(gemfile_file).to match(
/^gem "autoprefixer-rails"$/
)
expect(gemfile_file).to match(
/^gem "rails", "#{Suspenders::RAILS_VERSION}"$/o
)
Expand Down Expand Up @@ -255,10 +252,6 @@
expect(app_json_file).to match(/"name":\s*"#{app_name.dasherize}"/)
end

def app_name
TestPaths::APP_NAME
end

it "adds high_voltage" do
gemfile = IO.read("#{project_path}/Gemfile")
expect(gemfile).to match(/high_voltage/)
Expand All @@ -270,22 +263,43 @@ def app_name
expect(gemfile).to match(/sassc-rails/)
end

it "adds and configures bourbon" do
it "configures Timecop safe mode" do
spec_helper = read_project_file(%w[spec spec_helper.rb])
expect(spec_helper).to match(/Timecop.safe_mode = true/)
end

it "adds and configures a bundler strategy for css and js" do
gemfile = read_project_file("Gemfile")

expect(gemfile).to match(/bourbon/)
expect(gemfile).to match(/cssbundling-rails/)
expect(gemfile).to match(/jsbundling-rails/)
expect(File).to exist("#{project_path}/postcss.config.js")
expect(File).to exist("#{project_path}/package.json")
expect(File).to exist("#{project_path}/bin/dev")
expect(File).to exist("#{project_path}/app/assets/stylesheets/application.postcss.css")
expect(File).to exist("#{project_path}/app/javascript/application.js")
Comment on lines +271 to +280
Copy link
Contributor Author

@stevepolitodesign stevepolitodesign Dec 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ensures the --css=postcss flag did its job.

end

it "configures bourbon, and bitters" do
app_css = read_project_file(%w[app assets stylesheets application.scss])
expect(app_css).to match(
/normalize\.css\/normalize.*bourbon.*base/m
)
it "imports css and js" do
layout = read_project_file %w[app views layouts application.html.erb]

expect(layout)
.to include(%(<%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>))
expect(layout)
.to include(%(<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>))
end

it "configures Timecop safe mode" do
spec_helper = read_project_file(%w[spec spec_helper.rb])
expect(spec_helper).to match(/Timecop.safe_mode = true/)
it "loads security helpers" do
layout = read_project_file %w[app views layouts application.html.erb]

expect(layout)
.to include(%(<%= csp_meta_tag %>))
expect(layout)
.to include(%(<%= csrf_meta_tags %>))
end

def app_name
TestPaths::APP_NAME
end

def development_config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
config.action_controller.perform_caching = true
config.action_controller.enable_fragment_cache_logging = true
config.cache_store = :memory_store
config.public_file_server.headers = {
}
config.public_file_server.headers = {}
else
config.action_controller.perform_caching = false
config.cache_store = :null_store
Expand Down
21 changes: 9 additions & 12 deletions templates/Gemfile.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,27 @@ end

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

<% unless options[:api] %>
gem "autoprefixer-rails"
<% if options[:api] %>
gem "sprockets", "< 4"
Comment on lines +10 to +11
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need this for API only mode #1117

<% end %>

gem "bootsnap", require: false
gem "cssbundling-rails"
gem "honeybadger"
gem "jsbundling-rails"
gem "pg"
gem "puma"
gem "rack-canonical-host"
gem "rails", "<%= Suspenders::RAILS_VERSION %>"
gem "recipient_interceptor"
gem "sassc-rails"
gem "skylight"
gem "sprockets", "< 4"
gem "title"
gem "tzinfo-data", platforms: [:mingw, :x64_mingw, :mswin, :jruby]
<%# TODO: Remove this, and consider passing an option to the `rails new` command for esbuild %>
<%# TODO: Maybe this is how we conditionally handle dependencies that need a bundler %>
<%# unless options[:javascript] %>
<%# gem "webpacker" %>
# Rails 7
gem "sprockets-rails"
gem "importmap-rails"
gem "turbo-rails"
gem "stimulus-rails"
gem "title"
gem "turbo-rails"
gem "tzinfo-data", platforms: [:mingw, :x64_mingw, :mswin, :jruby]

group :development do
gem "listen"
gem "web-console"
Expand Down
5 changes: 0 additions & 5 deletions templates/_javascript.html.erb

This file was deleted.

8 changes: 0 additions & 8 deletions templates/application.scss

This file was deleted.

10 changes: 6 additions & 4 deletions templates/suspenders_layout.html.erb.erb
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
<!DOCTYPE html>
<html lang="<%= I18n.locale %>">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<%%#
Configure default and controller-, and view-specific titles in
config/locales/en.yml. For more see:
https://github.com/calebthompson/title#usage
%>
<title><%%= title %></title>
<%%= stylesheet_link_tag :application, media: "all" %>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<%%= csrf_meta_tags %>
<%%= csp_meta_tag %>

<%%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
<%%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>
Comment on lines +10 to +16
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I generated a new Rails app without suspenders, and this is what was in application.html.erb.

rails g new_app -c=postcss

</head>
<body>
<%%= render "flashes" -%>
<%%= yield %>
<%%= render "javascript" %>
<%%= render "css_overrides" %>
</body>
</html>