Module: CSSSprites

Defined in:
lib/css_sprites.rb,
lib/css_sprites/version.rb

Defined Under Namespace

Classes: CLI, ImageGrid, Sprite, SpriteStylesheet

Constant Summary collapse

VERSION =
'0.1.1'

Class Method Summary collapse

Class Method Details

.generate_sprite(path, options = {}) ⇒ Object

Generates a sprite from all PNG files in the directory specified by path. Saves a PNG file and a CSS file in the specified directory’s parent directory. Returns the path to the directory to which those files were saved to.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/css_sprites.rb', line 11

def self.generate_sprite(path, options = {})
  output_path = options[:output] || File.dirname(path)

  fail ArgumentError, "Directory #{ output_path } does not exist" unless Dir.exists?(output_path)
  fail ArgumentError, "You have no writing permissions for directory #{ output_path }" unless File.writable?(output_path)

  sprite = Sprite.new(path, options)

  output_file = "#{ output_path }/#{ sprite.name }"
  sprite.image.write("#{ output_file }.png")
  File.write("#{ output_file }.css", sprite.stylesheet)

  File.realpath(output_path)
end