asciidoctor-reducer 1.0.5 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.adoc +23 -2
- data/README.adoc +26 -9
- data/asciidoctor-reducer.gemspec +2 -2
- data/lib/asciidoctor/reducer/conditional_directive_tracker.rb +5 -5
- data/lib/asciidoctor/reducer/extensions.rb +14 -8
- data/lib/asciidoctor/reducer/header_attribute_tracker.rb +16 -0
- data/lib/asciidoctor/reducer/include_directive_tracker.rb +2 -2
- data/lib/asciidoctor/reducer/preprocessor.rb +4 -2
- data/lib/asciidoctor/reducer/version.rb +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3aad6e916f11307d608d015b5befc14567f71638ed6baf9023416846ee8d2136
|
4
|
+
data.tar.gz: e51e12a72a7b4acaa6335e69cf489a356e109d57640dff8b1c7f4bfdfedaed53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46f16ea6198d0aa04dc00c890522b8014a2f5e9bad8c684acf7a39dc275bc339ddc587409c8bc34bee1227aa976ba7f4d25c3a08e2412070a7963219483acec8
|
7
|
+
data.tar.gz: b5c42486dcccd3e178d1cbda2b09f1c7656746a830087f64a9ece7d79ab99ef9e67e40bacd19b9310063915a3bf76ea26af73b6ba18e957edc9580cdbc13773b
|
data/CHANGELOG.adoc
CHANGED
@@ -4,11 +4,32 @@
|
|
4
4
|
This document provides a curated view of the changes to Asciidoctor Reducer in each release.
|
5
5
|
For a detailed view of what has changed, refer to the {url-repo}/commits/main[commit history] on GitHub.
|
6
6
|
|
7
|
+
== 1.1.0 (2024-11-24) - @mojavelinux
|
8
|
+
|
9
|
+
=== Added
|
10
|
+
|
11
|
+
* Track header attributes in source document and assign to `source_header_attributes` attr reader on Document instance (#59)
|
12
|
+
* Add JavaScript build that publishes the `@antora/reducer` an npm package (#57)
|
13
|
+
|
14
|
+
=== Details
|
15
|
+
|
16
|
+
{url-repo}/releases/tag/v1.1.0[git tag] | {url-repo}/compare/v1.0.6\...v1.1.0[full diff]
|
17
|
+
|
18
|
+
== 1.0.6 (2024-02-12) - @mojavelinux
|
19
|
+
|
20
|
+
=== Fixed
|
21
|
+
|
22
|
+
* Reduce single line conditionals inside file included by include directive with `leveloffset` attribute (#53)
|
23
|
+
|
24
|
+
=== Details
|
25
|
+
|
26
|
+
{url-repo}/releases/tag/v1.0.6[git tag] | {url-repo}/compare/v1.0.5\...v1.0.6[full diff]
|
27
|
+
|
7
28
|
== 1.0.5 (2022-10-15) - @mojavelinux
|
8
29
|
|
9
30
|
=== Changed
|
10
31
|
|
11
|
-
*
|
32
|
+
* Insert `role=include` into link macro that replaces include directive more carefully
|
12
33
|
|
13
34
|
=== Details
|
14
35
|
|
@@ -18,7 +39,7 @@ For a detailed view of what has changed, refer to the {url-repo}/commits/main[co
|
|
18
39
|
|
19
40
|
=== Changed
|
20
41
|
|
21
|
-
*
|
42
|
+
* Don't add role to link that replaces include directive if role is already present
|
22
43
|
|
23
44
|
=== Details
|
24
45
|
|
data/README.adoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= {project-name}
|
2
2
|
Dan Allen <https://github.com/mojavelinux[@mojavelinux]>
|
3
|
-
v1.0
|
3
|
+
v1.1.0, 2024-11-24
|
4
4
|
:idprefix:
|
5
5
|
:idseparator: -
|
6
6
|
ifndef::env-github[:icons: font]
|
@@ -20,6 +20,9 @@ endif::[]
|
|
20
20
|
Additionally, the tool evaluates preprocessor conditionals (unless the option to preserve them is enabled), only keeping those lines from conditions which are true.
|
21
21
|
If the document does not contain any preprocessor directives, the tool returns the unmodified source.
|
22
22
|
|
23
|
+
TIP: This extension is also published as an npm package named `@asciidoctor/reducer` for use with Asciidoctor.js, and hence, with Antora.
|
24
|
+
See the xref:js/README.adoc[README] to find instructions on how to use this package.
|
25
|
+
|
23
26
|
== Prerequisites
|
24
27
|
|
25
28
|
{project-name} is a Ruby application that you install using Ruby packaging.
|
@@ -83,6 +86,10 @@ Thus, to use the command, pass the AsciiDoc file as the sole argument:
|
|
83
86
|
|
84
87
|
$ asciidoctor-reducer input.adoc
|
85
88
|
|
89
|
+
If you only want AsciiDoctor Reducer to process include directives, leaving preprocessor conditional directives untouched, add the `--preserve-conditionals` option:
|
90
|
+
|
91
|
+
$ asciidoctor-reducer --preserve-conditionals input.adoc
|
92
|
+
|
86
93
|
By default, the command will output the reduced AsciiDoc document to the terminal (via stdout).
|
87
94
|
To write the output to a file, specify an output file using the `-o` option:
|
88
95
|
|
@@ -108,7 +115,7 @@ require 'asciidoctor/reducer/api'
|
|
108
115
|
----
|
109
116
|
|
110
117
|
Next, reduce a parent document that contains includes.
|
111
|
-
This works without having to specify the safe mode since the default safe mode when using
|
118
|
+
(This works without having to specify the safe mode since the default safe mode when using this API is `:safe`).
|
112
119
|
|
113
120
|
[,ruby]
|
114
121
|
----
|
@@ -124,6 +131,13 @@ puts doc.source
|
|
124
131
|
|
125
132
|
The benefit of this approach is that you can access the reduced source and the parsed document that corresponds to it.
|
126
133
|
|
134
|
+
If you only want AsciiDoctor Reducer to process include directives, leaving preprocessor conditional directives untouched, set the `:preserve_conditionals` option:
|
135
|
+
|
136
|
+
[,ruby]
|
137
|
+
----
|
138
|
+
doc = Asciidoctor::Reducer.reduce_file 'sample.adoc', preserve_conditionals: true
|
139
|
+
----
|
140
|
+
|
127
141
|
If you don't need the parsed document, you can retrieve the reduced source directly by passing the `String` type to the `:to` option:
|
128
142
|
|
129
143
|
[,ruby]
|
@@ -186,8 +200,10 @@ The reducer then uses a tree processor extension to fold the include stack into
|
|
186
200
|
It does so by working from the end of the stack and inserting the lines into the parent until the stack has been flattened.
|
187
201
|
As it goes, it also removes lines that have been excluded by the preprocessor conditionals as well as the directive lines themselves (unless the option to preserve conditionals has been specified).
|
188
202
|
|
189
|
-
|
190
|
-
|
203
|
+
If the sourcemap is enabled, it loads the document again.
|
204
|
+
Finally, it returns the document.
|
205
|
+
The reduced source is available on the reconstructed document via `Document#source` or `Document#source_lines`.
|
206
|
+
The source header attributes (those defined in the header of the document) are available via `Document#source_header_attributes`.
|
191
207
|
|
192
208
|
=== Impact on Extensions
|
193
209
|
|
@@ -217,7 +233,7 @@ To use the include mapper when using the API, first require the extension:
|
|
217
233
|
|
218
234
|
[,ruby]
|
219
235
|
----
|
220
|
-
require '
|
236
|
+
require 'asciidoctor/reducer/include_mapper/extension'
|
221
237
|
----
|
222
238
|
|
223
239
|
You then need to register the extension when reducing the document:
|
@@ -243,7 +259,7 @@ You can also register the extension globally:
|
|
243
259
|
|
244
260
|
[,ruby]
|
245
261
|
----
|
246
|
-
require '
|
262
|
+
require 'asciidoctor/reducer/include_mapper'
|
247
263
|
----
|
248
264
|
|
249
265
|
In this case, you don't have to pass it to the API explicitly.
|
@@ -284,10 +300,11 @@ jobs:
|
|
284
300
|
runs-on: ubuntu-latest
|
285
301
|
steps:
|
286
302
|
- name: Checkout Repository
|
287
|
-
uses: actions/checkout@
|
303
|
+
uses: actions/checkout@v3
|
288
304
|
- name: Install Asciidoctor Reducer
|
289
305
|
run: sudo gem install asciidoctor-reducer
|
290
306
|
- name: Reduce README
|
307
|
+
# to preserve preprocessor conditionals, add the --preserve-conditionals option
|
291
308
|
run: asciidoctor-reducer -o README.adoc README-source.adoc
|
292
309
|
- name: Commit and Push README
|
293
310
|
uses: EndBug/add-and-commit@v9
|
@@ -335,7 +352,7 @@ The tests are based on RSpec.
|
|
335
352
|
|
336
353
|
You can run all of the tests using Rake:
|
337
354
|
|
338
|
-
$ bundle exec spec
|
355
|
+
$ bundle exec rake spec
|
339
356
|
|
340
357
|
For more fine-grained control, you can also run the tests directly using RSpec:
|
341
358
|
|
@@ -376,7 +393,7 @@ RSpec will only run the specifications that have a description containing the te
|
|
376
393
|
|
377
394
|
To generate a code coverage report when running tests using simplecov, set the `COVERAGE` environment variable as follows when running the tests:
|
378
395
|
|
379
|
-
$ COVERAGE=deep bundle exec rake
|
396
|
+
$ COVERAGE=deep bundle exec rake spec
|
380
397
|
|
381
398
|
You'll see a total coverage score, a detailed coverage report, and a link to HTML report in the output.
|
382
399
|
The HTML report helps you understand which lines and branches were missed, if any.
|
data/asciidoctor-reducer.gemspec
CHANGED
@@ -34,6 +34,6 @@ Gem::Specification.new do |s|
|
|
34
34
|
|
35
35
|
s.add_runtime_dependency 'asciidoctor', '~> 2.0'
|
36
36
|
|
37
|
-
s.add_development_dependency 'rake', '~> 13.
|
38
|
-
s.add_development_dependency 'rspec', '~> 3.
|
37
|
+
s.add_development_dependency 'rake', '~> 13.1.0'
|
38
|
+
s.add_development_dependency 'rspec', '~> 3.13.0'
|
39
39
|
end
|
@@ -10,17 +10,17 @@ module Asciidoctor::Reducer
|
|
10
10
|
return result if @skipping && skip_active
|
11
11
|
curr_inc_replacement = @include_replacements.current
|
12
12
|
drop = curr_inc_replacement[:drop] ||= []
|
13
|
-
directive_lineno
|
13
|
+
adjusted_directive_lineno = directive_lineno - (curr_inc_replacement[:offset] ||= 0)
|
14
14
|
if (depth_change = @conditional_stack.size - depth) < 0
|
15
15
|
if skip_active
|
16
|
-
drop.push(*(drop.pop..
|
16
|
+
drop.push(*(drop.pop..adjusted_directive_lineno))
|
17
17
|
else
|
18
|
-
drop <<
|
18
|
+
drop << adjusted_directive_lineno
|
19
19
|
end
|
20
20
|
elsif depth_change > 0 || directive_lineno == @lineno
|
21
|
-
drop <<
|
21
|
+
drop << adjusted_directive_lineno
|
22
22
|
else
|
23
|
-
drop << [
|
23
|
+
drop << [adjusted_directive_lineno, text]
|
24
24
|
end
|
25
25
|
result
|
26
26
|
end
|
@@ -1,8 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
require_relative '
|
3
|
+
unless RUBY_ENGINE == 'opal'
|
4
|
+
require 'asciidoctor' unless defined? Asciidoctor.load
|
5
|
+
require_relative 'header_attribute_tracker'
|
6
|
+
require_relative 'preprocessor'
|
7
|
+
require_relative 'tree_processor'
|
8
|
+
end
|
6
9
|
|
7
10
|
module Asciidoctor::Reducer
|
8
11
|
module Extensions
|
@@ -10,9 +13,11 @@ module Asciidoctor::Reducer
|
|
10
13
|
|
11
14
|
def group
|
12
15
|
proc do
|
13
|
-
|
16
|
+
document.extend HeaderAttributeTracker
|
17
|
+
next if document.options[:reduced] # group invoked again if includes are found and sourcemap option is true
|
14
18
|
preprocessor Preprocessor
|
15
19
|
tree_processor TreeProcessor
|
20
|
+
nil
|
16
21
|
end
|
17
22
|
end
|
18
23
|
|
@@ -31,12 +36,13 @@ module Asciidoctor::Reducer
|
|
31
36
|
end
|
32
37
|
end
|
33
38
|
|
34
|
-
def register
|
35
|
-
::Asciidoctor::Extensions.
|
39
|
+
def register registry = nil
|
40
|
+
(registry || ::Asciidoctor::Extensions).groups[key] ||= group
|
36
41
|
end
|
37
42
|
|
38
|
-
def unregister
|
39
|
-
::Asciidoctor::Extensions.groups.delete key
|
43
|
+
def unregister registry = nil
|
44
|
+
(registry || ::Asciidoctor::Extensions).groups.delete key
|
45
|
+
nil
|
40
46
|
end
|
41
47
|
end
|
42
48
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Asciidoctor::Reducer
|
4
|
+
module HeaderAttributeTracker
|
5
|
+
def self.extended instance
|
6
|
+
instance.singleton_class.send :attr_reader, :source_header_attributes
|
7
|
+
end
|
8
|
+
|
9
|
+
def finalize_header(*) # rubocop:disable Style/MethodDefParentheses
|
10
|
+
@source_header_attributes = @attributes_modified.each_with_object({}) do |name, accum|
|
11
|
+
accum[name] = @attributes[name]
|
12
|
+
end
|
13
|
+
super
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -38,13 +38,13 @@ module Asciidoctor::Reducer
|
|
38
38
|
result
|
39
39
|
end
|
40
40
|
|
41
|
+
private
|
42
|
+
|
41
43
|
def pop_include
|
42
44
|
@include_replacements.up unless @x_reducer[:include_pushed]
|
43
45
|
super
|
44
46
|
end
|
45
47
|
|
46
|
-
private
|
47
|
-
|
48
48
|
def push_include_replacement lineno, lines, offset, unresolved = false
|
49
49
|
(inc_replacements = @include_replacements) << {
|
50
50
|
into: inc_replacements.pointer,
|
@@ -1,7 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
require_relative '
|
3
|
+
unless RUBY_ENGINE == 'opal'
|
4
|
+
require_relative 'include_directive_tracker'
|
5
|
+
require_relative 'conditional_directive_tracker'
|
6
|
+
end
|
5
7
|
|
6
8
|
module Asciidoctor::Reducer
|
7
9
|
class Preprocessor < ::Asciidoctor::Extensions::Preprocessor
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asciidoctor-reducer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Allen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|
@@ -30,28 +30,28 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 13.
|
33
|
+
version: 13.1.0
|
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: 13.
|
40
|
+
version: 13.1.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 3.
|
47
|
+
version: 3.13.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 3.
|
54
|
+
version: 3.13.0
|
55
55
|
description: A tool that reduces an AsciiDoc document containing preprocessor directives
|
56
56
|
(includes and conditionals) to a single AsciiDoc document by expanding all includes
|
57
57
|
and evaluating all conditionals.
|
@@ -72,6 +72,7 @@ files:
|
|
72
72
|
- lib/asciidoctor/reducer/cli.rb
|
73
73
|
- lib/asciidoctor/reducer/conditional_directive_tracker.rb
|
74
74
|
- lib/asciidoctor/reducer/extensions.rb
|
75
|
+
- lib/asciidoctor/reducer/header_attribute_tracker.rb
|
75
76
|
- lib/asciidoctor/reducer/include_directive_tracker.rb
|
76
77
|
- lib/asciidoctor/reducer/include_mapper.rb
|
77
78
|
- lib/asciidoctor/reducer/include_mapper/extension.rb
|
@@ -101,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
102
|
- !ruby/object:Gem::Version
|
102
103
|
version: '0'
|
103
104
|
requirements: []
|
104
|
-
rubygems_version: 3.
|
105
|
+
rubygems_version: 3.5.22
|
105
106
|
signing_key:
|
106
107
|
specification_version: 4
|
107
108
|
summary: Reduces an AsciiDoc document containing includes and conditionals to a single
|