Sha256: 4f4145ec2d018d74494f646b437f27ad42aa4195b22807382190b6895901cbbc

Contents?: true

Size: 1.08 KB

Versions: 56

Compression:

Stored size: 1.08 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 (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

56 entries across 56 versions & 1 rubygems

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