richtext 0.2.1 → 0.2.2
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/richtext/document/entry.rb +9 -0
- data/lib/richtext/node.rb +12 -4
- data/lib/richtext/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c750e5ac82964ad3a75eb0853b2c6ca363560e9
|
4
|
+
data.tar.gz: 0ce973e87936ca86cabbdf1c69183d5724474bea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55fef02173c835b9aead67bbc442257d67d11113c3c6cebc5f80be1bc183ac3efc85062cb1fb41bab8fecc49529ba8a0eb0db5b370152bd0fb708557705e7ea2
|
7
|
+
data.tar.gz: ddbf1a7758d47ed564c7defeff25a5a2cc8a28cbe4d02eb1a5bb8d94a31783b72a2ea1f710d2a87acdff8e21acf4f985c7ef3637f219cfbcd0ba28302d67093d
|
@@ -52,6 +52,15 @@ module RichText
|
|
52
52
|
super attributes.merge(text: text)
|
53
53
|
end
|
54
54
|
|
55
|
+
# Optimize!
|
56
|
+
#
|
57
|
+
# See RichText::Node#optimize! for a description of the fundemental
|
58
|
+
# behavior. Entries differ from regular Nodes in that leaf children with
|
59
|
+
# no text in them will be removed.
|
60
|
+
def optimize!
|
61
|
+
super { |child| !child.leaf? || !child.text.empty? }
|
62
|
+
end
|
63
|
+
|
55
64
|
# To String
|
56
65
|
#
|
57
66
|
# Combine the text from all the leaf nodes in the tree, from left to
|
data/lib/richtext/node.rb
CHANGED
@@ -157,10 +157,16 @@ module RichText
|
|
157
157
|
# override those of the parent.
|
158
158
|
def optimize!
|
159
159
|
# If the node is a leaf it cannot be optimized further
|
160
|
-
return if leaf?
|
161
|
-
|
162
|
-
# First optimize each of the children
|
163
|
-
|
160
|
+
return self if leaf?
|
161
|
+
|
162
|
+
# First optimize each of the children. If a block was
|
163
|
+
# given each child will be yielded to it, and children
|
164
|
+
# for which the block returns false will be removed
|
165
|
+
if block_given?
|
166
|
+
@children.select! { |child| yield child.optimize! }
|
167
|
+
else
|
168
|
+
@children.map(&:optimize!)
|
169
|
+
end
|
164
170
|
|
165
171
|
# If we only have one child it is superfluous and
|
166
172
|
# should be merged. That means this node will inherrit
|
@@ -172,6 +178,8 @@ module RichText
|
|
172
178
|
@children = child.children
|
173
179
|
@attributes.merge! child.attributes
|
174
180
|
end
|
181
|
+
|
182
|
+
self
|
175
183
|
end
|
176
184
|
|
177
185
|
def optimize
|
data/lib/richtext/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: richtext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastian Lindberg
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|