From 96f0284b6793d85ba8078532c3fcabd74cae5eb1 Mon Sep 17 00:00:00 2001 From: Steve Polito Date: Thu, 15 Dec 2022 08:01:07 -0500 Subject: [PATCH 1/7] Remove deprecated CSS tooling. Introduce postcss. --- lib/suspenders.rb | 1 - lib/suspenders/generators/app_generator.rb | 7 ++- .../generators/stylesheet_base_generator.rb | 30 ------------ lib/suspenders/generators/views_generator.rb | 5 -- spec/features/new_project_spec.rb | 48 ++++++++++++------- templates/Gemfile.erb | 6 +-- templates/_javascript.html.erb | 5 -- templates/application.scss | 8 ---- templates/suspenders_layout.html.erb.erb | 10 ++-- 9 files changed, 44 insertions(+), 76 deletions(-) delete mode 100644 lib/suspenders/generators/stylesheet_base_generator.rb delete mode 100644 templates/_javascript.html.erb delete mode 100644 templates/application.scss diff --git a/lib/suspenders.rb b/lib/suspenders.rb index 9fb799444..a944d9f10 100644 --- a/lib/suspenders.rb +++ b/lib/suspenders.rb @@ -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" diff --git a/lib/suspenders/generators/app_generator.rb b/lib/suspenders/generators/app_generator.rb index 14251a163..a4bf895db 100644 --- a/lib/suspenders/generators/app_generator.rb +++ b/lib/suspenders/generators/app_generator.rb @@ -28,8 +28,11 @@ class AppGenerator < Rails::Generators::AppGenerator class_option :skip_test, type: :boolean, default: true, desc: "Skip Test Unit" - class_option :skip_system_test, - type: :boolean, default: true, desc: "Skip system test files" + class_option :css, + type: :string, default: "postcss", aliases: "-c", desc: "Choose CSS processor" + + class_option :version, type: :boolean, aliases: "-v", group: :suspenders, + desc: "Show Suspenders version number and quit" def finish_template invoke :suspenders_customization diff --git a/lib/suspenders/generators/stylesheet_base_generator.rb b/lib/suspenders/generators/stylesheet_base_generator.rb deleted file mode 100644 index 9e15aa3d8..000000000 --- a/lib/suspenders/generators/stylesheet_base_generator.rb +++ /dev/null @@ -1,30 +0,0 @@ -require_relative "base" - -module Suspenders - class StylesheetBaseGenerator < Generators::Base - def add_stylesheet_gems - gem "bourbon", ">= 6.0.0" - Bundler.with_unbundled_env { run "bundle install" } - end - - def remove_prior_config - remove_file "app/assets/stylesheets/application.css" - end - - def add_css_config - copy_file( - "application.scss", - "app/assets/stylesheets/application.scss", - force: true - ) - end - - def install_bitters - run "bitters install --path app/assets/stylesheets" - end - - def install_normalize_css - run "yarn add normalize.css" - end - end -end diff --git a/lib/suspenders/generators/views_generator.rb b/lib/suspenders/generators/views_generator.rb index b33a12b1b..68d94f65b 100644 --- a/lib/suspenders/generators/views_generator.rb +++ b/lib/suspenders/generators/views_generator.rb @@ -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" diff --git a/spec/features/new_project_spec.rb b/spec/features/new_project_spec.rb index 627c49e64..d4e08fd83 100644 --- a/spec/features/new_project_spec.rb +++ b/spec/features/new_project_spec.rb @@ -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 ) @@ -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/) @@ -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") 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 diff --git a/templates/Gemfile.erb b/templates/Gemfile.erb index 91cc1ef7d..5552f3128 100644 --- a/templates/Gemfile.erb +++ b/templates/Gemfile.erb @@ -7,9 +7,6 @@ end ruby "<%= Suspenders::RUBY_VERSION %>" -<% unless options[:api] %> -gem "autoprefixer-rails" -<% end %> gem "bootsnap", require: false gem "honeybadger" gem "pg" @@ -28,7 +25,8 @@ gem "tzinfo-data", platforms: [:mingw, :x64_mingw, :mswin, :jruby] <%# gem "webpacker" %> # Rails 7 gem "sprockets-rails" -gem "importmap-rails" +gem "jsbundling-rails" +gem "cssbundling-rails" gem "turbo-rails" gem "stimulus-rails" group :development do diff --git a/templates/_javascript.html.erb b/templates/_javascript.html.erb deleted file mode 100644 index 90505dcda..000000000 --- a/templates/_javascript.html.erb +++ /dev/null @@ -1,5 +0,0 @@ -<%# TODO: Replace this with javascript_tag %> -<%# TODO: We might want to do conditionally do this though, incase the app is using webpackeh %> -<%= javascript_pack_tag :application %> - -<%= yield :javascript %> diff --git a/templates/application.scss b/templates/application.scss deleted file mode 100644 index 6c4b8cce0..000000000 --- a/templates/application.scss +++ /dev/null @@ -1,8 +0,0 @@ -@charset "utf-8"; - -// TODO: We need to explore using cssbundling-rails with postcss to load this -@import "normalize.css/normalize"; - -@import "bourbon"; - -@import "base/base"; diff --git a/templates/suspenders_layout.html.erb.erb b/templates/suspenders_layout.html.erb.erb index 77f4fb95b..36486938e 100644 --- a/templates/suspenders_layout.html.erb.erb +++ b/templates/suspenders_layout.html.erb.erb @@ -1,21 +1,23 @@ - - <%%# Configure default and controller-, and view-specific titles in config/locales/en.yml. For more see: https://github.com/calebthompson/title#usage %> <%%= title %> - <%%= stylesheet_link_tag :application, media: "all" %> + + <%%= csrf_meta_tags %> + <%%= csp_meta_tag %> + + <%%= stylesheet_link_tag "application", "data-turbo-track": "reload" %> + <%%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %> <%%= render "flashes" -%> <%%= yield %> - <%%= render "javascript" %> <%%= render "css_overrides" %> From cb23ef485380f5eb2f915ae5de75c56eb30bf318 Mon Sep 17 00:00:00 2001 From: Steve Polito Date: Thu, 15 Dec 2022 08:48:40 -0500 Subject: [PATCH 2/7] Only load sprockets for API applications A future commit should explore if we can remove the Gem all together. --- templates/Gemfile.erb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/templates/Gemfile.erb b/templates/Gemfile.erb index 5552f3128..902752cbb 100644 --- a/templates/Gemfile.erb +++ b/templates/Gemfile.erb @@ -16,7 +16,9 @@ gem "rails", "<%= Suspenders::RAILS_VERSION %>" gem "recipient_interceptor" gem "sassc-rails" gem "skylight" +<% if options[:api] %> gem "sprockets", "< 4" +<% end %> 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 %> From b1fca8c0d7ab06c8b378b0878d8f7becbb12dac7 Mon Sep 17 00:00:00 2001 From: Steve Polito Date: Thu, 15 Dec 2022 09:47:37 -0500 Subject: [PATCH 3/7] Remove comments We will probably want to re-order these later --- templates/Gemfile.erb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/templates/Gemfile.erb b/templates/Gemfile.erb index 902752cbb..61e71a04e 100644 --- a/templates/Gemfile.erb +++ b/templates/Gemfile.erb @@ -21,10 +21,6 @@ gem "sprockets", "< 4" <% end %> 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 "jsbundling-rails" From 0765fc49f2ef31b7aae1525dd7c36a496d289371 Mon Sep 17 00:00:00 2001 From: Eric Milford Date: Thu, 15 Dec 2022 10:07:03 -0500 Subject: [PATCH 4/7] Run Standard to fix style issues --- .../fixtures/dummy_app/config/environments/development.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spec/support/fixtures/dummy_app/config/environments/development.rb b/spec/support/fixtures/dummy_app/config/environments/development.rb index 3dd38c237..eae7b883a 100644 --- a/spec/support/fixtures/dummy_app/config/environments/development.rb +++ b/spec/support/fixtures/dummy_app/config/environments/development.rb @@ -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 From 9fa5d1d3fa824e6c6351ec5bac1c54d81ec991b1 Mon Sep 17 00:00:00 2001 From: Steve Polito Date: Thu, 15 Dec 2022 09:50:26 -0500 Subject: [PATCH 5/7] Alphabetically order Gems --- templates/Gemfile.erb | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/templates/Gemfile.erb b/templates/Gemfile.erb index 61e71a04e..5442decb1 100644 --- a/templates/Gemfile.erb +++ b/templates/Gemfile.erb @@ -7,8 +7,14 @@ end ruby "<%= Suspenders::RUBY_VERSION %>" +<% if options[:api] %> +gem "sprockets", "< 4" +<% end %> + gem "bootsnap", require: false +gem "cssbundling-rails" gem "honeybadger" +gem "jsbundling-rails" gem "pg" gem "puma" gem "rack-canonical-host" @@ -16,17 +22,12 @@ gem "rails", "<%= Suspenders::RAILS_VERSION %>" gem "recipient_interceptor" gem "sassc-rails" gem "skylight" -<% if options[:api] %> -gem "sprockets", "< 4" -<% end %> -gem "title" -gem "tzinfo-data", platforms: [:mingw, :x64_mingw, :mswin, :jruby] -# Rails 7 gem "sprockets-rails" -gem "jsbundling-rails" -gem "cssbundling-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" From a2e611c066a52e26bbaa271ab1ca71a71c54941c Mon Sep 17 00:00:00 2001 From: Steve Polito Date: Thu, 15 Dec 2022 11:56:45 -0500 Subject: [PATCH 6/7] Add test back --- lib/suspenders/generators/app_generator.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/suspenders/generators/app_generator.rb b/lib/suspenders/generators/app_generator.rb index a4bf895db..52801c485 100644 --- a/lib/suspenders/generators/app_generator.rb +++ b/lib/suspenders/generators/app_generator.rb @@ -34,6 +34,9 @@ class AppGenerator < Rails::Generators::AppGenerator class_option :version, type: :boolean, aliases: "-v", group: :suspenders, desc: "Show Suspenders version number and quit" + class_option :skip_system_test, + type: :boolean, default: true, desc: "Skip system test files" + def finish_template invoke :suspenders_customization super From 9da6ea358b67feaf83780b4127e65c4ad1d92b2b Mon Sep 17 00:00:00 2001 From: Steve Polito Date: Thu, 15 Dec 2022 12:01:36 -0500 Subject: [PATCH 7/7] Fix duplicate options --- lib/suspenders/generators/app_generator.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/suspenders/generators/app_generator.rb b/lib/suspenders/generators/app_generator.rb index 52801c485..854599a03 100644 --- a/lib/suspenders/generators/app_generator.rb +++ b/lib/suspenders/generators/app_generator.rb @@ -28,15 +28,12 @@ class AppGenerator < Rails::Generators::AppGenerator class_option :skip_test, type: :boolean, default: true, desc: "Skip Test Unit" - class_option :css, - type: :string, default: "postcss", aliases: "-c", desc: "Choose CSS processor" - - class_option :version, type: :boolean, aliases: "-v", group: :suspenders, - desc: "Show Suspenders version number and quit" - class_option :skip_system_test, type: :boolean, default: true, desc: "Skip system test files" + class_option :css, + type: :string, default: "postcss", aliases: "-c", desc: "Choose CSS processor" + def finish_template invoke :suspenders_customization super