Module: Sprockets::Loader

Includes:
DigestUtils, Mime, PathUtils, Processing, ProcessorUtils, Resolve, Transformers, URIUtils
Included in:
Base
Defined in:
lib/sprockets/loader.rb

Overview

The loader phase takes a asset URI location and returns a constructed Asset object.

Constant Summary

Constants included from ProcessorUtils

ProcessorUtils::VALID_METADATA_COMPOUND_TYPES, ProcessorUtils::VALID_METADATA_COMPOUND_TYPES_HASH, ProcessorUtils::VALID_METADATA_TYPES, ProcessorUtils::VALID_METADATA_VALUE_TYPES, ProcessorUtils::VALID_METADATA_VALUE_TYPES_HASH

Constants included from PathUtils

PathUtils::SEPARATOR_PATTERN

Constants included from DigestUtils

DigestUtils::DIGEST_SIZES, DigestUtils::HASH_ALGORITHMS

Instance Method Summary collapse

Methods included from Mime

#mime_exts, #mime_type_charset_detecter, #mime_types, #read_file, #register_mime_type

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 Utils

#concat_javascript_sources, #dfs, #dfs_paths, #duplicable?, #hash_reassoc, #hash_reassoc1, #module_include, #string_end_with_semicolon?

Methods included from Processing

#bundle_processors, #pipelines, #postprocessors, #preprocessors, #register_bundle_metadata_reducer, #register_bundle_processor, #register_pipeline, #register_postprocessor, #register_preprocessor, #unregister_bundle_processor, #unregister_postprocessor, #unregister_preprocessor

Methods included from ProcessorUtils

#call_processor, #call_processors, #compose_processors, #processor_cache_key, #processors_cache_keys, #validate_processor_result!

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 Resolve

#resolve, #resolve!

Methods included from PathDependencyUtils

#entries_with_dependencies, #stat_directory_with_dependencies, #stat_sorted_tree_with_dependencies

Methods included from PathUtils

#absolute_path?, #atomic_write, #directory?, #entries, #file?, #find_matching_path_for_extensions, #find_upwards, #join, #match_path_extname, #path_extnames, #path_parents, #paths_split, #relative_path?, #relative_path_from, #set_pipeline, #split_subpath, #stat, #stat_directory, #stat_sorted_tree, #stat_tree

Methods included from Transformers

#compose_transformers, #expand_transform_accepts, #register_transformer, #register_transformer_suffix, #resolve_transform_type, #transformers

Methods included from DigestUtils

#already_digested?, #detect_digest_class, #digest, #digest_class, #hexdigest, #hexdigest_integrity_uri, #integrity_uri, #pack_base64digest, #pack_hexdigest, #pack_urlsafe_base64digest, #unpack_hexdigest

Instance Method Details

#load(uri) ⇒ Object

Public: Load Asset by Asset URI.

uri - A String containing complete URI to a file including schema

and full path such as:
"file:///Path/app/assets/js/app.js?type=application/javascript"

Returns Asset.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/sprockets/loader.rb', line 31

def load(uri)
  unloaded = UnloadedAsset.new(uri, self)
  if unloaded.params.key?(:id)
    unless asset = asset_from_cache(unloaded.asset_key)
      id = unloaded.params.delete(:id)
      uri_without_id = build_asset_uri(unloaded.filename, unloaded.params)
      asset = load_from_unloaded(UnloadedAsset.new(uri_without_id, self))
      if asset[:id] != id
        @logger.warn "Sprockets load error: Tried to find #{uri}, but latest was id #{asset[:id]}"
      end
    end
  else
    asset = fetch_asset_from_dependency_cache(unloaded) do |paths|
      # When asset is previously generated, its "dependencies" are stored in the cache.
      # The presence of `paths` indicates dependencies were stored.
      # We can check to see if the dependencies have not changed by "resolving" them and
      # generating a digest key from the resolved entries. If this digest key has not
      # changed, the asset will be pulled from cache.
      #
      # If this `paths` is present but the cache returns nothing then `fetch_asset_from_dependency_cache`
      # will confusingly be called again with `paths` set to nil where the asset will be
      # loaded from disk.
      if paths
        digest = DigestUtils.digest(resolve_dependencies(paths))
        if uri_from_cache = cache.get(unloaded.digest_key(digest), true)
          asset_from_cache(UnloadedAsset.new(uri_from_cache, self).asset_key)
        end
      else
        load_from_unloaded(unloaded)
      end
    end
  end
  Asset.new(asset)
end