Skip to content

Commit

Permalink
Remove deprecated CSS tooling. Introduce postcss.
Browse files Browse the repository at this point in the history
  • Loading branch information
stevepolitodesign committed Dec 15, 2022
1 parent ecb54e3 commit 4eb5ee8
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 76 deletions.
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
7 changes: 5 additions & 2 deletions lib/suspenders/generators/app_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
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")
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
6 changes: 2 additions & 4 deletions templates/Gemfile.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ end

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

<% unless options[:api] %>
gem "autoprefixer-rails"
<% end %>
gem "bootsnap", require: false
gem "honeybadger"
gem "pg"
Expand All @@ -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
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 %>
</head>
<body>
<%%= render "flashes" -%>
<%%= yield %>
<%%= render "javascript" %>
<%%= render "css_overrides" %>
</body>
</html>

0 comments on commit 4eb5ee8

Please sign in to comment.