Class: Compass::SassExtensions::Sprites::Image
- Inherits:
-
Object
- Object
- Compass::SassExtensions::Sprites::Image
- Includes:
- Sass::Script::Value::Helpers
- Defined in:
- lib/compass/sass_extensions/sprites/image.rb
Constant Summary collapse
- ACTIVE =
%r{[_-]active$}
- TARGET =
%r{[_-]target$}
- HOVER =
%r{[_-]hover$}
- FOCUS =
%r{[_-]focus$}
- PARENT =
%r{(.+)[-_](.+)$}
- REPEAT_X =
'repeat-x'
- REPEAT_Y =
'repeat-y'
- NO_REPEAT =
'no-repeat'
- VALID_REPEATS =
[REPEAT_Y, 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.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#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
-
#focus ⇒ Object
Active selector Image object if exsists.
-
#focus? ⇒ Boolean
Is active selector.
- #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.
- #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
- #repeat_y? ⇒ 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.
21 22 23 24 25 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 21 def initialize(base, relative_file, ) @base, @relative_file, @options = base, relative_file, @left = @top = 0 @name = File.basename(relative_file, '.png') end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
18 19 20 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 18 def base @base end |
#left ⇒ Object
Returns the value of attribute left.
19 20 21 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 19 def left @left end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
18 19 20 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 18 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
18 19 20 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 18 def @options end |
#relative_file ⇒ Object (readonly)
Returns the value of attribute relative_file.
18 19 20 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 18 def relative_file @relative_file end |
#top ⇒ Object
Returns the value of attribute top.
19 20 21 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 19 def top @top end |
Instance Method Details
#active ⇒ Object
Active selector Image object if exsists
134 135 136 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 134 def active base.get_magic_selector_image(name, 'active') end |
#active? ⇒ Boolean
Is active selector
129 130 131 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 129 def active? name =~ ACTIVE end |
#digest ⇒ Object
MD5 hash of this file
99 100 101 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 99 def digest Digest::MD5.file(file).hexdigest end |
#file ⇒ Object
The Full path to the image
28 29 30 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 28 def file @file ||= find_file end |
#find_file ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 32 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 |
#focus ⇒ Object
Active selector Image object if exsists
144 145 146 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 144 def focus base.get_magic_selector_image(name, 'focus') end |
#focus? ⇒ Boolean
Is active selector
139 140 141 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 139 def focus? name =~ FOCUS end |
#get_var_file(var) ⇒ Object
55 56 57 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 55 def get_var_file(var) .get_var "#{base.name}_#{name}_#{var}" end |
#height ⇒ Object
Height of the image
51 52 53 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 51 def height dimensions.last end |
#hover ⇒ Object
Hover selector Image object if exsists
114 115 116 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 114 def hover base.get_magic_selector_image(name, 'hover') end |
#hover? ⇒ Boolean
Is hover selector
109 110 111 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 109 def hover? name =~ HOVER end |
#mtime ⇒ Object
mtime of this file
104 105 106 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 104 def mtime File.mtime(file) end |
#no_repeat? ⇒ Boolean
79 80 81 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 79 def no_repeat? repeat == NO_REPEAT end |
#offset ⇒ Object
Offset within the sprite
89 90 91 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 89 def offset @offset ||= (position.unitless? || position.unit_str == "px") ? position.value : 0 end |
#parent ⇒ Object
148 149 150 151 152 153 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 148 def parent if [hover?, target?, active?, focus?].any? PARENT.match name base.image_for($1) end end |
#position ⇒ Object
Value of $#{name}-position
or $position
defaults to 0px
84 85 86 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 84 def position @position ||= get_var_file("position") || .get_var("position") || number(0, "px") end |
#repeat ⇒ Object
Value of $#{name}-repeat
or $repeat
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 60 def repeat @repeat ||= begin rep = (get_var_file("repeat") || .get_var("repeat") || identifier(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
71 72 73 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 71 def repeat_x? repeat == REPEAT_X end |
#repeat_y? ⇒ Boolean
75 76 77 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 75 def repeat_y? repeat == REPEAT_Y end |
#size ⇒ Object
46 47 48 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 46 def size @size ||= File.size(file) end |
#spacing ⇒ Object
Spacing between this image and the next
94 95 96 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 94 def spacing @spacing ||= (get_var_file("spacing") || .get_var("spacing") || number(0, 'px')).value end |
#target ⇒ Object
Target selector Image object if exsists
124 125 126 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 124 def target base.get_magic_selector_image(name, 'target') end |
#target? ⇒ Boolean
Is target selector
119 120 121 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 119 def target? name =~ TARGET end |
#width ⇒ Object
Width of the image
42 43 44 |
# File 'lib/compass/sass_extensions/sprites/image.rb', line 42 def width dimensions.first end |