mjml-rb 0.2.30 → 0.2.31

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: 60152ad5a5d0db48c258f49e6f8b0f3af02fafc7a792b2eb5466a9ea9a2e5648
4
- data.tar.gz: 39e06f0b1987f17f75a03a18b20e35926a46972d8a128be50dc903d52643629b
3
+ metadata.gz: 512c35b10aab7894e19942c4c881e3f08c127c8660c587192a0f9bc3972092cd
4
+ data.tar.gz: d18d2c2bc8bbdf369af791ebc41841b3b762d85e4811b5cdb408ff66a45dd3e7
5
5
  SHA512:
6
- metadata.gz: 68d49bbb4d009ab6438e7a768f9fcc83c585d9bb7b95ab7966eed475cfea825226adb5af16c86f6a457513b3abd46f4c3b8db3ff32fcc881cdc5a7c5d2993fea
7
- data.tar.gz: 104af894e026ca52a8132f8797ed57d9541da6ebe47f38cc24d61a67daf248df81f972fb90f9d5fb51eba3cc4294a428621db8f287fa0fd2a781a1de6de7a95c
6
+ metadata.gz: 46e4bb2310909df561685b8307543662bb90ab02678e2db7f81bf9ff0139ddc62a7aa12982bbbd97b0b416b4b0ca5dc5478cda8694f846a303060d7e27915921
7
+ data.tar.gz: d2ab3041d34a146c49528cb3c7e63c1f3acaab077f565707057626bacb77df5578787ce7ea955ed8e1e9884442c66aabde30af8411ddc552e418e39d8386f0fa
@@ -42,11 +42,18 @@ module MjmlRb
42
42
  css_class = attrs["css-class"]
43
43
  a = self.class.default_attributes.merge(attrs)
44
44
 
45
- pct_str = width_pct.to_f.to_s.sub(/\.?0+$/, "")
46
- col_class_suffix = pct_str.gsub(".", "-")
47
- context[:column_widths][col_class_suffix] = pct_str if context[:column_widths]
45
+ explicit_width = a["width"]
46
+ if explicit_width && explicit_width.strip.end_with?("px")
47
+ px_val = explicit_width.to_f.to_s.sub(/\.?0+$/, "")
48
+ col_class_name = "mj-column-px-#{px_val.gsub('.', '-')}"
49
+ context[:column_widths][col_class_name] = "#{px_val}px" if context[:column_widths]
50
+ else
51
+ pct_str = width_pct.to_f.to_s.sub(/\.?0+$/, "")
52
+ col_class_name = "mj-column-per-#{pct_str.gsub('.', '-')}"
53
+ context[:column_widths][col_class_name] = "#{pct_str}%" if context[:column_widths]
54
+ end
48
55
 
49
- col_class = "mj-column-per-#{col_class_suffix} mj-outlook-group-fix"
56
+ col_class = "#{col_class_name} mj-outlook-group-fix"
50
57
  col_class = "#{col_class} #{css_class}" if css_class && !css_class.empty?
51
58
 
52
59
  vertical_align = a["vertical-align"]
@@ -26,10 +26,10 @@ module MjmlRb
26
26
  css_class = a["css-class"]
27
27
 
28
28
  pct_str = width_pct.to_f.to_s.sub(/\.?0+$/, "")
29
- class_suffix = pct_str.gsub(".", "-")
30
- context[:column_widths][class_suffix] = pct_str if context[:column_widths]
29
+ col_class_name = "mj-column-per-#{pct_str.gsub('.', '-')}"
30
+ context[:column_widths][col_class_name] = "#{pct_str}%" if context[:column_widths]
31
31
 
32
- group_class = "mj-column-per-#{class_suffix} mj-outlook-group-fix"
32
+ group_class = "#{col_class_name} mj-outlook-group-fix"
33
33
  group_class = "#{group_class} #{css_class}" if css_class && !css_class.empty?
34
34
 
35
35
  group_width = group_container_width(context, a, width_pct)
@@ -502,7 +502,12 @@ module MjmlRb
502
502
  end
503
503
 
504
504
  # Generate Outlook IE conditional wrappers around each column/group.
505
+ # Mirrors npm section's getChildContext() by setting containerWidth to
506
+ # the section's box width so that column children compute correct widths.
505
507
  def render_section_columns(node, context, box_width)
508
+ previous_container_width = context[:container_width]
509
+ context[:container_width] = "#{box_width}px"
510
+
506
511
  columns = node.element_children.select { |e| %w[mj-column mj-group].include?(e.tag_name) }
507
512
  return render_children(node, context, parent: "mj-section") if columns.empty?
508
513
 
@@ -517,9 +522,16 @@ module MjmlRb
517
522
  columns.each_with_index.map do |col, i|
518
523
  col_attrs = resolved_attributes(col, context)
519
524
  v_align = col_attrs["vertical-align"] || "top"
520
- col_px = (box_width.to_f * widths[i] / 100.0).round
521
-
522
- td_open = %(<!--[if mso | IE]><td class="" style="vertical-align:#{v_align};width:#{col_px}px;" ><![endif]-->)
525
+ col_css = col_attrs["css-class"]
526
+ outlook_class = col_css ? col_css.split(" ").map { |c| "#{c}-outlook" }.join(" ") : ""
527
+ col_width_attr = col_attrs["width"]
528
+ col_px = if col_width_attr && col_width_attr.strip.end_with?("px")
529
+ col_width_attr.to_f.round
530
+ else
531
+ (box_width.to_f * widths[i] / 100.0).round
532
+ end
533
+
534
+ td_open = %(<!--[if mso | IE]><td class="#{escape_attr(outlook_class)}" style="vertical-align:#{v_align};width:#{col_px}px;" ><![endif]-->)
523
535
  td_close = %(<!--[if mso | IE]></td><![endif]-->)
524
536
 
525
537
  context[:_column_width_pct] = widths[i]
@@ -530,6 +542,8 @@ module MjmlRb
530
542
  end
531
543
 
532
544
  ([open_table, open_tr] + col_parts + [close_tr, close_table]).join("\n")
545
+ ensure
546
+ context[:container_width] = previous_container_width
533
547
  end
534
548
 
535
549
  # ── mj-wrapper ─────────────────────────────────────────────────────────
@@ -235,14 +235,14 @@ module MjmlRb
235
235
  widths = column_widths || {}
236
236
  return "" if widths.empty?
237
237
 
238
- base_rules = widths.map do |suffix, pct|
239
- ".mj-column-per-#{suffix} { width:#{pct}% !important; max-width: #{pct}%; }"
238
+ base_rules = widths.map do |class_name, width_str|
239
+ ".#{class_name} { width:#{width_str} !important; max-width: #{width_str}; }"
240
240
  end
241
- moz_rules = widths.map do |suffix, pct|
242
- ".moz-text-html .mj-column-per-#{suffix} { width:#{pct}% !important; max-width: #{pct}%; }"
241
+ moz_rules = widths.map do |class_name, width_str|
242
+ ".moz-text-html .#{class_name} { width:#{width_str} !important; max-width: #{width_str}; }"
243
243
  end
244
- owa_rules = widths.map do |suffix, pct|
245
- "[owa] .mj-column-per-#{suffix} { width:#{pct}% !important; max-width: #{pct}%; }"
244
+ owa_rules = widths.map do |class_name, width_str|
245
+ "[owa] .#{class_name} { width:#{width_str} !important; max-width: #{width_str}; }"
246
246
  end
247
247
 
248
248
  bp = breakpoint.to_s.strip
@@ -1,3 +1,3 @@
1
1
  module MjmlRb
2
- VERSION = "0.2.30".freeze
2
+ VERSION = "0.2.31".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.30
4
+ version: 0.2.31
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Andriichuk