Abstracting access to inner_html and inner_text to Webrat::XML methods
This commit is contained in:
parent
9a344fdc2b
commit
334108015f
@ -159,7 +159,7 @@ module Webrat
|
|||||||
class ButtonField < Field #:nodoc:
|
class ButtonField < Field #:nodoc:
|
||||||
|
|
||||||
def matches_text?(text)
|
def matches_text?(text)
|
||||||
@element.inner_html =~ /#{Regexp.escape(text.to_s)}/i
|
Webrat::XML.inner_html(@element) =~ /#{Regexp.escape(text.to_s)}/i
|
||||||
end
|
end
|
||||||
|
|
||||||
def matches_value?(value)
|
def matches_value?(value)
|
||||||
@ -284,7 +284,7 @@ module Webrat
|
|||||||
protected
|
protected
|
||||||
|
|
||||||
def default_value
|
def default_value
|
||||||
@element.inner_html
|
Webrat::XML.inner_html(@element)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -338,7 +338,7 @@ module Webrat
|
|||||||
|
|
||||||
selected_options.map do |option|
|
selected_options.map do |option|
|
||||||
return "" if option.nil?
|
return "" if option.nil?
|
||||||
Webrat::XML.attribute(option, "value") || option.inner_html
|
Webrat::XML.attribute(option, "value") || Webrat::XML.inner_html(option)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ module Webrat
|
|||||||
end
|
end
|
||||||
|
|
||||||
def text
|
def text
|
||||||
str = @element.inner_text
|
str = Webrat::XML.inner_text(@element)
|
||||||
str.gsub!("\n","")
|
str.gsub!("\n","")
|
||||||
str.strip!
|
str.strip!
|
||||||
str.squeeze!(" ")
|
str.squeeze!(" ")
|
||||||
|
@ -40,11 +40,11 @@ module Webrat
|
|||||||
end
|
end
|
||||||
|
|
||||||
def inner_html
|
def inner_html
|
||||||
@element.inner_html
|
Webrat::XML.inner_html(@element)
|
||||||
end
|
end
|
||||||
|
|
||||||
def text
|
def text
|
||||||
@element.inner_text
|
Webrat::XML.inner_text(@element)
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
@ -8,7 +8,7 @@ module Webrat
|
|||||||
|
|
||||||
def matches?(stringlike)
|
def matches?(stringlike)
|
||||||
@document = Webrat::XML.document(stringlike)
|
@document = Webrat::XML.document(stringlike)
|
||||||
@element = @document.inner_text
|
@element = Webrat::XML.inner_text(@document)
|
||||||
|
|
||||||
case @content
|
case @content
|
||||||
when String
|
when String
|
||||||
|
@ -8,9 +8,9 @@ module Webrat
|
|||||||
|
|
||||||
def matches_text?(text)
|
def matches_text?(text)
|
||||||
if text.is_a?(Regexp)
|
if text.is_a?(Regexp)
|
||||||
@element.inner_html =~ text
|
Webrat::XML.inner_html(@element) =~ text
|
||||||
else
|
else
|
||||||
@element.inner_html == text.to_s
|
Webrat::XML.inner_html(@element) == text.to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ module Webrat
|
|||||||
protected
|
protected
|
||||||
|
|
||||||
def value
|
def value
|
||||||
Webrat::XML.attribute(@element, "value") || @element.inner_html
|
Webrat::XML.attribute(@element, "value") || Webrat::XML.inner_html(@element)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -6,6 +6,7 @@ module Webrat #:nodoc:
|
|||||||
Webrat.nokogiri_document(stringlike)
|
Webrat.nokogiri_document(stringlike)
|
||||||
else
|
else
|
||||||
Webrat::XML.hpricot_document(stringlike)
|
Webrat::XML.hpricot_document(stringlike)
|
||||||
|
# Webrat.rexml_document(Webrat::XML.hpricot_document(stringlike).to_html)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -25,12 +26,26 @@ module Webrat #:nodoc:
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.inner_html(element)
|
||||||
|
element.inner_html
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.inner_text(element)
|
||||||
|
element.inner_text
|
||||||
|
end
|
||||||
|
|
||||||
def self.attribute(element, attribute_name)
|
def self.attribute(element, attribute_name)
|
||||||
element[attribute_name]
|
# case element
|
||||||
|
# when Nokogiri::XML::Element, Hash
|
||||||
|
element[attribute_name]
|
||||||
|
# else
|
||||||
|
# element.attributes[attribute_name]
|
||||||
|
# end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.xpath_search(element, *searches)
|
def self.xpath_search(element, *searches)
|
||||||
searches.flatten.map do |search|
|
searches.flatten.map do |search|
|
||||||
|
# REXML::XPath.match(element, search)
|
||||||
element.xpath(search)
|
element.xpath(search)
|
||||||
end.flatten.compact
|
end.flatten.compact
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user