mjml-rb 0.2.29 → 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 +4 -4
- data/lib/mjml-rb/components/column.rb +11 -4
- data/lib/mjml-rb/components/group.rb +3 -3
- data/lib/mjml-rb/components/section.rb +17 -3
- data/lib/mjml-rb/dependencies.rb +19 -3
- data/lib/mjml-rb/renderer.rb +6 -6
- data/lib/mjml-rb/validator.rb +4 -0
- 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: 512c35b10aab7894e19942c4c881e3f08c127c8660c587192a0f9bc3972092cd
|
|
4
|
+
data.tar.gz: d18d2c2bc8bbdf369af791ebc41841b3b762d85e4811b5cdb408ff66a45dd3e7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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 = "
|
|
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
|
-
|
|
30
|
-
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 = "
|
|
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
|
-
|
|
521
|
-
|
|
522
|
-
|
|
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 ─────────────────────────────────────────────────────────
|
data/lib/mjml-rb/dependencies.rb
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
|
+
require "set"
|
|
2
|
+
|
|
1
3
|
module MjmlRb
|
|
2
4
|
module Dependencies
|
|
5
|
+
# Components whose content is treated as raw HTML in NPM (endingTag = true).
|
|
6
|
+
# The parser preserves their inner markup as-is; the validator skips child
|
|
7
|
+
# element checks because REXML structurally parses what NPM treats as text.
|
|
8
|
+
ENDING_TAGS = Set.new(%w[
|
|
9
|
+
mj-accordion-text
|
|
10
|
+
mj-accordion-title
|
|
11
|
+
mj-button
|
|
12
|
+
mj-carousel-image
|
|
13
|
+
mj-navbar-link
|
|
14
|
+
mj-raw
|
|
15
|
+
mj-table
|
|
16
|
+
mj-text
|
|
17
|
+
]).freeze
|
|
18
|
+
|
|
3
19
|
RULES = {
|
|
4
20
|
"mjml" => ["mj-body", "mj-head", "mj-raw"],
|
|
5
21
|
"mj-accordion" => ["mj-accordion-element", "mj-raw"],
|
|
@@ -53,14 +69,14 @@ module MjmlRb
|
|
|
53
69
|
],
|
|
54
70
|
"mj-image" => [],
|
|
55
71
|
"mj-navbar" => ["mj-navbar-link", "mj-raw"],
|
|
56
|
-
"mj-raw" => [
|
|
72
|
+
"mj-raw" => [],
|
|
57
73
|
"mj-section" => ["mj-column", "mj-group", "mj-raw"],
|
|
58
74
|
"mj-selector" => ["mj-html-attribute"],
|
|
59
75
|
"mj-social" => ["mj-social-element", "mj-raw"],
|
|
60
76
|
"mj-social-element" => [],
|
|
61
77
|
"mj-spacer" => [],
|
|
62
|
-
"mj-table" => [
|
|
63
|
-
"mj-text" => [
|
|
78
|
+
"mj-table" => [],
|
|
79
|
+
"mj-text" => [],
|
|
64
80
|
"mj-wrapper" => ["mj-hero", "mj-raw", "mj-section"]
|
|
65
81
|
}.freeze
|
|
66
82
|
end
|
data/lib/mjml-rb/renderer.rb
CHANGED
|
@@ -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 |
|
|
239
|
-
"
|
|
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 |
|
|
242
|
-
".moz-text-html
|
|
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 |
|
|
245
|
-
"[owa]
|
|
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
|
data/lib/mjml-rb/validator.rb
CHANGED
|
@@ -52,6 +52,10 @@ module MjmlRb
|
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
def validate_allowed_children(node, errors)
|
|
55
|
+
# Ending-tag components treat content as raw HTML; REXML still parses
|
|
56
|
+
# children structurally, so skip child validation for those tags.
|
|
57
|
+
return if Dependencies::ENDING_TAGS.include?(node.tag_name)
|
|
58
|
+
|
|
55
59
|
allowed = Dependencies::RULES[node.tag_name]
|
|
56
60
|
return unless allowed
|
|
57
61
|
|
data/lib/mjml-rb/version.rb
CHANGED