Skip to content

Commit c4dedf7

Browse files
authored
Completely remove usage of sprockets or propshaft (#22)
Why: - Sprockets v4 manifest file has all sorts of rough edges with rails engines - Exposing the engines assets publicly can give away details about things that should be internal only - We can easily avoid it altogether and just load the assets as part of the application layout - There are such minimal amount of asset code that there really is no benefit to any HTTP caching
1 parent bc819f3 commit c4dedf7

File tree

14 files changed

+29
-74
lines changed

14 files changed

+29
-74
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
### Unreleased
44
- [View Diff](https://github.com/westonganger/rails_local_analytics/compare/v1.0.0...master)
5-
- Nothing yet
5+
- [#22](https://github.com/westonganger/rails_local_analytics/pull/22) - Completely remove usage of sprockets or propshaft
66

77
### v1.0.0 - Jan 17 2025
88
- [View Diff](https://github.com/westonganger/rails_local_analytics/compare/v0.2.4...v1.0.0)

Gemfile

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ rails_version = get_env("RAILS_VERSION")
2222

2323
gem "rails", rails_version
2424

25-
if RUBY_VERSION.to_f >= 2.7 && (rails_version.nil? || rails_version.sub("~>","").to_f >= 8.0)
26-
gem "propshaft"
27-
else
28-
gem 'sprockets-rails', require: 'sprockets/railtie'
29-
end
30-
3125
db_gem = get_env("DB_GEM") || "sqlite3"
3226
gem db_gem, get_env("DB_GEM_VERSION")
3327

app/assets/config/rails_local_analytics_manifest.js

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

app/assets/images/rails_local_analytics/.keep

Whitespace-only changes.

app/assets/javascripts/rails_local_analytics/.keep

Whitespace-only changes.

app/assets/stylesheets/rails_local_analytics/application.css

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<style>
2+
body{
3+
padding-bottom: 20px;
4+
}
5+
6+
table td{
7+
overflow-wrap: anywhere;
8+
}
9+
10+
input, select {
11+
border-radius: 5px;
12+
border: 1px solid #333;
13+
background: white;
14+
padding: 2px 5px;
15+
}
16+
17+
button.is-link{
18+
border: none;
19+
background: none;
20+
color: #2780e3;
21+
text-decoration: underline;
22+
cursor: pointer;
23+
}
24+
</style>

app/views/layouts/rails_local_analytics/application.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<%= csp_meta_tag %>
1010

1111
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootswatch/3.4.0/cosmo/bootstrap.min.css" crossorigin="anonymous" referrerpolicy="no-referrer" />
12-
<%= stylesheet_link_tag "rails_local_analytics/application" %>
12+
<%= render "layouts/rails_local_analytics/app_css" %>
1313
</head>
1414

1515
<body>

lib/rails_local_analytics/engine.rb

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,6 @@ module RailsLocalAnalytics
22
class Engine < ::Rails::Engine
33
isolate_namespace RailsLocalAnalytics
44

5-
initializer "rails_local_analytics.assets.precompile" do |app|
6-
# this initializer is only called when sprockets is in use
7-
8-
app.config.assets.precompile << "rails_local_analytics_manifest.js" ### manifest file required
9-
10-
### Automatically precompile assets in specified folders
11-
["app/assets/images/"].each do |folder|
12-
dir = app.root.join(folder)
13-
14-
if Dir.exist?(dir)
15-
Dir.glob(File.join(dir, "**/*")).each do |f|
16-
asset_name = f.to_s
17-
.split(folder).last # Remove fullpath
18-
.sub(/^\/*/, '') ### Remove leading '/'
19-
20-
app.config.assets.precompile << asset_name
21-
end
22-
end
23-
end
24-
end
25-
265
initializer "rails_local_analytics.load_static_assets" do |app|
276
### Expose static assets
287
app.middleware.use ::ActionDispatch::Static, "#{root}/public"
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
//= link_tree ../images
2-
//= link_directory ../stylesheets .css
3-
//= link rails_local_analytics_manifest.js
1+
// this file is only present to make Rails 6.1 and below work in our CI

0 commit comments

Comments
 (0)