some internal refactoring im image_functions
This commit is contained in:
parent
0667ccf89c
commit
abace68275
@ -1,23 +1,23 @@
|
|||||||
module Compass::SassExtensions::Functions::ImageSize
|
module Compass::SassExtensions::Functions::ImageSize
|
||||||
# Returns the width of the image relative to the images directory
|
# Returns the width of the image relative to the images directory
|
||||||
def image_width(image_file)
|
def image_width(image_file)
|
||||||
image_path = if File.exists?(image_file.value)
|
width, _ = image_demensions(image_file)
|
||||||
image_file.value
|
|
||||||
else
|
|
||||||
real_path(image_file)
|
|
||||||
end
|
|
||||||
width = ImageProperties.new(image_path).size.first
|
|
||||||
Sass::Script::Number.new(width,["px"])
|
Sass::Script::Number.new(width,["px"])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def image_demensions(image_file)
|
||||||
|
@image_demensions ||= {}
|
||||||
|
@image_demensions[image_file.value] ||= ImageProperties.new(image_path(image_file.value)).size
|
||||||
|
end
|
||||||
|
|
||||||
|
def image_path(image_file)
|
||||||
|
return image_file if File.exists?(image_file)
|
||||||
|
real_path(image_file)
|
||||||
|
end
|
||||||
|
|
||||||
# Returns the height of the image relative to the images directory
|
# Returns the height of the image relative to the images directory
|
||||||
def image_height(image_file)
|
def image_height(image_file)
|
||||||
image_path = if File.exists?(image_file.value)
|
_, height = image_demensions(image_file)
|
||||||
image_file.value
|
|
||||||
else
|
|
||||||
real_path(image_file)
|
|
||||||
end
|
|
||||||
height = ImageProperties.new(image_path).size.last
|
|
||||||
Sass::Script::Number.new(height, ["px"])
|
Sass::Script::Number.new(height, ["px"])
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -53,13 +53,13 @@ module Compass::SassExtensions::Functions::ImageSize
|
|||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def real_path(image_file)
|
def real_path(image_file)
|
||||||
path = image_file.value
|
|
||||||
# Compute the real path to the image on the file stystem if the images_dir is set.
|
# Compute the real path to the image on the file stystem if the images_dir is set.
|
||||||
if Compass.configuration.images_path
|
if Compass.configuration.images_path
|
||||||
File.join(Compass.configuration.images_path, path)
|
File.join(Compass.configuration.images_path, image_file)
|
||||||
else
|
else
|
||||||
File.join(Compass.configuration.project_path, path)
|
File.join(Compass.configuration.project_path, image_file)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user