Parent

Nokogiri::CSS::Parser

Attributes

cache_on[RW]

Turn on CSS parse caching

Public Class Methods

[](string) click to toggle source

Get the css selector in string from the cache

# File lib/nokogiri/css/parser.rb, line 17
        def [] string
          return unless @cache_on
          @mutex.synchronize { @cache[string] }
        end
[]=(string, value) click to toggle source

Set the css selector in string in the cache to value

# File lib/nokogiri/css/parser.rb, line 23
        def []= string, value
          return value unless @cache_on
          @mutex.synchronize { @cache[string] = value }
        end
clear_cache() click to toggle source

Clear the cache

# File lib/nokogiri/css/parser.rb, line 29
        def clear_cache
          @mutex.synchronize { @cache = {} }
        end
new(namespaces = {}) click to toggle source

Create a new CSS parser with respect to namespaces

# File lib/nokogiri/css/parser.rb, line 54
      def initialize namespaces = {}
        @namespaces = namespaces
        super()
      end
parse(selector) click to toggle source

Parse this CSS selector in selector. Returns an AST.

# File lib/nokogiri/css/parser.rb, line 43
        def parse selector
          @warned ||= false
          unless @warned
            $stderr.puts('Nokogiri::CSS::Parser.parse is deprecated, call Nokogiri::CSS.parse(), this will be removed August 1st or version 1.4.0 (whichever is first)')
            @warned = true
          end
          new.parse selector
        end
without_cache(&block) click to toggle source

Execute block without cache

# File lib/nokogiri/css/parser.rb, line 34
        def without_cache &block
          tmp = @cache_on
          @cache_on = false
          block.call
          @cache_on = tmp
        end

Public Instance Methods

on_error(error_token_id, error_value, value_stack) click to toggle source

On CSS parser error, raise an exception

# File lib/nokogiri/css/parser.rb, line 76
      def on_error error_token_id, error_value, value_stack
        after = value_stack.compact.last
        raise SyntaxError.new("unexpected '#{error_value}' after '#{after}'")
      end
xpath_for(string, options={}) click to toggle source

Get the xpath for string using options

# File lib/nokogiri/css/parser.rb, line 61
      def xpath_for string, options={}
        key = "#{string}#{options[:ns]}#{options[:prefix]}"
        v = self.class[key]
        return v if v

        args = [
          options[:prefix] || '//',
          options[:visitor] || XPathVisitor.new
        ]
        self.class[key] = parse(string).map { |ast|
          ast.to_xpath(*args)
        }
      end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.