mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Pull base tag injection into a helper
This commit is contained in:
parent
d908bc1d99
commit
f0fa707f26
2 changed files with 20 additions and 10 deletions
|
@ -27,6 +27,24 @@ module Capybara
|
|||
def to_regexp(text)
|
||||
text.is_a?(Regexp) ? text : Regexp.escape(normalize_whitespace(text))
|
||||
end
|
||||
|
||||
##
|
||||
#
|
||||
# Injects a `<base>` tag into the given HTML code, pointing to
|
||||
# `Capybara.asset_host`.
|
||||
#
|
||||
# @param [String] html HTML code to inject into
|
||||
# @param [String] The modified HTML code
|
||||
#
|
||||
def inject_asset_host(html)
|
||||
if Capybara.asset_host
|
||||
if Nokogiri::HTML(html).css("base").empty? and match = html.match(/<head[^<]*?>/)
|
||||
html.insert match.end(0), "<base href='#{Capybara.asset_host}' />"
|
||||
end
|
||||
else
|
||||
html
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -313,18 +313,10 @@ module Capybara
|
|||
def save_page(path=nil)
|
||||
path ||= "capybara-#{Time.new.strftime("%Y%m%d%H%M%S")}#{rand(10**10)}.html"
|
||||
path = File.expand_path(path, Capybara.save_and_open_page_path) if Capybara.save_and_open_page_path
|
||||
body_to_write = body
|
||||
|
||||
if Capybara.asset_host
|
||||
parsed = Nokogiri::HTML(body_to_write)
|
||||
if parsed.css("base").empty? && match = body_to_write.match(/<head[^<]*?>/)
|
||||
body_to_write.insert match.end(0), "<base href='#{Capybara.asset_host}' />"
|
||||
end
|
||||
end
|
||||
|
||||
FileUtils.mkdir_p(File.dirname(path))
|
||||
|
||||
File.open(path,'w') { |f| f.write(body_to_write) }
|
||||
File.open(path,'w') { |f| f.write(Capybara::Helpers.inject_asset_host(body)) }
|
||||
path
|
||||
end
|
||||
|
||||
|
@ -393,7 +385,7 @@ module Capybara
|
|||
end
|
||||
|
||||
private
|
||||
|
||||
|
||||
def scopes
|
||||
@scopes ||= [document]
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue