Module: Sprockets::Loader

Includes:
DigestUtils, Engines, 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 Utils

Utils::UNBOUND_METHODS_BIND_TO_ANY_OBJECT

Constants included from ProcessorUtils

ProcessorUtils::VALID_METADATA_COMPOUND_TYPES, ProcessorUtils::VALID_METADATA_TYPES, ProcessorUtils::VALID_METADATA_VALUE_TYPES

Constants included from PathUtils

PathUtils::SEPARATOR_PATTERN

Constants included from DigestUtils

DigestUtils::DIGEST_SIZES, DigestUtils::NI_HASH_ALGORITHMS

Instance Method Summary collapse

Methods included from Engines

#engine_mime_types, #engines, #register_engine

Methods included from Utils

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

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 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, #valid_processor_metadata_value?, #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, #file_digest_dependency_set, #stat_directory_with_dependencies, #stat_sorted_tree_with_dependencies

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

Methods included from Transformers

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

Methods included from DigestUtils

#detect_digest_class, #digest, #digest_class, #integrity_uri, #pack_base64digest, #pack_hexdigest, #pack_urlsafe_base64digest

Instance Method Details

#load(uri) ⇒ Object

Public: Load Asset by AssetURI.

uri - AssetURI

Returns Asset.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/sprockets/loader.rb', line 26

def load(uri)
  filename, params = parse_asset_uri(uri)
  if params.key?(:id)
    unless asset = cache.get("asset-uri:#{VERSION}:#{uri}", true)
      id = params.delete(:id)
      uri_without_id = build_asset_uri(filename, params)
      asset = load_asset_by_uri(uri_without_id, filename, params)
      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(uri, filename) do |paths|
      if paths
        digest = digest(resolve_dependencies(paths))
        if id_uri = cache.get("asset-uri-digest:#{VERSION}:#{uri}:#{digest}", true)
          cache.get("asset-uri:#{VERSION}:#{id_uri}", true)
        end
      else
        load_asset_by_uri(uri, filename, params)
      end
    end
  end
  Asset.new(self, asset)
end