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 +4 -4
- data/lib/mjml-rb/renderer.rb +32 -6
- 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: 990083fd9e656cfe50b74937926c14f37ea359adf49530e5ffbacf17ef0ea00a
|
|
4
|
+
data.tar.gz: a03cc468ddcdb25fdde896f3d53bbd8febaad32db0b3aae3ccad69725f11920c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ee2bff6d7a36be6fe4f95b19eefd60e9ff295d62d681cd7e3131ff9e298859b66fea7f5d6887ae3f984d9f13fc6aeda4f3f58b8ee6e6cfd9b603d804cb0305a2
|
|
7
|
+
data.tar.gz: fdd623a60697cb966591bfcad9fc973e71586ffc3776f6f3de5944fc63c2ea413324b3b6ca288303117b58fbfc12c8e2b13aca174b657a5e8c4a33eb73138e97
|
data/lib/mjml-rb/renderer.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
|
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"] =
|
|
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)
|
data/lib/mjml-rb/version.rb
CHANGED