Class: Asciidoctor::Rhrev::Catalog

Inherits:
Object
  • Object
show all
Defined in:
lib/asciidoctor/rhrev/catalog.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCatalog

Returns a new instance of Catalog.



8
9
10
11
12
13
# File 'lib/asciidoctor/rhrev/catalog.rb', line 8

def initialize
  @entries = {}  # Hash of revision => [entries]
  @all_entries = {}  # Hash of revision => text for 'all' entries
  @cover_entries = {}  # Hash of revision => text for 'cover' entries
  @sequence_counter = 0  # Counter to track document order
end

Instance Attribute Details

#all_entriesObject

Returns the value of attribute all_entries.



5
6
7
# File 'lib/asciidoctor/rhrev/catalog.rb', line 5

def all_entries
  @all_entries
end

#cover_entriesObject

Returns the value of attribute cover_entries.



6
7
8
# File 'lib/asciidoctor/rhrev/catalog.rb', line 6

def cover_entries
  @cover_entries
end

#entriesObject

Returns the value of attribute entries.



4
5
6
# File 'lib/asciidoctor/rhrev/catalog.rb', line 4

def entries
  @entries
end

Class Method Details

.default_columnsObject



22
23
24
# File 'lib/asciidoctor/rhrev/catalog.rb', line 22

def self.default_columns
  '30,70'  # location, change
end

.default_labelsObject



15
16
17
18
19
20
# File 'lib/asciidoctor/rhrev/catalog.rb', line 15

def self.default_labels
  {
    'page' => 'Page',
    'major_changes' => 'Major changes since'
  }
end

Instance Method Details

#add_all_entry(revision, change_text) ⇒ Object



50
51
52
# File 'lib/asciidoctor/rhrev/catalog.rb', line 50

def add_all_entry revision, change_text
  @all_entries[revision] = change_text
end

#add_cover_entry(revision, change_text) ⇒ Object



54
55
56
# File 'lib/asciidoctor/rhrev/catalog.rb', line 54

def add_cover_entry revision, change_text
  @cover_entries[revision] = change_text
end

#add_entry(revision, anchor, change_text, reftext: nil, title: nil, sectnum: nil, context: nil, is_chapter: false, sectname: nil, caption_number: nil, source_line: nil) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/asciidoctor/rhrev/catalog.rb', line 26

def add_entry revision, anchor, change_text, reftext: nil, title: nil, sectnum: nil, context: nil, is_chapter: false, sectname: nil, caption_number: nil, source_line: nil
  @entries[revision] ||= []
  
  # Prevent duplicates (e.g. if collected multiple times)
  return if @entries[revision].any? { |e| e[:anchor] == anchor }
  
  @sequence_counter += 1
  # Use source_line if available, otherwise fall back to sequence counter
  sequence = source_line || @sequence_counter
  @entries[revision] << {
    anchor: anchor,
    change: change_text,
    dest: nil,
    sequence: sequence,
    reftext: reftext,
    title: title,
    sectnum: sectnum,
    context: context,
    is_chapter: is_chapter,
    sectname: sectname,
    caption_number: caption_number
  }
end

#displayed_page_for(physical_page_number, start_page_number) ⇒ Object

The reader-visible page number for one physical page, given the physical page that displays as "1" (start_page_number) - a plain page number once numbering has started there, a lowercase roman numeral for anything still before it. Shared by link_dest_to_page (the eager, first-pass conversion, correct as-is for page-numbering-start-at: body, the common case) and recompute_display_pages (the deferred, corrected conversion for every other mode, see that method's own docblock).



81
82
83
84
# File 'lib/asciidoctor/rhrev/catalog.rb', line 81

def displayed_page_for physical_page_number, start_page_number
  virtual_page_number = physical_page_number - (start_page_number - 1)
  virtual_page_number < 1 ? (Asciidoctor::PDF::RomanNumeral.new physical_page_number, :lower) : virtual_page_number
end


58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/asciidoctor/rhrev/catalog.rb', line 58

def link_dest_to_page anchor, physical_page_number, start_page_number, y: nil
  @entries.each do |revision, entry_list|
    entry_list.each do |entry|
      next unless entry[:anchor] == anchor

      entry[:dest] = {
        anchor: anchor,
        page: (displayed_page_for physical_page_number, start_page_number).to_s,
        page_sortable: physical_page_number,
        y: y
      }
    end
  end
end

#parse_revision(rev_string) ⇒ Object



122
123
124
125
# File 'lib/asciidoctor/rhrev/catalog.rb', line 122

def parse_revision rev_string
  # Parse "1-1", "1-2", "1-10-2" into comparable array [1, 1], [1, 2], [1, 10, 2]
  rev_string.split('-').map(&:to_i)
end

#recompute_display_pages(start_page_number) ⇒ Object

Recomputes every entry's own :dest][:page] from its already-stored :page_sortable (the real physical page number, unconditionally correct, set by link_dest_to_page above regardless of mode) and the given, now-final start_page_number.

Needed because link_dest_to_page's own formula, applied eagerly during document traversal, is only ever correct for page- numbering-start-at: body: for toc/after-toc/cover/an explicit integer, the real physical page that displays as "1" is not knowable that early (asciidoctor-pdf itself only finalizes it after inking the table of contents, confirmed directly against its own source, converter.rb's convert_document). The converter calls this once, after the whole document (table of contents included) has rendered, with the real, corrected start_page_number its own compute_rhrev_page_numbering_start_page works out; entries already correct (body mode) are simply recomputed to the same value they already held, a harmless no-op.



103
104
105
106
107
108
109
110
# File 'lib/asciidoctor/rhrev/catalog.rb', line 103

def recompute_display_pages start_page_number
  @entries.each_value do |entry_list|
    entry_list.each do |entry|
      next unless (dest = entry[:dest]) && dest[:page_sortable]
      dest[:page] = (displayed_page_for dest[:page_sortable], start_page_number).to_s
    end
  end
end

#sorted_revisionsObject



112
113
114
115
116
117
118
119
120
# File 'lib/asciidoctor/rhrev/catalog.rb', line 112

def sorted_revisions
  # Collect all unique revisions from entries, all_entries, and cover_entries
  all_revisions = (@entries.keys + @all_entries.keys + @cover_entries.keys).uniq
  
  # Sort revisions in descending order (newest first)
  all_revisions.sort do |a, b|
    parse_revision(b) <=> parse_revision(a)
  end
end