mjml-rb 0.2.24 → 0.2.25

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4840c5584afa1ff603e996338a128d5808ae46742f084d03c0e34391259616f9
4
- data.tar.gz: ef16089bc907e5e5f649e10adac5389b27a25c63f3ee20aea3cb28db0e78da82
3
+ metadata.gz: e364fd8b1b8bb2e9020dec1afe71062b8efa5e6db3000edead4dad5280adb5c5
4
+ data.tar.gz: d975ccd74e68c83cd9324c538bd76046d9e2b29a9ce27e23054ebde79195bc6e
5
5
  SHA512:
6
- metadata.gz: d378634ab4a2905f65e3831292cb0b55ae22dca61a310bb4c6bf62e77610dfec609cd3d130324c99836a37fc61a34a64c0433fd80729ffcaa9073f528c8c1bee
7
- data.tar.gz: ea309a490a424440393727cd6e022f4c7372449e6e4f22a7506e8593051b7544d3a96e4af87846fc2d38a472c03aa97fe13fcc9c2ddfb8761912138238dc8210
6
+ metadata.gz: 147b6bf2c9abda80086c29e440d002d3fab3768e96ee71e7faa8e8be5defb2e91e11d51ee422ce07caf3f2a698f23dd1001382bc3e69a4e1bd0e49d68a7f0659
7
+ data.tar.gz: 142f4902cb84b3fa00adb1608186d13e40559e60127c18ac7213bcf89804069bafc97666b2013d67fd3fdd2083a75b27e38fa63e97d71ed7cc9600bf9d92eba6
@@ -541,10 +541,27 @@ module MjmlRb
541
541
  bg_color = a["background-color"]
542
542
  border_radius = a["border-radius"]
543
543
  full_width = a["full-width"] == "full-width"
544
+ bg_has = has_background?(a)
544
545
  wrapper_gap = context[:_wrapper_child_gap]
545
546
  has_border_radius = has_border_radius?(border_radius)
546
547
 
547
- # renderBefore same structure as section
548
+ # Background styles: url-based or color-only
549
+ background_styles = if bg_has
550
+ bg_value = get_background(a)
551
+ {
552
+ "background" => bg_value,
553
+ "background-position" => get_background_string(a),
554
+ "background-repeat" => a["background-repeat"],
555
+ "background-size" => a["background-size"]
556
+ }
557
+ else
558
+ {
559
+ "background" => bg_color,
560
+ "background-color" => bg_color
561
+ }
562
+ end
563
+
564
+ # renderBefore — Outlook conditional table wrapper
548
565
  outlook_class = css_class ? "#{css_class}-outlook" : ""
549
566
  before_pairs = [
550
567
  ["align", "center"],
@@ -560,22 +577,23 @@ module MjmlRb
560
577
 
561
578
  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]-->)
562
579
 
580
+ # div and table styles: include background only when not full-width
563
581
  div_style = style_join(
564
- "background" => bg_color,
565
- "background-color" => bg_color,
566
- "border-radius" => border_radius,
567
- "overflow" => (has_border_radius ? "hidden" : nil),
568
- "margin" => "0px auto",
569
- "margin-top" => wrapper_gap,
570
- "max-width" => (full_width ? nil : "#{container_px}px")
582
+ {
583
+ "border-radius" => border_radius,
584
+ "overflow" => (has_border_radius ? "hidden" : nil),
585
+ "margin" => "0px auto",
586
+ "margin-top" => wrapper_gap,
587
+ "max-width" => (full_width ? nil : "#{container_px}px")
588
+ }.merge(full_width ? {} : background_styles)
571
589
  )
572
590
 
573
591
  table_style = style_join(
574
- "background" => bg_color,
575
- "background-color" => bg_color,
576
- "border-radius" => border_radius,
577
- "border-collapse" => (has_border_radius ? "separate" : nil),
578
- "width" => "100%"
592
+ {
593
+ "border-radius" => border_radius,
594
+ "border-collapse" => (has_border_radius ? "separate" : nil),
595
+ "width" => "100%"
596
+ }.merge(full_width ? {} : background_styles)
579
597
  )
580
598
 
581
599
  td_style = style_join(
@@ -590,17 +608,49 @@ module MjmlRb
590
608
  "text-align" => a["text-align"]
591
609
  )
592
610
 
593
- div_attrs = {"class" => css_class, "style" => div_style}
611
+ div_attrs = {"class" => (full_width ? nil : css_class), "style" => div_style}
594
612
  inner = merge_outlook_conditionals(render_wrapped_children_wrapper(node, context, container_px, a["gap"]))
613
+ inner_content = bg_has ? %(<div style="line-height:0;font-size:0">#{inner}</div>) : inner
614
+
615
+ table_attrs = {
616
+ "align" => "center",
617
+ "background" => (bg_has && !full_width ? a["background-url"] : nil),
618
+ "border" => "0",
619
+ "cellpadding" => "0",
620
+ "cellspacing" => "0",
621
+ "role" => "presentation",
622
+ "style" => table_style,
623
+ "width" => "100%"
624
+ }
595
625
 
596
626
  wrapper_html =
597
627
  %(<div#{html_attrs(div_attrs)}>) +
598
- %(<table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="#{table_style}" width="100%">) +
599
- %(<tbody><tr><td style="#{td_style}">#{inner}</td></tr></tbody></table></div>)
628
+ %(<table#{html_attrs(table_attrs)}>) +
629
+ %(<tbody><tr><td style="#{td_style}">#{inner_content}</td></tr></tbody></table></div>)
600
630
 
601
631
  render_after = %(<!--[if mso | IE]></td></tr></table><![endif]-->)
602
632
 
603
- "#{render_before}\n#{wrapper_html}\n#{render_after}"
633
+ if full_width
634
+ inner_all = "#{render_before}\n#{wrapper_html}\n#{render_after}"
635
+ body = bg_has ? render_with_background(inner_all, a, container_px, full_width: true) : inner_all
636
+
637
+ outer_style = full_width_table_style(a)
638
+ outer_attrs = {
639
+ "align" => "center",
640
+ "class" => css_class,
641
+ "background" => bg_has ? a["background-url"] : nil,
642
+ "border" => "0",
643
+ "cellpadding" => "0",
644
+ "cellspacing" => "0",
645
+ "role" => "presentation",
646
+ "style" => outer_style
647
+ }
648
+
649
+ %(<table#{html_attrs(outer_attrs)}><tbody><tr><td>#{body}</td></tr></tbody></table>)
650
+ else
651
+ body = bg_has ? render_with_background(wrapper_html, a, container_px) : wrapper_html
652
+ "#{render_before}\n#{body}\n#{render_after}"
653
+ end
604
654
  end
605
655
 
606
656
  # Wrap each child mj-section/mj-wrapper in an Outlook conditional <td>.
@@ -1,3 +1,3 @@
1
1
  module MjmlRb
2
- VERSION = "0.2.24".freeze
2
+ VERSION = "0.2.25".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mjml-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.24
4
+ version: 0.2.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Andriichuk