richtext 0.2.2 → 0.2.3

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: 7c750e5ac82964ad3a75eb0853b2c6ca363560e9
4
- data.tar.gz: 0ce973e87936ca86cabbdf1c69183d5724474bea
3
+ metadata.gz: 41ad81aab0acaff875ab05feb5b8964ef70c6233
4
+ data.tar.gz: 9896997c9fc32208909266dad2f833c98e368fe3
5
5
  SHA512:
6
- metadata.gz: 55fef02173c835b9aead67bbc442257d67d11113c3c6cebc5f80be1bc183ac3efc85062cb1fb41bab8fecc49529ba8a0eb0db5b370152bd0fb708557705e7ea2
7
- data.tar.gz: ddbf1a7758d47ed564c7defeff25a5a2cc8a28cbe4d02eb1a5bb8d94a31783b72a2ea1f710d2a87acdff8e21acf4f985c7ef3637f219cfbcd0ba28302d67093d
6
+ metadata.gz: 9d759230e7393f2f95c6e5f8b609f9ef2635cc177f9b1185519fa3d9881d767098024feed9f69399d003e1f46a15e518321e3f9534430219074377ef5e3000c0
7
+ data.tar.gz: 4229b9f1b465daf570342da6cf08f34b8c7f4d6cf1793373b5cef7c301edbe4bf4ea959a02e787eeee52dd33db593cf68a7d22e5979a6422f682b1121128718c
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RichText
2
4
  class Document
3
5
  # Entry
@@ -18,8 +20,8 @@ module RichText
18
20
  # Extend the default Node initializer by also accepting a string. It will,
19
21
  # if given, be stored as a text attribute.
20
22
  def initialize(text = nil, **attributes)
23
+ attributes[:text] = text if text
21
24
  super attributes
22
- self[:text] = text if text
23
25
  end
24
26
 
25
27
  # Text
@@ -48,8 +50,13 @@ module RichText
48
50
  super
49
51
  end
50
52
 
51
- def create_child(text = '', **attributes)
52
- super attributes.merge(text: text)
53
+ # Create Child
54
+ #
55
+ # Create and append a new child, initialized with the given text and
56
+ # attributes.
57
+ def create_child(text = nil, **attributes)
58
+ attributes = attributes.merge(text: text) if text
59
+ super(attributes)
53
60
  end
54
61
 
55
62
  # Optimize!
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RichText
2
4
  # Document
3
5
  #
@@ -131,7 +133,6 @@ module RichText
131
133
  # tree of entry nodes. This method is intended to be overridden when the
132
134
  # Document is subclassed. The default implementation just creates a top
133
135
  # level Entry containing the given string.
134
-
135
136
  def self.parse(base, string)
136
137
  base[:text] = string
137
138
  end
@@ -141,7 +142,6 @@ module RichText
141
142
  # Document type specific method for rendering a tree of entry nodes. This
142
143
  # method is intended to be overridden when the Document is subclassed. The
143
144
  # default implementation just concatenates the text entries into.
144
-
145
145
  def self.render(base)
146
146
  base.to_s
147
147
  end
data/lib/richtext/node.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RichText
2
4
  # Node
3
5
  #
@@ -44,6 +46,20 @@ module RichText
44
46
  def leaf?
45
47
  @children.empty?
46
48
  end
49
+
50
+ # Child
51
+ #
52
+ # Access the individual children of the node. If the method is called
53
+ # without argument and the node has only one child it will be returned.
54
+ # Otherwise an exception will be raised.
55
+ def child n = nil
56
+ if n
57
+ @children[n]
58
+ else
59
+ raise 'Node does not have one child' unless count == 1
60
+ @children[0]
61
+ end
62
+ end
47
63
 
48
64
  # Append
49
65
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RichText
2
- VERSION = '0.2.2'.freeze
4
+ VERSION = '0.2.3'
3
5
  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.2
4
+ version: 0.2.3
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-12 00:00:00.000000000 Z
11
+ date: 2016-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler