mjml-rb 0.2.31 → 0.2.32
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/components/section.rb +34 -10
- 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: 5f70adefb32b3a7bb2df503b8749cfbd2fde06bb819c6bfc3e587a1a8eb65772
|
|
4
|
+
data.tar.gz: ef1c17cd44ec046c37c75b3a6650610161fe74f71824dfe64b72db2958e24f77
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 64230656cfbf00b6d220cb579e078cddda30edeb5ccf1faa9f4245ed389ba76f6fe1990a10f48a6ccc2e67ecc3deb0c09cb6d4d146079d992e08cf5376f55c60
|
|
7
|
+
data.tar.gz: cb12486d8dd7571e11f19bbed0054a7698def27350678874c65c07688baf28a5b2e19f5bb31db4d4ce7c761e3509114c6d2b85155567a842e1812a1d82ba985b
|
|
@@ -123,6 +123,12 @@ module MjmlRb
|
|
|
123
123
|
value && !value.to_s.strip.empty?
|
|
124
124
|
end
|
|
125
125
|
|
|
126
|
+
# Matches npm's suffixCssClasses: "foo bar" → "foo-outlook bar-outlook"
|
|
127
|
+
def suffix_css_classes(classes, suffix = "outlook")
|
|
128
|
+
return "" unless classes && !classes.strip.empty?
|
|
129
|
+
classes.split(" ").map { |c| "#{c}-#{suffix}" }.join(" ")
|
|
130
|
+
end
|
|
131
|
+
|
|
126
132
|
# Merge adjacent Outlook conditional comments. Applied locally within
|
|
127
133
|
# each section/wrapper to avoid incorrectly merging across sibling sections.
|
|
128
134
|
def merge_outlook_conditionals(html)
|
|
@@ -388,7 +394,8 @@ module MjmlRb
|
|
|
388
394
|
end
|
|
389
395
|
|
|
390
396
|
def render_section_before(css_class, container_px, bg_color, wrapper_gap)
|
|
391
|
-
outlook_class = css_class
|
|
397
|
+
outlook_class = suffix_css_classes(css_class)
|
|
398
|
+
has_gap = wrapper_gap && !wrapper_gap.to_s.strip.empty?
|
|
392
399
|
before_pairs = [
|
|
393
400
|
["align", "center"],
|
|
394
401
|
["border", "0"],
|
|
@@ -399,7 +406,7 @@ module MjmlRb
|
|
|
399
406
|
["style", style_join("width" => "#{container_px}px", "padding-top" => wrapper_gap) + ";"],
|
|
400
407
|
["width", container_px.to_s]
|
|
401
408
|
]
|
|
402
|
-
before_pairs << ["bgcolor", bg_color] if bg_color
|
|
409
|
+
before_pairs << ["bgcolor", bg_color] if bg_color && !has_gap
|
|
403
410
|
|
|
404
411
|
%(<!--[if mso | IE]><table#{outlook_attrs(before_pairs)}><tr><td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;"><![endif]-->)
|
|
405
412
|
end
|
|
@@ -576,7 +583,8 @@ module MjmlRb
|
|
|
576
583
|
end
|
|
577
584
|
|
|
578
585
|
# renderBefore — Outlook conditional table wrapper
|
|
579
|
-
outlook_class = css_class
|
|
586
|
+
outlook_class = suffix_css_classes(css_class)
|
|
587
|
+
has_gap = wrapper_gap && !wrapper_gap.to_s.strip.empty?
|
|
580
588
|
before_pairs = [
|
|
581
589
|
["align", "center"],
|
|
582
590
|
["border", "0"],
|
|
@@ -587,7 +595,7 @@ module MjmlRb
|
|
|
587
595
|
["style", style_join("width" => "#{container_px}px", "padding-top" => wrapper_gap) + ";"],
|
|
588
596
|
["width", container_px.to_s]
|
|
589
597
|
]
|
|
590
|
-
before_pairs << ["bgcolor", bg_color] if bg_color
|
|
598
|
+
before_pairs << ["bgcolor", bg_color] if bg_color && !has_gap
|
|
591
599
|
|
|
592
600
|
render_before = %(<!--[if mso | IE]><table#{outlook_attrs(before_pairs)}><tr><td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;"><![endif]-->)
|
|
593
601
|
|
|
@@ -622,6 +630,17 @@ module MjmlRb
|
|
|
622
630
|
"text-align" => a["text-align"]
|
|
623
631
|
)
|
|
624
632
|
|
|
633
|
+
# Compute box width and update context for children, matching npm
|
|
634
|
+
# wrapper's getChildContext() which sets containerWidth to box width.
|
|
635
|
+
border_left = parse_border_width(a["border-left"] || a["border"])
|
|
636
|
+
border_right = parse_border_width(a["border-right"] || a["border"])
|
|
637
|
+
pad_left = parse_padding_side(a, "left")
|
|
638
|
+
pad_right = parse_padding_side(a, "right")
|
|
639
|
+
box_width = container_px - pad_left - pad_right - border_left - border_right
|
|
640
|
+
|
|
641
|
+
previous_container_width = context[:container_width]
|
|
642
|
+
context[:container_width] = "#{box_width}px"
|
|
643
|
+
|
|
625
644
|
div_attrs = {"class" => (full_width ? nil : css_class), "style" => div_style}
|
|
626
645
|
inner = merge_outlook_conditionals(render_wrapped_children_wrapper(node, context, container_px, a["gap"]))
|
|
627
646
|
inner_content = bg_has ? %(<div style="line-height:0;font-size:0">#{inner}</div>) : inner
|
|
@@ -665,22 +684,27 @@ module MjmlRb
|
|
|
665
684
|
body = bg_has ? render_with_background(wrapper_html, a, container_px) : wrapper_html
|
|
666
685
|
"#{render_before}\n#{body}\n#{render_after}"
|
|
667
686
|
end
|
|
687
|
+
ensure
|
|
688
|
+
context[:container_width] = previous_container_width if previous_container_width
|
|
668
689
|
end
|
|
669
690
|
|
|
670
|
-
# Wrap each child mj-section/mj-wrapper in an Outlook conditional <td>.
|
|
691
|
+
# Wrap each child mj-section/mj-wrapper in an Outlook conditional <tr><td>.
|
|
692
|
+
# npm wrapper renders each child in its own row, unlike section which
|
|
693
|
+
# places all columns in a single row.
|
|
671
694
|
def render_wrapped_children_wrapper(node, context, container_px, gap)
|
|
672
695
|
children = node.element_children.select { |e| %w[mj-section mj-wrapper].include?(e.tag_name) }
|
|
673
696
|
return render_children(node, context, parent: "mj-wrapper") if children.empty?
|
|
674
697
|
|
|
675
698
|
open_table = %(<!--[if mso | IE]><table role="presentation" border="0" cellpadding="0" cellspacing="0"><![endif]-->)
|
|
676
|
-
open_tr = %(<!--[if mso | IE]><tr><![endif]-->)
|
|
677
|
-
close_tr = %(<!--[if mso | IE]></tr><![endif]-->)
|
|
678
699
|
close_table = %(<!--[if mso | IE]></table><![endif]-->)
|
|
679
700
|
|
|
680
701
|
section_parts = with_inherited_mj_class(context, node) do
|
|
681
702
|
children.each_with_index.map do |child, index|
|
|
682
|
-
|
|
683
|
-
|
|
703
|
+
child_attrs = resolved_attributes(child, context)
|
|
704
|
+
child_css = child_attrs["css-class"]
|
|
705
|
+
outlook_class = suffix_css_classes(child_css)
|
|
706
|
+
td_open = %(<!--[if mso | IE]><tr><td class="#{escape_attr(outlook_class)}" width="#{container_px}px" ><![endif]-->)
|
|
707
|
+
td_close = %(<!--[if mso | IE]></td></tr><![endif]-->)
|
|
684
708
|
child_html = with_wrapper_child_gap(context, index.zero? ? nil : gap) do
|
|
685
709
|
render_node(child, context, parent: "mj-wrapper")
|
|
686
710
|
end
|
|
@@ -688,7 +712,7 @@ module MjmlRb
|
|
|
688
712
|
end
|
|
689
713
|
end
|
|
690
714
|
|
|
691
|
-
([open_table
|
|
715
|
+
([open_table] + section_parts + [close_table]).join("\n")
|
|
692
716
|
end
|
|
693
717
|
|
|
694
718
|
def with_wrapper_child_gap(context, gap)
|
data/lib/mjml-rb/version.rb
CHANGED