Class: Middleman::Extensions::CacheBuster

Inherits:
Middleman::Extension show all
Defined in:
lib/middleman-more/extensions/cache_buster.rb

Overview

The Cache Buster extension

Instance Attribute Summary

Attributes inherited from Middleman::Extension

#app, #options

Instance Method Summary collapse

Methods inherited from Middleman::Extension

activate, activated_extension, after_extension_activated, clear_after_extension_callbacks, config, extension_name, helpers, option, register

Constructor Details

#initialize(app, options_hash = {}, &block) ⇒ CacheBuster

Returns a new instance of CacheBuster.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/middleman-more/extensions/cache_buster.rb', line 4

def initialize(app, options_hash={}, &block)
  super

  # After compass is setup, make it use the registered cache buster
  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(root, build_dir), source)
      if File.readable?(real_path)
        File.mtime(real_path).strftime("%s")
      else
        logger.warn "WARNING: '#{File.basename(path)}' was not found (or cannot be read) in #{File.dirname(real_path)}"
      end
    end
  end if app.respond_to?(:compass_config)
end