Class: Asciidoctor::PDF::Rhrev::Converter
Instance Method Summary
collapse
Methods included from ChangeBars
#arrange_block, #change_bar?, #change_bar_settings, #change_bar_x, #enter_change_bar_section, #exit_change_bar_section, #init_change_bars, #ink_change_bar, #ink_change_bar_for_extent, #ink_chapter_title, #ink_general_heading, #ink_part_title, #record_change_bar_start, #take_change_bar_start
Methods included from Exporter
#build_export_description_xrefs, #convert_anchor_to_xref_for_export, #export_change_text, #export_change_with_bullets, #export_to_adoc_file, #should_export_to_file?
Methods included from Renderer
#add_custom_first_row_to_markup, #allocate_revision_history_extent, #build_cell, #build_consolidated_list, #build_description_xrefs, #build_list_row, #build_location_text, #build_table_via_parsing, #build_text_cell, #build_text_row, #build_xref_text, #check_if_numbered, #create_revision_table_properly, #format_as_list, #format_location_for_display, #format_with_role, #get_column_widths, #ink_prose, #ink_revision_history, #ink_revision_history_content, #is_initial_release?, #render_adoc_include, #render_initial_release_table, #resolve_pagerhrefs_in_table, #stamp_foreground_image
#antora_build?, #convert_anchor_to_xref, #debug_log, #format_prev_rev, #needs_asciidoc_cell?, #preprocess_attribute_content, #with_attribute_missing_suppressed
Constructor Details
#initialize(*args) ⇒ Converter
Returns a new instance of Converter.
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/asciidoctor/rhrev/converter.rb', line 25
def initialize *args
super
@revision_history_extent = nil
@revision_prefix = nil
@rhrev_deferred_pages = nil
@pagerhref_tables = []
@export_completed = false
@catalog = nil
@manual_mode = false
end
|
Instance Method Details
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
|
# File 'lib/asciidoctor/rhrev/converter.rb', line 380
def node
@rendering_deferred_table = true
extent = dry_run onto: self do
super_convert_table node
end
@rendering_deferred_table = false
extent.each_page { |first_page| start_new_page unless first_page }
move_cursor_to extent.to.cursor
@pagerhref_tables << {
node: node,
extent: extent
}
end
|
#catalog_block_anchor(node) ⇒ Object
323
324
325
326
327
328
329
330
331
332
333
334
335
|
# File 'lib/asciidoctor/rhrev/converter.rb', line 323
def catalog_block_anchor node
@anchor_catalog ||= {}
if node.id
@anchor_catalog[node.id] ||= {
title: node.title,
context: node.context
}
page_num = page_number
@anchor_catalog[node.id][:dest] = { page: page_num, y: cursor }
revision_history.link_dest_to_page node.id, page_num, 1, y: cursor
end
end
|
#collect_document_level_entries(doc) ⇒ Object
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
|
# File 'lib/asciidoctor/rhrev/converter.rb', line 425
def collect_document_level_entries doc
return if @document_entries_collected
@document_entries_collected = true
doc.attributes.each_key do |key|
key_str = key.to_s
next unless key_str.end_with?('-prevrev')
revision = key_str.delete_suffix('-prevrev')
next unless revision.match?(/\A\d+(?:-\d+)*\z/)
all_attr_name = "#{@revision_prefix}#{revision}-all"
if (all_value = doc.attr(all_attr_name))
revision_history.add_all_entry revision, all_value
end
cover_attr_name = "#{@revision_prefix}#{revision}-cover"
if (cover_value = doc.attr(cover_attr_name))
revision_history.add_cover_entry revision, cover_value
end
end
end
|
#collect_revision_entries(node) ⇒ Object
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
269
270
271
272
273
274
275
276
277
278
279
280
|
# File 'lib/asciidoctor/rhrev/converter.rb', line 238
def collect_revision_entries node
return if @prescan_complete
return unless node.respond_to?(:attributes)
is_document = node.class.to_s.include?('Document')
return if is_document
attr_entries = node.instance_variable_get(:@attributes) rescue {}
return if attr_entries.nil? || attr_entries.empty?
has_rhrev = attr_entries.keys.any? { |k| k.to_s.start_with?(@revision_prefix) }
return unless has_rhrev
has_id = node.id && !node.id.empty? rescue false
unless has_id
debug_log "Node #{node.context} has rhrev attributes but NO ID. Skipping. Attributes: #{attr_entries.keys.select{|k| k.to_s.start_with?(@revision_prefix)}}", @document
return
end
debug_log "Found entry candidate on #{node.context} id=#{node.id}", @document
attr_entries.each do |key, value|
key_str = key.to_s
next unless key_str.start_with?(@revision_prefix)
next if key_str.include?('-all') || key_str.end_with?('-cover')
revision = key_str.sub("#{@revision_prefix}", '')
debug_log "Adding entry: Rev=#{revision}, Anchor=#{node.id}, Change=#{value}", @document
revision_history.add_entry revision, node.id, value.to_s,
reftext: nil,
title: nil,
sectnum: nil,
context: node.context,
is_chapter: false,
sectname: nil,
caption_number: nil,
source_line: node.lineno
end
end
|
#convert_document(node) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/asciidoctor/rhrev/converter.rb', line 40
def convert_document node
@revision_prefix = node.attr 'revhistoryprefix', 'rhrev'
init_change_bars node
@manual_mode = node.attr('rhrev') == 'manual'
@catalog = revision_history
prescan_document node
result = super
if @revision_history_extent && @catalog
ink_revision_history node, @revision_history_extent
end
if @manual_mode && @pagerhref_tables && !@pagerhref_tables.empty?
if node.attr?('rhrev-export-to-file') && @catalog
export_to_adoc_file node
end
result
end
|
#convert_example(node) ⇒ Object
162
163
164
165
166
167
168
169
|
# File 'lib/asciidoctor/rhrev/converter.rb', line 162
def convert_example node
collect_revision_entries node unless @prescan_complete
update_revision_entry_metadata node
result = super
catalog_block_anchor node
result
end
|
#convert_floating_title(node) ⇒ Object
180
181
182
183
184
185
186
187
188
189
190
|
# File 'lib/asciidoctor/rhrev/converter.rb', line 180
def convert_floating_title node
collect_revision_entries node unless @prescan_complete
update_revision_entry_metadata node
result = super
catalog_block_anchor node
if @change_bar_attr && !scratch? && (start_pos = take_change_bar_start node)
ink_change_bar start_pos, { page: page_number, cursor: cursor }
end
result
end
|
#convert_image(node) ⇒ Object
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
# File 'lib/asciidoctor/rhrev/converter.rb', line 142
def convert_image node
collect_revision_entries node unless @prescan_complete
update_revision_entry_metadata node
if @change_bar_attr && !scratch? && (change_bar? node) &&
!((node.attr 'target').to_s.downcase.end_with? '.pdf')
bar_from = { page: page_number, cursor: cursor }
end
result = super
catalog_block_anchor node
if bar_from
bar_to = { page: page_number, cursor: cursor }
bar_from = { page: bar_to[:page], cursor: bounds.top } if bar_to[:page] > bar_from[:page]
ink_change_bar bar_from, bar_to
end
result
end
|
#convert_inline_quoted(node) ⇒ Object
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
# File 'lib/asciidoctor/rhrev/converter.rb', line 201
def convert_inline_quoted node
if node.text&.match?(/^\[pagerhref:/)
if node.text =~ /^\[pagerhref:(.+)\]$/
anchor = $1
lookup_anchor = anchor.gsub('----', ':::')
if @anchor_catalog && @anchor_catalog[lookup_anchor] && @anchor_catalog[lookup_anchor][:dest]
page_num = @anchor_catalog[lookup_anchor][:dest][:page]
%(<a anchor="#{lookup_anchor}"><span class="pagerhref">#{page_num}</span></a>)
else
if scratch?
%(<a anchor="#{lookup_anchor}"><span class="pagerhref">99</span></a>)
else
%(<a anchor="#{lookup_anchor}"><span class="pagerhref">??</span></a>)
end
end
else
super
end
else
super
end
end
|
#convert_listing(node) ⇒ Object
171
172
173
174
175
176
177
178
|
# File 'lib/asciidoctor/rhrev/converter.rb', line 171
def convert_listing node
collect_revision_entries node unless @prescan_complete
update_revision_entry_metadata node
result = super
catalog_block_anchor node
result
end
|
#convert_rhrev(node) ⇒ Object
192
193
194
195
196
197
198
199
|
# File 'lib/asciidoctor/rhrev/converter.rb', line 192
def convert_rhrev node
return unless node.document.attr? 'rhrev'
return if @revision_history_extent
collect_document_level_entries node.document
@revision_history_extent = allocate_revision_history_extent node.document
nil
end
|
#convert_section(node, opts = {}) ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/asciidoctor/rhrev/converter.rb', line 73
def convert_section node, opts = {}
collect_revision_entries node unless @prescan_complete
update_revision_entry_metadata node
if node.id
@anchor_catalog ||= {}
@anchor_catalog[node.id] ||= {
title: node.title,
reftext: node.reftext,
sectnum: node.sectnum,
context: node.context,
level: node.level
}
@anchor_catalog[node.id][:dest] = { page: page_number, y: cursor }
revision_history.link_dest_to_page node.id, page_number, 1, y: cursor
end
enter_change_bar_section node
result = super
exit_change_bar_section node
if @change_bar_attr && !scratch? && (start_pos = take_change_bar_start node)
ink_change_bar start_pos, { page: page_number, cursor: cursor }
end
result
end
|
#convert_table(node) ⇒ Object
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/asciidoctor/rhrev/converter.rb', line 105
def convert_table node
has_id = node.id && !node.id.empty? rescue false
has_rhrev = false
if node.respond_to?(:attributes) && node.attributes
has_rhrev = node.attributes.keys.any? { |k| k.to_s.start_with?(@revision_prefix || 'rhrev') } rescue false
end
= @manual_mode && !@rendering_deferred_table && (node)
if !has_id && !has_rhrev && !
return super
end
collect_revision_entries node unless @prescan_complete
update_revision_entry_metadata node
if
node
else
if @change_bar_attr && !scratch? && (change_bar? node) &&
!(!at_page_top? && ((node.option? 'unbreakable') ||
((node.option? 'breakable') && (node.id || node.title?))))
bar_from = { page: page_number, cursor: cursor }
end
result = super
catalog_block_anchor node
ink_change_bar bar_from, { page: page_number, cursor: cursor } if bar_from
result
end
end
|
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
|
# File 'lib/asciidoctor/rhrev/converter.rb', line 405
def
return if scratch?
@anchor_catalog ||= {}
@pagerhref_tables.each do |table_info|
extent = table_info[:extent]
node = table_info[: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
|
#prescan_document(doc) ⇒ Object
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
|
# File 'lib/asciidoctor/rhrev/converter.rb', line 449
def prescan_document doc
debug_log "Starting prescan_document", doc
with_attribute_missing_suppressed doc do
collect_document_level_entries doc
[:section, :floating_title, :example, :listing, :table, :image].each do |ctx|
doc.find_by(context: ctx).each do |node|
collect_revision_entries node
end
end
@prescan_complete = true
debug_log "Prescan complete. Catalog has #{revision_history.entries.values.flatten.size} entries.", doc
end
end
|
#revision_history ⇒ Object
36
37
38
|
# File 'lib/asciidoctor/rhrev/converter.rb', line 36
def revision_history
@catalog ||= Catalog.new
end
|
#start_new_chapter(chapter) ⇒ Object
225
226
227
228
229
230
231
232
233
234
235
236
|
# File 'lib/asciidoctor/rhrev/converter.rb', line 225
def start_new_chapter chapter
if !@revision_history_extent && chapter.document && (chapter.document.attr? 'rhrev')
rhrev_value = chapter.document.attr('rhrev')
export_to_file = chapter.document.attr? 'rhrev-export-to-file'
if rhrev_value != 'macro' && rhrev_value != 'manual' && !export_to_file
collect_document_level_entries chapter.document
@revision_history_extent = allocate_revision_history_extent chapter.document
end
end
super
end
|
#super_convert_table(node) ⇒ Object
400
401
402
403
|
# File 'lib/asciidoctor/rhrev/converter.rb', line 400
def super_convert_table node
self.class.superclass.instance_method(:convert_table).bind(self).call(node)
end
|
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
|
# File 'lib/asciidoctor/rhrev/converter.rb', line 337
def node
return false unless node.context == :table
node.rows[:body].each do |row|
row.each do |cell|
if cell.instance_variable_defined?(:@text)
raw_text = cell.instance_variable_get(:@text).to_s
return true if raw_text.include?('pagerhref:')
end
if cell.instance_variable_defined?(:@inner_document)
inner_doc = cell.instance_variable_get(:@inner_document)
if inner_doc && inner_doc.instance_variable_defined?(:@lines)
lines = inner_doc.instance_variable_get(:@lines) || []
return true if lines.any? { |l| l.to_s.include?('pagerhref:') }
end
end
if cell.style == :asciidoc
if cell.instance_variable_defined?(:@inner_document)
inner = cell.instance_variable_get(:@inner_document)
if inner && inner.respond_to?(:blocks)
inner.blocks.each do |block|
if block.instance_variable_defined?(:@lines)
lines = block.instance_variable_get(:@lines) || []
return true if lines.any? { |l| l.to_s.include?('pagerhref:') }
end
end
end
end
end
end
end
false
end
|
#update_revision_entry_metadata(node) ⇒ Object
282
283
284
285
286
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
|
# File 'lib/asciidoctor/rhrev/converter.rb', line 282
def update_revision_entry_metadata node
return unless node.id
return unless node.respond_to?(:attributes)
with_attribute_missing_suppressed node.document do
node.attributes.each do |key, value|
key_str = key.to_s
next unless key_str.start_with?(@revision_prefix)
next if key_str.include?('-all') || key_str.end_with?('-cover')
revision = key_str.sub("#{@revision_prefix}", '')
entries = revision_history.entries[revision]
next unless entries
entry = entries.find { |e| e[:anchor] == node.id }
next unless entry
if entry[:change].to_s.empty?
entry[:change] = value
end
entry[:reftext] = node.reftext
entry[:title] = node.title
entry[:sectnum] = node.respond_to?(:sectnum) ? node.sectnum : nil
if node.context == :section && node.document.doctype == 'book'
entry[:is_chapter] = (node.level == 0 || node.level == 1)
end
if node.respond_to?(:caption) && node.caption
if node.caption =~ /(\d+)/
entry[:caption_number] = $1
end
end
entry[:sectname] = node.sectname if node.respond_to?(:sectname)
end
end
end
|