Module: TipTap::HasContent
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#attrs ⇒ Object
readonly
Returns the value of attribute attrs.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
Class Method Summary collapse
Instance Method Summary collapse
- #add_content(node) ⇒ Object (also: #<<)
- #blank? ⇒ Boolean
- #each ⇒ Object
- #find_node(type_class_or_name) ⇒ Object
-
#initialize(content = [], **attributes) {|_self| ... } ⇒ Object
Create a new document or node, optionally passing in attributes (attrs) and nodes.
- #size ⇒ Object
Instance Attribute Details
#attrs ⇒ Object (readonly)
Returns the value of attribute attrs.
9 10 11 |
# File 'lib/tip_tap/has_content.rb', line 9 def attrs @attrs end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
9 10 11 |
# File 'lib/tip_tap/has_content.rb', line 9 def content @content end |
Class Method Details
.included(base) ⇒ Object
11 12 13 |
# File 'lib/tip_tap/has_content.rb', line 11 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#add_content(node) ⇒ Object Also known as: <<
34 35 36 |
# File 'lib/tip_tap/has_content.rb', line 34 def add_content(node) @content << node end |
#blank? ⇒ Boolean
43 44 45 |
# File 'lib/tip_tap/has_content.rb', line 43 def blank? content&.all?(&:blank?) end |
#each ⇒ Object
25 26 27 |
# File 'lib/tip_tap/has_content.rb', line 25 def each content.each { |child| yield child } end |
#find_node(type_class_or_name) ⇒ Object
29 30 31 32 |
# File 'lib/tip_tap/has_content.rb', line 29 def find_node(type_class_or_name) node_type = type_class_or_name.is_a?(String) ? TipTap.node_for(type_class_or_name) : type_class_or_name find { |child| child.is_a?(node_type) } end |
#initialize(content = [], **attributes) {|_self| ... } ⇒ Object
Create a new document or node, optionally passing in attributes (attrs) and nodes
18 19 20 21 22 23 |
# File 'lib/tip_tap/has_content.rb', line 18 def initialize(content = [], **attributes) # This will convert the attrs key to camelcase for example :image_id is converted into 'imageId' @attrs = Hash(attributes).deep_transform_keys { |key| key.to_s.camelcase(:lower) } @content = content yield self if block_given? end |
#size ⇒ Object
39 40 41 |
# File 'lib/tip_tap/has_content.rb', line 39 def size content.size end |