class Compass::SassExtensions::Sprites::Image
Constants
- ACTIVE
- HOVER
- NO_REPEAT
- PARENT
- REPEAT_X
- TARGET
- VALID_REPEATS
Attributes
base[R]
left[RW]
options[R]
relative_file[R]
top[RW]
Public Class Methods
new(base, relative_file, options)
click to toggle source
# File lib/compass/sass_extensions/sprites/image.rb, line 18 def initialize(base, relative_file, options) @base, @relative_file, @options = base, relative_file, options @left = @top = 0 end
Public Instance Methods
active()
click to toggle source
Active selector Image object if exsists
# File lib/compass/sass_extensions/sprites/image.rb, line 131 def active base.image_for("#{name}_active") end
active?()
click to toggle source
Is active selector
# File lib/compass/sass_extensions/sprites/image.rb, line 126 def active? name =~ ACTIVE end
digest()
click to toggle source
MD5 hash of this file
# File lib/compass/sass_extensions/sprites/image.rb, line 96 def digest Digest::MD5.file(file).hexdigest end
file()
click to toggle source
The Full path to the image
# File lib/compass/sass_extensions/sprites/image.rb, line 24 def file @file ||= find_file end
find_file()
click to toggle source
# File lib/compass/sass_extensions/sprites/image.rb, line 28 def find_file Compass.configuration.sprite_load_path.compact.each do |path| f = File.join(path, relative_file) if File.exists?(f) return f end end end
get_var_file(var)
click to toggle source
# File lib/compass/sass_extensions/sprites/image.rb, line 56 def get_var_file(var) options.get_var "#{base.name}_#{name}_#{var}" end
height()
click to toggle source
Height of the image
# File lib/compass/sass_extensions/sprites/image.rb, line 47 def height dimensions.last end
hover()
click to toggle source
Hover selector Image object if exsists
# File lib/compass/sass_extensions/sprites/image.rb, line 111 def hover base.image_for("#{name}_hover") end
hover?()
click to toggle source
Is hover selector
# File lib/compass/sass_extensions/sprites/image.rb, line 106 def hover? name =~ HOVER end
mtime()
click to toggle source
mtime of this file
# File lib/compass/sass_extensions/sprites/image.rb, line 101 def mtime File.mtime(file) end
name()
click to toggle source
Basename of the image
# File lib/compass/sass_extensions/sprites/image.rb, line 52 def name File.basename(relative_file, '.png') end
no_repeat?()
click to toggle source
# File lib/compass/sass_extensions/sprites/image.rb, line 76 def no_repeat? repeat == NO_REPEAT end
offset()
click to toggle source
Offset within the sprite
# File lib/compass/sass_extensions/sprites/image.rb, line 86 def offset @offset ||= (position.unitless? || position.unit_str == "px") ? position.value : 0 end
parent()
click to toggle source
# File lib/compass/sass_extensions/sprites/image.rb, line 136 def parent if [hover?, target?, active?].any? PARENT.match name base.image_for($1) end end
position()
click to toggle source
Value of $#{name}-position
or $position
defaults to 0px
# File lib/compass/sass_extensions/sprites/image.rb, line 81 def position @position||= get_var_file("position") || options.get_var("position") || Sass::Script::Number.new(0, ["px"]) end
repeat()
click to toggle source
Value of $#{name}-repeat
or $repeat
# File lib/compass/sass_extensions/sprites/image.rb, line 61 def repeat @repeat ||= begin rep = (get_var_file("repeat") || options.get_var("repeat") || Sass::Script::String.new(NO_REPEAT)).value unless VALID_REPEATS.include? rep raise SpriteException, "Invalid option for repeat \"#{rep}\" - valid options are #{VALID_REPEATS.join(', ')}" end rep end end
repeat_x?()
click to toggle source
# File lib/compass/sass_extensions/sprites/image.rb, line 72 def repeat_x? repeat == REPEAT_X end
size()
click to toggle source
# File lib/compass/sass_extensions/sprites/image.rb, line 42 def size @size ||= File.size(file) end
spacing()
click to toggle source
Spacing between this image and the next
# File lib/compass/sass_extensions/sprites/image.rb, line 91 def spacing @spacing ||= (get_var_file("spacing") || options.get_var("spacing") || Sass::Script::Number.new(0, ['px'])).value end
target()
click to toggle source
Target selector Image object if exsists
# File lib/compass/sass_extensions/sprites/image.rb, line 121 def target base.image_for("#{name}_target") end
target?()
click to toggle source
Is target selector
# File lib/compass/sass_extensions/sprites/image.rb, line 116 def target? name =~ TARGET end
width()
click to toggle source
Width of the image
# File lib/compass/sass_extensions/sprites/image.rb, line 38 def width dimensions.first end
Private Instance Methods
dimensions()
click to toggle source
# File lib/compass/sass_extensions/sprites/image.rb, line 145 def dimensions @dimensions ||= Compass::SassExtensions::Functions::ImageSize::ImageProperties.new(file).size end