lib/asciidoctor/abstract_block.rb in asciidoctor-2.0.0.rc.2 vs lib/asciidoctor/abstract_block.rb in asciidoctor-2.0.0.rc.3
- old
+ new
@@ -21,14 +21,10 @@
# Public: Get/Set the String numeral of this block (if section, relative to parent, otherwise absolute).
# Only assigned to section if automatic section numbering is enabled.
# Only assigned to formal block (block with title) if corresponding caption attribute is present.
attr_accessor :numeral
- # Deprecated: Legacy property to get/set the numeral of this block.
- alias number numeral
- alias number= numeral=
-
# Public: Gets/Sets the location in the AsciiDoc source where this block begins.
attr_accessor :source_location
# Public: Get/Set the String style (block type qualifier) for this block.
attr_accessor :style
@@ -140,20 +136,23 @@
# Returns A [Boolean] to indicate whether this block has child Section objects
def sections?
@next_section_index > 0
end
- # Public: Walk the document tree and find all block-level nodes that match
- # the specified selector (context, style, id, role, and/or custom filter).
+ # Deprecated: Legacy property to get the String or Integer numeral of this section.
+ def number
+ (Integer @numeral) rescue @numeral
+ end
+
+ # Public: Walk the document tree and find all block-level nodes that match the specified selector (context, style, id,
+ # role, and/or custom filter).
#
- # If a Ruby block is given, it's treated as an supplemental filter. If the
- # filter returns true, the node is accepted and traversal continues. If the
- # filter returns false, the node is rejected, but traversal continues. If the
- # filter returns :skip, the node and all its descendants are rejected. If the
- # filter returns :skip_children, the node is accepted, but its descendants
- # are rejected. If no selector or filter block is supplied, all block-level
- # nodes in the tree are returned.
+ # If a Ruby block is given, it's applied as a supplemental filter. If the filter returns true (which implies :accept),
+ # the node is accepted and node traversal continues. If the filter returns false (which implies :skip), the node is
+ # skipped, but its children are still visited. If the filter returns :reject, the node and all its descendants are
+ # rejected. If the filter returns :prune, the node is accepted, but its descendants are rejected. If no selector
+ # or filter block is supplied, all block-level nodes in the tree are returned.
#
# Examples
#
# doc.find_by context: :section
# #=> Asciidoctor::Section@14459860 { level: 0, title: "Hello, AsciiDoc!", blocks: 0 }
@@ -177,11 +176,17 @@
alias query find_by
# Move to the next adjacent block in document order. If the current block is the last
# item in a list, this method will return the following sibling of the list block.
def next_adjacent_block
- (sib = (p = parent).blocks[(p.blocks.find_index self) + 1]) ? sib : p.next_adjacent_block unless @context == :document
+ unless @context == :document
+ if (p = @parent).context == :dlist && @context == :list_item
+ (sib = p.items[(p.items.find_index {|terms, desc| (terms.include? self) || desc == self }) + 1]) ? sib : p.next_adjacent_block
+ else
+ (sib = p.blocks[(p.blocks.find_index self) + 1]) ? sib : p.next_adjacent_block
+ end
+ end
end
# Public: Get the Array of child Section objects
#
# Only applies to Document and Section instances
@@ -395,20 +400,16 @@
def assign_numeral section
@next_section_index = (section.index = @next_section_index) + 1
if (like = section.numbered)
if (sectname = section.sectname) == 'appendix'
section.numeral = @document.counter 'appendix-number', 'A'
- if (caption = @document.attributes['appendix-caption'])
- section.caption = %(#{caption} #{section.numeral}: )
- else
- section.caption = %(#{section.numeral}. )
- end
+ section.caption = (caption = @document.attributes['appendix-caption']) ? %(#{caption} #{section.numeral}: ) : %(#{section.numeral}. )
# NOTE currently chapters in a book doctype are sequential even for multi-part books (see #979)
elsif sectname == 'chapter' || like == :chapter
- section.numeral = @document.counter 'chapter-number', 1
+ section.numeral = (@document.counter 'chapter-number', 1).to_s
else
- section.numeral = @next_section_ordinal
+ section.numeral = sectname == 'part' ? (Helpers.int_to_roman @next_section_ordinal) : @next_section_ordinal.to_s
@next_section_ordinal += 1
end
end
nil
end
@@ -438,26 +439,31 @@
protected def find_by_internal selector = {}, result = [], &block
if ((any_context = (context_selector = selector[:context]) ? nil : true) || context_selector == @context) &&
(!(style_selector = selector[:style]) || style_selector == @style) &&
(!(role_selector = selector[:role]) || (has_role? role_selector)) &&
(!(id_selector = selector[:id]) || id_selector == @id)
- if id_selector
- block_given? && !(yield self) ? result.clear : (result.replace [self])
- raise ::StopIteration
- elsif block_given?
+ if block_given?
if (verdict = yield self)
case verdict
- when :skip_children
+ when :prune
result << self
+ raise ::StopIteration if id_selector
return result
- when :skip
+ when :reject
+ raise ::StopIteration if id_selector
return result
+ when :stop
+ raise ::StopIteration
else
result << self
+ raise ::StopIteration if id_selector
end
+ elsif id_selector
+ raise ::StopIteration
end
else
result << self
+ raise ::StopIteration if id_selector
end
end
case @context
when :document
unless context_selector == :document