lib/inky.rb in inky-rb-1.3.7.0 vs lib/inky.rb in inky-rb-1.3.7.1

- old
+ new

@@ -1,9 +1,11 @@ +require 'nokogiri' +require_relative 'inky/configuration' +require_relative 'inky/component_factory' + module Inky class Core - require 'nokogiri' - require_relative 'component_factory' attr_accessor :components, :column_count, :component_lookup, :component_tags include ComponentFactory def initialize(options = {}) self.components = { @@ -26,17 +28,16 @@ self.column_count = options[:column_count] || 12 self.component_tags = components.values end - def release_the_kraken(xml_string) - xml_string = xml_string.gsub(/doctype/i, 'DOCTYPE') - raws, str = Inky::Core.extract_raws(xml_string) + def release_the_kraken(html_string) + html_string.force_encoding('utf-8') # transform_doc barfs if encoding is ASCII-8bit + html_string = html_string.gsub(/doctype/i, 'DOCTYPE') + raws, str = Inky::Core.extract_raws(html_string) parse_cmd = str =~ /<html/i ? :parse : :fragment html = Nokogiri::HTML.public_send(parse_cmd, str) - html.elements.each do |elem| - transform_doc(elem) - end + transform_doc(html) string = html.to_html(encoding: 'US-ASCII') Inky::Core.re_inject_raws(string, raws) end def transform_doc(elem)