Class: Abscss::Traverser

Inherits:
Object
  • Object
show all
Defined in:
lib/abscss.rb

Instance Method Summary collapse

Constructor Details

#initializeTraverser

Returns a new instance of Traverser.



7
8
9
# File 'lib/abscss.rb', line 7

def initialize
  @selectors = {}
end

Instance Method Details

#outputObject



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

def output
  @selectors.keys.collect do |selector|
    selector + " {}"
  end
end

#traverse(node, parent = "") ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/abscss.rb', line 11

def traverse(node,parent="")
  has_id = node.attributes['id']
  name_to_use = has_id ? "##{node.attributes['id'].value}" : node.name
  parent = "" if has_id
  @selectors[[parent,name_to_use].join(" ").strip] = 1 unless (node.text? or node.name == "meta" or node.name == "link" or node.name == "style" or node.name == "#cdata-section" or node.name == "head")
  if node.children.size > 0
    node.children.each do |child|
      traverse(child,[parent, name_to_use].join(" "))
    end
  end
end