Class: Asciidoctor::AbstractBlock
- Inherits:
-
AbstractNode
- Object
- AbstractNode
- Asciidoctor::AbstractBlock
- Defined in:
- lib/asciidoctor/abstract_block.rb
Constant Summary
Constants included from Substitutors
Substitutors::CAN, Substitutors::CGI, Substitutors::DEL, Substitutors::ESC_R_SB, Substitutors::HighlightedPassSlotRx, Substitutors::PASS_END, Substitutors::PASS_START, Substitutors::PLUS, Substitutors::PassSlotRx, Substitutors::QuotedTextSniffRx, Substitutors::RS, Substitutors::R_SB, Substitutors::SUB_GROUPS, Substitutors::SUB_HINTS, Substitutors::SUB_OPTIONS, Substitutors::SpecialCharsRx, Substitutors::SpecialCharsTr
Instance Attribute Summary collapse
-
#blocks ⇒ Object
readonly
Get the Array of AbstractBlock child blocks for this block.
-
#caption ⇒ String
Gets the caption for this block.
-
#content_model ⇒ Object
Describes the type of content this block accepts and how it should be converted.
-
#level ⇒ Object
Set the Integer level of this Section or the level of the Section to which this AbstractBlock belongs.
-
#numeral ⇒ Object
Get/Set the String numeral of this block (if section, relative to parent, otherwise absolute).
-
#source_location ⇒ Object
Gets/Sets the location in the AsciiDoc source where this block begins.
-
#style ⇒ Object
Get/Set the String style (block type qualifier) for this block.
-
#subs ⇒ Object
readonly
Substitutions to be applied to content in this block.
Attributes inherited from AbstractNode
#attributes, #context, #document, #id, #node_name, #parent
Instance Method Summary collapse
-
#<<(block) ⇒ The
(also: #append)
Append a content block to this block’s list of blocks.
-
#alt ⇒ String
Returns the converted alt text for this block image.
-
#assign_caption(value, caption_context = @context) ⇒ void
Generate and assign caption to block if not already assigned.
- #block? ⇒ Boolean
-
#blocks? ⇒ A
Determine whether this Block contains block content.
-
#captioned_title ⇒ Object
Convenience method that returns the interpreted title of the Block with the caption prepended.
-
#content ⇒ Object
Get the converted result of the child blocks by converting the children appropriate to content model that this block supports.
-
#context=(context) ⇒ Object
Update the context of this block.
-
#convert ⇒ Object
(also: #render)
Get the converted String content for this Block.
-
#file ⇒ Object
Get the source file where this block started.
-
#find_by(selector = {}, &block) ⇒ An
(also: #query)
Walk the document tree and find all block-level nodes that match the specified selector (context, style, id, role, and/or custom filter).
-
#initialize(parent, context, opts = {}) ⇒ AbstractBlock
constructor
A new instance of AbstractBlock.
- #inline? ⇒ Boolean
-
#lineno ⇒ Object
Get the source line number where this block started.
-
#list_marker_keyword(list_type = nil) ⇒ String
Retrieve the list marker keyword for the specified list type.
-
#next_adjacent_block ⇒ Object
Move to the next adjacent block in document order.
-
#number ⇒ Object
deprecated
Deprecated.
Do not use this in new code, and replace it when updating old code.
-
#number=(val) ⇒ Object
deprecated
Deprecated.
Do not use this in new code, and replace it when updating old code.
-
#remove_sub(sub) ⇒ void
Remove a substitution from this block.
-
#sections ⇒ Array
Get the Array of child Section objects.
-
#sections? ⇒ Boolean
Check whether this block has any child Section objects.
-
#sub?(name) ⇒ A
A convenience method that checks whether the specified substitution is enabled for this block.
-
#title ⇒ Object
Get the String title of this Block with title substitutions applied.
-
#title=(val) ⇒ Object
Set the String block title.
-
#title? ⇒ Boolean
A convenience method that checks whether the title of this block is defined.
-
#xreftext(xrefstyle = nil) ⇒ String
Generate cross reference text (xreftext) that can be used to refer to this block.
Methods inherited from AbstractNode
#add_role, #attr, #attr?, #converter, #enabled_options, #generate_data_uri, #generate_data_uri_from_uri, #has_role?, #icon_uri, #image_uri, #is_uri?, #media_uri, #normalize_asset_path, #normalize_system_path, #normalize_web_path, #option?, #read_asset, #read_contents, #reftext, #reftext?, #remove_attr, #remove_role, #role, #role=, #role?, #roles, #set_attr, #set_option, #update_attributes
Methods included from Substitutors
#apply_header_subs, #apply_normal_subs, #apply_reftext_subs, #apply_subs, #expand_subs, #extract_passthroughs, #highlight_source, #resolve_block_subs, #resolve_lines_to_highlight, #resolve_pass_subs, #resolve_subs, #restore_passthroughs, #sub_attributes, #sub_callouts, #sub_macros, #sub_post_replacements, #sub_quotes, #sub_replacements, #sub_source, #sub_specialchars
Methods included from Logging
#logger, #message_with_context
Constructor Details
#initialize(parent, context, opts = {}) ⇒ AbstractBlock
Returns a new instance of AbstractBlock.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/asciidoctor/abstract_block.rb', line 35 def initialize parent, context, opts = {} super @content_model = :compound @blocks = [] @subs = [] @id = @title = @caption = @numeral = @style = @default_subs = @source_location = nil if context == :document || context == :section @level = @next_section_index = 0 @next_section_ordinal = 1 elsif AbstractBlock === parent @level = parent.level else @level = nil end end |
Instance Attribute Details
#blocks ⇒ Object (readonly)
Get the Array of Asciidoctor::AbstractBlock child blocks for this block. Only applies if content model is :compound.
5 6 7 |
# File 'lib/asciidoctor/abstract_block.rb', line 5 def blocks @blocks end |
#caption ⇒ String
Gets the caption for this block.
This method routes the deprecated use of the caption method on an admonition block to the textlabel attribute.
245 246 247 |
# File 'lib/asciidoctor/abstract_block.rb', line 245 def @context == :admonition ? @attributes['textlabel'] : @caption end |
#content_model ⇒ Object
Describes the type of content this block accepts and how it should be converted. Acceptable values are:
-
:compound - this block contains other blocks
-
:simple - this block holds a paragraph of prose that receives normal substitutions
-
:verbatim - this block holds verbatim text (displayed “as is”) that receives verbatim substitutions
-
:raw - this block holds unprocessed content passed directly to the output with no substitutions applied
-
:empty - this block has no content
16 17 18 |
# File 'lib/asciidoctor/abstract_block.rb', line 16 def content_model @content_model end |
#level ⇒ Object
Set the Integer level of this Section or the level of the Section to which this Asciidoctor::AbstractBlock belongs.
19 20 21 |
# File 'lib/asciidoctor/abstract_block.rb', line 19 def level @level end |
#numeral ⇒ Object
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.
24 25 26 |
# File 'lib/asciidoctor/abstract_block.rb', line 24 def numeral @numeral end |
#source_location ⇒ Object
Gets/Sets the location in the AsciiDoc source where this block begins.
27 28 29 |
# File 'lib/asciidoctor/abstract_block.rb', line 27 def source_location @source_location end |
#style ⇒ Object
Get/Set the String style (block type qualifier) for this block.
30 31 32 |
# File 'lib/asciidoctor/abstract_block.rb', line 30 def style @style end |
#subs ⇒ Object (readonly)
Substitutions to be applied to content in this block.
33 34 35 |
# File 'lib/asciidoctor/abstract_block.rb', line 33 def subs @subs end |
Instance Method Details
#<<(block) ⇒ The Also known as: append
Append a content block to this block’s list of blocks.
114 115 116 117 118 |
# File 'lib/asciidoctor/abstract_block.rb', line 114 def << block block.parent = self unless block.parent == self @blocks << block self end |
#alt ⇒ String
Returns the converted alt text for this block image.
225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/asciidoctor/abstract_block.rb', line 225 def alt if (text = @attributes['alt']) if text == @attributes['default-alt'] sub_specialchars text else text = sub_specialchars text (ReplaceableTextRx.match? text) ? (sub_replacements text) : text end else '' end end |
#assign_caption(value, caption_context = @context) ⇒ void
This method returns an undefined value.
Generate and assign caption to block if not already assigned.
If the block has a title and a caption prefix is available for this block, then build a caption from this information, assign it a number and store it to the caption attribute on the block.
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.
388 389 390 391 392 393 394 395 |
# File 'lib/asciidoctor/abstract_block.rb', line 388 def value, = @context unless @caption || !@title || (@caption = value || @document.attributes['caption']) if (attr_name = CAPTION_ATTRIBUTE_NAMES[]) && (prefix = @document.attributes[attr_name]) @caption = %(#{prefix} #{@numeral = @document.increment_and_store_counter %(#{}-number), self}. ) nil end end end |
#block? ⇒ Boolean
51 52 53 |
# File 'lib/asciidoctor/abstract_block.rb', line 51 def block? true end |
#blocks? ⇒ A
Determine whether this Block contains block content
126 127 128 |
# File 'lib/asciidoctor/abstract_block.rb', line 126 def blocks? @blocks.empty? ? false : true end |
#captioned_title ⇒ Object
Convenience method that returns the interpreted title of the Block with the caption prepended.
Concatenates the value of this Block’s caption instance variable and the return value of this Block’s title method. No space is added between the two values. If the Block does not have a caption, the interpreted title is returned.
259 260 261 |
# File 'lib/asciidoctor/abstract_block.rb', line 259 def %(#{@caption}#{title}) end |
#content ⇒ Object
Get the converted result of the child blocks by converting the children appropriate to content model that this block supports.
83 84 85 |
# File 'lib/asciidoctor/abstract_block.rb', line 83 def content @blocks.map {|b| b.convert }.join LF end |
#context=(context) ⇒ Object
Update the context of this block.
This method changes the context of this block. It also updates the node name accordingly.
94 95 96 |
# File 'lib/asciidoctor/abstract_block.rb', line 94 def context= context @node_name = (@context = context).to_s end |
#convert ⇒ Object Also known as: render
Get the converted String content for this Block. If the block has child blocks, the content method should cause them to be converted and returned as content that can be included in the parent block’s template.
73 74 75 76 |
# File 'lib/asciidoctor/abstract_block.rb', line 73 def convert @document.playback_attributes @attributes converter.convert self end |
#file ⇒ Object
Get the source file where this block started
60 61 62 |
# File 'lib/asciidoctor/abstract_block.rb', line 60 def file @source_location && @source_location.file end |
#find_by(selector = {}, &block) ⇒ An Also known as: query
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 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.
175 176 177 178 179 |
# File 'lib/asciidoctor/abstract_block.rb', line 175 def find_by selector = {}, &block find_by_internal selector, (result = []), &block rescue ::StopIteration result end |
#inline? ⇒ Boolean
55 56 57 |
# File 'lib/asciidoctor/abstract_block.rb', line 55 def inline? false end |
#lineno ⇒ Object
Get the source line number where this block started
65 66 67 |
# File 'lib/asciidoctor/abstract_block.rb', line 65 def lineno @source_location && @source_location.lineno end |
#list_marker_keyword(list_type = nil) ⇒ String
Retrieve the list marker keyword for the specified list type.
For use in the HTML type attribute.
270 271 272 |
# File 'lib/asciidoctor/abstract_block.rb', line 270 def list_marker_keyword list_type = nil ORDERED_LIST_KEYWORDS[list_type || @style] end |
#next_adjacent_block ⇒ Object
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.
185 186 187 188 189 190 191 192 193 |
# File 'lib/asciidoctor/abstract_block.rb', line 185 def next_adjacent_block 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 |
#number ⇒ Object
Do not use this in new code, and replace it when updating old code.
Legacy property to get the String or Integer numeral of this section.
142 143 144 |
# File 'lib/asciidoctor/abstract_block.rb', line 142 def number (Integer @numeral) rescue @numeral end |
#number=(val) ⇒ Object
Do not use this in new code, and replace it when updating old code.
Legacy property to set the numeral of this section by coercing the value to a String.
147 148 149 |
# File 'lib/asciidoctor/abstract_block.rb', line 147 def number= val @numeral = val.to_s end |
#remove_sub(sub) ⇒ void
This method returns an undefined value.
Remove a substitution from this block
323 324 325 326 |
# File 'lib/asciidoctor/abstract_block.rb', line 323 def remove_sub sub @subs.delete sub nil end |
#sections ⇒ Array
Get the Array of child Section objects
Only applies to Document and Section instances
217 218 219 |
# File 'lib/asciidoctor/abstract_block.rb', line 217 def sections @blocks.select {|block| block.context == :section } end |
#sections? ⇒ Boolean
Check whether this block has any child Section objects.
Acts an an abstract method that always returns false unless this block is an instance of Document or Section. Both Document and Section provide overrides for this method.
137 138 139 |
# File 'lib/asciidoctor/abstract_block.rb', line 137 def sections? false end |
#sub?(name) ⇒ A
A convenience method that checks whether the specified substitution is enabled for this block.
314 315 316 |
# File 'lib/asciidoctor/abstract_block.rb', line 314 def sub? name @subs.include? name end |
#title ⇒ Object
Get the String title of this Block with title substitutions applied
The following substitutions are applied to block and section titles:
:specialcharacters, :quotes, :replacements, :macros, :attributes and :post_replacements
287 288 289 290 |
# File 'lib/asciidoctor/abstract_block.rb', line 287 def title # prevent substitutions from being applied to title multiple times @converted_title ||= @title && (apply_title_subs @title) end |
#title=(val) ⇒ Object
Set the String block title.
302 303 304 305 |
# File 'lib/asciidoctor/abstract_block.rb', line 302 def title= val @converted_title = nil @title = val end |
#title? ⇒ Boolean
A convenience method that checks whether the title of this block is defined.
295 296 297 |
# File 'lib/asciidoctor/abstract_block.rb', line 295 def title? @title ? true : false end |
#xreftext(xrefstyle = nil) ⇒ String
Generate cross reference text (xreftext) that can be used to refer to this block.
Use the explicit reftext for this block, if specified, retrieved from the Asciidoctor::AbstractNode#reftext method. Otherwise, if this is a section or captioned block (a block with both a title and caption), generate the xreftext according to the value of the xrefstyle argument (e.g., full, short). This logic may leverage the Substitutors#sub_quotes method to apply formatting to the text. If this is not a captioned block, return the title, if present, or nil otherwise.
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 |
# File 'lib/asciidoctor/abstract_block.rb', line 344 def xreftext xrefstyle = nil if (val = reftext) && !val.empty? val # NOTE xrefstyle only applies to blocks with a title and a caption or number elsif xrefstyle && @title && !@caption.nil_or_empty? case xrefstyle when 'full' quoted_title = sub_placeholder (sub_quotes @document.compat_mode ? %q(``%s'') : '"`%s`"'), title if @numeral && ( = CAPTION_ATTRIBUTE_NAMES[@context]) && (prefix = @document.attributes[]) %(#{prefix} #{@numeral}, #{quoted_title}) else %(#{@caption.chomp '. '}, #{quoted_title}) end when 'short' if @numeral && ( = CAPTION_ATTRIBUTE_NAMES[@context]) && (prefix = @document.attributes[]) %(#{prefix} #{@numeral}) else @caption.chomp '. ' end else # 'basic' title end else title end end |