Class: Prosereflect::Blockquote
- Defined in:
- lib/prosereflect/blockquote.rb
Overview
It can contain other block-level content like paragraphs, lists, etc.
Constant Summary collapse
- PM_TYPE =
"blockquote"
Class Method Summary collapse
Instance Method Summary collapse
-
#add_block(content) ⇒ Object
Add a content block to the blockquote.
-
#add_blocks(blocks_content) ⇒ Object
Add multiple content blocks at once.
- #add_paragraph(text) ⇒ Object
-
#block_at(index) ⇒ Object
Get block at specific position.
-
#blocks ⇒ Object
Get all content blocks within the blockquote.
-
#citation ⇒ Object
Get citation/source of the blockquote.
-
#citation=(source) ⇒ Object
Update citation/source for the blockquote.
-
#citation? ⇒ Boolean
Check if blockquote has a citation.
-
#initialize(attributes = {}) ⇒ Blockquote
constructor
A new instance of Blockquote.
-
#remove_citation ⇒ Object
Remove citation.
- #to_h ⇒ Object
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?, #text_content, #to_yaml
Constructor Details
#initialize(attributes = {}) ⇒ Blockquote
Returns a new instance of Blockquote.
20 21 22 23 |
# File 'lib/prosereflect/blockquote.rb', line 20 def initialize(attributes = {}) attributes[:content] ||= [] super end |
Class Method Details
.create(attrs = nil) ⇒ Object
25 26 27 |
# File 'lib/prosereflect/blockquote.rb', line 25 def self.create(attrs = nil) new(attrs: attrs, content: []) end |
Instance Method Details
#add_block(content) ⇒ Object
Add a content block to the blockquote
37 38 39 |
# File 'lib/prosereflect/blockquote.rb', line 37 def add_block(content) add_child(content) end |
#add_blocks(blocks_content) ⇒ Object
Add multiple content blocks at once
42 43 44 45 46 |
# File 'lib/prosereflect/blockquote.rb', line 42 def add_blocks(blocks_content) blocks_content.each do |block_content| add_block(block_content) end end |
#add_paragraph(text) ⇒ Object
86 87 88 89 90 91 |
# File 'lib/prosereflect/blockquote.rb', line 86 def add_paragraph(text) paragraph = Paragraph.new paragraph.add_text(text) add_child(paragraph) paragraph end |
#block_at(index) ⇒ Object
Get block at specific position
49 50 51 52 53 |
# File 'lib/prosereflect/blockquote.rb', line 49 def block_at(index) return nil if index.negative? blocks[index] end |
#blocks ⇒ Object
Get all content blocks within the blockquote
30 31 32 33 34 |
# File 'lib/prosereflect/blockquote.rb', line 30 def blocks return [] unless content content end |
#citation ⇒ Object
Get citation/source of the blockquote
62 63 64 |
# File 'lib/prosereflect/blockquote.rb', line 62 def citation attrs&.[]("citation") end |
#citation=(source) ⇒ Object
Update citation/source for the blockquote
56 57 58 59 |
# File 'lib/prosereflect/blockquote.rb', line 56 def citation=(source) self.attrs ||= {} attrs["citation"] = source end |
#citation? ⇒ Boolean
Check if blockquote has a citation
67 68 69 |
# File 'lib/prosereflect/blockquote.rb', line 67 def citation? !citation.nil? && !citation.empty? end |
#remove_citation ⇒ Object
Remove citation
72 73 74 75 |
# File 'lib/prosereflect/blockquote.rb', line 72 def remove_citation self.attrs ||= {} attrs.delete("citation") end |
#to_h ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/prosereflect/blockquote.rb', line 77 def to_h hash = super if hash["attrs"]&.key?("citation") && hash["attrs"]["citation"].nil? hash["attrs"].delete("citation") hash.delete("attrs") if hash["attrs"].empty? end hash end |