Class: Compass::SassExtensions::Sprites::Image
- Inherits:
-
Object
- Object
- Compass::SassExtensions::Sprites::Image
- Defined in:
- lib/compass/sass_extensions/sprites/image.rb
Constant Summary collapse
- ACTIVE =
%r{[_-]active$}
- TARGET =
%r{[_-]target$}
- HOVER =
%r{[_-]hover$}
- PARENT =
%r{(.+)[-_](.+)$}
- REPEAT_X =
'repeat-x'
- NO_REPEAT =
'no-repeat'
- VALID_REPEATS =
[REPEAT_X, NO_REPEAT]
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#left ⇒ Object
Returns the value of attribute left.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#relative_file ⇒ Object
readonly
Returns the value of attribute relative_file.
-
#top ⇒ Object
Returns the value of attribute top.
Instance Method Summary collapse
-
#active ⇒ Object
Active selector Image object if exsists.
-
#active? ⇒ Boolean
Is active selector.
-
#digest ⇒ Object
MD5 hash of this file.
-
#file ⇒ Object
The Full path to the image.
- #find_file ⇒ Object
- #get_var_file(var) ⇒ Object
-
#height ⇒ Object
Height of the image.
-
#hover ⇒ Object
Hover selector Image object if exsists.
-
#hover? ⇒ Boolean
Is hover selector.
-
#initialize(base, relative_file, options) ⇒ Image
constructor
A new instance of Image.
-
#mtime ⇒ Object
mtime of this file.
-
#name ⇒ Object
Basename of the image.
- #no_repeat? ⇒ Boolean
-
#offset ⇒ Object
Offset within the sprite.
- #parent ⇒ Object
-
#position ⇒ Object
Value of
$#{name}-position
or$position
defaults to0px
. -
#repeat ⇒ Object
Value of
$#{name}-repeat
or$repeat
. - #repeat_x? ⇒ Boolean
- #size ⇒ Object
-
#spacing ⇒ Object
Spacing between this image and the next.
-
#target ⇒ Object
Target selector Image object if exsists.
-
#target? ⇒ Boolean
Is target selector.
-
#width ⇒ Object
Width of the image.
Constructor Details
#initialize(base, relative_file, options) ⇒ Image
Returns a new instance of Image.
18 19 20 21 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 18 def initialize(base, relative_file, ) @base, @relative_file, = base, relative_file, @left = @top = 0 end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
15 16 17 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 15 def base @base end |
#left ⇒ Object
Returns the value of attribute left.
16 17 18 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 16 def left @left end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
15 16 17 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 15 def end |
#relative_file ⇒ Object (readonly)
Returns the value of attribute relative_file.
15 16 17 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 15 def relative_file @relative_file end |
#top ⇒ Object
Returns the value of attribute top.
16 17 18 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 16 def top @top end |
Instance Method Details
#active ⇒ Object
Active selector Image object if exsists
131 132 133 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 131 def active base.image_for("#{name}_active") end |
#active? ⇒ Boolean
Is active selector
126 127 128 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 126 def active? name =~ ACTIVE end |
#digest ⇒ Object
MD5 hash of this file
96 97 98 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 96 def digest Digest::MD5.file(file).hexdigest end |
#file ⇒ Object
The Full path to the image
24 25 26 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 24 def file @file ||= find_file end |
#find_file ⇒ Object
28 29 30 31 32 33 34 35 |
# 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) ⇒ Object
56 57 58 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 56 def get_var_file(var) .get_var "#{base.name}_#{name}_#{var}" end |
#height ⇒ Object
Height of the image
47 48 49 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 47 def height dimensions.last end |
#hover ⇒ Object
Hover selector Image object if exsists
111 112 113 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 111 def hover base.image_for("#{name}_hover") end |
#hover? ⇒ Boolean
Is hover selector
106 107 108 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 106 def hover? name =~ HOVER end |
#mtime ⇒ Object
mtime of this file
101 102 103 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 101 def mtime File.mtime(file) end |
#name ⇒ Object
Basename of the image
52 53 54 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 52 def name File.basename(relative_file, '.png') end |
#no_repeat? ⇒ Boolean
76 77 78 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 76 def no_repeat? repeat == NO_REPEAT end |
#offset ⇒ Object
Offset within the sprite
86 87 88 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 86 def offset @offset ||= (position.unitless? || position.unit_str == "px") ? position.value : 0 end |
#parent ⇒ Object
136 137 138 139 140 141 |
# 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 ⇒ Object
Value of $#{name}-position
or $position
defaults to 0px
81 82 83 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 81 def position @position||= get_var_file("position") || .get_var("position") || Sass::Script::Number.new(0, ["px"]) end |
#repeat ⇒ Object
Value of $#{name}-repeat
or $repeat
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 61 def repeat @repeat ||= begin rep = (get_var_file("repeat") || .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? ⇒ Boolean
72 73 74 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 72 def repeat_x? repeat == REPEAT_X end |
#size ⇒ Object
42 43 44 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 42 def size @size ||= File.size(file) end |
#spacing ⇒ Object
Spacing between this image and the next
91 92 93 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 91 def spacing @spacing ||= (get_var_file("spacing") || .get_var("spacing") || Sass::Script::Number.new(0, ['px'])).value end |
#target ⇒ Object
Target selector Image object if exsists
121 122 123 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 121 def target base.image_for("#{name}_target") end |
#target? ⇒ Boolean
Is target selector
116 117 118 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 116 def target? name =~ TARGET end |
#width ⇒ Object
Width of the image
38 39 40 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 38 def width dimensions.first end |