jekyll-responsive-image/lib/jekyll/responsive_image/utils.rb

32 lines
810 B
Ruby
Raw Normal View History

module Jekyll
class ResponsiveImage
module Utils
def symbolize_keys(hash)
result = {}
hash.each_key do |key|
result[key.to_sym] = hash[key]
end
result
end
2014-12-08 00:06:28 +11:00
def format_output_path(format, path, width, height)
params = symbolize_keys(image_hash(path, width, height))
format % params
end
2014-12-08 00:06:28 +11:00
# Build a hash containing image information
def image_hash(path, width, height)
2014-12-08 00:06:28 +11:00
{
'path' => path,
'dirname' => File.dirname(path),
2014-12-08 00:06:28 +11:00
'basename' => File.basename(path),
'filename' => File.basename(path, '.*'),
'extension' => File.extname(path).delete('.'),
'width' => width,
'height' => height,
}
end
end
end
end