Skip to content

Commit

Permalink
Moving around XML code
Browse files Browse the repository at this point in the history
  • Loading branch information
brynary committed Nov 30, 2008
1 parent f3ff8d4 commit 53539ed
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 44 deletions.
2 changes: 1 addition & 1 deletion lib/webrat.rb
Expand Up @@ -17,7 +17,7 @@ def self.require_xml
require "rexml/document"
else
require "nokogiri"
require "webrat/core/nokogiri"
require "webrat/core/xml/nokogiri"
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/webrat/core.rb
@@ -1,6 +1,6 @@
require "webrat/core/configuration"
require "webrat/core/xml"
require "webrat/core/nokogiri"
require "webrat/core/xml/nokogiri"
require "webrat/core/logging"
require "webrat/core/elements/form"
require "webrat/core/scope"
Expand Down
17 changes: 1 addition & 16 deletions lib/webrat/core/elements/form.rb
Expand Up @@ -11,13 +11,6 @@ def self.xpath_search
".//form"
end

def initialize(*args)
super

fields # preload
labels # preload
end

def find_select_option(option_text)
select_fields = fields_by_type([SelectField])

Expand All @@ -30,15 +23,7 @@ def find_select_option(option_text)
end

def fields
@fields ||= Webrat::XML.xpath_search(@element, *Field.xpath_search).map do |element|
@session.element_to_webrat_element(element)
end
end

def labels
@labels ||= Webrat::XML.css_search(element, "label").map do |element|
@session.element_to_webrat_element(element)
end
@fields ||= Field.load_all(@session, @element)
end

def submit
Expand Down
2 changes: 1 addition & 1 deletion lib/webrat/core/matchers/have_content.rb
Expand Up @@ -10,7 +10,7 @@ def matches?(stringlike)
if Webrat.configuration.parse_with_nokogiri?
@document = Webrat.nokogiri_document(stringlike)
else
@document = Webrat::XML.hpricot_document(stringlike)
@document = Webrat.hpricot_document(stringlike)
end

@element = Webrat::XML.inner_text(@document)
Expand Down
4 changes: 2 additions & 2 deletions lib/webrat/core/matchers/have_xpath.rb
@@ -1,5 +1,5 @@
require "webrat/core/nokogiri"
require "webrat/core/rexml"
require "webrat/core/xml/nokogiri"
require "webrat/core/xml/rexml"

module Webrat
module Matchers
Expand Down
15 changes: 10 additions & 5 deletions lib/webrat/core/scope.rb
Expand Up @@ -29,11 +29,8 @@ def initialize(session, &block) #:nodoc:
@session = session
instance_eval(&block) if block_given?

labels
fields
forms # preload
areas # preload
links # preload
# preload
load_elements
end

# Verifies an input field or textarea exists on the current page, and stores a value for
Expand Down Expand Up @@ -283,6 +280,14 @@ def dom # :nodoc:

protected

def load_elements
labels
fields
forms
areas
links
end

def page_dom #:nodoc:
return @response.dom if @response.respond_to?(:dom)
dom = Webrat::XML.document(@response_body)
Expand Down
23 changes: 5 additions & 18 deletions lib/webrat/core/xml.rb
@@ -1,28 +1,15 @@
require "webrat/core/xml/nokogiri"
require "webrat/core/xml/hpricot"
require "webrat/core/xml/rexml"

module Webrat #:nodoc:
module XML #:nodoc:

def self.document(stringlike) #:nodoc:
if Webrat.configuration.parse_with_nokogiri?
Webrat.nokogiri_document(stringlike)
else
# Webrat::XML.hpricot_document(stringlike)
Webrat.rexml_document(Webrat::XML.hpricot_document(stringlike).to_html)
end
end

def self.hpricot_document(stringlike)
return stringlike.dom if stringlike.respond_to?(:dom)

if Hpricot::Doc === stringlike
stringlike
elsif Hpricot::Elements === stringlike
stringlike
elsif StringIO === stringlike
Hpricot(stringlike.string)
elsif stringlike.respond_to?(:body)
Hpricot(stringlike.body.to_s)
else
Hpricot(stringlike.to_s)
Webrat.rexml_document(Webrat.hpricot_document(stringlike).to_html)
end
end

Expand Down
19 changes: 19 additions & 0 deletions lib/webrat/core/xml/hpricot.rb
@@ -0,0 +1,19 @@
module Webrat

def self.hpricot_document(stringlike)
return stringlike.dom if stringlike.respond_to?(:dom)

if Hpricot::Doc === stringlike
stringlike
elsif Hpricot::Elements === stringlike
stringlike
elsif StringIO === stringlike
Hpricot(stringlike.string)
elsif stringlike.respond_to?(:body)
Hpricot(stringlike.body.to_s)
else
Hpricot(stringlike.to_s)
end
end

end
File renamed without changes.
File renamed without changes.

0 comments on commit 53539ed

Please sign in to comment.