Class: Middleman::Extensions::CacheBuster

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

Overview

The Cache Buster extension

Constant Summary

Constants included from Contracts

Contracts::PATH_MATCHER

Instance Attribute Summary

Attributes inherited from Middleman::Extension

#app, #options

Instance Method Summary collapse

Methods inherited from Middleman::Extension

activated_extension, #add_exposed_to_context, #after_build, after_extension_activated, #after_extension_activated, #before_build, #before_configuration, clear_after_extension_callbacks, config, expose_to_application, expose_to_config, expose_to_template, helpers, #manipulate_resource_list, option, #ready, resources

Methods included from Contracts

#Contract

Constructor Details

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

Returns a new instance of CacheBuster.



7
8
9
10
11
# File 'lib/middleman-core/extensions/cache_buster.rb', line 7

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

  require 'middleman-core/middleware/inline_url_rewriter'
end

Instance Method Details

#after_configurationObject



13
14
15
16
17
18
19
20
21
# File 'lib/middleman-core/extensions/cache_buster.rb', line 13

def after_configuration
  app.use ::Middleman::Middleware::InlineURLRewriter,
          id: :cache_buster,
          url_extensions: options.exts,
          source_extensions: options.sources,
          ignore: options.ignore,
          middleman_app: app,
          proc: method(:rewrite_url)
end

#rewrite_url(asset_path, _dirpath, _request_path) ⇒ Object



24
25
26
# File 'lib/middleman-core/extensions/cache_buster.rb', line 24

def rewrite_url(asset_path, _dirpath, _request_path)
  asset_path + '?' + Time.now.strftime('%s')
end