Class: AsciidoctorBibliography::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/asciidoctor-bibliography/index.rb

Constant Summary collapse

REGEXP =
/^(bibliography)::(\S+)?\[(|.*?[^\\])\]$/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(macro, target, attributes) ⇒ Index

Returns a new instance of Index.



10
11
12
13
14
# File 'lib/asciidoctor-bibliography/index.rb', line 10

def initialize(macro, target, attributes)
  @macro = macro
  @target = target.to_s.empty? ? "default" : target
  @attributes = ::Asciidoctor::AttributeList.new(attributes).parse
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



8
9
10
# File 'lib/asciidoctor-bibliography/index.rb', line 8

def attributes
  @attributes
end

#macroObject (readonly)

Returns the value of attribute macro.



8
9
10
# File 'lib/asciidoctor-bibliography/index.rb', line 8

def macro
  @macro
end

#targetObject (readonly)

Returns the value of attribute target.



8
9
10
# File 'lib/asciidoctor-bibliography/index.rb', line 8

def target
  @target
end

Instance Method Details

#render(bibliographer) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/asciidoctor-bibliography/index.rb', line 16

def render(bibliographer)
  formatter = setup_formatter bibliographer

  lines = []
  formatter.bibliography.each_with_index do |reference, index|
    id = anchor_id "bibliography", target, formatter.data[index].id
    lines << wrap_up_reference(reference: reference, id: id, bibliographer: bibliographer)
  end

  # Intersperse the lines with empty ones to render as paragraphs.
  lines.join("\n\n").lines.map(&:strip)
end