Sha256: 9153a8757e764cf7cfc62b93c7fd5ea082a4e75035d863bd6c79d9d8fdc36548

Contents?: true

Size: 1.18 KB

Versions: 15

Compression:

Stored size: 1.18 KB

Contents

require 'nokogiri'

module XPath
  autoload :Expression, 'xpath/expression'
  autoload :Union, 'xpath/union'
  autoload :HTML, 'xpath/html'

  extend self

  def self.generate
    yield(Expression::Self.new)
  end

  def current
    Expression::Self.new
  end

  def name
    Expression::Name.new(current)
  end

  def descendant(*expressions)
    Expression::Descendant.new(current, expressions)
  end

  def child(*expressions)
    Expression::Child.new(current, expressions)
  end

  def anywhere(expression)
    Expression::Anywhere.new(expression)
  end

  def attr(expression)
    Expression::Attribute.new(current, expression)
  end

  def contains(expression)
    Expression::Contains.new(current, expression)
  end

  def text
    Expression::Text.new(current)
  end

  def var(name)
    Expression::Variable.new(name)
  end

  def string
    Expression::StringFunction.new(current)
  end

  def tag(name)
    Expression::Tag.new(name)
  end

  def css(selector)
    paths = Nokogiri::CSS.xpath_for(selector).map do |selector|
      Expression::CSS.new(current, Expression::Literal.new(selector))
    end
    Union.new(*paths)
  end

  def varstring(name)
    var(name).string_literal
  end
end

Version data entries

15 entries across 15 versions & 4 rubygems

Version Path
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/xpath-0.1.4/lib/xpath.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/xpath-0.1.4/lib/xpath.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/xpath-0.1.4/lib/xpath.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/xpath-0.1.4/lib/xpath.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/xpath-0.1.4/lib/xpath.rb
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/xpath-0.1.4/lib/xpath.rb
frameworks-capybara-0.2.0.rc6 vendor/bundle/ruby/1.8/gems/xpath-0.1.4/lib/xpath.rb
frameworks-capybara-0.2.0.rc5 vendor/bundle/ruby/1.8/gems/xpath-0.1.4/lib/xpath.rb
frameworks-capybara-0.2.0.rc4 vendor/bundle/ruby/1.8/gems/xpath-0.1.4/lib/xpath.rb
frameworks-capybara-0.2.0.rc3 vendor/bundle/ruby/1.8/gems/xpath-0.1.4/lib/xpath.rb
frameworks-capybara-0.2.0.rc2 vendor/bundle/ruby/1.8/gems/xpath-0.1.4/lib/xpath.rb
xpath-0.1.4 lib/xpath.rb
wgibbs-xpath-0.1.4 lib/xpath.rb
xpath-0.1.3 lib/xpath.rb
xpath-0.1.2 lib/xpath.rb