module RogerSassc::SassC::AssetFunctions

Defintion of asset functions

Public Instance Methods

asset_path(path) click to toggle source

The asset_path method will search for the file and if it exists will append a fingerprint hexdigest to the output url (?v=DIGEST)

# File lib/roger_sassc/sassc/asset_functions.rb, line 11
def asset_path(path)
  file = find_file(path)

  if File.exist?(file)
    digest = Digest::SHA256.file(file).hexdigest
    finger_printed_path = "#{path.value}?v=#{digest}"
  else
    finger_printed_path = path.value
  end

  ::SassC::Script::String.new("url(#{finger_printed_path})", :identifier)
end

Private Instance Methods

find_file(path) click to toggle source

Translate the given path to a path on disk

# File lib/roger_sassc/sassc/asset_functions.rb, line 27
def find_file(path)
  # Absolute url, starting with /
  if path.value.match(%r{^\/[^\/]})
    File.join(@options[:roger_html_path], path.value)
  else
    # Relative url - we can join from .scss position
    File.join(File.dirname(@options[:filename]), path.value)
  end
end