Class: Proscenium::Middleware::Engines

Inherits:
Esbuild show all
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 << self
  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

#attempt

Methods inherited from Base

attempt, #initialize, #renderable!

Constructor Details

This class inherits a constructor from Proscenium::Middleware::Base

Instance Method Details

#engineObject



30
31
32
33
34
# File 'lib/proscenium/middleware/engines.rb', line 30

def engine
  @engine ||= Proscenium.config.engines.find do |x|
    @request.path.start_with?("/#{x.engine_name}")
  end
end

#engine_nameObject



36
37
38
# File 'lib/proscenium/middleware/engines.rb', line 36

def engine_name
  ui? ? 'proscenium/ui' : engine.engine_name
end

#real_pathObject



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_readableObject



26
27
28
# File 'lib/proscenium/middleware/engines.rb', line 26

def root_for_readable
  ui? ? Proscenium.ui_path : engine.root
end

#ui?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/proscenium/middleware/engines.rb', line 40

def ui?
  @request.path.start_with?('/proscenium/ui/')
end