Module: Sprockets::Resolve
- Includes:
- HTTPUtils, PathDependencyUtils, URIUtils
- Defined in:
- lib/sprockets/resolve.rb
Constant Summary
Constants included from PathUtils
Instance Method Summary collapse
-
#resolve(path, options = {}) ⇒ Object
Public: Find Asset URI for given a logical path by searching the environment’s load paths.
-
#resolve!(path, options = {}) ⇒ Object
Public: Same as resolve() but raises a FileNotFound exception instead of nil if no assets are found.
Methods included from HTTPUtils
#find_best_mime_type_match, #find_best_q_match, #find_mime_type_matches, #find_q_matches, #match_mime_type?, #match_mime_type_keys, #parse_q_values
Methods included from PathDependencyUtils
#entries_with_dependencies, #file_digest_dependency_set, #stat_directory_with_dependencies, #stat_sorted_tree_with_dependencies
Methods included from URIUtils
#build_asset_uri, #build_file_digest_uri, #encode_uri_query_params, #join_file_uri, #join_uri, #parse_asset_uri, #parse_file_digest_uri, #parse_uri_query_params, #split_file_uri, #split_uri, #valid_asset_uri?
Methods included from PathUtils
#absolute_path?, #atomic_write, #directory?, #entries, #file?, #find_upwards, #match_path_extname, #path_extnames, #path_parents, #paths_split, #relative_path?, #split_subpath, #stat, #stat_directory, #stat_sorted_tree, #stat_tree
Instance Method Details
#resolve(path, options = {}) ⇒ Object
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.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/sprockets/resolve.rb', line 23 def resolve(path, = {}) path = path.to_s paths = [:load_paths] || config[:paths] accept = [:accept] 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, pipeline, deps = resolve_relative_path(paths, path, [:base_path], accept) else filename, type, pipeline, deps = resolve_logical_path(paths, path, accept) end if filename params = {} params[:type] = type if type params[:pipeline] = pipeline if pipeline params[:pipeline] = [:pipeline] if [:pipeline] uri = build_asset_uri(filename, params) end return uri, deps end |
#resolve!(path, options = {}) ⇒ Object
Public: Same as resolve() but raises a FileNotFound exception instead of nil if no assets are found.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/sprockets/resolve.rb', line 51 def resolve!(path, = {}) uri, deps = resolve(path, .merge(compat: false)) unless uri = "couldn't find file '#{path}'" if relative_path?(path) && [:base_path] load_path, _ = paths_split(config[:paths], [:base_path]) << " under '#{load_path}'" end << " with type '#{[:accept]}'" if [:accept] raise FileNotFound, end return uri, deps end |