Class: HiLite::CssFile

Inherits:
Object
  • Object
show all
Defined in:
lib/hi-lite/css_file.rb

Instance Method Summary collapse

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_selectorObject



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

#selectorsObject



18
19
20
# File 'lib/hi-lite/css_file.rb', line 18

def selectors
  @css.keys
end

#stylesObject



22
23
24
# File 'lib/hi-lite/css_file.rb', line 22

def styles
  @css.values
end

#to_sObject



32
33
34
# File 'lib/hi-lite/css_file.rb', line 32

def to_s
  @css.map { |k,v| "#{k}{#{v}}" }.join("\n")
end