Class: Middleman::Extensions::AssetHash::AssetHashManager

Inherits:
Object
  • Object
show all
Defined in:
lib/middleman-more/extensions/asset_hash.rb

Overview

Central class for managing asset_hash extension

Instance Method Summary collapse

Constructor Details

#initialize(app, exts, ignore) ⇒ AssetHashManager

Returns a new instance of AssetHashManager.



25
26
27
28
29
# File 'lib/middleman-more/extensions/asset_hash.rb', line 25

def initialize(app, exts, ignore)
  @app = app
  @exts = exts
  @ignore = ignore
end

Instance Method Details

#manipulate_resource_list(resources) ⇒ void

This method returns an undefined value.

Update the main sitemap resource list



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/middleman-more/extensions/asset_hash.rb', line 33

def manipulate_resource_list(resources)
  resources.each do |resource|
    next unless @exts.include? resource.ext
    next if @ignore.any? { |ignore| Middleman::Util.path_match(ignore, resource.destination_path) }

    if resource.template? # if it's a template, render it out
      digest = Digest::SHA1.hexdigest(resource.render)[0..7]
    else # if it's a static file, just hash it
      digest = Digest::SHA1.file(resource.source_file).hexdigest[0..7]
    end

    resource.destination_path = resource.destination_path.sub(/\.(\w+)$/) { |ext| "-#{digest}#{ext}" }
  end
end