123456789_123456789_123456789_123456789_123456789_

Module: Sprockets::Resolve

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Included In:
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
Defined in: lib/sprockets/resolve.rb

Constant Summary

PathUtils - Included

SEPARATOR_PATTERN

Instance Method Summary

HTTPUtils - Included

#find_best_mime_type_match

Internal: Find the best qvalue match from an Array of available mime type options.

#find_best_q_match

Internal: Find the best qvalue match from an Array of available options.

#find_mime_type_matches

Internal: Find the all qvalue match from an Array of available mime type options.

#find_q_matches

Internal: Find all qvalue matches from an Array of available options.

#match_mime_type?

Public: Test mime type against mime range.

#match_mime_type_keys

Public: Return values from Hash where the key matches the mime type.

#parse_q_values

Internal: Parse Accept header quality values.

PathDependencyUtils - Included

#entries_with_dependencies

Internal: List directory entries and return a set of dependencies that would invalid the cached return result.

#stat_directory_with_dependencies

Internal: List directory filenames and associated Stats under a directory.

#stat_sorted_tree_with_dependencies

Internal: List directory filenames and associated Stats under an entire directory tree.

PathUtils - Included

#absolute_path?

On Windows, ALT_SEPARATOR is \ Delegate to Pathname since the logic gets complex.

#atomic_write

Public: Write to a file atomically.

#directory?

Public: Like File.directory?.

#entries

Public: A version of Dir.entries that filters out ‘.` files and ~ swap files.

#file?

Public: Like File.file?.

#find_matching_path_for_extensions

Internal: Match paths in a directory against available extensions.

#find_upwards

Internal: Find target basename checking upwards from path.

#join

Public: Joins path to base path.

#match_path_extname

Internal: Match path extnames against available extensions.

#path_extnames

Internal: Get path’s extensions.

#path_parents

Internal: Returns all parents for path.

#paths_split

Internal: Detect root path and base for file in a set of paths.

#relative_path?

Public: Check if path is explicitly relative.

#relative_path_from

Public: Get relative path from start to dest.

#set_pipeline

Public: Sets pipeline for path.

#split_subpath

Internal: Get relative path for root path and subpath.

#stat

Public: Like File.stat.

#stat_directory

Public: Stat all the files under a directory.

#stat_sorted_tree

Public: Recursive stat all the files under a directory in alphabetical order.

#stat_tree

Public: Recursive stat all the files under a directory.

URIUtils - Included

#build_asset_uri

Internal: Build Asset URI.

#build_file_digest_uri

Internal: Build file-digest dependency URI.

#encode_uri_query_params

Internal: Serialize hash of params into query string.

#join_file_uri

Internal: Join file: URI component parts into String.

#join_uri

Internal: Join URI component parts into String.

#parse_asset_uri

Internal: Parse Asset URI.

#parse_file_digest_uri

Internal: Parse file-digest dependency URI.

#parse_uri_query_params

Internal: Parse query string into hash of params.

#split_file_uri

Internal: Parse file: URI into component parts.

#split_uri

Internal: Parse URI into component parts.

#valid_asset_uri?

Internal: Check if String is a valid Asset URI.

Instance Method Details

#resolve(path, load_paths: config[:paths], accept: nil, pipeline: nil, base_path: nil)

Public: Find Asset URI for given a logical path by searching the environment’s load paths.

resolve("application.js")
# => "file:///path/to/app/javascripts/application.js?type=application/javascript"

An accept content type can be given if the logical path doesn’t have a format extension.

resolve("application", accept: "application/javascript")
# => "file:///path/to/app/javascripts/application.coffee?type=application/javascript"

The String Asset URI is returned or nil if no results are found.

[ GitHub ]

  
# File 'lib/sprockets/resolve.rb', line 24

def resolve(path, load_paths: config[:paths], accept: nil, pipeline: nil, base_path: nil)
  paths = load_paths

  if valid_asset_uri?(path)
    uri, deps = resolve_asset_uri(path)
  elsif absolute_path?(path)
    filename, type, deps = resolve_absolute_path(paths, path, accept)
  elsif relative_path?(path)
    filename, type, path_pipeline, deps, index_alias = resolve_relative_path(paths, path, base_path, accept)
  else
    filename, type, path_pipeline, deps, index_alias = resolve_logical_path(paths, path, accept)
  end

  if filename
    uri = build_asset_uri(filename, type: type, pipeline: pipeline || path_pipeline, index_alias: index_alias)
  end

  return uri, deps
end

#resolve!(path, **kargs)

Public: Same as resolve() but raises a FileNotFound exception instead of nil if no assets are found.

[ GitHub ]

  
# File 'lib/sprockets/resolve.rb', line 46

def resolve!(path, **kargs)
  uri, deps = resolve(path, **kargs)

  unless uri
    message = +"couldn't find file '#{path}'"

    if relative_path?(path) && kargs[:base_path]
      load_path, _ = paths_split(config[:paths], kargs[:base_path])
      message << " under '#{load_path}'"
    end

    message << " with type '#{kargs[:accept]}'" if kargs[:accept]

    load_paths = kargs[:load_paths] || config[:paths]
    message << "\nChecked in these paths: \n  #{ load_paths.join("\n  ") }"

    raise FileNotFound, message
  end

  return uri, deps
end