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, #copy, #cut, #descendants, #eq?, #find_all, #find_children, #find_first, #marks, #marks=, #node, #node_size, #nodes_between, #parse_content, #process_attrs_data, #raw_marks, #resolve, #text?, #to_h, #to_yaml
Constructor Details
#initialize(attributes = {}) ⇒ OrderedList
Returns a new instance of OrderedList.
20 21 22 23 |
# File 'lib/prosereflect/ordered_list.rb', line 20 def initialize(attributes = {}) attributes[:content] ||= [] super end |
Class Method Details
.create(attrs = nil) ⇒ Object
25 26 27 |
# File 'lib/prosereflect/ordered_list.rb', line 25 def self.create(attrs = nil) new(attrs: attrs) end |
Instance Method Details
#add_item(text) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/prosereflect/ordered_list.rb', line 41 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
55 56 57 58 59 |
# File 'lib/prosereflect/ordered_list.rb', line 55 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
62 63 64 65 66 |
# File 'lib/prosereflect/ordered_list.rb', line 62 def item_at(index) return nil if index.negative? items[index] end |
#items ⇒ Object
48 49 50 51 52 |
# File 'lib/prosereflect/ordered_list.rb', line 48 def items return [] unless content content end |
#order ⇒ Object
Get the order value
75 76 77 |
# File 'lib/prosereflect/ordered_list.rb', line 75 def order attrs&.[]("order") || 1 end |
#order=(order_value) ⇒ Object
Update the order (1 for numerical, ‘a’ for alphabetical, etc.)
69 70 71 72 |
# File 'lib/prosereflect/ordered_list.rb', line 69 def order=(order_value) self.attrs ||= {} attrs["order"] = order_value end |
#start ⇒ Object
37 38 39 |
# File 'lib/prosereflect/ordered_list.rb', line 37 def start @start || attrs&.[]("start") || 1 end |
#start=(value) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/prosereflect/ordered_list.rb', line 29 def start=(value) @start = value return if value.nil? self.attrs ||= {} attrs["start"] = value end |
#text_content ⇒ Object
Get text content with proper formatting
80 81 82 83 84 85 86 |
# File 'lib/prosereflect/ordered_list.rb', line 80 def text_content return "" unless content content.map do |item| item.respond_to?(:text_content) ? item.text_content : "" end.join("\n") end |