slate_serializer 1.0.0 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +18 -18
- data/lib/slate_serializer/html.rb +18 -5
- data/lib/slate_serializer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4abe4cb9f13367b5ab5314c2ecf348307ae5f14bb6520f8887f30e6ad30cd55
|
4
|
+
data.tar.gz: 1930bb2fb209bac981d68aaba448ef45e5c4d8e02302c3284670c79a3dedf197
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1bc7f72a4494bf92d462f19d117fd726e195039930b223006b742abf951ebfee918aebfefd653de2db89bf357f2254b371645761865181406aff2f31174125c4
|
7
|
+
data.tar.gz: 7bc1b5592eb6bd6df93d5fbf108cd3f453126bd463d9c9e282fb6d08f7c8c72b20c288511e5712f36cd0fc0547d27fbb351f1a91e750d17a23a9eab86089fe1d
|
data/Gemfile.lock
CHANGED
@@ -1,32 +1,32 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
slate_serializer (0.
|
4
|
+
slate_serializer (1.0.2)
|
5
5
|
nokogiri (~> 1.11)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
diff-lcs (1.
|
11
|
-
mini_portile2 (2.
|
12
|
-
nokogiri (1.
|
13
|
-
mini_portile2 (~> 2.
|
10
|
+
diff-lcs (1.5.1)
|
11
|
+
mini_portile2 (2.8.6)
|
12
|
+
nokogiri (1.16.4)
|
13
|
+
mini_portile2 (~> 2.8.2)
|
14
14
|
racc (~> 1.4)
|
15
|
-
racc (1.
|
16
|
-
rake (13.0
|
17
|
-
rspec (3.
|
18
|
-
rspec-core (~> 3.
|
19
|
-
rspec-expectations (~> 3.
|
20
|
-
rspec-mocks (~> 3.
|
21
|
-
rspec-core (3.
|
22
|
-
rspec-support (~> 3.
|
23
|
-
rspec-expectations (3.
|
15
|
+
racc (1.7.3)
|
16
|
+
rake (13.1.0)
|
17
|
+
rspec (3.13.0)
|
18
|
+
rspec-core (~> 3.13.0)
|
19
|
+
rspec-expectations (~> 3.13.0)
|
20
|
+
rspec-mocks (~> 3.13.0)
|
21
|
+
rspec-core (3.13.0)
|
22
|
+
rspec-support (~> 3.13.0)
|
23
|
+
rspec-expectations (3.13.0)
|
24
24
|
diff-lcs (>= 1.2.0, < 2.0)
|
25
|
-
rspec-support (~> 3.
|
26
|
-
rspec-mocks (3.
|
25
|
+
rspec-support (~> 3.13.0)
|
26
|
+
rspec-mocks (3.13.0)
|
27
27
|
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
-
rspec-support (~> 3.
|
29
|
-
rspec-support (3.
|
28
|
+
rspec-support (~> 3.13.0)
|
29
|
+
rspec-support (3.13.1)
|
30
30
|
|
31
31
|
PLATFORMS
|
32
32
|
ruby
|
@@ -6,6 +6,8 @@ module SlateSerializer
|
|
6
6
|
# Default lookup list to convert html tags to object types
|
7
7
|
ELEMENTS = {
|
8
8
|
'a': 'link',
|
9
|
+
'center': 'align-center',
|
10
|
+
'code': 'code',
|
9
11
|
'img': 'image',
|
10
12
|
'li': 'list-item',
|
11
13
|
'p': 'paragraph',
|
@@ -15,7 +17,9 @@ module SlateSerializer
|
|
15
17
|
'ol': 'ordered-list',
|
16
18
|
'ul': 'unordered-list',
|
17
19
|
'table': 'table',
|
20
|
+
'thead': 'thead',
|
18
21
|
'tbody': 'tbody',
|
22
|
+
'th': 'th',
|
19
23
|
'tr': 'tr',
|
20
24
|
'td': 'td',
|
21
25
|
'text': 'text',
|
@@ -24,7 +28,7 @@ module SlateSerializer
|
|
24
28
|
'figcaption': 'figcaption'
|
25
29
|
}.freeze
|
26
30
|
# Default block types list
|
27
|
-
BLOCK_ELEMENTS = %w[figure figcaption hr img li p ol ul table tbody tr td].freeze
|
31
|
+
BLOCK_ELEMENTS = %w[center code figure figcaption hr img li p ol ul table tbody thead th tr td].freeze
|
28
32
|
# Default inline types list
|
29
33
|
INLINE_ELEMENTS = %w[a].freeze
|
30
34
|
# Default mark types list
|
@@ -71,6 +75,8 @@ module SlateSerializer
|
|
71
75
|
def serializer(value)
|
72
76
|
return '' unless value.key?(:document)
|
73
77
|
|
78
|
+
self.mark_elements = MARK_ELEMENTS.invert
|
79
|
+
|
74
80
|
serialize_node(value[:document])
|
75
81
|
end
|
76
82
|
|
@@ -121,7 +127,7 @@ module SlateSerializer
|
|
121
127
|
nodes = []
|
122
128
|
mark = convert_name_to_mark(element.name)
|
123
129
|
|
124
|
-
if element.
|
130
|
+
if element.instance_of?(Nokogiri::XML::Element)
|
125
131
|
element.children.each do |child|
|
126
132
|
nodes << element_to_text(child, mark)
|
127
133
|
end
|
@@ -189,9 +195,10 @@ module SlateSerializer
|
|
189
195
|
end
|
190
196
|
|
191
197
|
def serialize_node(node)
|
192
|
-
|
198
|
+
case node[:object]
|
199
|
+
when 'document'
|
193
200
|
node[:nodes].map { |n| serialize_node(n) }.join
|
194
|
-
|
201
|
+
when 'block'
|
195
202
|
children = node[:nodes].map { |n| serialize_node(n) }.join
|
196
203
|
|
197
204
|
element = ELEMENTS.find { |_, v| v == node[:type] }[0]
|
@@ -204,7 +211,13 @@ module SlateSerializer
|
|
204
211
|
|
205
212
|
"<#{element}#{!data.empty? ? " #{data.join(' ')}" : ''}>#{children}</#{element}>"
|
206
213
|
else
|
207
|
-
node[:
|
214
|
+
if node[:marks].nil? || node[:marks].empty?
|
215
|
+
node[:text]
|
216
|
+
else
|
217
|
+
elements = node[:marks].map { |m| mark_elements[m[:type]] }
|
218
|
+
marks = elements.map { |m| "<#{m}>" }.join
|
219
|
+
"#{marks}#{node[:text]}#{elements.map { |m| "</#{m}>" }.join}"
|
220
|
+
end
|
208
221
|
end
|
209
222
|
end
|
210
223
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slate_serializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wesley Stam
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|