Class: HiLite::CssFile
- Inherits:
-
Object
- Object
- HiLite::CssFile
- Defined in:
- lib/hi-lite/css_file.rb
Instance Method Summary collapse
- #each_selector ⇒ Object
-
#initialize(csstext) ⇒ CssFile
constructor
A new instance of CssFile.
- #selectors ⇒ Object
- #styles ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(csstext) ⇒ CssFile
Returns a new instance of CssFile.
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/hi-lite/css_file.rb', line 4 def initialize(csstext) @css = {} csstext.scan(/([.#:]?[-_\w]+(?:\s+[.#:]?[-_\w]+)?)\s?\{([^{}]*)\}/im).each do |rule| selector = rule.first selector.strip! style = rule.last style.strip! style.gsub!(/\s+/, ' ') style.gsub!(/([:;])\s+/, '\1') style = style.split(';').join(';') @css.merge!({ selector => style }) if style != "" end end |
Instance Method Details
#each_selector ⇒ Object
26 27 28 29 30 |
# File 'lib/hi-lite/css_file.rb', line 26 def each_selector @css.each do |k,v| yield k, v end end |
#selectors ⇒ Object
18 19 20 |
# File 'lib/hi-lite/css_file.rb', line 18 def selectors @css.keys end |
#styles ⇒ Object
22 23 24 |
# File 'lib/hi-lite/css_file.rb', line 22 def styles @css.values end |
#to_s ⇒ Object
32 33 34 |
# File 'lib/hi-lite/css_file.rb', line 32 def to_s @css.map { |k,v| "#{k}{#{v}}" }.join("\n") end |