From 208ade8b9fa95afae0e81b8cd0bb23ab96371e5b Mon Sep 17 00:00:00 2001 From: Orhan Toy Date: Thu, 28 Mar 2019 21:35:03 +0100 Subject: [PATCH] Improve JRuby support JRuby Nokogiri seems to strip ``s without a proper `` parent. On MRI Nokogiri this does not happen. A solution is to use a different tag in the transformation process itself and then end by converting it back to `} + %{<#{INTERIM_TH_TAG} #{attributes}>#{inner}} end def _transform_container(component, inner) @@ -91,7 +96,7 @@ def _transform_columns(component, inner) subrows = component.elements.css(".row").to_a.concat(component.elements.css("row").to_a) expander = %{} if large_size.to_i == column_count && subrows.empty? - %{} + %{<#{INTERIM_TH_TAG} class="#{classes}" #{_pass_through_attributes(component)}>
`. --- .rubocop.yml | 3 +++ lib/inky.rb | 1 + lib/inky/component_factory.rb | 9 +++++++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index f301326..fcc8d46 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -153,5 +153,8 @@ Metrics/BlockLength: - 'Rakefile' - 'spec/**/*.rb' +Style/MutableConstant: + Enabled: false + Style/Encoding: Enabled: false diff --git a/lib/inky.rb b/lib/inky.rb index e0c1864..a97bfb6 100644 --- a/lib/inky.rb +++ b/lib/inky.rb @@ -40,6 +40,7 @@ def release_the_kraken(html_string) html = Nokogiri::HTML.public_send(parse_cmd, str) transform_doc(html) string = html.to_html + string.gsub!(INTERIM_TH_TAG_REGEX, 'th') Inky::Core.re_inject_raws(string, raws) end diff --git a/lib/inky/component_factory.rb b/lib/inky/component_factory.rb index cc6b353..794e5b0 100644 --- a/lib/inky/component_factory.rb +++ b/lib/inky/component_factory.rb @@ -12,6 +12,11 @@ def component_factory(elem) tags = tags.to_set if tags.respond_to? :to_set IGNORED_ON_PASSTHROUGH = tags.freeze + # These constants are used to circumvent an issue with JRuby Nokogiri. + # For more details see https://github.com/zurb/inky-rb/pull/94 + INTERIM_TH_TAG = 'inky-interim-th'.freeze + INTERIM_TH_TAG_REGEX = %r{(?<=\<|\<\/)#{Regexp.escape(INTERIM_TH_TAG)}} + def _pass_through_attributes(elem) elem.attributes.reject { |e| IGNORED_ON_PASSTHROUGH.include?(e.downcase) }.map do |name, value| %{#{name}="#{value}" } @@ -60,7 +65,7 @@ def _transform_menu(component, inner) def _transform_menu_item(component, inner) target = _target_attribute(component) attributes = _combine_attributes(component, 'menu-item') - %{#{inner}#{expander}
#{inner}
#{expander}
#{inner}
} end def _transform_block_grid(component, inner)