mjml-rb 0.5.0 → 0.5.1
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/README.md +2 -0
- data/lib/mjml-rb/renderer.rb +4 -40
- 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: 46b2a8437d579f58fe7a39ef2355935c9d6cf728fb42a861b1fe84ae6c0d1a85
|
|
4
|
+
data.tar.gz: 28897aaecd04098a2b4757d0fbf7c22a7f16ff9c3894c71f0346487aedbe87ef
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5eb50165e738fe194a88ca08e6b51c97bee21eeaa8935527c32aa07c67353a5ce54557dd033577c6c43f5fbf8e11506e0de45b14059a7198e8851a170d590926
|
|
7
|
+
data.tar.gz: 3232dc21d03d6ab082dffff4429578bab6c3e12bd49fb440be3272c5b3f54880089bd5dd87c80a2acc303f02b3673916c3d4767080593d8fb7cad69bb5319e9e
|
data/README.md
CHANGED
data/lib/mjml-rb/renderer.rb
CHANGED
|
@@ -26,8 +26,6 @@ require_relative "components/spacer"
|
|
|
26
26
|
|
|
27
27
|
module MjmlRb
|
|
28
28
|
class Renderer
|
|
29
|
-
HTML_VOID_TAGS = Set.new(%w[area base br col embed hr img input link meta param source track wbr]).freeze
|
|
30
|
-
|
|
31
29
|
DEFAULT_FONTS = {
|
|
32
30
|
"Open Sans" => "https://fonts.googleapis.com/css?family=Open+Sans:300,400,500,700",
|
|
33
31
|
"Droid Sans" => "https://fonts.googleapis.com/css?family=Droid+Sans:300,400,500,700",
|
|
@@ -690,16 +688,8 @@ module MjmlRb
|
|
|
690
688
|
end
|
|
691
689
|
|
|
692
690
|
def html_inner(node)
|
|
693
|
-
if node.respond_to?(:
|
|
694
|
-
node.
|
|
695
|
-
if child.text?
|
|
696
|
-
serialize_text_content(escape_html(child.content.to_s))
|
|
697
|
-
elsif child.comment?
|
|
698
|
-
"<!--#{child.content}-->"
|
|
699
|
-
else
|
|
700
|
-
serialize_node(child)
|
|
701
|
-
end
|
|
702
|
-
end.join
|
|
691
|
+
if node.respond_to?(:inner_html)
|
|
692
|
+
node.inner_html
|
|
703
693
|
else
|
|
704
694
|
escape_html(node.text_content)
|
|
705
695
|
end
|
|
@@ -712,11 +702,9 @@ module MjmlRb
|
|
|
712
702
|
if node.respond_to?(:children)
|
|
713
703
|
node.children.map do |child|
|
|
714
704
|
if child.text?
|
|
715
|
-
|
|
716
|
-
elsif child.comment?
|
|
717
|
-
"<!--#{child.content}-->"
|
|
705
|
+
child.content.to_s
|
|
718
706
|
else
|
|
719
|
-
|
|
707
|
+
child.to_html
|
|
720
708
|
end
|
|
721
709
|
end.join
|
|
722
710
|
else
|
|
@@ -750,30 +738,6 @@ module MjmlRb
|
|
|
750
738
|
text.to_s.gsub(" ", " ").gsub("\t", "	")
|
|
751
739
|
end
|
|
752
740
|
|
|
753
|
-
def serialize_node(node)
|
|
754
|
-
attrs = node.attributes.map { |k, v| %( #{k}="#{escape_attr(v)}") }.join
|
|
755
|
-
return "<#{node.tag_name}#{attrs} />" if node.children.empty? && html_void_tag?(node.tag_name)
|
|
756
|
-
return "<#{node.tag_name}#{attrs}></#{node.tag_name}>" if node.children.empty?
|
|
757
|
-
|
|
758
|
-
inner = node.children.map { |child| child.text? ? serialize_text_content(child.content.to_s) : serialize_node(child) }.join
|
|
759
|
-
"<#{node.tag_name}#{attrs}>#{inner}</#{node.tag_name}>"
|
|
760
|
-
end
|
|
761
|
-
|
|
762
|
-
def serialize_text_content(text)
|
|
763
|
-
value = text.to_s
|
|
764
|
-
return value unless significant_whitespace_text?(value)
|
|
765
|
-
|
|
766
|
-
value.gsub(" ", " ").gsub("\t", "	")
|
|
767
|
-
end
|
|
768
|
-
|
|
769
|
-
def significant_whitespace_text?(text)
|
|
770
|
-
!text.empty? && text.strip.empty? && !text.match?(/[\r\n]/)
|
|
771
|
-
end
|
|
772
|
-
|
|
773
|
-
def html_void_tag?(tag_name)
|
|
774
|
-
HTML_VOID_TAGS.include?(tag_name.to_s.downcase)
|
|
775
|
-
end
|
|
776
|
-
|
|
777
741
|
def style_join(hash)
|
|
778
742
|
hash.each_with_object([]) do |(key, value), memo|
|
|
779
743
|
next if value.nil? || value.to_s.empty?
|
data/lib/mjml-rb/version.rb
CHANGED