Class: Asciidoctor::Rhrev::Catalog
- Inherits:
-
Object
- Object
- Asciidoctor::Rhrev::Catalog
- Defined in:
- lib/asciidoctor/rhrev/catalog.rb
Instance Attribute Summary collapse
-
#all_entries ⇒ Object
Returns the value of attribute all_entries.
-
#cover_entries ⇒ Object
Returns the value of attribute cover_entries.
-
#entries ⇒ Object
Returns the value of attribute entries.
Class Method Summary collapse
Instance Method Summary collapse
- #add_all_entry(revision, change_text) ⇒ Object
- #add_cover_entry(revision, change_text) ⇒ Object
- #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
-
#initialize ⇒ Catalog
constructor
A new instance of Catalog.
- #link_dest_to_page(anchor, physical_page_number, start_page_number, y: nil) ⇒ Object
- #parse_revision(rev_string) ⇒ Object
- #sorted_revisions ⇒ Object
Constructor Details
#initialize ⇒ Catalog
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_entries ⇒ Object
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_entries ⇒ Object
Returns the value of attribute cover_entries.
6 7 8 |
# File 'lib/asciidoctor/rhrev/catalog.rb', line 6 def cover_entries @cover_entries end |
#entries ⇒ Object
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_columns ⇒ Object
22 23 24 |
# File 'lib/asciidoctor/rhrev/catalog.rb', line 22 def self.default_columns '30,70' # location, change end |
.default_labels ⇒ Object
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 |
#link_dest_to_page(anchor, physical_page_number, start_page_number, y: nil) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# 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 virtual_page_number = physical_page_number - (start_page_number - 1) entry[:dest] = { anchor: anchor, page: (virtual_page_number < 1 ? (Asciidoctor::PDF::RomanNumeral.new physical_page_number, :lower) : virtual_page_number).to_s, page_sortable: physical_page_number, y: y } end end end |
#parse_revision(rev_string) ⇒ Object
86 87 88 89 |
# File 'lib/asciidoctor/rhrev/catalog.rb', line 86 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 |
#sorted_revisions ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/asciidoctor/rhrev/catalog.rb', line 76 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 |