Module: Nanoc3::Helpers::CacheBusting

Defined in:
lib/nanoc3/helpers/cache_busting.rb

Instance Method Summary collapse

Instance Method Details

#cachebust?(item) ⇒ Boolean

Test if we want to filter the output filename for a given item. This is logic used in the Rules file, but doesn’t belong there.

Examples:

Determining whether to rewrite an output filename

# in your Rules file
route '/assets/*' do
  hash = cachebust?(item) ? cachebusting_hash(item) : ''
  item.identifier + hash + '.' + item[:extension]
end

Parameters:

  • item (Item)

    is the item to test

Returns:

  • (Boolean)


17
18
19
# File 'lib/nanoc3/helpers/cache_busting.rb', line 17

def cachebust?(item)
  Nanoc3::Cachebuster.should_apply_fingerprint_to_file?(item)
end

#fingerprint(filename) ⇒ String

TODO:

Also allow passing in an item rather than a path

Get a unique fingerprint for a file’s content. This currently uses an MD5 hash of the file contents.

Parameters:

  • filename (String)

    is the path to the file to fingerprint.

Returns:

  • (String)

    file fingerprint



27
28
29
# File 'lib/nanoc3/helpers/cache_busting.rb', line 27

def fingerprint(filename)
  Nanoc3::Cachebuster.fingerprint_file(filename)
end