Skip to content

Commit da6fa63

Browse files
committed
Fix Sprockets bugs
When installing Rails, Sprockets is the default use case for assets like CSS, JavaScript, and Images. A few folks were getting double render errors which lead me to the manifest.js file. On a first run Rails will append both a javascript and css file there. Rails UI leverages cssbundling so these aren’t necessary. This update removes them outright to hopefully make the double render error non-existent going forward. Also fixed some typos.
1 parent e31a7b4 commit da6fa63

4 files changed

Lines changed: 19 additions & 16 deletions

File tree

app/views/railsui/themes/bootstrap/retriever/components/flash/_dynamic.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ document.addEventListener('turbo:load', () => {
3535
<%= doc_label(:stimulus) %>
3636

3737
<% content_for :html, flush: true do %>
38-
<div class="notice" role="alert" data-controller="flash">
38+
<div class="flash flash-warning" role="alert" data-controller="flash">
3939
<p>...</p>
4040
</div>
4141
<% end %>

lib/install/bootstrap/install.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
say "🥾 Bootstrap is already installed."
33
else
44

5-
def swap_sprockets_to_builds
5+
# ensure sprockets plays nicely
6+
def optimize_sprockets
67
if (sprockets_manifest_path = Rails.root.join("app/assets/config/manifest.js")).exist?
7-
append_to_file sprockets_manifest_path, %(//= link_tree ../builds\n)
8-
9-
gsub_file "app/assets/config/manifest.js", "//= link_directory ../stylesheets .css\n", ""
8+
gsub_file "app/assets/config/manifest.js", "//= link_directory ../stylesheets .css\n", ""
9+
gsub_file "app/assets/config/manifest.js", "//= link_tree ../../javascript .js\n", ""
10+
gsub_file "app/assets/config/manifest.js", "//= link_tree ../../../vendor/javascript .js\n", ""
1011
end
1112
end
1213

@@ -19,8 +20,6 @@ def copy_custom_css
1920
end
2021

2122
def install_bootstrap
22-
# source: https://github.com/rails/cssbundling-rails/blob/main/lib/install/bootstrap/install.rb
23-
2423
# Copy customized Bootstrap CSS
2524
copy_file "#{__dir__}/themes/#{Railsui.config.theme}/stylesheets/application.bootstrap.scss",
2625
"app/assets/stylesheets/application.bootstrap.scss"
@@ -107,8 +106,8 @@ def copy_stimulus_js_controllers
107106
end
108107
end
109108

110-
say "Stop linking stylesheets automatically"
111-
swap_sprockets_to_builds
109+
say "Make Sprockets behave"
110+
optimize_sprockets
112111

113112
say "🎨️ Copy custom CSS"
114113
copy_custom_css

lib/install/install.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,12 @@ def remove_importmaps
5454
end
5555

5656
def add_esbuild
57-
# rails_command "javascript:install:esbuild", force: true
58-
# Node versions make this thing a chore and we want it to be fully automated not dependent on a specific version so we gotta go full manual for now
57+
# rails_command "javascript:install:esbuild", force: true <<- replacement
5958

6059
if (sprockets_manifest_path = Rails.root.join("app/assets/config/manifest.js")).exist?
6160
append_to_file sprockets_manifest_path, %(//= link_tree ../builds\n)
61+
gsub_file "app/assets/config/manifest.js", "//= link_tree ../../javascript .js\n", ""
62+
gsub_file "app/assets/config/manifest.js", "//= link_tree ../../../vendor/javascript .js\n", ""
6263
end
6364

6465
if Rails.root.join(".gitignore").exist?
@@ -257,7 +258,7 @@ def add_devise_customizations
257258
initializer_content = <<-RUBY
258259
Rails.application.config.to_prepare do
259260
Devise::SessionsController.layout "devise"
260-
Devise::RegistrationsController.layout proc{ |controller| user_signed_in? ? "application" : "devise" }
261+
Devise::RegistrationsController.layout proc { |controller| user_signed_in? ? "application" : "devise" }
261262
Devise::ConfirmationsController.layout "devise"
262263
Devise::UnlocksController.layout "devise"
263264
Devise::PasswordsController.layout "devise"

lib/install/tailwind/install.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@
1919
say "✅ tailwind.config.js already exists"
2020
end
2121

22+
# ensure sprockets plays nicely
23+
if (sprockets_manifest_path = Rails.root.join("app/assets/config/manifest.js")).exist?
24+
gsub_file "app/assets/config/manifest.js", "//= link_directory ../stylesheets .css\n", ""
25+
gsub_file "app/assets/config/manifest.js", "//= link_tree ../../javascript .js\n", ""
26+
gsub_file "app/assets/config/manifest.js", "//= link_tree ../../../vendor/javascript .js\n", ""
27+
end
28+
2229
# remove application.css
2330
say "⚡️ Remove app/assets/stylesheets/application.css so build output can take over"
2431
remove_file "app/assets/stylesheets/application.css"
@@ -40,10 +47,7 @@
4047
directory "#{__dir__}/themes/#{Railsui.config.theme}/devise", Rails.root.join("app/views/devise")
4148
end
4249

43-
# TODO: Do we need this? - Inherited from railsui/lib/generators/railsui/templates/tailwind/<theme> somehow? Seems it's using the config in `application.rb - g.template_engine :railsui`. Pretty cool.
44-
# Keeping for now
4550
say "⚡️ Add Tailwind-themed scaffold .erb templates"
46-
# directory "#{__dir__}/themes/#{Railsui.config.theme}/templates/erb/scaffold", Rails.root.join("lib/templates/erb/scaffold"), force: true
4751
file_names = ["_form.html.erb.tt", "edit.html.erb.tt", "index.html.erb.tt", "new.html.erb.tt", "partial.html.erb.tt", "show.html.erb.tt"]
4852

4953
file_names.each do |name|
@@ -56,7 +60,6 @@
5660

5761
# Copy themed globally shared partials
5862
# These files overide those shipped during first install of Rails UI
59-
# TODO: Improve this so we don't have to call explicit file names but rather files within the folder per theme
6063
say "⚡️ Copy shared partial files"
6164
shared_files = ["_error_messages.html.erb", "_flash.html.erb", "_nav.html.erb", "_nav_menu.html.erb", "_footer.html.erb"]
6265

0 commit comments

Comments
 (0)