asciidoctor-multipage 0.0.9 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/asciidoctor-multipage.rb +67 -23
  3. metadata +7 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b61bac9f5757d7dd1864896ce026ba9459f05a4b2860b8fcc04087b02f6d99e4
4
- data.tar.gz: 80e39a0c29b8a125f4001cd290e3d2b8494b51b67f0a4e96f3a3951ffccde583
3
+ metadata.gz: f3969d1ba0eb1078d827fb24791759e87a66f646c0de7bbe2a88d8937d4cda5a
4
+ data.tar.gz: b7bce56dee751a9e13b16cd6eeba2939aad51e98bf8f2090d7e5780b0c381251
5
5
  SHA512:
6
- metadata.gz: 921880fa69d16485028b378017b680ea7cab5f30376361da442cdf3f7c53d144e67d7a8af76dc0134bb0cff41a66b00242e82519878bf2a91c748ba98931adc3
7
- data.tar.gz: 2430e67e5d8992737a9b77f7d0512853b4ae7a8771b44e57347cf9547930f91860acb70acb3acbd0161ff0dc3c1b69fb968f5c1d96b2785db699aca2129f0f9f
6
+ metadata.gz: 5966efde3e3d4728a5ff2f65d381d89d7f0e2d81c18ec7bc647b2f02bf2d9fee5aef190f321e1573ac61b33a629f4204de3f40fabd234fd0a77c85eec8528ec0
7
+ data.tar.gz: ccf9339527d9cf6c9876e5317349e7ce6ea4ba3fed445becee5c1bcbc62efd5a20304095de59e4c467057952222906baf105b332053c20c1de88ee558d7de4aa
@@ -52,6 +52,14 @@ class Asciidoctor::Document
52
52
  # nodes are no longer accessible.
53
53
  attr_writer :sectnum
54
54
 
55
+ # A pointer to the original converter (first converter instantiated to
56
+ # convert the original document). As we create additional documents
57
+ # ourselves, AsciiDoctor will instantiate additional instances of
58
+ # MultipageHtml5Converter for each created document. These instances need
59
+ # to share state, so they can use the original converter instance
60
+ # for that purpose.
61
+ attr_accessor :mp_root
62
+
55
63
  # Override the AbstractBlock sections?() check to enable the Table Of
56
64
  # Contents. This extension may generate short pages that would normally have
57
65
  # no need for a TOC. However, we override the Html5Converter outline() in
@@ -77,17 +85,11 @@ class Asciidoctor::Section
77
85
  # Sections. The sectnum is saved in section() below.
78
86
  def sectnum(delimiter = '.', append = nil)
79
87
  append ||= (append == false ? '' : delimiter)
80
- if @level == 1
81
- %(#{@numeral}#{append})
82
- elsif @level > 1
83
- if @parent.class == Asciidoctor::Section ||
84
- (@mplevel && @parent.class == Asciidoctor::Document)
88
+ if @level > 1 and @parent.class == Asciidoctor::Section ||
89
+ (@mplevel && @parent.class == Asciidoctor::Document)
85
90
  %(#{@parent.sectnum(delimiter)}#{@numeral}#{append})
86
- else
87
- %(#{@numeral}#{append})
88
- end
89
- else # @level == 0
90
- %(#{Asciidoctor::Helpers.int_to_roman @numeral}#{append})
91
+ else
92
+ %(#{@numeral}#{append})
91
93
  end
92
94
  end
93
95
  end
@@ -101,6 +103,12 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
101
103
 
102
104
  attr_accessor :pages
103
105
 
106
+ # contains the entire outline of the top-level document, used
107
+ # as a guide-rail for creating TOC elements for documents we
108
+ # split off. Only expected to be set in the top-level converter
109
+ # (see AsciiDoctor::Document::mp_root)
110
+ attr_accessor :full_outline
111
+
104
112
  def initialize(backend, opts = {})
105
113
  @xml_mode = false
106
114
  @void_element_slash = nil
@@ -118,8 +126,29 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
118
126
  page << block
119
127
  end
120
128
 
129
+ # ensures that the AsciiDoctor::Document::mp_root is correctly
130
+ # set on the document object. The variable could have already been
131
+ # set if we created the document ourselves
132
+ # (see ::MultipageHtml5Converter::convert_section), in which case it's
133
+ # not changed. If the documented is "nested", then we expect the parent
134
+ # document to already have it set. Otherwise, this is expected to be
135
+ # a top-level document, and we assign ourselves as its original converter.
136
+ def check_root(doc)
137
+ unless doc.mp_root
138
+ if doc.nested?
139
+ doc.mp_root = doc.parent_document.mp_root
140
+ else
141
+ doc.mp_root = self
142
+ end
143
+ end
144
+ end
145
+
121
146
  # Process Document (either the original full document or a processed page)
122
147
  def convert_document(node)
148
+
149
+ # make sure document has original converter reference
150
+ check_root(node)
151
+
123
152
  if node.processed
124
153
  # This node (an individual page) can now be handled by
125
154
  # Html5Converter.
@@ -166,8 +195,16 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
166
195
  # Generate navigation links for all pages
167
196
  generate_nav_links(node)
168
197
 
169
- # Create and save a skeleton document for generating the TOC lists.
170
- @@full_outline = new_outline_doc(node)
198
+ # Create and save a skeleton document for generating the TOC lists,
199
+ # but don't attempt to create outline for nested documents.
200
+ unless node.nested?
201
+ # if the original converter has the @full_outline set already, we are about
202
+ # to replace it. That's not supposed to happen, and probably means we encountered
203
+ # a document structure we aren't prepared for. Log an error and move on.
204
+ logger.error "Regenerating document outline, something wrong?" if node.mp_root.full_outline
205
+ node.mp_root.full_outline = new_outline_doc(node)
206
+ end
207
+
171
208
  # Save the document catalog to use for each part/chapter page.
172
209
  @catalog = node.catalog
173
210
 
@@ -179,7 +216,7 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
179
216
  part = block
180
217
  part.convert
181
218
  text = %(<<#{part.id},#{part.captioned_title}>>)
182
- if desc = block.attr('desc') then text << %( – #{desc}) end
219
+ if (desc = block.attr('desc')) then text << %( – #{desc}) end
183
220
  parts_list << Asciidoctor::ListItem.new(parts_list, text)
184
221
  end
185
222
  end
@@ -197,6 +234,8 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
197
234
  # Process Document in embeddable mode (either the original full document or a
198
235
  # processed page)
199
236
  def convert_embedded(node)
237
+ # make sure document has original converter reference
238
+ check_root(node)
200
239
  if node.processed
201
240
  # This node (an individual page) can now be handled by
202
241
  # Html5Converter.
@@ -223,14 +262,14 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
223
262
  # NOTE: There are some non-breaking spaces (U+00A0) below, in
224
263
  # the "links <<" lines and "links.join" line.
225
264
  if previous_page != parent_page
226
- links << %(← Previous: <<#{previous_page.id}>>)
265
+ links << %(← #{doc.attr('multipage-nav-previous-label') || "Previous"}: <<#{previous_page.id}>>)
227
266
  end
228
- links << %(↑ Up: <<#{parent_page.id}>>)
229
- links << %(⌂ Home: <<#{home_page.id}>>) if home_page != parent_page
267
+ links << %(↑ #{doc.attr('multipage-nav-up-label') || "Up"}: <<#{parent_page.id}>>)
268
+ links << %(⌂ #{doc.attr('multipage-nav-home-label') || "Home"}: <<#{home_page.id}>>) if home_page != parent_page
230
269
  end
231
270
  if page_index != pages.length-1
232
271
  next_page = pages[page_index+1]
233
- links << %(Next: <<#{next_page.id}>> →)
272
+ links << %(#{doc.attr('multipage-nav-next-label') || "Next"}: <<#{next_page.id}>> →)
234
273
  end
235
274
  block = Asciidoctor::Block.new(parent = doc,
236
275
  context = :paragraph,
@@ -245,7 +284,7 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
245
284
  # Html5Converter convert_outline().
246
285
  def generate_outline(node, opts = {})
247
286
  # Do the same as Html5Converter convert_outline() here
248
- return unless node.sections?
287
+ return unless node.sections? && node.sections.length > 0
249
288
  sectnumlevels = opts[:sectnumlevels] || (node.document.attributes['sectnumlevels'] || 3).to_i
250
289
  toclevels = opts[:toclevels] || (node.document.attributes['toclevels'] || 2).to_i
251
290
  sections = node.sections
@@ -350,7 +389,7 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
350
389
  end
351
390
 
352
391
  # From node, create a skeleton document that will be used to generate the
353
- # TOC. This is first used to create a full skeleton (@@full_outline) from the
392
+ # TOC. This is first used to create a full skeleton (@full_outline) from the
354
393
  # original document (for_page=nil). Then it is used for each individual page
355
394
  # to create a second skeleton from the first. In this way, TOC entries are
356
395
  # included that are not part of the current page, or excluded if not
@@ -392,10 +431,10 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
392
431
  # outline.
393
432
  def convert_outline(node, opts = {})
394
433
  doc = node.document
395
- # Find this node in the @@full_outline skeleton document
396
- page_node = @@full_outline.find_by(id: node.id).first
434
+ # Find this node in the @full_outline skeleton document
435
+ page_node = doc.mp_root.full_outline.find_by(id: node.id).first
397
436
  # Create a skeleton document for this particular page
398
- custom_outline_doc = new_outline_doc(@@full_outline, for_page: page_node)
437
+ custom_outline_doc = new_outline_doc(doc.mp_root.full_outline, for_page: page_node)
399
438
  opts[:page_id] = node.id
400
439
  # Generate an extra TOC entry for the root page. Add additional styling if
401
440
  # the current page is the root page.
@@ -455,6 +494,8 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
455
494
  page.sectnum = node.parent.sectnum
456
495
  end
457
496
 
497
+ page.mp_root = doc.mp_root
498
+
458
499
  # Process node according to mplevel
459
500
  if node.mplevel == :branch
460
501
  # Retain any part intro blocks, delete others, and add a list
@@ -537,7 +578,6 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
537
578
  # Write remaining part/chapter pages
538
579
  outdir = ::File.dirname(target)
539
580
  ext = ::File.extname(target)
540
- target_name = ::File.basename(target, ext)
541
581
  @pages.each do |doc|
542
582
  chapter_target = doc.id + ext
543
583
  outfile = ::File.join(outdir, chapter_target)
@@ -553,6 +593,10 @@ class MultipageHtml5CSS < Asciidoctor::Extensions::DocinfoProcessor
553
593
  at_location :head
554
594
 
555
595
  def process doc
596
+ # Disable this entirely if the multipage-disable-css attribute is set
597
+ if doc.attr('multipage-disable-css')
598
+ return
599
+ end
556
600
  css = []
557
601
  # Style Table Of Contents entry for current page
558
602
  css << %(.toc-current{font-weight: bold;})
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-multipage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Owen T. Heisler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-13 00:00:00.000000000 Z
11
+ date: 2021-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: appraisal
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '1'
33
+ version: 2.2.18
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '1'
40
+ version: 2.2.18
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -116,8 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  requirements: []
119
- rubyforge_project:
120
- rubygems_version: 2.7.6.2
119
+ rubygems_version: 3.2.5
121
120
  signing_key:
122
121
  specification_version: 4
123
122
  summary: Asciidoctor multipage HTML output extension