turbo-sprockets-rails3 0.1.12 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -32,50 +32,51 @@ module Sprockets
|
|
32
32
|
end
|
33
33
|
next unless compile_path?(logical_path)
|
34
34
|
|
35
|
-
digest_path
|
36
|
-
|
37
|
-
|
35
|
+
if digest_path = @digest_files[logical_path]
|
36
|
+
abs_digest_path = "#{@target}/#{digest_path}"
|
37
|
+
abs_logical_path = "#{@target}/#{logical_path}"
|
38
38
|
|
39
|
-
|
39
|
+
mtime = File.mtime(abs_digest_path)
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
# Remove known digests from css & js
|
42
|
+
if abs_digest_path.match(/\.(?:js|css)$/)
|
43
|
+
asset_body = File.read(abs_digest_path)
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
45
|
+
# Find all hashes in the asset body with a leading '-'
|
46
|
+
asset_body.gsub!(DIGEST_REGEX) do |match|
|
47
|
+
# Only remove if known digest
|
48
|
+
$1.in?(@asset_digests.values) ? '' : match
|
49
|
+
end
|
50
50
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
51
|
+
# Write non-digest file
|
52
|
+
File.open abs_logical_path, 'w' do |f|
|
53
|
+
f.write asset_body
|
54
|
+
end
|
55
|
+
# Set modification and access times
|
56
|
+
File.utime(File.atime(abs_digest_path), mtime, abs_logical_path)
|
57
|
+
|
58
|
+
# Also write gzipped asset
|
59
|
+
File.open("#{abs_logical_path}.gz", 'wb') do |f|
|
60
|
+
gz = Zlib::GzipWriter.new(f, Zlib::BEST_COMPRESSION)
|
61
|
+
gz.mtime = mtime.to_i
|
62
|
+
gz.write asset_body
|
63
|
+
gz.close
|
64
|
+
end
|
65
65
|
|
66
|
-
|
66
|
+
env.logger.debug "Stripped digests, copied to #{logical_path}, and created gzipped asset"
|
67
67
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
68
|
+
else
|
69
|
+
# Otherwise, treat file as binary and copy it.
|
70
|
+
# Ignore paths that have no digests, such as READMEs
|
71
|
+
unless abs_digest_path == abs_logical_path
|
72
|
+
FileUtils.cp_r abs_digest_path, abs_logical_path, :remove_destination => true
|
73
|
+
env.logger.debug "Copied binary asset to #{logical_path}"
|
74
|
+
|
75
|
+
# Copy gzipped asset if exists
|
76
|
+
if File.exist? "#{abs_digest_path}.gz"
|
77
|
+
FileUtils.cp_r "#{abs_digest_path}.gz", "#{abs_logical_path}.gz", :remove_destination => true
|
78
|
+
env.logger.debug "Copied gzipped asset to #{logical_path}.gz"
|
79
|
+
end
|
79
80
|
end
|
80
81
|
end
|
81
82
|
end
|
@@ -34,27 +34,27 @@ if defined?(Sprockets::StaticCompiler)
|
|
34
34
|
|
35
35
|
# Fetch asset without any processing or compression,
|
36
36
|
# to calculate a digest of the concatenated source files
|
37
|
-
asset = env.find_asset(logical_path, :process => false)
|
37
|
+
if asset = env.find_asset(logical_path, :process => false)
|
38
|
+
@source_digests[logical_path] = asset.digest
|
38
39
|
|
39
|
-
|
40
|
+
# Recompile if digest has changed or compiled digest file is missing
|
41
|
+
current_digest_file = @current_digest_files[logical_path]
|
40
42
|
|
41
|
-
|
42
|
-
|
43
|
+
if @source_digests[logical_path] != @current_source_digests[logical_path] ||
|
44
|
+
!(current_digest_file && File.exists?("#{@target}/#{current_digest_file}"))
|
43
45
|
|
44
|
-
|
45
|
-
|
46
|
+
if asset = env.find_asset(logical_path)
|
47
|
+
@digest_files[logical_path] = write_asset(asset)
|
48
|
+
end
|
46
49
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
else
|
52
|
-
# Set asset file from manifest.yml
|
53
|
-
digest_file = @current_digest_files[logical_path]
|
54
|
-
@digest_files[logical_path] = digest_file
|
50
|
+
else
|
51
|
+
# Set asset file from manifest.yml
|
52
|
+
digest_file = @current_digest_files[logical_path]
|
53
|
+
@digest_files[logical_path] = digest_file
|
55
54
|
|
56
|
-
|
57
|
-
|
55
|
+
env.logger.debug "Not compiling #{logical_path}, sources digest has not changed " <<
|
56
|
+
"(#{@source_digests[logical_path][0...7]})"
|
57
|
+
end
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|