mjml-rb 0.2.21 → 0.2.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/mjml-rb/renderer.rb +17 -2
- data/lib/mjml-rb/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f62367f40ca4f73440f35e4878e7adcfcb8002cb1011639bbe1cd55f922b7580
|
|
4
|
+
data.tar.gz: 952c39acdd8b9cf3e1f84da47b4b3dc11c4f35c4cf521cfaf30ad4c890197dc5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bd7df7e7cb49e766d89895bf5cd38351e5ce00a5b33c28ceabbf9de99a6bc88b5f2c66eec31cec72b36506c7a0a871b170d77bea0441ba964ec17990f4411d3f
|
|
7
|
+
data.tar.gz: 11a977350b4941d6dc852e5b4a7caa0d0a7f3b5e42a4e53d0f44bbb0ccee1ce55425d4bf66bed4024c9896ec9a44d64d884f986c56f8080b0dfb8684b625de1b
|
data/lib/mjml-rb/renderer.rb
CHANGED
|
@@ -24,6 +24,8 @@ require_relative "components/spacer"
|
|
|
24
24
|
|
|
25
25
|
module MjmlRb
|
|
26
26
|
class Renderer
|
|
27
|
+
HTML_VOID_TAGS = %w[area base br col embed hr img input link meta param source track wbr].freeze
|
|
28
|
+
|
|
27
29
|
DEFAULT_FONTS = {
|
|
28
30
|
"Roboto" => "https://fonts.googleapis.com/css?family=Roboto:300,400,500,700"
|
|
29
31
|
}.freeze
|
|
@@ -277,7 +279,7 @@ module MjmlRb
|
|
|
277
279
|
css_blocks = unique_strings(context[:inline_styles]).reject { |css| css.nil? || css.strip.empty? }
|
|
278
280
|
return html if css_blocks.empty?
|
|
279
281
|
|
|
280
|
-
document =
|
|
282
|
+
document = parse_html_document(html)
|
|
281
283
|
parse_inline_css_rules(css_blocks.join("\n")).each do |selector, declarations|
|
|
282
284
|
next if selector.empty? || declarations.empty?
|
|
283
285
|
|
|
@@ -289,6 +291,14 @@ module MjmlRb
|
|
|
289
291
|
document.to_html
|
|
290
292
|
end
|
|
291
293
|
|
|
294
|
+
def parse_html_document(html)
|
|
295
|
+
if defined?(Nokogiri::HTML5)
|
|
296
|
+
Nokogiri::HTML5(html)
|
|
297
|
+
else
|
|
298
|
+
Nokogiri::HTML(html)
|
|
299
|
+
end
|
|
300
|
+
end
|
|
301
|
+
|
|
292
302
|
def select_nodes(document, selector)
|
|
293
303
|
document.css(selector)
|
|
294
304
|
rescue Nokogiri::CSS::SyntaxError, Nokogiri::XML::XPath::SyntaxError
|
|
@@ -571,12 +581,17 @@ module MjmlRb
|
|
|
571
581
|
|
|
572
582
|
def serialize_node(node)
|
|
573
583
|
attrs = node.attributes.map { |k, v| %( #{k}="#{escape_attr(v)}") }.join
|
|
574
|
-
return "<#{node.tag_name}#{attrs} />" if node.children.empty?
|
|
584
|
+
return "<#{node.tag_name}#{attrs} />" if node.children.empty? && html_void_tag?(node.tag_name)
|
|
585
|
+
return "<#{node.tag_name}#{attrs}></#{node.tag_name}>" if node.children.empty?
|
|
575
586
|
|
|
576
587
|
inner = node.children.map { |child| child.text? ? child.content.to_s : serialize_node(child) }.join
|
|
577
588
|
"<#{node.tag_name}#{attrs}>#{inner}</#{node.tag_name}>"
|
|
578
589
|
end
|
|
579
590
|
|
|
591
|
+
def html_void_tag?(tag_name)
|
|
592
|
+
HTML_VOID_TAGS.include?(tag_name.to_s.downcase)
|
|
593
|
+
end
|
|
594
|
+
|
|
580
595
|
def style_join(hash)
|
|
581
596
|
hash.each_with_object([]) do |(key, value), memo|
|
|
582
597
|
next if value.nil? || value.to_s.empty?
|
data/lib/mjml-rb/version.rb
CHANGED