Sha256: f0d5b08936c44e2f57a4bd02ed9ebc55f543bf7e5405cab55bf9ba80e632f363

Contents?: true

Size: 1.47 KB

Versions: 64

Compression:

Stored size: 1.47 KB

Contents

module Middleman::Features::CacheBuster
  class << self
    def registered(app)
      app.register_asset_handler :cache_buster do |path, prefix, request|
        http_path = app.before_asset_handler(:cache_buster, path, prefix, request)

        if http_path.include?("://") || !%w(.css .png .jpg .js .gif).include?(File.extname(http_path))
          http_path
        else
          begin
            prefix = app.images_dir if prefix == app.http_images_path
          rescue
          end

          real_path_static  = File.join(app.views, prefix, path)

          if File.readable?(real_path_static)
            http_path << "?" + File.mtime(real_path_static).strftime("%s") 
          elsif app.build?
            real_path_dynamic = File.join(app.root, app.build_dir, prefix, path)
            http_path << "?" + File.mtime(real_path_dynamic).strftime("%s") if File.readable?(real_path_dynamic)
          end

          http_path
        end
      end

      app.compass_config do |config|
        config.asset_cache_buster do |path, real_path|
          real_path = real_path.path if real_path.is_a? File
          real_path = real_path.gsub(File.join(app.root, app.build_dir), app.views)
          if File.readable?(real_path)
            File.mtime(real_path).strftime("%s") 
          else
            $stderr.puts "WARNING: '#{File.basename(path)}' was not found (or cannot be read) in #{File.dirname(real_path)}"
          end
        end
      end
    end
    alias :included :registered
  end
end

Version data entries

64 entries across 64 versions & 1 rubygems

Version Path
middleman-2.0.16.1-x86-mingw32 lib/middleman/features/cache_buster.rb
middleman-2.0.16.1 lib/middleman/features/cache_buster.rb
middleman-2.0.16-x86-mingw32 lib/middleman/features/cache_buster.rb
middleman-2.0.16 lib/middleman/features/cache_buster.rb
middleman-2.0.15.4-x86-mingw32 lib/middleman/features/cache_buster.rb
middleman-2.0.15.4 lib/middleman/features/cache_buster.rb
middleman-2.0.15.3-x86-mingw32 lib/middleman/features/cache_buster.rb
middleman-2.0.15.3 lib/middleman/features/cache_buster.rb
middleman-2.0.15.2-x86-mingw32 lib/middleman/features/cache_buster.rb
middleman-2.0.15.2 lib/middleman/features/cache_buster.rb
middleman-2.0.15.1-x86-mingw32 lib/middleman/features/cache_buster.rb
middleman-2.0.15.1 lib/middleman/features/cache_buster.rb
middleman-2.0.15-x86-mingw32 lib/middleman/features/cache_buster.rb
middleman-2.0.15 lib/middleman/features/cache_buster.rb
middleman-2.0.14-x86-mingw32 lib/middleman/features/cache_buster.rb
middleman-2.0.14 lib/middleman/features/cache_buster.rb
middleman-2.0.14.pre2-x86-mingw32 lib/middleman/features/cache_buster.rb
middleman-2.0.14.pre2 lib/middleman/features/cache_buster.rb
middleman-2.0.13.2-x86-mingw32 lib/middleman/features/cache_buster.rb
middleman-2.0.14.pre-x86-mingw32 lib/middleman/features/cache_buster.rb