Module: Asciidoctor::PDF::Rhrev::Renderer

Includes:
Helpers
Included in:
Converter
Defined in:
lib/asciidoctor/rhrev/renderer.rb

Instance Method Summary collapse

Instance Method Details

#add_custom_first_row_to_markup(markup_lines, doc) ⇒ Object



353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
# File 'lib/asciidoctor/rhrev/renderer.rb', line 353

def add_custom_first_row_to_markup markup_lines, doc
  if (first_row_merged = doc.attr 'rhrev-customization-first-row')
    processed = preprocess_attribute_content(first_row_merged)
    cell_prefix = needs_asciidoc_cell?(processed) ? "2+a|" : "2+|"
    markup_lines << ""
    markup_lines << "#{cell_prefix}#{processed}"
  else
    first_row_left = doc.attr 'rhrev-customization-first-row-left'
    first_row_right = doc.attr 'rhrev-customization-first-row-right'
    
    if first_row_left || first_row_right
      left_processed = first_row_left ? preprocess_attribute_content(first_row_left) : ''
      right_processed = first_row_right ? preprocess_attribute_content(first_row_right) : ''
      left_prefix = needs_asciidoc_cell?(left_processed) ? "a|" : "|"
      right_prefix = needs_asciidoc_cell?(right_processed) ? "a|" : "|"
      markup_lines << ""
      markup_lines << "#{left_prefix}#{left_processed}"
      markup_lines << "#{right_prefix}#{right_processed}"
    end
  end
end

#allocate_pagerhref_table_extent(node) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/asciidoctor/rhrev/renderer.rb', line 92

def allocate_pagerhref_table_extent node
  extent = dry_run onto: self do
    @rendering_deferred_table = true
    super_convert_table node
    @rendering_deferred_table = false
  end
  
  @pagerhref_tables ||= []
  @pagerhref_tables << {
    node: node,
    extent: extent,
    page: page_number
  }
  
  move_cursor_to extent.to.cursor
end

#allocate_revision_history_extent(doc) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/asciidoctor/rhrev/renderer.rb', line 9

def allocate_revision_history_extent doc
  # Use accessor method, not instance variable
  return unless revision_history
  
  start_page_number = page_number
  
  extent = dry_run onto: self do
    ink_revision_history_content doc
  end
  
  extent.each_page { |first_page| start_new_page unless first_page }
  move_cursor_to extent.to.cursor
  
  end_page_number = page_number
  @rhrev_deferred_pages = (extent.from.page..end_page_number)
  
  unless doc.attr? 'rhrev-suppress-new-page-after'
    start_new_page
  end
  
  extent
end

#build_cell(table, col_idx, text) ⇒ Object



569
570
571
572
# File 'lib/asciidoctor/rhrev/renderer.rb', line 569

def build_cell table, col_idx, text
  column = table.columns[col_idx]
  ::Asciidoctor::Table::Cell.new column, text
end

#build_consolidated_list(doc, items) ⇒ Object



282
283
284
285
# File 'lib/asciidoctor/rhrev/renderer.rb', line 282

def build_consolidated_list doc, items
  return "" if items.empty?
  items.map { |item| "* #{item}" }.join("\n")
end

#build_description_xrefs(anchor, doc, entry) ⇒ Object



287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
# File 'lib/asciidoctor/rhrev/renderer.rb', line 287

def build_description_xrefs anchor, doc, entry
  # Build description xref text directly using <a anchor="..."> markup
  # This is necessary because xref: syntax won't resolve in a parsed subdocument
  xrefstyle_config = doc.attr 'rhrev-description-xrefstyle', ''
  styles = xrefstyle_config.split(/\s+/).reject(&:empty?)
  
  has_reftext = entry && entry[:reftext]
  
  if styles.empty?
    # Default: use basic style
    display_text = build_xref_text(anchor, 'basic', entry, doc)
    formatted_text = format_with_role(display_text, 'rhrevdescription')
    "<a anchor=\"#{anchor}\">#{formatted_text}</a>"
  elsif styles.length == 1
    display_text = build_xref_text(anchor, styles[0], entry, doc)
    formatted_text = format_with_role(display_text, 'rhrevdescription')
    "<a anchor=\"#{anchor}\">#{formatted_text}</a>"
  elsif styles.join(' ') == 'short basic'
    # Special case: add both short and basic xrefs
    # For sections: check if numbered (respects :!sectnum:)
    is_numbered = entry ? check_if_numbered(entry, anchor, doc) : false
    
    if has_reftext || !is_numbered
      # If reftext is defined OR section is unnumbered, just use basic to avoid duplication
      display_text = build_xref_text(anchor, 'basic', entry, doc)
      formatted_text = format_with_role(display_text, 'rhrevdescription')
      "<a anchor=\"#{anchor}\">#{formatted_text}</a>"
    else
      # No reftext and numbered section, safe to add both
      display_short = build_xref_text(anchor, 'short', entry, doc)
      display_basic = build_xref_text(anchor, 'basic', entry, doc)
      formatted_short = format_with_role(display_short, 'rhrevdescription')
      formatted_basic = format_with_role(display_basic, 'rhrevdescription')
      "<a anchor=\"#{anchor}\">#{formatted_short}</a> <a anchor=\"#{anchor}\">#{formatted_basic}</a>"
    end
  else
    # Multiple styles - output each
    xrefs = styles.map do |style|
      display_text = build_xref_text(anchor, style, entry, doc)
      formatted_text = format_with_role(display_text, 'rhrevdescription')
      "<a anchor=\"#{anchor}\">#{formatted_text}</a>"
    end
    xrefs.join(" ")
  end
end

#build_list_row(table, location_text, change_text, anchor, entry, template_location_cell, template_asciidoc_cell, doc, is_all_or_cover: false) ⇒ Object



502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
# File 'lib/asciidoctor/rhrev/renderer.rb', line 502

def build_list_row table, location_text, change_text, anchor, entry, template_location_cell, template_asciidoc_cell, doc, is_all_or_cover: false
  if anchor && location_text != '???'
    location_cell = ::Asciidoctor::Table::Cell.new(template_location_cell.column, "", template_asciidoc_cell.attributes.dup)
    location_cell.inner_document.blocks.clear
    para_block = ::Asciidoctor::Block.new(location_cell.inner_document, :paragraph)
    formatted_location = format_with_role(location_text, 'rhrevpage')
    para_block.lines = ["<a anchor=\"#{anchor}\">#{formatted_location}</a>"]
    location_cell.inner_document.blocks << para_block
  else
    location_cell = ::Asciidoctor::Table::Cell.new(template_location_cell.column, location_text, template_location_cell.attributes.dup)
  end
  
  change_cell = ::Asciidoctor::Table::Cell.new(template_asciidoc_cell.column, "", template_asciidoc_cell.attributes.dup)
  change_cell.inner_document.blocks.clear
  
  cell_doc = change_cell.inner_document
  
  if is_all_or_cover
    # For all/cover entries, just add the change text
    processed = preprocess_attribute_content(change_text)
    if processed.include?('* ')
      processed = format_as_list(processed)
    end
    if needs_asciidoc_cell?(processed)
      parsed = ::Asciidoctor.load(processed, safe: :safe, backend: 'pdf')
      parsed.blocks.each do |block|
        block.parent = cell_doc
        cell_doc.blocks << block
      end
    else
      para = ::Asciidoctor::Block.new(cell_doc, :paragraph, source: processed)
      cell_doc.blocks << para
    end
  else
    description_config = doc.attr 'rhrev-customization-description-format', 'xref,desc'
    show_desc = description_config.include?('desc')
    show_xref = description_config.include?('xref')
    
    # Add xref as a direct paragraph block (not parsed) - <a anchor="..."> is PDF converter syntax
    if show_xref && anchor
      xref_markup = build_description_xrefs(anchor, doc, entry)
      xref_block = ::Asciidoctor::Block.new(cell_doc, :paragraph)
      xref_block.lines = [xref_markup]
      cell_doc.blocks << xref_block
    end
    
    # Add change description text
    if show_desc && !change_text.to_s.empty?
      processed = preprocess_attribute_content(change_text)
      processed = format_as_list(processed)
      
      if needs_asciidoc_cell?(processed)
        parsed = ::Asciidoctor.load(processed, safe: :safe, backend: 'pdf')
        parsed.blocks.each do |block|
          block.parent = cell_doc
          cell_doc.blocks << block
        end
      else
        para = ::Asciidoctor::Block.new(cell_doc, :paragraph, source: processed)
        cell_doc.blocks << para
      end
    end
  end
  
  [location_cell, change_cell]
end

#build_location_text(entry, doc) ⇒ Object



578
579
580
581
582
583
584
# File 'lib/asciidoctor/rhrev/renderer.rb', line 578

def build_location_text entry, doc
  if entry[:dest]
     entry[:dest][:page]
  else
     "???"
  end
end

#build_table_via_parsing(doc) ⇒ Object



375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
# File 'lib/asciidoctor/rhrev/renderer.rb', line 375

def build_table_via_parsing doc
  column_widths = get_column_widths doc
  markup_lines = []
  formatted_widths = column_widths.map { |w| w.to_i.to_s }.join(',')
  markup_lines << "[cols='#{formatted_widths}']"
  markup_lines << "|==="
  
  add_custom_first_row_to_markup markup_lines, doc
  
  markup_lines << "|Placeholder"
  markup_lines << "a|* Placeholder list"
  markup_lines << "|==="
  
  markup_str = markup_lines.join("\n")
  parsed_doc = ::Asciidoctor.load(markup_str, safe: :safe, backend: 'pdf')
  table = parsed_doc.blocks[0]
  
  table.set_attr 'frame', (doc.attr 'rhrev-table-frame', 'all')
  table.set_attr 'grid', (doc.attr 'rhrev-table-grid', 'all')
  if (stripes = doc.attr 'rhrev-table-stripes')
    table.set_attr 'stripes', stripes
  end
  if (caption = doc.attr 'rhrev-table-caption')
    table.title = caption
  end
  
  has_custom_first_row = (doc.attr? 'rhrev-customization-first-row') || 
                        (doc.attr? 'rhrev-customization-first-row-left') || 
                        (doc.attr? 'rhrev-customization-first-row-right')
  
  custom_first_row = has_custom_first_row ? table.rows.body[0] : nil
  
  placeholder_row = has_custom_first_row ? table.rows.body[1] : table.rows.body[0]
  template_location_cell = placeholder_row[0]
  template_asciidoc_cell = placeholder_row[1]
  
  table.rows.body.clear
  table.rows.body << custom_first_row if custom_first_row
  
  page_label = doc.attr 'rhrev-localization-page', 'Page'
  major_changes_text = doc.attr 'rhrev-localization-major-changes', 'Major changes since'
  all_text = doc.attr 'rhrev-localization-all', 'All'
  cover_text = doc.attr 'rhrev-localization-cover', 'Cover'
  
  revision_history.sorted_revisions.each do |revision|
    prevrev_attr = "#{revision}-prevrev"
    prevrevdate_attr = "#{revision}-prevrevdate"
    revision_label = doc.attr('version-label', 'Revision')
    prev_title = doc.attr(prevrev_attr) || "#{revision.tr('-', '.')}"
    prev_date = doc.attr(prevrevdate_attr) || ""
    prev_rev_text = format_prev_rev(prev_title, prev_date, doc)
    
    if prev_title.strip.downcase.start_with?(revision_label.downcase)
      header_text = "*#{major_changes_text} #{prev_rev_text}*"
    else
      header_text = "*#{major_changes_text} #{revision_label} #{prev_rev_text}*"
    end
    
    page_cell = build_text_cell table, 0, "*#{page_label}*"
    header_cell = build_text_cell table, 1, header_text
    table.rows.body << [page_cell, header_cell]
    
    if (all_change = revision_history.instance_variable_get(:@all_entries)[revision])
      row = build_list_row table, all_text, all_change, nil, nil, template_location_cell, template_asciidoc_cell, doc, is_all_or_cover: true
      table.rows.body << row
    end
    
    if (cover_change = revision_history.instance_variable_get(:@cover_entries)[revision])
      unless doc.backend.to_s == 'html5'
        row = build_list_row table, cover_text, cover_change, nil, nil, template_location_cell, template_asciidoc_cell, doc, is_all_or_cover: true
        table.rows.body << row
      end
    end
    
    entries = revision_history.entries[revision] || []
    entries = entries.sort_by do |e|
      page_num = e[:dest] ? e[:dest][:page_sortable] : Float::INFINITY
      y_pos = e[:dest] && e[:dest][:y] ? e[:dest][:y] : 0
      # Sort by page (ASC) then y_pos (DESC - top to bottom) then sequence (ASC)
      [page_num, -y_pos, e[:sequence] || 0]
    end
    
    entries.each do |entry|
      location = build_location_text entry, doc
      row = build_list_row table, location, entry[:change], entry[:anchor], entry, template_location_cell, template_asciidoc_cell, doc
      table.rows.body << row
    end
  end
  
  if doc.attr? 'rhrev-table-extra-blank-row'
    blank_row = build_text_row table, ["\u00A0", "\u00A0"]
    table.rows.body << blank_row
  end
  
  table
end

#build_text_cell(table, col_idx, text) ⇒ Object



574
575
576
# File 'lib/asciidoctor/rhrev/renderer.rb', line 574

def build_text_cell table, col_idx, text
  build_cell table, col_idx, text
end

#build_text_row(table, cells_data) ⇒ Object



472
473
474
475
476
# File 'lib/asciidoctor/rhrev/renderer.rb', line 472

def build_text_row table, cells_data
  cells_data.map.with_index do |text, col_idx|
    build_cell table, col_idx, text
  end
end

#build_xref_text(anchor, style, entry, doc) ⇒ Object



606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
# File 'lib/asciidoctor/rhrev/renderer.rb', line 606

def build_xref_text(anchor, style, entry, doc)
   # If reftext is defined, it overrides everything
   return entry[:reftext] if entry && entry[:reftext]
   
   title = entry && entry[:title] ? entry[:title] : nil
   sectnum = entry && entry[:sectnum] ? entry[:sectnum] : nil
   context = entry && entry[:context] ? entry[:context] : nil
   is_chapter = entry && entry[:is_chapter]
   caption_number = entry && entry[:caption_number]
   
   # Fallback if no title - convert anchor to title case
   unless title
     # Handle Antora ::: separator - extract fragment for display
     display_anchor = anchor.include?(':::') ? anchor.split(':::').last : anchor
     clean_anchor = display_anchor.sub(/^_/, '')
     return clean_anchor.tr('-', ' ').split.map(&:capitalize).join(' ')
   end
   
   # For sections with numbers, construct appropriate xreftext
   if sectnum && context == :section
     numbered = check_if_numbered(entry, anchor, doc)
     
     if numbered
       if doc.attr? 'rhrev-customization-xrefstyleshort-remove-trailling-period'
         clean_sectnum = sectnum.to_s.sub(/\.$/, '')
       else
         clean_sectnum = sectnum.to_s
         clean_sectnum += '.' unless clean_sectnum.end_with?('.')
       end
       signifier = is_chapter ? 'Chapter' : 'Section'
       
       case style
       when 'full'
         "#{signifier} #{clean_sectnum}, \"#{title}\""
       when 'short'
         "#{signifier} #{clean_sectnum}"
       when 'basic'
         title
       else
         title
       end
     else
       # Section numbering is disabled, just return the title
       title
     end
   elsif caption_number && [:example, :table, :listing, :image].include?(context)
    # For numbered blocks (examples, tables, listings, images), the period must be added to match AsciiDoctor-PDF's default built-in theming/presentation behavior.
     if doc.attr? 'rhrev-customization-xrefstyleshort-remove-trailling-period'
       clean_caption_number = caption_number.to_s.sub(/\.$/, '')
     else
       clean_caption_number = caption_number.to_s
       clean_caption_number += '.' unless clean_caption_number.end_with?('.')
     end

     signifier = case context
     when :example
       doc.attr('example-caption', 'Example').sub(/\.?\s*$/, '')
     when :table
       doc.attr('table-caption', 'Table').sub(/\.?\s*$/, '')
     when :listing
       doc.attr('listing-caption', 'Listing').sub(/\.?\s*$/, '')
     when :image
       doc.attr('figure-caption', 'Figure').sub(/\.?\s*$/, '')
     else
       context.to_s.capitalize
     end
     
     case style
     when 'full'
       "#{signifier} #{clean_caption_number}, \"#{title}\""
     when 'short'
       "#{signifier} #{clean_caption_number}"
     when 'basic'
       title
     else
       title
     end
   else
     # No section number or caption number, just return title for all styles
     title
   end
end

#check_if_numbered(entry, anchor, doc) ⇒ Object



586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
# File 'lib/asciidoctor/rhrev/renderer.rb', line 586

def check_if_numbered(entry, anchor, doc)
  context = entry[:context]
  if context == :section
    return true unless entry[:sectnum]
    if doc.respond_to?(:catalog) && doc.catalog && doc.catalog[:refs]
       section = doc.catalog[:refs][anchor]
       if section && section.respond_to?(:numbered)
          return section.numbered
       elsif section && section.respond_to?(:numbered?)
          return section.numbered?
       end
    end
    return true
  end
  if entry[:caption_number]
    return true
  end
  false
end

#create_revision_table_properly(doc) ⇒ Object



333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
# File 'lib/asciidoctor/rhrev/renderer.rb', line 333

def create_revision_table_properly doc
  asciidoc_table = build_table_via_parsing doc
  
  disable_caption = doc.attr? 'rhrev-disable-caption'
  if disable_caption
    saved_caption = doc.attr 'table-caption'
    doc.set_attr 'table-caption', ''
  end
  
  convert_table asciidoc_table
  
  if disable_caption
    if saved_caption
      doc.set_attr 'table-caption', saved_caption
    else
      doc.delete_attribute 'table-caption'
    end
  end
end

#format_as_list(text) ⇒ Object



478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
# File 'lib/asciidoctor/rhrev/renderer.rb', line 478

def format_as_list text
  text_str = text.to_s
  # Don't skip if it doesn't have * - we might want to force list
  
  tokens = text_str.split(/\s(?=\*+\s)/)
  return text_str if tokens.empty?
  
  lines = []
  first = tokens.shift
  
  # Check if first item already starts with *
  if first.strip.start_with?('*')
     lines << first.strip
  else
     lines << "* #{first.strip}"
  end
  
  tokens.each do |token|
    lines << token.strip
  end
  
  lines.join("\n")
end

#format_location_for_display(location_text, entry, doc) ⇒ Object



274
275
276
# File 'lib/asciidoctor/rhrev/renderer.rb', line 274

def format_location_for_display location_text, entry, doc
  %(<span class="rhrevpage">#{location_text}</span>)
end

#format_with_role(text, role) ⇒ Object



278
279
280
# File 'lib/asciidoctor/rhrev/renderer.rb', line 278

def format_with_role text, role
  %(<span class="#{role}">#{text}</span>)
end

#get_column_widths(doc) ⇒ Object



689
690
691
692
# File 'lib/asciidoctor/rhrev/renderer.rb', line 689

def get_column_widths doc
   widths_str = doc.attr 'rhrev-table-column-width', Asciidoctor::PDF::Rhrev::Catalog.default_columns
   widths_str.split(',').map(&:strip)
end

#ink_pagerhref_tablesObject



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/asciidoctor/rhrev/renderer.rb', line 109

def ink_pagerhref_tables
  @anchor_catalog ||= {}
  
  @pagerhref_tables.each do |table_info|
    extent = table_info[:extent]
    node = table_info[:node]
    
    # Resolve pagerhrefs before rendering
    resolve_pagerhrefs_in_table node
    
    go_to_page extent.from.page
    move_cursor_to extent.from.cursor
    
    @rendering_deferred_table = true
    super_convert_table node
    @rendering_deferred_table = false
  end
end

#ink_prose(text, opts = {}) ⇒ Object



270
271
272
# File 'lib/asciidoctor/rhrev/renderer.rb', line 270

def ink_prose text, opts = {}
  layout_prose text, opts
end

#ink_revision_history(doc, extent) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/asciidoctor/rhrev/renderer.rb', line 32

def ink_revision_history doc, extent
  return if scratch?
  
  go_to_page extent.from.page
  move_cursor_to extent.from.cursor
  
  ink_revision_history_content doc
  
  end_page = page_number
  start_page = extent.from.page
  
  has_foreground = @theme.page_foreground_image || doc.attr('page-foreground-image')
  
  if has_foreground
    fg_image = resolve_background_image doc, @theme, 'page-foreground-image'
    if fg_image && fg_image[0]
      (start_page..end_page).each do |pg|
        go_to_page pg
        next if page.imported_page?
        stamp_name = %(foreground-image-#{page.layout})
        stamp stamp_name if (stamp_dictionary_registry.key? stamp_name rescue false)
      end
    end
  end
  
  @rhrev_deferred_pages = nil
end

#ink_revision_history_content(doc) ⇒ Object



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/asciidoctor/rhrev/renderer.rb', line 167

def ink_revision_history_content doc
  collect_document_level_entries doc
  
  if doc.attr? 'rhrev-export-to-file'
    export_to_adoc_file doc
    return
  end
  
  return if doc.attr('rhrev') == 'manual'
  
  if is_initial_release?(doc)
    initial_handling = doc.attr 'rhrev-initial-handling', 'initial-release'
    case initial_handling
    when 'skip'; return
    when 'normal'; # Continue
    else
      render_initial_release_table doc
      return
    end
  end
  
  block_type = doc.attr 'rhrev-block-type', 'section'
  
  if block_type == 'table' && !(doc.attr? 'rhrev-disable-caption')
    unless doc.attr? 'table-caption'
      doc.set_attr 'table-caption', (doc.attr 'table-caption', 'Table')
    end
  end
  
  if block_type == 'section'
    version_label = doc.attr('version-label')
    default_title = "#{version_label} History"
    if (title = doc.attr 'rhrev-customization-title', default_title)
      unless title.empty?
        heading_opts = { align: :left, margin_bottom: (@theme.heading_margin_bottom || 12) }
        theme_font :heading, level: 2 do
          ink_prose title, heading_opts
        end
      end
    end
  end
  
  create_revision_table_properly doc if revision_history
end

#is_initial_release?(doc) ⇒ Boolean

Returns:

  • (Boolean)


212
213
214
215
216
# File 'lib/asciidoctor/rhrev/renderer.rb', line 212

def is_initial_release? doc
  revnumber = doc.attr('revnumber')
  return false unless revnumber
  revnumber.to_s.strip == '1.0' || revnumber.to_s.strip == '1'
end

#render_adoc_include(doc, filepath) ⇒ Object



156
157
158
159
160
161
162
163
164
165
# File 'lib/asciidoctor/rhrev/renderer.rb', line 156

def render_adoc_include doc, filepath
  return unless filepath && File.exist?(filepath)
  begin
    content = File.read(filepath)
    subdoc = ::Asciidoctor.load content, safe: :safe, backend: 'pdf'
    subdoc.blocks.each { |block| traverse block }
  rescue => e
    warn "asciidoctor: WARNING: Failed to render include file #{filepath}: #{e.message}"
  end
end

#render_initial_release_table(doc) ⇒ Object



218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/asciidoctor/rhrev/renderer.rb', line 218

def render_initial_release_table doc
  block_type = doc.attr 'rhrev-block-type', 'section'
  
  if block_type == 'section'
    version_label = doc.attr('version-label')
    default_title = "#{version_label} History"
    if (title = doc.attr 'rhrev-customization-title', default_title)
      unless title.empty?
        heading_opts = { align: :left, margin_bottom: (@theme.heading_margin_bottom || 12) }
        theme_font :heading, level: 2 do
          ink_prose title, heading_opts
        end
      end
    end
  end
  
  column_widths = get_column_widths doc
  table_data = []
  
  page_label = doc.attr 'rhrev-localization-page', 'Page'
  major_changes_text = doc.attr 'rhrev-localization-major-changes', 'Major changes since'
  
  revision_label = doc.attr('version-label', 'Revision')
  revnumber = doc.attr('revnumber')
  
  header_text = "*#{major_changes_text} #{revision_label} #{revnumber}*"
  table_data << ["*#{page_label}*", header_text]
  
  initial_text = doc.attr 'rhrev-customization-initial-release-text', 'Initial Release'
  table_data << ["", initial_text]
  
  formatted_widths = column_widths.map { |w| w.to_i.to_s }.join(',')
  markup_lines = []
  markup_lines << "[cols='#{formatted_widths}']"
  markup_lines << "|==="
  table_data.each do |row|
     markup_lines << "|#{row[0]} |#{row[1]}"
  end
  markup_lines << "|==="
  
  parsed_doc = ::Asciidoctor.load(markup_lines.join("\n"), safe: :safe, backend: 'pdf')
  table = parsed_doc.blocks[0]
  
  table.set_attr 'frame', (doc.attr 'rhrev-table-frame', 'all')
  table.set_attr 'grid', (doc.attr 'rhrev-table-grid', 'all')
  if (stripes = doc.attr 'rhrev-table-stripes')
    table.set_attr 'stripes', stripes
  end
  
  convert_table table
end

#resolve_pagerhrefs_in_table(table) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/asciidoctor/rhrev/renderer.rb', line 128

def resolve_pagerhrefs_in_table table
   # Recursively search for pagerhref markers in the table and replace them
   debug_log "Resolving pagerhrefs. Anchor catalog has #{@anchor_catalog.keys.size} entries: #{@anchor_catalog.keys.take(10)}", @document
   
   table.rows[:body].each do |row|
     row.each do |cell|
       next unless cell.text && cell.text.to_s.include?('pagerhref:')
       
       # Replace [pagerhref:anchor] with page number
       # We use a regex that matches the marker created by the inline macro
       cell.text = cell.text.to_s.gsub(/\[pagerhref:(.*?)\]/) do |match|
         anchor = $1
         if (entry = @anchor_catalog[anchor]) && entry[:dest]
            # TODO: Convert physical page to logical page if needed
            entry[:dest][:page].to_s
         else
            debug_log "Pagerhref resolution failed for anchor '#{anchor}'. Catalog has entry? #{@anchor_catalog.key?(anchor)}", @document
            "??"
         end
       end
     end
   end
end

#stamp_foreground_image(doc, has_front_cover) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/asciidoctor/rhrev/renderer.rb', line 60

def stamp_foreground_image doc, has_front_cover
  pages = state.pages
  if (first_page = (has_front_cover ? (pages.drop 1) : pages).find {|it| !it.imported_page? }) &&
      (first_page_num = (pages.index first_page) + 1) &&
      (fg_image = resolve_background_image doc, @theme, 'page-foreground-image') && fg_image[0]
    stamps = ::Set.new
    rhrev_range = @rhrev_deferred_pages || (0..0)
    (first_page_num..page_count).each do |num|
      next if rhrev_range.include?(num)
      go_to_page num
      next if page.imported_page?
      unless stamps.include? (stamp_name = %(foreground-image-#{page.layout}))
        create_stamp stamp_name do
          canvas { image fg_image[0], ({ position: :center, vposition: :center }.merge fg_image[1]) }
        end
        stamps << stamp_name
      end
      stamp stamp_name
    end
  end
end

#super_convert_table(node) ⇒ Object



152
153
154
# File 'lib/asciidoctor/rhrev/renderer.rb', line 152

def super_convert_table node
  self.class.superclass.instance_method(:convert_table).bind(self).call(node)
end

#table_contains_pagerhref?(node) ⇒ Boolean

Returns:

  • (Boolean)


82
83
84
85
86
87
88
89
90
# File 'lib/asciidoctor/rhrev/renderer.rb', line 82

def table_contains_pagerhref? node
  return false unless node.context == :table
  node.rows[:body].each do |row|
    row.each do |cell|
      return true if cell.text.to_s.include?('pagerhref:')
    end
  end
  false
end