From 58b5b7d01ce86e92d4185db34a7923487ebd04ad Mon Sep 17 00:00:00 2001 From: JP Boily Date: Mon, 28 Oct 2024 14:57:44 -0400 Subject: [PATCH] add a patch for assets based on comments in https://github.com/basecamp/audits1984/issues/50 --- lib/audits1984/engine.rb | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/audits1984/engine.rb b/lib/audits1984/engine.rb index cf6a58c..64dd0ea 100644 --- a/lib/audits1984/engine.rb +++ b/lib/audits1984/engine.rb @@ -20,7 +20,31 @@ class Engine < ::Rails::Engine end initializer "audits1984.assets.precompile" do |app| - app.config.assets.precompile << "audits1984_manifest.js" + if app.config.respond_to?(:assets) + app.config.assets.precompile << "audits1984_manifest.js" + else + gem_asset_root = Audits1984::Engine.root.join("app/assets") + tmp_asset_root = Rails.root.join("tmp/audits1984/assets") + + # Create audits1984 css and js files + asset_files = [ + "javascripts/audits1984/application.js", + "stylesheets/audits1984/bulma.min.css", + "stylesheets/audits1984/application.css", + ] + + asset_files.each do |file| + unless (local_file = tmp_asset_root.join(file)).exist? + local_file.dirname.mkpath + local_file.write gem_asset_root.join(File.dirname(file)).children.map(&:read).join("\n\n") + end + end + + # Serve custom assets instead of audits1984's (that will 404 without the asset pipeline) + Rails.application.config.middleware.use Rack::Static, + urls: %w[/javascripts/audits1984 /stylesheets/audits1984 /images/audits1984], + root: tmp_asset_root + end end end end