Module: SpriteFactory::Style
- Defined in:
- lib/sprite_factory/style.rb
Class Method Summary collapse
-
.comment(style_name, comment) ⇒ Object
—————————————————————————-.
-
.css(selector, name, attributes) ⇒ Object
—————————————————————————-.
- .css_comment(comment) ⇒ Object
- .css_style(attributes) ⇒ Object
-
.generate(style_name, selector, url, images) ⇒ Object
—————————————————————————-.
-
.sass(selector, name, attributes) ⇒ Object
—————————————————————————-.
- .sass_comment(comment) ⇒ Object
- .sass_style(attributes) ⇒ Object
-
.scss(selector, name, attributes) ⇒ Object
—————————————————————————-.
- .scss_comment(comment) ⇒ Object
- .scss_style(attributes) ⇒ Object
Class Method Details
.comment(style_name, comment) ⇒ Object
66 67 68 |
# File 'lib/sprite_factory/style.rb', line 66 def self.comment(style_name, comment) send("#{style_name}_comment", comment) end |
.css(selector, name, attributes) ⇒ Object
6 7 8 |
# File 'lib/sprite_factory/style.rb', line 6 def self.css(selector, name, attributes) "#{selector}#{name} { #{css_style(attributes)}; }" end |
.css_comment(comment) ⇒ Object
14 15 16 |
# File 'lib/sprite_factory/style.rb', line 14 def self.css_comment(comment) return "/*\n#{comment}\n*/" end |
.css_style(attributes) ⇒ Object
10 11 12 |
# File 'lib/sprite_factory/style.rb', line 10 def self.css_style(attributes) attributes.join("; ") end |
.generate(style_name, selector, url, images) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# 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) ⇒ Object
34 35 36 |
# File 'lib/sprite_factory/style.rb', line 34 def self.sass(selector, name, attributes) "#{selector}#{name}\n" + sass_style(attributes) end |
.sass_comment(comment) ⇒ Object
42 43 44 |
# 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) ⇒ Object
38 39 40 |
# 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) ⇒ Object
20 21 22 |
# 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) ⇒ Object
28 29 30 |
# File 'lib/sprite_factory/style.rb', line 28 def self.scss_comment(comment) css_comment(comment) end |
.scss_style(attributes) ⇒ Object
24 25 26 |
# File 'lib/sprite_factory/style.rb', line 24 def self.scss_style(attributes) css_style(attributes) end |