Class: Asciidoctor::Callouts
- Inherits:
-
Object
- Object
- Asciidoctor::Callouts
- Defined in:
- lib/asciidoctor/callouts.rb
Overview
Maintains a catalog of callouts and their associations.
Instance Method Summary collapse
-
#callout_ids(li_ordinal) ⇒ A
Get a space-separated list of callout ids for the specified list item.
-
#current_list ⇒ The
The current list for which callouts are being collected.
-
#initialize ⇒ Callouts
constructor
A new instance of Callouts.
-
#next_list ⇒ void
Advance to the next callout list in the document.
-
#read_next_id ⇒ The
Get the next callout index in the document.
-
#register(li_ordinal) ⇒ The
Register a new callout for the given list item ordinal.
-
#rewind ⇒ void
Rewind the list index pointer, intended to be used when switching from the parsing to conversion phase.
Constructor Details
#initialize ⇒ Callouts
Returns a new instance of Callouts.
5 6 7 8 9 |
# File 'lib/asciidoctor/callouts.rb', line 5 def initialize @lists = [] @list_index = 0 next_list end |
Instance Method Details
#callout_ids(li_ordinal) ⇒ A
Get a space-separated list of callout ids for the specified list item
61 62 63 |
# File 'lib/asciidoctor/callouts.rb', line 61 def callout_ids li_ordinal current_list.map {|it| it[:ordinal] == li_ordinal ? %(#{it[:id]} ) : '' }.join.chop end |
#current_list ⇒ The
The current list for which callouts are being collected
68 69 70 |
# File 'lib/asciidoctor/callouts.rb', line 68 def current_list @lists[@list_index - 1] end |
#next_list ⇒ void
This method returns an undefined value.
Advance to the next callout list in the document
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/asciidoctor/callouts.rb', line 75 def next_list @list_index += 1 if @lists.size < @list_index @lists << [] end @co_index = 1 nil end |
#read_next_id ⇒ The
Get the next callout index in the document
Reads the next callout index in the document and advances the pointer. This method is used during conversion to retrieve the unique id of the callout that was generated during parsing.
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/asciidoctor/callouts.rb', line 43 def read_next_id id = nil list = current_list if @co_index <= list.size id = list[@co_index - 1][:id] end @co_index += 1 id end |
#register(li_ordinal) ⇒ The
Register a new callout for the given list item ordinal.
Generates a unique id for this callout based on the index of the next callout list in the document and the index of this callout since the end of the last callout list.
30 31 32 33 34 |
# File 'lib/asciidoctor/callouts.rb', line 30 def register li_ordinal current_list << { ordinal: li_ordinal.to_i, id: (id = generate_next_callout_id) } @co_index += 1 id end |
#rewind ⇒ void
This method returns an undefined value.
Rewind the list index pointer, intended to be used when switching from the parsing to conversion phase.
90 91 92 93 94 |
# File 'lib/asciidoctor/callouts.rb', line 90 def rewind @list_index = 1 @co_index = 1 nil end |