lib/inky.rb in inky-rb-1.3.6.3 vs lib/inky.rb in inky-rb-1.3.7.0
- old
+ new
@@ -1,9 +1,9 @@
module Inky
class Core
require 'nokogiri'
- require 'component_factory'
+ require_relative 'component_factory'
attr_accessor :components, :column_count, :component_lookup, :component_tags
include ComponentFactory
def initialize(options = {})
self.components = {
@@ -29,18 +29,16 @@
end
def release_the_kraken(xml_string)
xml_string = xml_string.gsub(/doctype/i, 'DOCTYPE')
raws, str = Inky::Core.extract_raws(xml_string)
- xml_doc = Nokogiri::XML(str)
- transform_doc(xml_doc.root) if components_exist?(xml_doc)
- string = xml_doc.to_s
- string.sub!(/^<\?xml.*\?>\n/, '')
+ parse_cmd = str =~ /<html/i ? :parse : :fragment
+ html = Nokogiri::HTML.public_send(parse_cmd, str)
+ html.elements.each do |elem|
+ transform_doc(elem)
+ end
+ string = html.to_html(encoding: 'US-ASCII')
Inky::Core.re_inject_raws(string, raws)
- end
-
- def components_exist?(_xml_doc)
- true
end
def transform_doc(elem)
if elem.respond_to?(:children)
elem.children.each do |child|