Skip to content
This repository has been archived by the owner on Jun 10, 2018. It is now read-only.

Commit

Permalink
Push source metadata processing logic to process
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Apr 18, 2014
1 parent fb15915 commit 6ceaacd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 28 deletions.
35 changes: 10 additions & 25 deletions lib/sprockets/base.rb
Expand Up @@ -320,25 +320,15 @@ def build_asset_hash(filename, bundle = true)
end

def build_processed_asset_hash(asset)
encoding = encoding_for_mime_type(asset[:content_type])
data = read_unicode_file(asset[:filename], encoding)
filename = asset[:filename]
encoding = encoding_for_mime_type(asset[:content_type])
data = read_unicode_file(filename, encoding)
processed = process(attributes_for(filename).processors, filename, data)

result = process(
attributes_for(asset[:filename]).processors,
asset[:filename],
data
)

asset.merge(
asset.merge(processed).merge(
type: 'processed',
source: result[:data],
length: result[:data].bytesize,
digest: digest.update(result[:data]).hexdigest,
required_paths: (result[:required_paths] + [asset[:filename]]),
stubbed_paths: result[:stubbed_paths].to_a,
dependency_paths: result[:dependency_paths].to_a,
dependency_digest: dependencies_hexdigest(result[:dependency_paths]),
mtime: result[:dependency_paths].map { |path| stat(path).mtime }.max.to_i
dependency_digest: dependencies_hexdigest(processed[:dependency_paths]),
mtime: processed[:dependency_paths].map { |path| stat(path).mtime }.max.to_i
)
end

Expand Down Expand Up @@ -369,22 +359,17 @@ def build_bundled_asset_hash(asset)
asset_hash
end

source = process(
asset.merge(process(
bundle_processors(asset[:content_type]),
asset[:filename],
required_asset_hashes.map { |h| h[:source] }.join
)[:data]

asset.merge({
)).merge({
type: 'bundled',
required_paths: required_paths.to_a,
required_asset_hashes: required_asset_hashes,
dependency_paths: dependency_paths.to_a,
dependency_digest: dependencies_hexdigest(dependency_paths),
mtime: required_asset_hashes.map { |h| h[:mtime] }.max,
source: source,
length: source.bytesize,
digest: digest.update(source).hexdigest
mtime: required_asset_hashes.map { |h| h[:mtime] }.max
})
end

Expand Down
12 changes: 9 additions & 3 deletions lib/sprockets/processing.rb
Expand Up @@ -190,11 +190,17 @@ def process(processors, filename, data)
end
end

unless required_paths.include?(filename)
required_paths << filename
end

{
data: data,
source: data,
length: data.bytesize,
digest: digest.update(data).hexdigest, # FIXME: Avoid Env#digest
required_paths: required_paths,
stubbed_paths: stubbed_paths,
dependency_paths: dependency_paths
stubbed_paths: stubbed_paths.to_a,
dependency_paths: dependency_paths.to_a
}
end

Expand Down
1 change: 1 addition & 0 deletions test/test_manifest.rb
@@ -1,6 +1,7 @@
require 'sprockets_test'
require 'fileutils'
require 'tmpdir'
require 'securerandom'

class TestManifest < Sprockets::TestCase
def setup
Expand Down

0 comments on commit 6ceaacd

Please sign in to comment.