module SpriteFactory::Style

Public Class Methods

comment(style_name, comment) click to toggle source
# File lib/sprite_factory/style.rb, line 66
def self.comment(style_name, comment)
  send("#{style_name}_comment", comment)
end
css(selector, name, attributes) click to toggle source
# File lib/sprite_factory/style.rb, line 6
def self.css(selector, name, attributes)
  "#{selector}#{name} { #{css_style(attributes)}; }"
end
css_comment(comment) click to toggle source
# File lib/sprite_factory/style.rb, line 14
def self.css_comment(comment)
  return "/*\n#{comment}\n*/"
end
css_style(attributes) click to toggle source
# File lib/sprite_factory/style.rb, line 10
def self.css_style(attributes)
  attributes.join("; ")
end
generate(style_name, selector, url, images) click to toggle source
# File lib/sprite_factory/style.rb, line 48
def self.generate(style_name, selector, url, images)
  styles = []
  images.each do |image|
    attr = [
      "width: #{image[:cssw]}px",
      "height: #{image[:cssh]}px",
      "background: #{url} #{-image[:cssx]}px #{-image[:cssy]}px no-repeat"
    ]
    image[:selector] = selector                          # make selector available for (optional) custom rule generators
    image[:style]    = send("#{style_name}_style", attr) # make pure style available for (optional) custom rule generators (see usage of yield inside Runner#style)
    styles << send(style_name, selector, image[:name], attr)
  end
  styles << ""
  styles.join("\n")
end
sass(selector, name, attributes) click to toggle source
# File lib/sprite_factory/style.rb, line 34
def self.sass(selector, name, attributes)
  "#{selector}#{name}\n" + sass_style(attributes)
end
sass_comment(comment) click to toggle source
# File lib/sprite_factory/style.rb, line 42
def self.sass_comment(comment)
  return "/* #{comment.rstrip} */" # SASS has peculiar indenting requirements in order to recognise closing block comment
end
sass_style(attributes) click to toggle source
# File lib/sprite_factory/style.rb, line 38
def self.sass_style(attributes)
  attributes.map{|a| "  #{a}"}.join("\n") + "\n"
end
scss(selector, name, attributes) click to toggle source
# File lib/sprite_factory/style.rb, line 20
def self.scss(selector, name, attributes)
  css(selector, name, attributes) # scss is a superset of css, but we dont actually need any of the extra bits, so just defer to the css generator instead
end
scss_comment(comment) click to toggle source
# File lib/sprite_factory/style.rb, line 28
def self.scss_comment(comment)
  css_comment(comment)
end
scss_style(attributes) click to toggle source
# File lib/sprite_factory/style.rb, line 24
def self.scss_style(attributes)
  css_style(attributes)
end