def load_asset_by_uri(uri, filename, params)
def load_asset_by_uri(uri, filename, params)
# Internal assertion, should be routed through load_asset_by_id_uri
if params.key?(:id)
raise ArgumentError, "expected uri to have no id: #{uri}"
end
unless file?(filename)
raise FileNotFound, "could not find file: #{filename}"
end
load_path, logical_path = paths_split(config[:paths], filename)
unless load_path
raise FileOutsidePaths, "#{filename} is no longer under a load path: #{self.paths.join(', ')}"
end
logical_path, file_type, engine_extnames, _ = parse_path_extnames(logical_path)
logical_path = normalize_logical_path(logical_path)
name = logical_path
if pipeline = params[:pipeline]
logical_path += ".#{pipeline}"
end
if type = params[:type]
logical_path += config[:mime_types][type][:extensions].first
end
if type != file_type && !config[:transformers][file_type][type]
raise ConversionError, "could not convert #{file_type.inspect} to #{type.inspect}"
end
processors = processors_for(type, file_type, engine_extnames, pipeline)
processors_dep_uri = build_processors_uri(type, file_type, engine_extnames, pipeline)
dependencies = config[:dependencies] + [processors_dep_uri]
# Read into memory and process if theres a processor pipeline
if processors.any?
result = call_processors(processors, {
environment: self,
cache: self.cache,
uri: uri,
filename: filename,
load_path: load_path,
name: name,
content_type: type,
metadata: { dependencies: dependencies }
})
source = result.delete(:data)
metadata = result.merge!(
charset: source.encoding.name.downcase,
digest: digest(source),
length: source.bytesize
)
else
metadata = {
digest: file_digest(filename),
length: self.stat(filename).size,
dependencies: dependencies
}
end
asset = {
uri: uri,
load_path: load_path,
filename: filename,
name: name,
logical_path: logical_path,
content_type: type,
source: source,
metadata: metadata,
integrity: integrity_uri(metadata[:digest], type),
dependencies_digest: digest(resolve_dependencies(metadata[:dependencies]))
}
asset[:id] = pack_hexdigest(digest(asset))
asset[:uri] = build_asset_uri(filename, params.merge(id: asset[:id]))
# Deprecated: Avoid tracking Asset mtime
asset[:mtime] = metadata[:dependencies].map { |u|
if u.start_with?("file-digest:")
s = self.stat(parse_file_digest_uri(u))
s ? s.mtime.to_i : 0
else
0
end
}.max
cache.set("asset-uri:#{VERSION}:#{asset[:uri]}", asset, true)
cache.set("asset-uri-digest:#{VERSION}:#{uri}:#{asset[:dependencies_digest]}", asset[:uri], true)
asset
end