Skip to content

Instantly share code, notes, and snippets.

@westonganger
Last active April 18, 2023 00:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save westonganger/c0c082b2f9a202772dae75938a0f7377 to your computer and use it in GitHub Desktop.
Save westonganger/c0c082b2f9a202772dae75938a0f7377 to your computer and use it in GitHub Desktop.
# lib/<project_name>/engine.rb
module RailsI18nManager
class Engine < ::Rails::Engine
isolate_namespace RailsI18nManager
initializer "rails_i18n_manager.load_static_assets" do |app|
### Expose static assets
app.middleware.use ::ActionDispatch::Static, "#{root}/public"
end
### Sprockets Config below
initializer "rails_i18n_manager.assets.precompile" do |app|
app.config.assets.precompile << "rails_i18n_manager_manifest.js" ### manifest file required
app.config.assets.precompile << "rails_i18n_manager/favicon.ico"
### Automatically precompile assets in specified folders
["app/assets/images/"].each do |folder|
dir = app.root.join(folder)
if Dir.exist?(dir)
Dir.glob(File.join(dir, "**/*")).each do |f|
asset_name = f.to_s
.split(folder).last # Remove fullpath
.sub(/^\/*/, '') ### Remove leading '/'
app.config.assets.precompile << asset_name
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment