Skip to content

Commit

Permalink
format: rubocop html/document_fragment.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
flavorjones committed Feb 5, 2021
1 parent 7f50aa8 commit c99eaa7
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions lib/nokogiri/html/document_fragment.rb
Expand Up @@ -4,26 +4,26 @@ module HTML
class DocumentFragment < Nokogiri::XML::DocumentFragment
####
# Create a Nokogiri::XML::DocumentFragment from +tags+, using +encoding+
def self.parse tags, encoding = nil
def self.parse(tags, encoding = nil)
doc = HTML::Document.new

encoding ||= if tags.respond_to?(:encoding)
encoding = tags.encoding
if encoding == ::Encoding::ASCII_8BIT
'UTF-8'
else
encoding.name
end
else
'UTF-8'
end
encoding = tags.encoding
if encoding == ::Encoding::ASCII_8BIT
'UTF-8'
else
encoding.name
end
else
'UTF-8'
end

doc.encoding = encoding

new(doc, tags)
end

def initialize document, tags = nil, ctx = nil
def initialize(document, tags = nil, ctx = nil)
return self unless tags

if ctx
Expand All @@ -33,13 +33,13 @@ def initialize document, tags = nil, ctx = nil
self.errors = document.errors - preexisting_errors
else
# This is a horrible hack, but I don't care
if /^\s*?<body/i.match?(tags)
path = "/html/body"
path = if /^\s*?<body/i.match?(tags)
"/html/body"
else
path = "/html/body/node()"
"/html/body/node()"
end

temp_doc = HTML::Document.parse "<html><body>#{tags}", nil, document.encoding
temp_doc = HTML::Document.parse("<html><body>#{tags}", nil, document.encoding)
temp_doc.xpath(path).each { |child| child.parent = self }
self.errors = temp_doc.errors
end
Expand Down

0 comments on commit c99eaa7

Please sign in to comment.