mjml-rb 0.2.1 → 0.2.2

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: 8c04515032bc1da0a7fcbbad05d5d2b8bb10f684cb34e3b25920f96e10e63207
4
- data.tar.gz: 778c683334aecab61498fde20ea06ba55e417c5080fd1776dacf5668f609988e
3
+ metadata.gz: 8065e65f3045ffc642525cb247d79591a4c1c2cd3d57541ec768dc2d0fec6ef9
4
+ data.tar.gz: 304dc0c8474a87438378344264bcc4e56e27052ea9e09d6003352a3c94f3dd4e
5
5
  SHA512:
6
- metadata.gz: 3c2b46d74bb5804fd9db901c529aec0fd2a4d9cb9b8b97872ce5d7bef2fc22077cfa1b0471f368ab268b5c3d8b231e0cbc13f5b565da937692689233b98a55ae
7
- data.tar.gz: 37e1b8ce0fa0134c5cbe41e8977fb3f0722dcbcea69728f2b810a1bf615a81691f27fa55805ccd52f37b23c078d957ed3fbc388f9898a9cad4fd667773fe2781
6
+ metadata.gz: a9bc2dd17fe59a21d311aca96332ba32a5c09222641bf566518e9aa856f5a9f45121d72ed6b53f74217cf26b61a3378d2f800abe482a772585e0353eb8b5627b
7
+ data.tar.gz: 90991a406d6ecc5ed614d0a12a6bba3094bb0c72535407fcf709e5e5d9bceab802d137e85e319ac47aa57ad3c5ab4bf58fddbd8524996468cdeb18ebb521d30e
data/README.md CHANGED
@@ -58,7 +58,7 @@ The table below tracks current JS-to-Ruby migration status for MJML components i
58
58
  | `mj-hero` | migrated | Implemented in `hero.rb` with fixed/fluid modes, inner content wrapper, and Outlook VML background fallback. |
59
59
  | `mj-navbar` | migrated | Implemented in `navbar.rb`, including `base-url` propagation and breakpoint-aware hamburger CSS. |
60
60
  | `mj-navbar-link` | migrated | Implemented in `navbar.rb` as an ending-tag navbar child component. |
61
- | `mj-raw` | partial | Supported as passthrough content, but not as a dedicated migrated component. |
61
+ | `mj-raw` | migrated | Implemented in `raw.rb`, including head insertion and top-level `position="file-start"` output before the doctype. |
62
62
  | `mj-head` | partial | Core tags such as `mj-title`, `mj-preview`, `mj-style`, `mj-font`, and `mj-attributes` are supported. |
63
63
  | `mj-attributes` | partial | `mj-all`, `mj-class`, and per-tag defaults are supported. |
64
64
  | `mj-all` | partial | Supported through `mj-attributes`. |
@@ -0,0 +1,21 @@
1
+ require_relative "base"
2
+
3
+ module MjmlRb
4
+ module Components
5
+ class Raw < Base
6
+ TAGS = ["mj-raw"].freeze
7
+
8
+ ALLOWED_ATTRIBUTES = {
9
+ "position" => "enum(file-start)"
10
+ }.freeze
11
+
12
+ def tags
13
+ TAGS
14
+ end
15
+
16
+ def render(tag_name:, node:, context:, attrs:, parent:)
17
+ raw_inner(node)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -7,6 +7,7 @@ require_relative "components/button"
7
7
  require_relative "components/hero"
8
8
  require_relative "components/image"
9
9
  require_relative "components/navbar"
10
+ require_relative "components/raw"
10
11
  require_relative "components/text"
11
12
  require_relative "components/divider"
12
13
  require_relative "components/html_attributes"
@@ -36,6 +37,7 @@ module MjmlRb
36
37
  raise ArgumentError, "Missing <mj-body>" unless body
37
38
 
38
39
  context = build_context(head, options)
40
+ context[:before_doctype] = root_file_start_raw(document)
39
41
  context[:lang] = options[:lang] || document.attributes["lang"] || "und"
40
42
  context[:dir] = options[:dir] || document.attributes["dir"] || "auto"
41
43
  context[:column_widths] = {}
@@ -52,9 +54,10 @@ module MjmlRb
52
54
  title: "",
53
55
  preview: "",
54
56
  breakpoint: "480px",
57
+ before_doctype: "",
58
+ head_raw: [],
55
59
  head_styles: [],
56
60
  inline_styles: [],
57
- body_styles: [],
58
61
  html_attributes: {},
59
62
  fonts: DEFAULT_FONTS.merge(hash_or_empty(options[:fonts])),
60
63
  global_defaults: {},
@@ -85,7 +88,7 @@ module MjmlRb
85
88
  when "mj-html-attributes"
86
89
  absorb_html_attributes_node(node, context)
87
90
  when "mj-raw"
88
- context[:body_styles] << raw_inner(node)
91
+ context[:head_raw] << raw_inner(node)
89
92
  end
90
93
  end
91
94
 
@@ -135,6 +138,8 @@ module MjmlRb
135
138
  title = context[:title].to_s
136
139
  preview = context[:preview]
137
140
  head_styles = ([DOCUMENT_RESET_CSS] + unique_strings(context[:head_styles])).join("\n")
141
+ head_raw = Array(context[:head_raw]).join("\n")
142
+ before_doctype = context[:before_doctype].to_s
138
143
  font_links = context[:fonts].values.uniq.map { |href| %(<link href="#{escape_attr(href)}" rel="stylesheet" type="text/css">) }.join("\n")
139
144
  preview_block = preview.empty? ? "" : %(<div style="display:none;max-height:0;overflow:hidden;opacity:0;">#{escape_html(preview)}</div>)
140
145
  html_attributes = { "lang" => context[:lang], "dir" => context[:dir] }
@@ -153,6 +158,7 @@ module MjmlRb
153
158
  <title>#{escape_html(title)}</title>
154
159
  #{font_links}
155
160
  <style type="text/css">#{head_styles}</style>
161
+ #{head_raw}
156
162
  </head>
157
163
  <body style="#{body_style}">
158
164
  #{preview_block}
@@ -162,7 +168,8 @@ module MjmlRb
162
168
  HTML
163
169
 
164
170
  html = apply_html_attributes(html, context)
165
- apply_inline_styles(html, context)
171
+ html = apply_inline_styles(html, context)
172
+ before_doctype.empty? ? html : "#{before_doctype}\n#{html}"
166
173
  end
167
174
 
168
175
  def render_children(node, context, parent:)
@@ -181,8 +188,6 @@ module MjmlRb
181
188
  case node.tag_name
182
189
  when "mj-group"
183
190
  render_group(node, context)
184
- when "mj-raw"
185
- raw_inner(node)
186
191
  else
187
192
  render_children(node, context, parent: node.tag_name)
188
193
  end
@@ -392,6 +397,7 @@ module MjmlRb
392
397
  register_component(registry, Components::Hero.new(self))
393
398
  register_component(registry, Components::Image.new(self))
394
399
  register_component(registry, Components::Navbar.new(self))
400
+ register_component(registry, Components::Raw.new(self))
395
401
  register_component(registry, Components::Text.new(self))
396
402
  register_component(registry, Components::Divider.new(self))
397
403
  register_component(registry, Components::Table.new(self))
@@ -476,6 +482,15 @@ module MjmlRb
476
482
  node.element_children.find { |child| child.tag_name == tag_name }
477
483
  end
478
484
 
485
+ def root_file_start_raw(document)
486
+ document.element_children.filter_map do |child|
487
+ next unless child.tag_name == "mj-raw"
488
+ next unless child.attributes["position"] == "file-start"
489
+
490
+ raw_inner(child)
491
+ end.join("\n")
492
+ end
493
+
479
494
  def contains_tag?(node, tag_name)
480
495
  return false unless node.respond_to?(:tag_name)
481
496
  return true if node.tag_name == tag_name
@@ -1,3 +1,3 @@
1
1
  module MjmlRb
2
- VERSION = "0.2.1".freeze
2
+ VERSION = "0.2.2".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.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Andriichuk
@@ -64,6 +64,7 @@ files:
64
64
  - lib/mjml-rb/components/html_attributes.rb
65
65
  - lib/mjml-rb/components/image.rb
66
66
  - lib/mjml-rb/components/navbar.rb
67
+ - lib/mjml-rb/components/raw.rb
67
68
  - lib/mjml-rb/components/section.rb
68
69
  - lib/mjml-rb/components/social.rb
69
70
  - lib/mjml-rb/components/spacer.rb