mjml-rb 0.3.2 → 0.3.3
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 +53 -4
- 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: 99c98b34eee9aea7822dc4f59250b3b8ca008b98a17cd7e5063eb04595460c31
|
|
4
|
+
data.tar.gz: 6541eb2234e61dd3399dce72b6f0f45f4e810601ecf1c7ff2ccc9a6405d74b84
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3ae18240675e7e9bf5572634a09cb2ae1079e93c874088b917181245a8b20947f59368b07d911fc781cd96676a7953e9f2aaa650bf69ed7eae9e4e5ff2962782
|
|
7
|
+
data.tar.gz: d6ae46c90053abdfeeb2445c87c7ebc07fbd9e36ac47b335577b03d2bfa0debb2dd5c6f9ce9208910c338ae7e7798d29b0c98ed4fc2b9a8b2aaf9eedd045a2f4
|
data/lib/mjml-rb/renderer.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require "cgi"
|
|
2
2
|
require "nokogiri"
|
|
3
|
+
require "set"
|
|
3
4
|
require_relative "components/accordion"
|
|
4
5
|
require_relative "components/attributes"
|
|
5
6
|
require_relative "components/body"
|
|
@@ -539,6 +540,7 @@ module MjmlRb
|
|
|
539
540
|
existing[property] = merged
|
|
540
541
|
end
|
|
541
542
|
normalize_background_fallbacks!(node, existing)
|
|
543
|
+
sync_html_attributes!(node, existing)
|
|
542
544
|
node["style"] = serialize_css_declarations(existing)
|
|
543
545
|
end
|
|
544
546
|
|
|
@@ -552,12 +554,59 @@ module MjmlRb
|
|
|
552
554
|
important: declarations.fetch("background-color", {}).fetch(:important, false)
|
|
553
555
|
}
|
|
554
556
|
end
|
|
557
|
+
end
|
|
558
|
+
|
|
559
|
+
# Sync HTML attributes from inlined CSS declarations.
|
|
560
|
+
# Mirrors Juice's attribute syncing: width/height on TABLE/TD/TH/IMG,
|
|
561
|
+
# and style-to-attribute mappings (bgcolor, background, align, valign)
|
|
562
|
+
# on table-related elements.
|
|
563
|
+
# See: https://github.com/Automattic/juice/blob/master/lib/inline.js
|
|
564
|
+
WIDTH_HEIGHT_ELEMENTS = Set.new(%w[table td th img]).freeze
|
|
565
|
+
TABLE_ELEMENTS = Set.new(%w[table th tr td caption colgroup col thead tbody tfoot]).freeze
|
|
566
|
+
STYLE_TO_ATTRIBUTE = {
|
|
567
|
+
"background-color" => "bgcolor",
|
|
568
|
+
"background-image" => "background",
|
|
569
|
+
"text-align" => "align",
|
|
570
|
+
"vertical-align" => "valign"
|
|
571
|
+
}.freeze
|
|
572
|
+
|
|
573
|
+
def sync_html_attributes!(node, declarations)
|
|
574
|
+
tag = node.name.downcase
|
|
575
|
+
|
|
576
|
+
# Sync width/height on TABLE, TD, TH, IMG
|
|
577
|
+
if WIDTH_HEIGHT_ELEMENTS.include?(tag)
|
|
578
|
+
%w[width height].each do |prop|
|
|
579
|
+
css_value = declaration_value(declarations[prop])
|
|
580
|
+
next if css_value.nil? || css_value.empty?
|
|
555
581
|
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
582
|
+
# Convert CSS px values to plain numbers for HTML attributes;
|
|
583
|
+
# keep other values (auto, %) as-is.
|
|
584
|
+
html_value = css_value.sub(/px\z/i, "")
|
|
585
|
+
node[prop] = html_value
|
|
586
|
+
end
|
|
587
|
+
end
|
|
559
588
|
|
|
560
|
-
|
|
589
|
+
# Sync style-to-attribute mappings on table elements
|
|
590
|
+
if TABLE_ELEMENTS.include?(tag)
|
|
591
|
+
STYLE_TO_ATTRIBUTE.each do |css_prop, html_attr|
|
|
592
|
+
css_value = declaration_value(declarations[css_prop])
|
|
593
|
+
next if css_value.nil? || css_value.empty?
|
|
594
|
+
|
|
595
|
+
case html_attr
|
|
596
|
+
when "bgcolor"
|
|
597
|
+
next if %w[none transparent].include?(css_value.downcase)
|
|
598
|
+
node[html_attr] = css_value
|
|
599
|
+
when "background"
|
|
600
|
+
# Extract url(...) from background-image
|
|
601
|
+
url = css_value[/url\(['"]?([^'")]+)['"]?\)/i, 1]
|
|
602
|
+
node[html_attr] = url if url
|
|
603
|
+
when "align"
|
|
604
|
+
node[html_attr] = css_value
|
|
605
|
+
when "valign"
|
|
606
|
+
node[html_attr] = css_value
|
|
607
|
+
end
|
|
608
|
+
end
|
|
609
|
+
end
|
|
561
610
|
end
|
|
562
611
|
|
|
563
612
|
def syncable_background?(value)
|
data/lib/mjml-rb/version.rb
CHANGED