Module: Sprite::Sass::Extensions
- Included in:
- Sass::Script::Functions
- Defined in:
- lib/sprite/sass_extensions.rb
Class Method Summary collapse
Instance Method Summary collapse
- #sprite_background(group, image) ⇒ Object
- #sprite_height(*args) ⇒ Object
- #sprite_image(group) ⇒ Object
-
#sprite_offset(group, image, x = nil, y = nil) ⇒ Object
Return a sprite offset for the given image.
- #sprite_path(group) ⇒ Object
- #sprite_url(group) ⇒ Object
- #sprite_width(*args) ⇒ Object
- #sprite_x_offset(*args) ⇒ Object
- #sprite_y_offset(*args) ⇒ Object
Class Method Details
.asset_id(&block) ⇒ Object
4 5 6 |
# File 'lib/sprite/sass_extensions.rb', line 4 def self.asset_id(&block) @asset_id = block if block end |
.query_string_for(asset) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/sprite/sass_extensions.rb', line 8 def self.query_string_for(asset) if @asset_id "?#{@asset_id.call(asset)}" else '' end end |
Instance Method Details
#sprite_background(group, image) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/sprite/sass_extensions.rb', line 21 def sprite_background(group, image) sprite = sprite_data(group, image) if sprite sprite_path = sprite_path(group) ::Sass::Script::String.new "url('#{sprite_path}') no-repeat #{sprite[:x]}px #{sprite[:y]}px" else ::Sass::Script::String.new "" end end |
#sprite_height(*args) ⇒ Object
35 36 37 |
# File 'lib/sprite/sass_extensions.rb', line 35 def sprite_height(*args) ::Sass::Script::String.new sprite_attr(:height, *args) end |
#sprite_image(group) ⇒ Object
47 48 49 |
# File 'lib/sprite/sass_extensions.rb', line 47 def sprite_image(group) ::Sass::Script::String.new sprite_path(group) end |
#sprite_offset(group, image, x = nil, y = nil) ⇒ Object
Return a sprite offset for the given image. When the optional x and y values are passed, numeric values are treated as additional offsets to the sprite image offset. Any string values are treated as replacement offsets.
Examples:
-
sprite_offset(“common”, “icon”, “100%”, 5) => offset is “100% x+5” where x is the x offset in the sprite
-
sprite_offset(“common”, “icon”, “top”, “right”) => offset is “top right”
63 64 65 66 67 |
# File 'lib/sprite/sass_extensions.rb', line 63 def sprite_offset(group, image, x=nil, y=nil) xoff = compute_offset(group, image, :x, x) yoff = compute_offset(group, image, :y, y) ::Sass::Script::String.new "#{xoff} #{yoff}" end |
#sprite_path(group) ⇒ Object
16 17 18 19 |
# File 'lib/sprite/sass_extensions.rb', line 16 def sprite_path(group) path = sprite_builder.image_path(group.value) "#{path}#{Sprite::Sass::Extensions.query_string_for(path)}" end |
#sprite_url(group) ⇒ Object
51 52 53 |
# File 'lib/sprite/sass_extensions.rb', line 51 def sprite_url(group) ::Sass::Script::String.new "url('#{sprite_path(group)}')" end |
#sprite_width(*args) ⇒ Object
31 32 33 |
# File 'lib/sprite/sass_extensions.rb', line 31 def sprite_width(*args) ::Sass::Script::String.new sprite_attr(:width, *args) end |
#sprite_x_offset(*args) ⇒ Object
39 40 41 |
# File 'lib/sprite/sass_extensions.rb', line 39 def sprite_x_offset(*args) ::Sass::Script::String.new sprite_attr(:x, *args) end |
#sprite_y_offset(*args) ⇒ Object
43 44 45 |
# File 'lib/sprite/sass_extensions.rb', line 43 def sprite_y_offset(*args) ::Sass::Script::String.new sprite_attr(:y, *args) end |