-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
336 additions
and
390 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,6 @@ PLATFORMS | |
ruby | ||
|
||
DEPENDENCIES | ||
nokogiri (~> 1.3) | ||
rspec (~> 2.0) | ||
xpath! | ||
yard (>= 0.5.8) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module XPath | ||
module Convertable | ||
def to_s | ||
to_xpaths.join(' | ') | ||
end | ||
|
||
def to_xpaths | ||
[to_xpath(:exact), to_xpath(:fuzzy)].uniq | ||
end | ||
|
||
def to_xpath(predicate=nil) | ||
Renderer.render(predicate, self) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
module XPath | ||
module DSL | ||
module TopLevel | ||
def current | ||
Expression.new(:this_node) | ||
end | ||
|
||
def name | ||
Expression.new(:node_name, current) | ||
end | ||
|
||
def descendant(*expressions) | ||
Expression.new(:descendant, current, expressions) | ||
end | ||
|
||
def child(*expressions) | ||
Expression.new(:child, current, expressions) | ||
end | ||
|
||
def anywhere(expression) | ||
Expression.new(:anywhere, expression) | ||
end | ||
|
||
def attr(expression) | ||
Expression.new(:attribute, current, expression) | ||
end | ||
|
||
def contains(expression) | ||
Expression.new(:contains, current, expression) | ||
end | ||
|
||
def text | ||
Expression.new(:text, current) | ||
end | ||
|
||
def var(name) | ||
Expression.new(:variable, name) | ||
end | ||
|
||
def string | ||
Expression.new(:string_function, current) | ||
end | ||
|
||
def tag(name) | ||
Expression.new(:tag, name) | ||
end | ||
|
||
def css(selector) | ||
Expression.new(:css, current, Literal.new(selector)) | ||
end | ||
|
||
def varstring(name) | ||
var(name).string_literal | ||
end | ||
end | ||
|
||
module ExpressionLevel | ||
include XPath::DSL::TopLevel | ||
|
||
def where(expression) | ||
Expression.new(:where, current, expression) | ||
end | ||
alias_method :[], :where | ||
|
||
def next_sibling(*expressions) | ||
Expression.new(:next_sibling, current, expressions) | ||
end | ||
|
||
def one_of(*expressions) | ||
Expression.new(:one_of, current, expressions) | ||
end | ||
|
||
def equals(expression) | ||
Expression.new(:equality, current, expression) | ||
end | ||
alias_method :==, :equals | ||
|
||
def is(expression) | ||
Expression.new(:is, current, expression) | ||
end | ||
|
||
def or(expression) | ||
Expression.new(:or, current, expression) | ||
end | ||
alias_method :|, :or | ||
|
||
def and(expression) | ||
Expression.new(:and, current, expression) | ||
end | ||
alias_method :&, :and | ||
|
||
def union(*expressions) | ||
Union.new(*[self, expressions].flatten) | ||
end | ||
alias_method :+, :union | ||
|
||
def inverse | ||
Expression.new(:inverse, current) | ||
end | ||
alias_method :~, :inverse | ||
|
||
def string_literal | ||
Expression.new(:string_literal, self) | ||
end | ||
|
||
def apply(variables={}) | ||
Expression.new(:applied, current, Literal.new(variables)) | ||
end | ||
|
||
def normalize | ||
Expression.new(:normalized_space, current) | ||
end | ||
alias_method :n, :normalize | ||
end | ||
end | ||
end |
Oops, something went wrong.