mjml-rb 0.2.14 → 0.2.15

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: 2d1dc49d39635e3f4530f642a8699646f3bff8e545213387f91d95bb461ea67d
4
- data.tar.gz: 15139737ec96a78601bd7d0e0a992b8743060d4923664eea05462a76e70dc7d3
3
+ metadata.gz: 990083fd9e656cfe50b74937926c14f37ea359adf49530e5ffbacf17ef0ea00a
4
+ data.tar.gz: a03cc468ddcdb25fdde896f3d53bbd8febaad32db0b3aae3ccad69725f11920c
5
5
  SHA512:
6
- metadata.gz: 486e95fb106f03ebb1ae929ec548996f9d53868b360fcff23cfd0aa28d9e4240e3a3181f611b3270837c9012e523c32f3089c0ebe3a82e9bd6e067735a955bec
7
- data.tar.gz: 5bf0eb72f669aed9eb59dc1b8fbe16563082392bbc8d05e2f8d4ce4098a492606303cea65692757fdf5b8eed2c0fc2be7080daeac73f6f242b0a1dfc1c0d5551
6
+ metadata.gz: ee2bff6d7a36be6fe4f95b19eefd60e9ff295d62d681cd7e3131ff9e298859b66fea7f5d6887ae3f984d9f13fc6aeda4f3f58b8ee6e6cfd9b603d804cb0305a2
7
+ data.tar.gz: fdd623a60697cb966591bfcad9fc973e71586ffc3776f6f3de5944fc63c2ea413324b3b6ca288303117b58fbfc12c8e2b13aca174b657a5e8c4a33eb73138e97
@@ -344,25 +344,32 @@ module MjmlRb
344
344
  property, value = entry.split(":", 2).map { |part| part&.strip }
345
345
  next if property.nil? || property.empty? || value.nil? || value.empty?
346
346
 
347
- memo[property] = value.sub(/\s*!important\s*\z/, "").strip
347
+ important = value.match?(/\s*!important\s*\z/)
348
+ memo[property] = {
349
+ value: value.sub(/\s*!important\s*\z/, "").strip,
350
+ important: important
351
+ }
348
352
  end
349
353
  end
350
354
 
351
355
  def merge_inline_style!(node, declarations)
352
356
  existing = parse_css_declarations(node["style"].to_s)
353
357
  declarations.each do |property, value|
354
- existing[property] = value
358
+ existing[property] = merge_css_declaration(existing[property], value)
355
359
  end
356
360
  normalize_background_fallbacks!(node, existing)
357
- node["style"] = existing.map { |property, value| "#{property}: #{value}" }.join("; ")
361
+ node["style"] = serialize_css_declarations(existing)
358
362
  end
359
363
 
360
364
  def normalize_background_fallbacks!(node, declarations)
361
- background_color = declarations["background-color"]
365
+ background_color = declaration_value(declarations["background-color"])
362
366
  return if background_color.nil? || background_color.empty?
363
367
 
364
- if syncable_background?(declarations["background"])
365
- declarations["background"] = background_color
368
+ if syncable_background?(declaration_value(declarations["background"]))
369
+ declarations["background"] = {
370
+ value: background_color,
371
+ important: declarations.fetch("background-color", {}).fetch(:important, false)
372
+ }
366
373
  end
367
374
 
368
375
  return unless node.name == "td"
@@ -390,6 +397,25 @@ module MjmlRb
390
397
  !normalized.include?(" right")
391
398
  end
392
399
 
400
+ def merge_css_declaration(existing, incoming)
401
+ return incoming if existing.nil?
402
+ return existing if existing[:important] && !incoming[:important]
403
+
404
+ incoming
405
+ end
406
+
407
+ def declaration_value(declaration)
408
+ declaration && declaration[:value]
409
+ end
410
+
411
+ def serialize_css_declarations(declarations)
412
+ declarations.map do |property, declaration|
413
+ value = declaration[:value]
414
+ value = "#{value} !important" if declaration[:important]
415
+ "#{property}: #{value}"
416
+ end.join("; ")
417
+ end
418
+
393
419
  def append_component_head_styles(document, context)
394
420
  component_registry.each_value.uniq.each do |component|
395
421
  next unless component.respond_to?(:head_style)
@@ -1,3 +1,3 @@
1
1
  module MjmlRb
2
- VERSION = "0.2.14".freeze
2
+ VERSION = "0.2.15".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.14
4
+ version: 0.2.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Andriichuk