richtext 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 012cee663ed1efca031915dd89ff28e024672ae0
4
- data.tar.gz: fca547a531683b1b3735694003a50de4da4e04dc
3
+ metadata.gz: 7c750e5ac82964ad3a75eb0853b2c6ca363560e9
4
+ data.tar.gz: 0ce973e87936ca86cabbdf1c69183d5724474bea
5
5
  SHA512:
6
- metadata.gz: df20313ea30e3bb70d44e1a474ace49cee4dbf6a6dd25ae561ed8ef0630502836e1654d0c59776cf14e72242ca3ff835f9c5ca7d458f7dc158af38b9e990ed7d
7
- data.tar.gz: 0975be57c7d9dd6592205fae965ca8be7cf946d00965f8ba72b3e8054c981831682dd87e7361e5083165310a0f45d1b504a00e0adb51456270cb07a8d2354c0c
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
- @children.map(&:optimize!)
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
@@ -1,3 +1,3 @@
1
1
  module RichText
2
- VERSION = '0.2.1'.freeze
2
+ VERSION = '0.2.2'.freeze
3
3
  end
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.1
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-03 00:00:00.000000000 Z
11
+ date: 2016-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler