Parent

Class Index [+]

Quicksearch

Nokogiri::CSS::Node

Attributes

type[RW]

Get the type of this node

value[RW]

Get the value of this node

Public Class Methods

new(type, value) click to toggle source

Create a new Node with type and value

    # File lib/nokogiri/css/node.rb, line 10
10:       def initialize type, value
11:         @type = type
12:         @value = value
13:       end

Public Instance Methods

accept(visitor) click to toggle source

Accept visitor

    # File lib/nokogiri/css/node.rb, line 16
16:       def accept visitor
17:         visitor.send(:"visit_#{type.to_s.downcase}", self)
18:       end
find_by_type(types) click to toggle source

Find a node by type using types

    # File lib/nokogiri/css/node.rb, line 77
77:       def find_by_type types
78:         matches = []
79:         matches << self if to_type == types
80:         @value.each do |v|
81:           matches += v.find_by_type(types) if v.respond_to?(:find_by_type)
82:         end
83:         matches
84:       end
preprocess!() click to toggle source

Preprocess this node tree

    # File lib/nokogiri/css/node.rb, line 28
28:       def preprocess!
29:         ### Deal with nth-child
30:         matches = find_by_type(
31:           [:CONDITIONAL_SELECTOR,
32:             [:ELEMENT_NAME],
33:             [:PSEUDO_CLASS,
34:               [:FUNCTION]
35:             ]
36:           ]
37:         )
38:         matches.each do |match|
39:           if match.value[1].value[0].value[0] =~ /^nth-(last-)?child/
40:             tag_name = match.value[0].value.first
41:             match.value[0].value = ['*']
42:             match.value[1] = Node.new(:COMBINATOR, [
43:               match.value[1].value[0],
44:               Node.new(:FUNCTION, ['self(', tag_name])
45:             ])
46:           end
47:         end
48: 
49:         ### Deal with first-child, last-child
50:         matches = find_by_type(
51:           [:CONDITIONAL_SELECTOR,
52:             [:ELEMENT_NAME], [:PSEUDO_CLASS]
53:         ])
54:         matches.each do |match|
55:           if ['first-child', 'last-child'].include?(match.value[1].value.first)
56:             which = match.value[1].value.first.gsub(/-\w*$/, '')
57:             tag_name = match.value[0].value.first
58:             match.value[0].value = ['*']
59:             match.value[1] = Node.new(:COMBINATOR, [
60:               Node.new(:FUNCTION, ["#{which}("]),
61:               Node.new(:FUNCTION, ['self(', tag_name])
62:             ])
63:           elsif 'only-child' == match.value[1].value.first
64:             tag_name = match.value[0].value.first
65:             match.value[0].value = ['*']
66:             match.value[1] = Node.new(:COMBINATOR, [
67:               Node.new(:FUNCTION, ["#{match.value[1].value.first}("]),
68:               Node.new(:FUNCTION, ['self(', tag_name])
69:             ])
70:           end
71:         end
72: 
73:         self
74:       end
to_a() click to toggle source

Convert to array

    # File lib/nokogiri/css/node.rb, line 94
94:       def to_a
95:         [@type] + @value.map { |n| n.respond_to?(:to_a) ? n.to_a : [n] }
96:       end
to_type() click to toggle source

Convert to_type

    # File lib/nokogiri/css/node.rb, line 87
87:       def to_type
88:         [@type] + @value.map { |n|
89:           n.to_type if n.respond_to?(:to_type)
90:         }.compact
91:       end
to_xpath(prefix = '//', visitor = XPathVisitor.new) click to toggle source
 

Convert this CSS node to xpath with prefix using visitor

    # File lib/nokogiri/css/node.rb, line 22
22:       def to_xpath prefix = '//', visitor = XPathVisitor.new
23:         self.preprocess!
24:         prefix + visitor.accept(self)
25:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.