Sha256: da1d18e7967ccdacca05314e8b8fc10bef5af3dcdd32435f06eef87a83c36ed6

Contents?: true

Size: 1.14 KB

Versions: 56

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

module Proscenium
  class Middleware
    # 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`.
    #
    class Engines < Esbuild
      def real_path
        @real_path ||= Pathname.new(@request.path.delete_prefix("/#{engine.engine_name}")).to_s
      end

      def root_for_readable
        engine.root
      end

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

Version data entries

56 entries across 56 versions & 1 rubygems

Version Path
proscenium-0.15.0.beta.4-x86_64-linux lib/proscenium/middleware/engines.rb
proscenium-0.15.0.beta.4-aarch64-linux lib/proscenium/middleware/engines.rb
proscenium-0.15.0.beta.4-arm64-darwin lib/proscenium/middleware/engines.rb
proscenium-0.15.0.beta.4-x86_64-darwin lib/proscenium/middleware/engines.rb
proscenium-0.15.0.beta.3-x86_64-linux lib/proscenium/middleware/engines.rb
proscenium-0.15.0.beta.3-aarch64-linux lib/proscenium/middleware/engines.rb
proscenium-0.15.0.beta.3-arm64-darwin lib/proscenium/middleware/engines.rb
proscenium-0.15.0.beta.3-x86_64-darwin lib/proscenium/middleware/engines.rb
proscenium-0.15.0.beta.2-x86_64-linux lib/proscenium/middleware/engines.rb
proscenium-0.15.0.beta.2-aarch64-linux lib/proscenium/middleware/engines.rb
proscenium-0.15.0.beta.2-arm64-darwin lib/proscenium/middleware/engines.rb
proscenium-0.15.0.beta.2-x86_64-darwin lib/proscenium/middleware/engines.rb
proscenium-0.15.0.beta.1-x86_64-linux lib/proscenium/middleware/engines.rb
proscenium-0.15.0.beta.1-aarch64-linux lib/proscenium/middleware/engines.rb
proscenium-0.15.0.beta.1-arm64-darwin lib/proscenium/middleware/engines.rb
proscenium-0.15.0.beta.1-x86_64-darwin lib/proscenium/middleware/engines.rb
proscenium-0.14.0-x86_64-linux lib/proscenium/middleware/engines.rb
proscenium-0.14.0-aarch64-linux lib/proscenium/middleware/engines.rb
proscenium-0.14.0-arm64-darwin lib/proscenium/middleware/engines.rb
proscenium-0.14.0-x86_64-darwin lib/proscenium/middleware/engines.rb