class Asciidoctor::PDF::IndexCatalog
Constants
- LeadingAlphaRx
Attributes
Public Class Methods
Source
# File lib/asciidoctor/pdf/index_catalog.rb, line 15 def initialize @categories = {} @start_page_number = 1 @dests = {} @sequence = 0 end
Public Instance Methods
Source
# File lib/asciidoctor/pdf/index_catalog.rb, line 103 def categories @categories.values.sort end
Source
# File lib/asciidoctor/pdf/index_catalog.rb, line 99 def empty? @categories.empty? end
Source
# File lib/asciidoctor/pdf/index_catalog.rb, line 56 def find_category name @categories[name] end
Source
# File lib/asciidoctor/pdf/index_catalog.rb, line 60 def find_primary_term name @categories.each_value do |category| term = category.terms.find {|candidate| candidate.name == name } return term if term end nil end
Source
# File lib/asciidoctor/pdf/index_catalog.rb, line 51 def init_category name name = '@' unless LeadingAlphaRx.match? name @categories[name] ||= IndexTermCategory.new name end
Source
# File lib/asciidoctor/pdf/index_catalog.rb, line 68 def link_associations group = nil if group group.terms.each do |term| associations = term.associations if (see_name = associations[:see]) see_name = FormattedString.new see_name term.see = (find_primary_term see_name) || (UnresolvedIndexTerm.new see_name) elsif (see_also_names = associations[:see_also]) term.see_also = see_also_names.map do |see_also_name| see_also_name = FormattedString.new see_also_name (find_primary_term see_also_name) || (UnresolvedIndexTerm.new see_also_name) end end link_associations term unless term.leaf? end else @categories.each_value {|category| link_associations category } end end
Source
# File lib/asciidoctor/pdf/index_catalog.rb, line 92 def link_dest_to_page anchor, physical_page_number if (dest = @dests[anchor]) virtual_page_number = (dest[:page_sortable] = physical_page_number) - (@start_page_number - 1) dest[:page] = (virtual_page_number < 1 ? (RomanNumeral.new physical_page_number, :lower) : virtual_page_number).to_s end end
Source
# File lib/asciidoctor/pdf/index_catalog.rb, line 22 def next_anchor_name %(__indexterm-#{@sequence += 1}) end
Source
# File lib/asciidoctor/pdf/index_catalog.rb, line 88 def store_dest dest @dests[dest[:anchor]] = dest end
Source
# File lib/asciidoctor/pdf/index_catalog.rb, line 36 def store_primary_term name, dest = nil, assoc = {} store_dest dest if dest (init_category name.chr.upcase).store_term name, dest, assoc end
Source
# File lib/asciidoctor/pdf/index_catalog.rb, line 41 def store_secondary_term primary_name, secondary_name, dest = nil, assoc = {} store_dest dest if dest (store_primary_term primary_name).store_term secondary_name, dest, assoc end
Source
# File lib/asciidoctor/pdf/index_catalog.rb, line 26 def store_term names, dest, assoc = {} if (num_terms = (names = names.map {|name| FormattedString.new name }).size) == 1 store_primary_term names[0], dest, assoc elsif num_terms == 2 store_secondary_term names[0], names[1], dest, assoc elsif num_terms > 2 store_tertiary_term names[0], names[1], names[2], dest, assoc end end
Source
# File lib/asciidoctor/pdf/index_catalog.rb, line 46 def store_tertiary_term primary_name, secondary_name, tertiary_name, dest, assoc = {} store_dest dest (store_secondary_term primary_name, secondary_name).store_term tertiary_name, dest, assoc end