Sha256: f6273d7c89c75087ae2eb36cb67ea78ec7afadf107ba0a3779d0cf51ad8b4cc0

Contents?: true

Size: 1.2 KB

Versions: 34

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

require 'active_support/current_attributes'

module Proscenium
  class Resolver < ActiveSupport::CurrentAttributes
    # TODO: cache this across requests in production.
    attribute :resolved

    # Resolve the given `path` to a URL path.
    #
    # @param path [String] Can be URL path, file system path, or bare specifier (ie. NPM package).
    # @return [String] URL path.
    #
    # rubocop:disable Metrics/*
    def self.resolve(path)
      self.resolved ||= {}

      self.resolved[path] ||= begin
        if path.start_with?('./', '../')
          raise ArgumentError, 'path must be an absolute file system or URL path'
        end

        if path.start_with?('@proscenium/')
          "/#{path}"
        elsif path.start_with?(Proscenium.ui_path.to_s)
          path.delete_prefix Proscenium.root.join('lib').to_s
        elsif (engine = Proscenium.config.engines.find { |e| path.start_with? "#{e.root}/" })
          path.sub(/^#{engine.root}/, "/#{engine.engine_name}")
        elsif path.start_with?("#{Rails.root}/")
          path.delete_prefix Rails.root.to_s
        else
          Builder.resolve path
        end
      end
    end
    # rubocop:enable Metrics/*
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
proscenium-0.19.0.beta4-x86_64-linux lib/proscenium/resolver.rb
proscenium-0.19.0.beta4-aarch64-linux lib/proscenium/resolver.rb
proscenium-0.19.0.beta4-arm64-darwin lib/proscenium/resolver.rb
proscenium-0.19.0.beta4-x86_64-darwin lib/proscenium/resolver.rb
proscenium-0.19.0.beta4 lib/proscenium/resolver.rb
proscenium-0.19.0.beta3-x86_64-linux lib/proscenium/resolver.rb
proscenium-0.19.0.beta3-aarch64-linux lib/proscenium/resolver.rb
proscenium-0.19.0.beta3-arm64-darwin lib/proscenium/resolver.rb
proscenium-0.19.0.beta3-x86_64-darwin lib/proscenium/resolver.rb
proscenium-0.19.0.beta3 lib/proscenium/resolver.rb
proscenium-0.18.0-x86_64-linux lib/proscenium/resolver.rb
proscenium-0.18.0-aarch64-linux lib/proscenium/resolver.rb
proscenium-0.18.0-arm64-darwin lib/proscenium/resolver.rb
proscenium-0.18.0-x86_64-darwin lib/proscenium/resolver.rb
proscenium-0.17.0-x86_64-linux lib/proscenium/resolver.rb
proscenium-0.17.0-aarch64-linux lib/proscenium/resolver.rb
proscenium-0.17.0-arm64-darwin lib/proscenium/resolver.rb
proscenium-0.17.0-x86_64-darwin lib/proscenium/resolver.rb
proscenium-0.16.0-aarch64-linux lib/proscenium/resolver.rb
proscenium-0.16.0-arm64-darwin lib/proscenium/resolver.rb