From 2623ab55db0e2e077b7837b1e8130a2c7a07166d Mon Sep 17 00:00:00 2001 From: Nicolae Claudius Date: Wed, 25 Sep 2013 21:02:00 +0300 Subject: [PATCH] webshims issue --- Gemfile | 2 +- Gemfile.lock | 4 ++-- lib/tasks/assets_nondigest.rake | 29 +++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 lib/tasks/assets_nondigest.rake diff --git a/Gemfile b/Gemfile index 4c3fe33..d0f3b67 100644 --- a/Gemfile +++ b/Gemfile @@ -24,7 +24,7 @@ gem 'unicorn', '~> 4.6.3' gem 'sass-rails', '~> 4.0.0' gem 'compass-rails', github: 'milgner/compass-rails', branch: 'rails4' gem 'bootstrap-sass', github: 'thomas-mcdonald/bootstrap-sass', branch: '3' -gem 'webshims-rails', '~> 1.10.10' +gem 'webshims-rails', '~> 1.11.1' gem 'detect_timezone_rails', '~> 0.0.3' gem 'nprogress-rails', '~> 0.1.2.2' gem 'animate-rails', '~> 1.0.0' diff --git a/Gemfile.lock b/Gemfile.lock index b009bc9..3fec814 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -263,7 +263,7 @@ GEM raindrops (~> 0.7) warden (1.2.3) rack (>= 1.0) - webshims-rails (1.10.11) + webshims-rails (1.11.1) rails (> 3.1.0) xpath (2.0.0) nokogiri (~> 1.3) @@ -318,4 +318,4 @@ DEPENDENCIES unicorn (~> 4.6.3) userstamp (~> 2.0.2)! validates_hostname (~> 1.0.0)! - webshims-rails (~> 1.10.10) + webshims-rails (~> 1.11.1) diff --git a/lib/tasks/assets_nondigest.rake b/lib/tasks/assets_nondigest.rake new file mode 100644 index 0000000..acb08b5 --- /dev/null +++ b/lib/tasks/assets_nondigest.rake @@ -0,0 +1,29 @@ +# Needed for webshims +# https://github.com/whatcould/webshims-rails +# https://gist.github.com/eric1234/5692456 + +require 'fileutils' + +desc "Create nondigest versions of all digest assets" +task "assets:precompile" 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