Sha256: 26b6e5ba09d0f37dae5fbb77d75e6aa6a7de60e07c908cb1c8f35afa908a4a3b

Contents?: true

Size: 1.68 KB

Versions: 43

Compression:

Stored size: 1.68 KB

Contents

module Middleman::Features::CacheBuster
  class << self
    def registered(app)
      Middleman::Assets.register :cache_buster do |path, prefix, request|
        http_path = Middleman::Assets.before(: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 = Middleman::Server.images_dir if prefix == Middleman::Server.http_images_path
          rescue
          end

          real_path_static  = File.join(Middleman::Server.public, prefix, path)

          if File.readable?(real_path_static)
            http_path << "?" + File.mtime(real_path_static).strftime("%s") 
          elsif Middleman::Server.environment == :build
            real_path_dynamic = File.join(Middleman::Server.root, Middleman::Server.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.after_feature_init do 
        ::Compass.configuration 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(Middleman::Server.root, Middleman::Server.build_dir), Middleman::Server.public)
            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
    end
    alias :included :registered
  end
end

Version data entries

43 entries across 43 versions & 2 rubygems

Version Path
beans-middleman-1.0.14 lib/middleman/features/cache_buster.rb
beans-middleman-1.0.13 lib/middleman/features/cache_buster.rb
beans-middleman-1.0.12 lib/middleman/features/cache_buster.rb
beans-middleman-1.0.11 lib/middleman/features/cache_buster.rb
middleman-1.2.8 lib/middleman/features/cache_buster.rb
middleman-1.2.7 lib/middleman/features/cache_buster.rb
middleman-1.2.6 lib/middleman/features/cache_buster.rb
middleman-1.2.5 lib/middleman/features/cache_buster.rb
middleman-1.2.4 lib/middleman/features/cache_buster.rb
middleman-1.2.3 lib/middleman/features/cache_buster.rb
middleman-1.2.2 lib/middleman/features/cache_buster.rb
middleman-1.2.1 lib/middleman/features/cache_buster.rb
beans-middleman-1.0.9 lib/middleman/features/cache_buster.rb
middleman-1.2.0 lib/middleman/features/cache_buster.rb
middleman-1.1.6 lib/middleman/features/cache_buster.rb
middleman-1.1.5 lib/middleman/features/cache_buster.rb
middleman-1.1.4 lib/middleman/features/cache_buster.rb
middleman-1.1.3 lib/middleman/features/cache_buster.rb
middleman-1.1.2 lib/middleman/features/cache_buster.rb
middleman-1.1.1.a lib/middleman/features/cache_buster.rb