mjml-rb 0.2.20 → 0.2.22

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: 97ca7a3d968fdd4dee9f34ef7806283cb1a53fda0810dcf2456770f298831b35
4
- data.tar.gz: 53a50ac16e06c719fa6533de98e43c35233a1ab0470bf81c366c1be62726c2b4
3
+ metadata.gz: fb97af0d72ddb5898c28c33ccc0efafc27532f3709062f563f8d3d39fdcc642b
4
+ data.tar.gz: 2bb9d55e089309e74ab77766360b3c2a094c633a73ba8fb1fa4599780813dab4
5
5
  SHA512:
6
- metadata.gz: 22bb47ef2611887dbf6a19ee38cfb7da366060b632bf3cfb9ea548798a29e120287ae4de035255560d36dc5c407eeef3c04a007695b297da9230ecbd17d0dcb1
7
- data.tar.gz: f9f14bde5dd817a322e40da7b0de8645185c6b25e884d9d3aa45df7f3a5fca94eb92723204f4a193fc696bfe93f1b31a2033bf99042a3637adc7d0d61aa65343
6
+ metadata.gz: a0fbd53af9fc541a29f0d70e123efb0d390f9023a1388f8d1f6ef23ff1ad3aa6a16a0a410975744f03d934538cb99766620ebca44ba561272ce845057dc86277
7
+ data.tar.gz: 40f1fdcf06405a730a37b7d095fa6d92270e09cfd21c8fce71a2bcd8c79da52ef1f72175bfc9766395d011bec3582731b4a66135bd5f0ac8978d6c117c96e82f
@@ -24,6 +24,8 @@ require_relative "components/spacer"
24
24
 
25
25
  module MjmlRb
26
26
  class Renderer
27
+ HTML_VOID_TAGS = %w[area base br col embed hr img input link meta param source track wbr].freeze
28
+
27
29
  DEFAULT_FONTS = {
28
30
  "Roboto" => "https://fonts.googleapis.com/css?family=Roboto:300,400,500,700"
29
31
  }.freeze
@@ -36,6 +38,27 @@ module MjmlRb
36
38
  p { display:block;margin:13px 0; }
37
39
  CSS
38
40
 
41
+ OUTLOOK_DOCUMENT_SETTINGS = <<~HTML.chomp.freeze
42
+ <!--[if mso]>
43
+ <noscript>
44
+ <xml>
45
+ <o:OfficeDocumentSettings>
46
+ <o:AllowPNG/>
47
+ <o:PixelsPerInch>96</o:PixelsPerInch>
48
+ </o:OfficeDocumentSettings>
49
+ </xml>
50
+ </noscript>
51
+ <![endif]-->
52
+ HTML
53
+
54
+ OUTLOOK_GROUP_FIX = <<~HTML.chomp.freeze
55
+ <!--[if lte mso 11]>
56
+ <style type="text/css">
57
+ .mj-outlook-group-fix { width:100% !important; }
58
+ </style>
59
+ <![endif]-->
60
+ HTML
61
+
39
62
  def render(document, options = {})
40
63
  head = find_child(document, "mj-head")
41
64
  body = find_child(document, "mj-body")
@@ -90,20 +113,28 @@ module MjmlRb
90
113
  before_doctype = context[:before_doctype].to_s
91
114
  font_tags = build_font_tags(content, context[:inline_styles], context[:fonts])
92
115
  preview_block = preview.empty? ? "" : %(<div style="display:none;max-height:0;overflow:hidden;opacity:0;">#{escape_html(preview)}</div>)
93
- html_attributes = { "lang" => context[:lang], "dir" => context[:dir] }
94
- body_style = style_join(
95
- "margin" => "0",
96
- "padding" => "0",
97
- "background" => context[:background_color] || "#ffffff"
98
- )
116
+ html_attributes = {
117
+ "lang" => context[:lang],
118
+ "dir" => context[:dir],
119
+ "xmlns" => "http://www.w3.org/1999/xhtml",
120
+ "xmlns:v" => "urn:schemas-microsoft-com:vml",
121
+ "xmlns:o" => "urn:schemas-microsoft-com:office:office"
122
+ }
123
+ body_style = style_join("word-spacing" => "normal")
99
124
 
100
125
  html = <<~HTML
101
126
  <!doctype html>
102
127
  <html#{html_attrs(html_attributes)}>
103
128
  <head>
129
+ <title>#{escape_html(title)}</title>
130
+ <!--[if !mso]><!-->
131
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
132
+ <!--<![endif]-->
133
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
104
134
  <meta charset="utf-8">
105
135
  <meta name="viewport" content="width=device-width, initial-scale=1">
106
- <title>#{escape_html(title)}</title>
136
+ #{OUTLOOK_DOCUMENT_SETTINGS}
137
+ #{OUTLOOK_GROUP_FIX}
107
138
  #{font_tags}
108
139
  <style type="text/css">#{head_styles}</style>
109
140
  #{head_raw}
@@ -202,12 +233,21 @@ module MjmlRb
202
233
  css = widths.map do |suffix, pct|
203
234
  ".mj-column-per-#{suffix} { width:#{pct}% !important; max-width: #{pct}%; }"
204
235
  end.join("\n")
236
+ moz_css = widths.map do |suffix, pct|
237
+ ".moz-text-html .mj-column-per-#{suffix} { width:#{pct}% !important; max-width: #{pct}%; }"
238
+ end.join("\n")
239
+ owa_css = widths.map do |suffix, pct|
240
+ "[owa] .mj-column-per-#{suffix} { width:#{pct}% !important; max-width: #{pct}%; }"
241
+ end.join("\n")
205
242
  breakpoint = context[:breakpoint].to_s.strip
206
243
  if breakpoint.empty?
207
244
  context[:head_styles] << css
245
+ context[:head_styles] << moz_css
208
246
  else
209
247
  context[:head_styles] << "@media only screen and (min-width:#{breakpoint}) {\n#{css}\n}"
248
+ context[:head_styles] << "@media screen and (min-width:#{breakpoint}) {\n#{moz_css}\n}"
210
249
  end
250
+ context[:head_styles] << owa_css
211
251
  end
212
252
 
213
253
  def merge_outlook_conditionals(html)
@@ -533,12 +573,17 @@ module MjmlRb
533
573
 
534
574
  def serialize_node(node)
535
575
  attrs = node.attributes.map { |k, v| %( #{k}="#{escape_attr(v)}") }.join
536
- return "<#{node.tag_name}#{attrs} />" if node.children.empty?
576
+ return "<#{node.tag_name}#{attrs} />" if node.children.empty? && html_void_tag?(node.tag_name)
577
+ return "<#{node.tag_name}#{attrs}></#{node.tag_name}>" if node.children.empty?
537
578
 
538
579
  inner = node.children.map { |child| child.text? ? child.content.to_s : serialize_node(child) }.join
539
580
  "<#{node.tag_name}#{attrs}>#{inner}</#{node.tag_name}>"
540
581
  end
541
582
 
583
+ def html_void_tag?(tag_name)
584
+ HTML_VOID_TAGS.include?(tag_name.to_s.downcase)
585
+ end
586
+
542
587
  def style_join(hash)
543
588
  hash.each_with_object([]) do |(key, value), memo|
544
589
  next if value.nil? || value.to_s.empty?
@@ -1,3 +1,3 @@
1
1
  module MjmlRb
2
- VERSION = "0.2.20".freeze
2
+ VERSION = "0.2.22".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.20
4
+ version: 0.2.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Andriichuk