Class: RubySprites::CSS

Inherits:
Object
  • Object
show all
Defined in:
lib/lash-sprites/css.rb

Class Method Summary collapse

Class Method Details

.generate(sprite, file = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/lash-sprites/css.rb', line 6

def self.generate(sprite, file = nil)
  css = ''
  css_template = ".%s {
  background: url(%s) %dpx %dpx no-repeat;
  height: %dpx;
  width: %dpx;
}\n\n"
  sprite.images.each do |path, image|
    class_name = path[0,path.rindex('.')].gsub('/','_')
    css += sprintf(css_template, class_name, sprite.filename, -image.x, -image.y, image.height, image.width)
  end

  if file.nil?
    return css
  else
    fp = File.open(sprite.file_root + file, 'w')
    fp.write(css)
    fp.close
  end
end