mjml-rb 0.3.4 → 0.3.6

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: c87c74bfccdb5ffe347fba7099a9f17855e1c42446b1edd0d013dbfa08fe5c67
4
- data.tar.gz: b18e8124ded52ecc49a7d43f00da55ff902068f3b1593d195aaecb95e042346f
3
+ metadata.gz: 8416ab91e9a9d1c4addbbed2368136715d3726b5524e3cce2f27865c5522b6f2
4
+ data.tar.gz: 576c18c2307ca32b30012e2e91450b2888e1f6cf13c9398bd0c7da7ef616bb7d
5
5
  SHA512:
6
- metadata.gz: 0e4714a86a42c8270a6ec66a8b7d50bc21f54ea9d0aebb8cbf5424fac2af621de1ab8fa79d8b51cdc92954b615e8c66dd55e499593dec4861a65052b6c7eacab
7
- data.tar.gz: 80f36f9bea2094a8a13b8bffea1b8b3c3f62b67bfefb44a540ecdc96b479dc50366f7ca182f5f601387f31e8dc44cebf6c9c60c0f8761dfa530ad27aca9e6419
6
+ metadata.gz: c3ed81729d5550ae8611f0b4fd17545373b8c4041fc286f655c6c975be42182aab441a8c11d07e7a15578a55a6d83849e33e4507f99f45d925ea81212e04607c
7
+ data.tar.gz: e407a972325006108bce56759035dfa0b00f93d1917c162d04c2c2ad3d299c0bb03f15a36d3f49c6a26d3d3e2ee058f45fbf29c96a016034c85372af87db4404
data/README.md CHANGED
@@ -20,6 +20,8 @@ This gem provides a Ruby-first implementation of the main MJML tooling:
20
20
  - pure Ruby parser, AST, validator, and renderer
21
21
  - no Node.js runtime and no shelling out to the official npm renderer
22
22
 
23
+ Remaining parity work is tracked in [npm ↔ Ruby Parity Audit](docs/PARITY_AUDIT.md).
24
+
23
25
  ## Compatibility
24
26
 
25
27
  This project targets **MJML v4 only**.
@@ -205,5 +207,3 @@ If you want the full internal walkthrough, see [docs/ARCHITECTURE.md](docs/ARCHI
205
207
  > plain Ruby project and render MJML templates the same way you render ERB — no
206
208
  > extra runtime, no
207
209
  > `package.json`, no `node_modules`.
208
-
209
- Remaining parity work is tracked in [npm ↔ Ruby Parity Audit](docs/PARITY_AUDIT.md).
@@ -92,7 +92,7 @@ module MjmlRb
92
92
  <<~HTML.chomp
93
93
  <a#{html_attrs(link_attrs)}>
94
94
  <label#{html_attrs(label_attrs)}>
95
- #{build_img_tag(image_attrs)}
95
+ <img#{html_attrs(image_attrs)} />
96
96
  </label>
97
97
  </a>
98
98
  HTML
@@ -117,7 +117,7 @@ module MjmlRb
117
117
  "width" => container_width.to_i.to_s,
118
118
  "border" => "0"
119
119
  }
120
- image_tag = build_img_tag(img_attrs)
120
+ image_tag = "<img#{html_attrs(img_attrs)} />"
121
121
 
122
122
  content = if a["href"]
123
123
  link_attrs = {
@@ -146,17 +146,6 @@ module MjmlRb
146
146
  classes.split(/\s+/).map { |klass| "#{klass}-#{suffix}" }.join(" ")
147
147
  end
148
148
 
149
- def build_img_tag(attrs)
150
- ordered_keys = %w[title src alt style width border]
151
- rendered = ordered_keys.filter_map do |key|
152
- next unless attrs.key?(key)
153
- next if key != "alt" && (attrs[key].nil? || attrs[key].to_s.empty?)
154
-
155
- %(#{key}="#{escape_attr(attrs[key].to_s)}")
156
- end
157
-
158
- "<img #{rendered.join(' ')} />"
159
- end
160
149
  end
161
150
  end
162
151
  end
@@ -304,11 +304,16 @@ module MjmlRb
304
304
  "display" => "block"
305
305
  )
306
306
 
307
- # alt must always be rendered (even as alt=""), so build img tag manually
308
- img_tag = build_img_tag(
309
- alt: alt_val, title: title_val, src: src,
310
- style: img_style, width: icon_width, sizes: sizes_attr, srcset: srcset
311
- )
307
+ img_attrs = {
308
+ "alt" => alt_val,
309
+ "title" => title_val,
310
+ "src" => src,
311
+ "style" => img_style.empty? ? nil : img_style,
312
+ "width" => icon_width,
313
+ "sizes" => sizes_attr,
314
+ "srcset" => srcset
315
+ }
316
+ img_tag = "<img#{html_attrs(img_attrs)} />"
312
317
 
313
318
  if has_link
314
319
  link_attrs_str = html_attrs({ "href" => final_href, "rel" => rel_val, "target" => target_val })
@@ -360,17 +365,6 @@ module MjmlRb
360
365
  %(<tr#{tr_class}>#{cells}</tr>)
361
366
  end
362
367
 
363
- # Build an <img> tag where alt is always rendered (even as alt="")
364
- def build_img_tag(alt:, title:, src:, style:, width:, sizes:, srcset:)
365
- parts = [%( alt="#{escape_attr(alt.to_s)}")]
366
- parts << %( title="#{escape_attr(title)}") unless title.nil? || title.to_s.empty?
367
- parts << %( src="#{escape_attr(src)}") unless src.nil? || src.to_s.empty?
368
- parts << %( style="#{style}") unless style.nil? || style.empty?
369
- parts << %( width="#{escape_attr(width)}") unless width.nil? || width.to_s.empty?
370
- parts << %( sizes="#{escape_attr(sizes)}") unless sizes.nil? || sizes.to_s.empty?
371
- parts << %( srcset="#{escape_attr(srcset)}") unless srcset.nil? || srcset.to_s.empty?
372
- "<img#{parts.join} />"
373
- end
374
368
  end
375
369
  end
376
370
  end
@@ -830,16 +830,13 @@ module MjmlRb
830
830
  CGI.escapeHTML(value.to_s)
831
831
  end
832
832
 
833
- # HTML attributes that are meaningful even when empty.
834
- # `alt=""` signals a decorative image to browsers, suppressing the
835
- # broken-image placeholder icon.
836
- KEEP_WHEN_EMPTY = Set.new(%w[alt]).freeze
837
-
833
+ # Match npm MJML behaviour: omit only nil/undefined attributes.
834
+ # lodash `omitBy(attributes, isNil)` keeps empty strings, so we do the same.
835
+ # This preserves semantically meaningful empty values like `alt=""`.
838
836
  def html_attrs(hash)
839
837
  attrs = hash.each_with_object([]) do |(key, value), memo|
840
- if value.nil? || value.to_s.empty?
841
- next unless KEEP_WHEN_EMPTY.include?(key) && !value.nil?
842
- end
838
+ next if value.nil?
839
+
843
840
  memo << %(#{key}="#{escape_attr(value)}")
844
841
  end
845
842
  return "" if attrs.empty?
@@ -1,3 +1,3 @@
1
1
  module MjmlRb
2
- VERSION = "0.3.4".freeze
2
+ VERSION = "0.3.6".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.3.4
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Andriichuk