Class: Asciidoctor::PDF::IndexCatalog
Constant Summary
collapse
- LeadingAlphaRx =
/^\p{Alpha}/
- CategoryNameTransliterationIDs =
'Any-Latin;Latin-ASCII;Any-Upper'
TextTransformer::ContiguousCharsRx, TextTransformer::Hyphen, TextTransformer::LowerAlphaChars, TextTransformer::PCDATAFilterRx, TextTransformer::SmallCapsChars, TextTransformer::SoftHyphen, TextTransformer::TagFilterRx, TextTransformer::WordRx, TextTransformer::XMLMarkupRx
Instance Attribute Summary collapse
Instance Method Summary
collapse
#capitalize_words, #capitalize_words_pcdata, #hyphenate_words, #hyphenate_words_pcdata, #lowercase_pcdata, #smallcaps_pcdata, #transform_text, #uppercase_pcdata
Constructor Details
#initialize(locale = nil) ⇒ IndexCatalog
Returns a new instance of IndexCatalog.
18
19
20
21
22
23
24
|
# File 'lib/asciidoctor/pdf/index_catalog.rb', line 18
def initialize locale = nil
@categories = {}
@start_page_number = 1
@dests = {}
@sequence = 0
@locale = locale || 'en'
end
|
Instance Attribute Details
#start_page_number ⇒ Object
Returns the value of attribute start_page_number.
16
17
18
|
# File 'lib/asciidoctor/pdf/index_catalog.rb', line 16
def start_page_number
@start_page_number
end
|
Instance Method Details
#categories ⇒ Object
86
87
88
|
# File 'lib/asciidoctor/pdf/index_catalog.rb', line 86
def categories
@categories.values.sort
end
|
#empty? ⇒ Boolean
82
83
84
|
# File 'lib/asciidoctor/pdf/index_catalog.rb', line 82
def empty?
@categories.empty?
end
|
#find_category(name) ⇒ Object
67
68
69
|
# File 'lib/asciidoctor/pdf/index_catalog.rb', line 67
def find_category name
@categories[name]
end
|
#init_category(term) ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/asciidoctor/pdf/index_catalog.rb', line 55
def init_category term
if LeadingAlphaRx.match? term
name = term.chr
name = !(defined? ::ICU::Transliteration) || name.ascii_only? ?
name.upcase :
((::ICU::Transliteration::Transliterator.new CategoryNameTransliterationIDs).transliterate name)
else
name = '@'
end
@categories[name] ||= (IndexTermCategory.new name, @locale)
end
|
#link_dest_to_page(anchor, physical_page_number) ⇒ Object
75
76
77
78
79
80
|
# File 'lib/asciidoctor/pdf/index_catalog.rb', line 75
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
|
#next_anchor_name ⇒ Object
26
27
28
|
# File 'lib/asciidoctor/pdf/index_catalog.rb', line 26
def next_anchor_name
%(__indexterm-#{@sequence += 1})
end
|
#store_dest(dest) ⇒ Object
71
72
73
|
# File 'lib/asciidoctor/pdf/index_catalog.rb', line 71
def store_dest dest
@dests[dest[:anchor]] = dest
end
|
#store_primary_term(name, dest = nil) ⇒ Object
40
41
42
43
|
# File 'lib/asciidoctor/pdf/index_catalog.rb', line 40
def store_primary_term name, dest = nil
store_dest dest if dest
(init_category name).store_term name, dest
end
|
#store_secondary_term(primary_name, secondary_name, dest = nil) ⇒ Object
45
46
47
48
|
# File 'lib/asciidoctor/pdf/index_catalog.rb', line 45
def store_secondary_term primary_name, secondary_name, dest = nil
store_dest dest if dest
(store_primary_term primary_name).store_term secondary_name, dest
end
|
#store_term(names, dest) ⇒ Object
30
31
32
33
34
35
36
37
38
|
# File 'lib/asciidoctor/pdf/index_catalog.rb', line 30
def store_term names, dest
if (num_terms = names.size) > 2
store_tertiary_term names[0], names[1], names[2], dest
elsif num_terms == 2
store_secondary_term names[0], names[1], dest
elsif num_terms == 1
store_primary_term names[0], dest
end
end
|
#store_tertiary_term(primary_name, secondary_name, tertiary_name, dest) ⇒ Object
50
51
52
53
|
# File 'lib/asciidoctor/pdf/index_catalog.rb', line 50
def store_tertiary_term primary_name, secondary_name, tertiary_name, dest
store_dest dest
(store_secondary_term primary_name, secondary_name).store_term tertiary_name, dest
end
|