lib/asciidoctor/abstract_block.rb in asciidoctor-2.0.1 vs lib/asciidoctor/abstract_block.rb in asciidoctor-2.0.2
- old
+ new
@@ -30,13 +30,10 @@
attr_accessor :style
# Public: Substitutions to be applied to content in this block.
attr_reader :subs
- # Internal: Set the default subs applied to this block; used during block creation
- attr_writer :default_subs
-
def initialize parent, context, opts = {}
super
@content_model = :compound
@blocks = []
@subs = []
@@ -124,11 +121,11 @@
# Public: Determine whether this Block contains block content
#
# Returns A Boolean indicating whether this Block has block content
def blocks?
- !@blocks.empty?
+ @blocks.empty? ? false : true
end
# Public: Check whether this block has any child Section objects.
#
# Only applies to Document and Section instances
@@ -340,17 +337,17 @@
# NOTE xrefstyle only applies to blocks with a title and a caption or number
elsif xrefstyle && @title && @caption
case xrefstyle
when 'full'
quoted_title = sub_placeholder (sub_quotes @document.compat_mode ? %q(``%s'') : '"`%s`"'), title
- if @numeral && (prefix = @document.attributes[@context == :image ? 'figure-caption' : %(#{@context}-caption)])
+ if @numeral && (caption_attr_name = CAPTION_ATTR_NAMES[@context]) && (prefix = @document.attributes[caption_attr_name])
%(#{prefix} #{@numeral}, #{quoted_title})
else
%(#{@caption.chomp '. '}, #{quoted_title})
end
when 'short'
- if @numeral && (prefix = @document.attributes[@context == :image ? 'figure-caption' : %(#{@context}-caption)])
+ if @numeral && (caption_attr_name = CAPTION_ATTR_NAMES[@context]) && (prefix = @document.attributes[caption_attr_name])
%(#{prefix} #{@numeral})
else
@caption.chomp '. '
end
else # 'basic'
@@ -370,19 +367,20 @@
# If a caption has already been assigned to this block, do nothing.
#
# The parts of a complete caption are: <prefix> <number>. <title>
# This partial caption represents the part the precedes the title.
#
- # value - The explicit String caption to assign to this block (default: nil).
- # key - The String prefix for the caption and counter attribute names.
- # If not provided, the name of the context for this block is used.
- # (default: @context)
+ # value - The explicit String caption to assign to this block (default: nil).
+ # caption_context - The Symbol context to use when resolving caption-related attributes.
+ # If not provided, the name of the context for this block is used.
+ # (default: @context)
#
# Returns nothing.
- def assign_caption value = nil, key = @context
+ def assign_caption value = nil, caption_context = @context
unless @caption || !@title || (@caption = value || @document.attributes['caption'])
- if (prefix = @document.attributes[%(#{key}-caption)])
- @caption = %(#{prefix} #{@numeral = @document.increment_and_store_counter %[#{key}-number], self}. )
+ if (attr_name = CAPTION_ATTR_NAMES[caption_context]) && (prefix = @document.attributes[attr_name])
+ counter_name = caption_context == :image ? 'figure-number' : %(#{caption_context}-number)
+ @caption = %(#{prefix} #{@numeral = @document.increment_and_store_counter counter_name, self}. )
nil
end
end
end