class Asciidoctor::AbstractBlock
def <<(block)
# => ["p1", "p2"]
block.blocks
block << Block.new(block, :paragraph, 'p2')
block << Block.new(block, :paragraph, 'p1')
block = Block.new(parent, :preamble)
Examples
block - The new child block.
Public: Append a content block to this block's list of blocks.
def <<(block) if block.is_a?(Asciidoctor::Section) assign_index(block) end @blocks << block end
def [](i)
section[1]
section << 'bar'
section << 'foo'
section = Section.new
i - The Integer array index number.
Public: Get the element at i in the array of blocks.
def [](i) @blocks[i] end
def assign_index(section)
Block (in document order)
Assign the next index of this section within the parent
Internal: Assign the next index (0-based) to this section
def assign_index(section) section.index = @next_section_index @next_section_index += 1 end
def blocks?
whether this Block *can* have block content
TODO we still need another method that answers
--
returns Whether this Block has block content
Public: Determine whether this Block contains block content
def blocks? !blocks.empty? end
def clear_blocks
section.blocks
section.clear_blocks
=> ["foo", "bar"]
section.blocks
section << 'bar'
section << 'foo'
section = Section.new
Public: Clear this Block's list of blocks.
def clear_blocks @blocks = [] end
def delete_at(i)
section.blocks
=> "bar"
section.delete_at(1)
section << 'bar'
section << 'foo'
section = Section.new
i - The Integer array index number.
returning that element or nil if i is out of range.
Public: Delete the element at i in the array of section blocks,
def delete_at(i) @blocks.delete_at(i) end
def initialize(parent, context)
def initialize(parent, context) super(parent, context) @blocks = [] @id = nil @title = nil if context == :document @level = 0 elsif !parent.nil? && !self.is_a?(Asciidoctor::Section) @level = parent.level else @level = nil end @next_section_index = 0 end
def insert(i, block)
section.blocks
section.insert(1, 'bar')
section << 'baz'
section << 'foo'
section = Section.new
val = The content block to insert.
i - The Integer array index number.
list of blocks.
Public: Insert a content block at the specified index in this block's
def insert(i, block) @blocks.insert(i, block) end
def reindex_sections
as it appears in document order.
and reassign the section 0-based index value to each Section
Walk the descendents of the current Document or Section
Internal: Reassign the section indexes
def reindex_sections @next_section_index = 0 @blocks.each {|block| if block.is_a?(Asciidoctor::Section) assign_index(block) block.reindex_sections end } end
def sections
# => 1
section.sections.size
section << Block.new(section, :paragraph, 'paragraph 2')
section << Section.new(parent)
section << Block.new(section, :paragraph, 'paragraph 1')
section = Section.new(parent)
Examples
Only applies to Document and Section instances
Public: Get the Array of child Section objects
def sections @blocks.inject([]) {|collector, block| collector << block if block.is_a?(Asciidoctor::Section) collector } end
def size
section.size
section << 'bar'
section << 'foo'
=> 0
section.size
section = Section.new
Examples
Public: Get the Integer number of blocks in this block
def size @blocks.size end
def title
=> "Foo 3^ # :: Bar(1)"
block.title
block.title = "Foo 3^ # {two-colons} Bar(1)"
Examples
:specialcharacters, :quotes, :replacements, :macros, :attributes and :post_replacements
The following substitutions are applied to block and section titles:
Public: Get the String title of this Block with title substitions applied
def title # prevent substitutions from being applied multiple times if defined?(@subbed_title) @subbed_title elsif @title @subbed_title = apply_title_subs(@title) else @title end end
def title?
Public: A convenience method that indicates whether the title instance
def title? !@title.to_s.empty? end