Class: Prosereflect::OrderedList
- Defined in:
- lib/prosereflect/ordered_list.rb
Overview
OrderedList class represents a numbered list in ProseMirror.
Constant Summary collapse
- PM_TYPE =
'ordered_list'
Class Method Summary collapse
Instance Method Summary collapse
- #add_item(text) ⇒ Object
-
#add_items(items_content) ⇒ Object
Add multiple items at once.
-
#initialize(attributes = {}) ⇒ OrderedList
constructor
A new instance of OrderedList.
-
#item_at(index) ⇒ Object
Get item at specific position.
- #items ⇒ Object
-
#order ⇒ Object
Get the order value.
-
#order=(order_value) ⇒ Object
Update the order (1 for numerical, ‘a’ for alphabetical, etc.).
- #start ⇒ Object
- #start=(value) ⇒ Object
-
#text_content ⇒ Object
Get text content with proper formatting.
Methods inherited from Node
#add_child, #find_all, #find_children, #find_first, #marks, #marks=, #parse_content, #process_attrs_data, #raw_marks, #to_h, #to_yaml
Constructor Details
#initialize(attributes = {}) ⇒ OrderedList
Returns a new instance of OrderedList.
21 22 23 24 |
# File 'lib/prosereflect/ordered_list.rb', line 21 def initialize(attributes = {}) attributes[:content] ||= [] super end |
Class Method Details
.create(attrs = nil) ⇒ Object
26 27 28 |
# File 'lib/prosereflect/ordered_list.rb', line 26 def self.create(attrs = nil) new(attrs: attrs) end |
Instance Method Details
#add_item(text) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/prosereflect/ordered_list.rb', line 40 def add_item(text) item = ListItem.new item.add_paragraph(text) add_child(item) item end |
#add_items(items_content) ⇒ Object
Add multiple items at once
54 55 56 57 58 |
# File 'lib/prosereflect/ordered_list.rb', line 54 def add_items(items_content) items_content.each do |item_content| add_item(item_content) end end |
#item_at(index) ⇒ Object
Get item at specific position
61 62 63 64 65 |
# File 'lib/prosereflect/ordered_list.rb', line 61 def item_at(index) return nil if index.negative? items[index] end |
#items ⇒ Object
47 48 49 50 51 |
# File 'lib/prosereflect/ordered_list.rb', line 47 def items return [] unless content content end |
#order ⇒ Object
Get the order value
74 75 76 |
# File 'lib/prosereflect/ordered_list.rb', line 74 def order attrs&.[]('order') || 1 end |
#order=(order_value) ⇒ Object
Update the order (1 for numerical, ‘a’ for alphabetical, etc.)
68 69 70 71 |
# File 'lib/prosereflect/ordered_list.rb', line 68 def order=(order_value) self.attrs ||= {} attrs['order'] = order_value end |
#start ⇒ Object
36 37 38 |
# File 'lib/prosereflect/ordered_list.rb', line 36 def start @start || attrs&.[]('start') || 1 end |
#start=(value) ⇒ Object
30 31 32 33 34 |
# File 'lib/prosereflect/ordered_list.rb', line 30 def start=(value) @start = value self.attrs ||= {} attrs['start'] = value end |
#text_content ⇒ Object
Get text content with proper formatting
79 80 81 82 83 |
# File 'lib/prosereflect/ordered_list.rb', line 79 def text_content return '' unless content content.map { |item| item.respond_to?(:text_content) ? item.text_content : '' }.join("\n") end |