Class: Proscenium::Middleware::Engines
- Defined in:
- lib/proscenium/middleware/engines.rb
Overview
This middleware handles requests for assets in Rails engines. An engine that wants to expose its assets via Proscenium to the application must add itself to the list of engines in the Proscenium config options ‘Proscenium.config.engines`.
For example, we have a gem that exposes a Rails engine.
module Gem1
class Engine < ::Rails::Engine
config.proscenium.engines['gem1'] = root
end
end
When this gem is installed in any Rails application, its assets will be available at the URL ‘/gem1/…`. For example, if the gem has a file `lib/styles.css`, it can be requested at `/gem1/lib/styles.css`.
Instance Method Summary collapse
Methods inherited from Esbuild
Methods inherited from Base
attempt, #initialize, #renderable!
Constructor Details
This class inherits a constructor from Proscenium::Middleware::Base
Instance Method Details
#engine ⇒ Object
30 31 32 33 34 |
# File 'lib/proscenium/middleware/engines.rb', line 30 def engine @engine ||= Proscenium.config.engines.find do |k, _| @request.path.start_with?("/#{k}") end end |
#engine_name ⇒ Object
36 37 38 |
# File 'lib/proscenium/middleware/engines.rb', line 36 def engine_name engine.first end |
#real_path ⇒ Object
22 23 24 |
# File 'lib/proscenium/middleware/engines.rb', line 22 def real_path @real_path ||= Pathname.new(@request.path.delete_prefix("/#{engine_name}")).to_s end |
#root_for_readable ⇒ Object
26 27 28 |
# File 'lib/proscenium/middleware/engines.rb', line 26 def root_for_readable engine.last end |