Parent

Class Index [+]

Quicksearch

Nokogiri::CSS::Node

Constants

ALLOW_COMBINATOR_ON_SELF

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 12
12:       def initialize type, value
13:         @type = type
14:         @value = value
15:       end

Public Instance Methods

accept(visitor) click to toggle source

Accept visitor

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

Find a node by type using types

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

Preprocess this node tree

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

Convert to array

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

Convert to_type

    # File lib/nokogiri/css/node.rb, line 90
90:       def to_type
91:         [@type] + @value.map { |n|
92:           n.to_type if n.respond_to?(:to_type)
93:         }.compact
94:       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 24
24:       def to_xpath prefix = '//', visitor = XPathVisitor.new
25:         self.preprocess!
26:         prefix = '.' if ALLOW_COMBINATOR_ON_SELF.include?(type) && value.first.nil?
27:         prefix + visitor.accept(self)
28:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.