Class: CSSTree

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/csstree.rb

Constant Summary collapse

VERSION =
"0.0.1"
RULESET_REGEX =
/([^{]*){([^}]*)}/

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCSSTree

Returns a new instance of CSSTree.



19
20
21
# File 'lib/csstree.rb', line 19

def initialize
  @tree = {}
end

Class Method Details

.parse(s) ⇒ Object



15
16
17
# File 'lib/csstree.rb', line 15

def self.parse s
  new.parse s
end

Instance Method Details

#find(s) ⇒ Object



28
29
30
# File 'lib/csstree.rb', line 28

def find s
  @tree[s]
end

#parse(s) ⇒ Object



23
24
25
26
# File 'lib/csstree.rb', line 23

def parse s
  @tree = Hash[*trim(s).scan(RULESET_REGEX).collect { |a| parse_block *a }.flatten]
  self
end

#renderObject



32
33
34
# File 'lib/csstree.rb', line 32

def render
  @tree.map { |s,d| "#{s.strip} { #{render_declarations d} }" }.join("\n")
end

#to_sObject



36
37
38
# File 'lib/csstree.rb', line 36

def to_s
  "#<CSSTree:0x#{self.object_id}>"
end