Sha256: 46d7239824b6d8b0f42b7b402c88ef526393f80d32b1c1611c4cf193ee5319c5

Contents?: true

Size: 1.12 KB

Versions: 10

Compression:

Stored size: 1.12 KB

Contents

module Sprite::Sass::Extensions
  def sprite_background(group, image)
    sprite = sprite_data(group, image)
    if sprite
      "url('#{sprite[:img]}') no-repeat #{sprite[:x]}px #{sprite[:y]}px"
    else
      ""
    end
  end

  def sprite_width(group, image)
    sprite = sprite_data(group, image)
    if sprite
      "#{sprite[:width]}px"
    else
      ""
    end
  end
  
  def sprite_height(group, image)
    sprite = sprite_data(group, image)
    if sprite
      "#{sprite[:height]}px"
    else
      ""
    end
  end
  
  protected
  def sprite_data(group, image)
    unless @__sprite_data
      
      # TODO: read template from !sprite_data
      sprite_data_path = "public/sass/sprites.yml"
      
      # figure out the site root
      root = "./"
      
      # read sprite data from yml
      @__sprite_data = File.open(File.join(root, sprite_data_path)) { |yf| YAML::load( yf ) }
    end
    
    group_data = @__sprite_data[group.to_s]
    if group_data
      return group_data[image.to_s]
    else
      nil
    end
  end
  
end

if defined?(Sass)
  module Sass::Script::Functions
    include Sprite::Sass::Extensions
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
sprite-generator-0.1.11 lib/sprite/sass_extensions.rb
sprite-0.1.7 lib/sprite/sass_extensions.rb
sprite-generator-0.1.10 lib/sprite/sass_extensions.rb
sprite-generator-0.1.9 lib/sprite/sass_extensions.rb
sprite-generator-0.1.8 lib/sprite/sass_extensions.rb
sprite-generator-0.1.7 lib/sprite/sass_extensions.rb
sprite-0.1.6 lib/sprite/sass_extensions.rb
sprite-0.1.5 lib/sprite/sass_extensions.rb
sprite-0.1.4 lib/sprite/sass_extensions.rb
sprite-0.1.3 lib/sprite/sass_extensions.rb