Class: Kin::Sprites::SassGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/kin/sprites/sass_generator.rb

Overview

Converts an IconSet to a SASS partial.

Constant Summary collapse

TEMPLATE =
File.read(__FILE__).split(/^__END__/)[1]

Instance Method Summary collapse

Constructor Details

#initialize(set, name) ⇒ SassGenerator

Creates a new Generator instance.

Parameters:

  • set (IconSet)

    An IconSet instance.

  • name (String)

    The name of this sprite.



19
20
21
# File 'lib/kin/sprites/sass_generator.rb', line 19

def initialize(set, name)
  @set, @name = set, name
end

Instance Method Details

#to_sass(dir) ⇒ Object

Converts the icon set to a SASS partial.

Parameters:

  • dir (String)

    The web directory in which the sprite files are located (no trailing space please).



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/kin/sprites/sass_generator.rb', line 32

def to_sass(dir)
  # Holds all the if/else statements.
  conditions = []
  conditions << if_statement(@set[0], true)
  @set[1..-1].each { |icon| conditions << if_statement(icon) }

  # Permits supplying an offset, rather than an icon name.
  conditions << '  @else'
  conditions << '    !pos = !icon'
  conditions << ''

  # Put the data into the template.
  template = TEMPLATE.dup
  template.gsub!(/NAME/, @name)
  template.gsub!(/DIR/, dir)
  template.gsub!(/CONDITIONS/, conditions.join("\n"))
  template
end