Created
          January 31, 2014 08:50 
        
      - 
      
- 
        Save freegenie/8728605 to your computer and use it in GitHub Desktop. 
    Supposed to copy assets to non fingerprinted name
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | namespace :app do | |
| task :nonfingerprint_assets => :environment do | |
| fingerprint = /\-[0-9a-f]{32}\./ | |
| filemap = {} | |
| Dir["public/assets/**/*"].each do |file| | |
| next if file !~ fingerprint | |
| next if File.directory?(file) | |
| next if file.split(File::Separator).last =~ /^manifest/ | |
| nondigest = file.sub fingerprint, '.' | |
| if filemap[nondigest] | |
| if File.mtime(file) > filemap[nondigest][:time] | |
| filemap[nondigest] = {file: file, time: File.mtime(file)} | |
| end | |
| else | |
| filemap[nondigest] = {file: file, time: File.mtime(file)} | |
| end | |
| end | |
| filemap.each do |nondigest, v| | |
| FileUtils.cp v[:file], nondigest, verbose: true | |
| end | |
| end | |
| desc 'Precompile assets and symlink non fingerprint versions' | |
| task :prepare_assets => :environment do | |
| ENV['RAILS_ENV'] = 'production' | |
| Rake::Task['assets:clean'].invoke | |
| Rake::Task['assets:precompile'].invoke | |
| Rake::Task['app:nonfingerprint_assets'].invoke | |
| end | |
| end | |
| Rake::Task['assets:precompile'].enhance do | |
| puts "Invoke nonfingerprint_assets" | |
| Rake::Task['app:nonfingerprint_assets'].invoke | |
| end | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment