Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #26 #27

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions lib/non-stupid-digest-assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class Manifest
def compile_with_non_digest *args
compile_without_non_digest *args

assets_path = ::Rails.root.join('public', 'assets', 'manifest*.json')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this line be replaced with @filename. The initializer for the Manifest class allows for passing a completely different manifest file name.

https://github.com/sstephenson/sprockets/blob/master/lib/sprockets/manifest.rb#L18-L54

manifest_files = Dir.glob(assets_path)
manifests = {}
manifest_files.each { |f| manifests[f] = File.read(f) }

NonStupidDigestAssets.files(files).each do |(digest_path, info)|
full_digest_path = File.join dir, digest_path
full_digest_gz_path = "#{full_digest_path}.gz"
Expand All @@ -34,18 +39,36 @@ def compile_with_non_digest *args
if File.exists? full_digest_path
logger.debug "Writing #{full_non_digest_path}"
FileUtils.copy_file full_digest_path, full_non_digest_path, :preserve_attributes
logger.info "Clearing #{full_digest_path} and modifying manifest"
FileUtils.rm full_digest_path
manifests_swap_filenames manifests, digest_path, info['logical_path']
else
logger.debug "Could not find: #{full_digest_path}"
end
if File.exists? full_digest_gz_path
logger.debug "Writing #{full_non_digest_gz_path}"
FileUtils.copy_file full_digest_gz_path, full_non_digest_gz_path, :preserve_attributes
logger.info "Clearing #{full_digest_gz_path}"
FileUtils.rm full_digest_gz_path
else
logger.debug "Could not find: #{full_digest_gz_path}"
end
end

manifests.each { |f, m|
File.open(f, 'w') do |fh|
fh.write m
end
}
end

alias_method_chain :compile, :non_digest

private
def manifests_swap_filenames manifests, old, new
manifests.each do |f, m|
m.gsub!(old, new)
end
end
end
end