slate_serializer 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +13 -13
- data/lib/slate_serializer/html.rb +31 -1
- 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: ad1313f396bb1a55f67bb82b73ed8e07fee411e0d3da02a79efa418c99757fac
|
4
|
+
data.tar.gz: b48b2ff038ba8d98cdbe85c58c48f647a09df79fde78e512aed2a64ba4dda1b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8fa0dcb749d81b4f0685ee818ac9c0d8a4d61dba35def25b59b1c7d117ed4d56f3343b8c6fabd85c87112715ac8a096e416ff4aa45fc36bd858a0b1db09ad87
|
7
|
+
data.tar.gz: fb0865d8ea46b17bd189711e54896bd3b4fa19e53168cdcdf45c396a89340d5193b57db4afa34b44d9872ab83e9a636ca3193973b9dc0e98b5cd9707123f90e4
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
slate_serializer (0.
|
4
|
+
slate_serializer (0.5.0)
|
5
5
|
nokogiri (~> 1.10)
|
6
6
|
|
7
7
|
GEM
|
@@ -9,22 +9,22 @@ GEM
|
|
9
9
|
specs:
|
10
10
|
diff-lcs (1.3)
|
11
11
|
mini_portile2 (2.4.0)
|
12
|
-
nokogiri (1.10.
|
12
|
+
nokogiri (1.10.8)
|
13
13
|
mini_portile2 (~> 2.4.0)
|
14
14
|
rake (10.5.0)
|
15
|
-
rspec (3.
|
16
|
-
rspec-core (~> 3.
|
17
|
-
rspec-expectations (~> 3.
|
18
|
-
rspec-mocks (~> 3.
|
19
|
-
rspec-core (3.
|
20
|
-
rspec-support (~> 3.
|
21
|
-
rspec-expectations (3.
|
15
|
+
rspec (3.9.0)
|
16
|
+
rspec-core (~> 3.9.0)
|
17
|
+
rspec-expectations (~> 3.9.0)
|
18
|
+
rspec-mocks (~> 3.9.0)
|
19
|
+
rspec-core (3.9.1)
|
20
|
+
rspec-support (~> 3.9.1)
|
21
|
+
rspec-expectations (3.9.0)
|
22
22
|
diff-lcs (>= 1.2.0, < 2.0)
|
23
|
-
rspec-support (~> 3.
|
24
|
-
rspec-mocks (3.
|
23
|
+
rspec-support (~> 3.9.0)
|
24
|
+
rspec-mocks (3.9.1)
|
25
25
|
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
-
rspec-support (~> 3.
|
27
|
-
rspec-support (3.
|
26
|
+
rspec-support (~> 3.9.0)
|
27
|
+
rspec-support (3.9.2)
|
28
28
|
|
29
29
|
PLATFORMS
|
30
30
|
ruby
|
@@ -35,7 +35,7 @@ module SlateSerializer
|
|
35
35
|
}.freeze
|
36
36
|
|
37
37
|
class << self
|
38
|
-
# Convert html to a
|
38
|
+
# Convert html to a Slate document
|
39
39
|
#
|
40
40
|
# @param html format [String] the HTML
|
41
41
|
# @param options [Hash]
|
@@ -64,6 +64,16 @@ module SlateSerializer
|
|
64
64
|
}
|
65
65
|
end
|
66
66
|
|
67
|
+
# Convert html to a Slate document
|
68
|
+
#
|
69
|
+
# @param value format [Hash] the Slate document
|
70
|
+
# @return [String] plain text version of the Slate documnent
|
71
|
+
def serializer(value)
|
72
|
+
return '' unless value.key?(:document)
|
73
|
+
|
74
|
+
serialize_node(value[:document])
|
75
|
+
end
|
76
|
+
|
67
77
|
private
|
68
78
|
|
69
79
|
attr_accessor :elements, :block_elements, :inline_elements, :mark_elements
|
@@ -177,6 +187,26 @@ module SlateSerializer
|
|
177
187
|
}
|
178
188
|
}
|
179
189
|
end
|
190
|
+
|
191
|
+
def serialize_node(node)
|
192
|
+
if node[:object] == 'document'
|
193
|
+
node[:nodes].map { |n| serialize_node(n) }.join
|
194
|
+
elsif node[:object] == 'block'
|
195
|
+
children = node[:nodes].map { |n| serialize_node(n) }.join
|
196
|
+
|
197
|
+
element = ELEMENTS.find { |_, v| v == node[:type] }[0]
|
198
|
+
data = node[:data].map { |k, v| "#{k}=\"#{v}\"" }
|
199
|
+
|
200
|
+
if %i[ol1 ola].include?(element)
|
201
|
+
data << ["type=\"#{element.to_s[-1]}\""]
|
202
|
+
element = :ol
|
203
|
+
end
|
204
|
+
|
205
|
+
"<#{element}#{!data.empty? ? " #{data.join(' ')}" : ''}>#{children}</#{element}>"
|
206
|
+
else
|
207
|
+
node[:text]
|
208
|
+
end
|
209
|
+
end
|
180
210
|
end
|
181
211
|
end
|
182
212
|
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: 0.
|
4
|
+
version: 0.5.0
|
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: 2020-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|