asciidoctor-reducer 1.0.0-beta.1 → 1.0.1
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 +28 -1
- data/README.adoc +5 -5
- data/asciidoctor-reducer.gemspec +2 -2
- data/lib/asciidoctor/reducer/api.rb +18 -0
- data/lib/asciidoctor/reducer/cli.rb +1 -1
- data/lib/asciidoctor/reducer/conditional_directive_tracker.rb +6 -6
- data/lib/asciidoctor/reducer/include_directive_tracker.rb +7 -10
- data/lib/asciidoctor/reducer/preprocessor.rb +2 -1
- data/lib/asciidoctor/reducer/tree_processor.rb +4 -4
- data/lib/asciidoctor/reducer/version.rb +1 -1
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '042939f0b251163208b57a67bed8a7b16d15d0972a616e67c171b8462a5ae61b'
|
4
|
+
data.tar.gz: 9065fc1b7a742f057441f873956883e6c87ba88afb1984496c821f378e666e2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53e3e2cd52cf60ff810b93c5409cf521c1e5509106c8cece15ac89262d5a7d0ac998b2369ebb1cd8854675de930ea3a2f10c762bf072f758db663f3b6e7aa0ed
|
7
|
+
data.tar.gz: 1785df7825bd0fb902dd619bf42b2de90360acdf975f3356ca5ad8ed7b65a32c71c8824b51b966aecce774078d14d5c6dcdf281d899eb6f54e61307dbec0b0ce
|
data/CHANGELOG.adoc
CHANGED
@@ -1,9 +1,36 @@
|
|
1
1
|
= Asciidoctor Reducer Changelog
|
2
2
|
:url-repo: https://github.com/asciidoctor/asciidoctor-reducer
|
3
3
|
|
4
|
-
This document provides a
|
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.0.1 (2022-05-08) - @mojavelinux
|
8
|
+
|
9
|
+
=== Changed
|
10
|
+
|
11
|
+
* Use summary from gemspec in help text for `asciidoctor-reducer` command
|
12
|
+
* Consistently access `source_lines` from document; use `#replace` to update
|
13
|
+
|
14
|
+
=== Details
|
15
|
+
|
16
|
+
{url-repo}/releases/tag/v1.0.1[git tag] | {url-repo}/compare/v1.0.0\...v1.0.1[full diff]
|
17
|
+
|
18
|
+
== 1.0.0 (2022-04-22) - @mojavelinux
|
19
|
+
|
20
|
+
_No changes since previous release._
|
21
|
+
|
22
|
+
=== Details
|
23
|
+
|
24
|
+
{url-repo}/releases/tag/v1.0.0[git tag] | {url-repo}/compare/v1.0.0-rc.1\...v1.0.0[full diff]
|
25
|
+
|
26
|
+
== 1.0.0-rc.1 (2022-04-22) - @mojavelinux
|
27
|
+
|
28
|
+
_No changes since previous release._
|
29
|
+
|
30
|
+
=== Details
|
31
|
+
|
32
|
+
{url-repo}/releases/tag/v1.0.0-rc.1[git tag] | {url-repo}/compare/v1.0.0-beta.1\...v1.0.0-rc.1[full diff]
|
33
|
+
|
7
34
|
== 1.0.0-beta.1 (2022-04-21) - @mojavelinux
|
8
35
|
|
9
36
|
=== Changed
|
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.0.1, 2022-05-08
|
4
4
|
:idprefix:
|
5
5
|
:idseparator: -
|
6
6
|
ifndef::env-github[:icons: font]
|
@@ -16,9 +16,9 @@ endif::[]
|
|
16
16
|
:url-rvm: https://rvm.io
|
17
17
|
:url-repo: https://github.com/asciidoctor/{project-handle}
|
18
18
|
|
19
|
-
{project-name} is a tool that reduces an AsciiDoc document
|
20
|
-
|
21
|
-
If the document does not contain any preprocessor directives, the tool returns the
|
19
|
+
{project-name} is a tool that reduces an AsciiDoc document containing include directives to a single AsciiDoc document by expanding the includes reachable from the parent document.
|
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
|
+
If the document does not contain any preprocessor directives, the tool returns the unmodified source.
|
22
22
|
|
23
23
|
== Prerequisites
|
24
24
|
|
@@ -38,7 +38,7 @@ We generally recommend using RVM as it allows you to install gems without requir
|
|
38
38
|
|
39
39
|
You can install the latest version of the gem using the following command:
|
40
40
|
|
41
|
-
$ gem install asciidoctor-reducer
|
41
|
+
$ gem install asciidoctor-reducer
|
42
42
|
|
43
43
|
Installing this gem makes the `asciidoctor-reducer` command available on your $PATH.
|
44
44
|
You can also require the gem into the Ruby runtime to use it as a library or Asciidoctor extension.
|
data/asciidoctor-reducer.gemspec
CHANGED
@@ -7,8 +7,8 @@ end
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = 'asciidoctor-reducer'
|
9
9
|
s.version = Asciidoctor::Reducer::VERSION
|
10
|
-
s.summary = 'Reduces
|
11
|
-
s.description = 'A tool that reduces
|
10
|
+
s.summary = 'Reduces an AsciiDoc document containing includes and conditionals to a single AsciiDoc document.'
|
11
|
+
s.description = 'A tool that reduces an AsciiDoc document containing preprocessor directives (includes and conditionals) to a single AsciiDoc document by expanding all includes and evaluating all conditionals.'
|
12
12
|
s.authors = ['Dan Allen']
|
13
13
|
s.email = 'dan.j.allen@gmail.com'
|
14
14
|
s.homepage = 'https://asciidoctor.org'
|
@@ -7,6 +7,15 @@ module Asciidoctor::Reducer
|
|
7
7
|
autoload :VERSION, (::File.join __dir__, 'version.rb')
|
8
8
|
|
9
9
|
class << self
|
10
|
+
# Reduces the AsciiDoc source and either returns the reduced Asciidoctor::Document or writes the source to a file.
|
11
|
+
#
|
12
|
+
# This method accepts all the options supported by Asciidoctor.load.
|
13
|
+
#
|
14
|
+
# @param input [String, File, Pathname] the AsciiDoc source to reduce.
|
15
|
+
# @param opts [Hash] additional options to configure the behavior of the reducer.
|
16
|
+
# @option opts [File, Pathname, Class] :to (nil) the target to which to write the reduced source.
|
17
|
+
#
|
18
|
+
# @return [Asciidoctor::Document, nil] the reduced document object or nil if the :to option is specified.
|
10
19
|
def reduce input, opts = {}
|
11
20
|
opts = opts&.merge || {}
|
12
21
|
if (extension_registry = Extensions.prepare_registry opts[:extension_registry] || opts[:extensions])
|
@@ -25,6 +34,15 @@ module Asciidoctor::Reducer
|
|
25
34
|
write doc, to
|
26
35
|
end
|
27
36
|
|
37
|
+
# Reduces the AsciiDoc file and either returns the reduced Asciidoctor::Document or writes the source to a file.
|
38
|
+
#
|
39
|
+
# This method accepts all the options supported by Asciidoctor.load.
|
40
|
+
#
|
41
|
+
# @param input_file [String] the path of the AsciiDoc file to reduce.
|
42
|
+
# @param opts [Hash] additional options to configure the behavior of the reducer.
|
43
|
+
# @option opts [File, Pathname, Class] :to (nil) the target to which to write the reduced source.
|
44
|
+
#
|
45
|
+
# @return [Asciidoctor::Document, nil] the reduced document object or nil if the :to option is specified.
|
28
46
|
def reduce_file input_file, opts = {}
|
29
47
|
reduce (::Pathname.new input_file), opts
|
30
48
|
end
|
@@ -14,7 +14,7 @@ module Asciidoctor::Reducer
|
|
14
14
|
opts.banner = <<~END
|
15
15
|
Usage: #{opts.program_name} [OPTION]... FILE
|
16
16
|
|
17
|
-
|
17
|
+
#{::Gem.loaded_specs['asciidoctor-reducer'].summary}
|
18
18
|
|
19
19
|
END
|
20
20
|
|
@@ -5,20 +5,20 @@ module Asciidoctor::Reducer
|
|
5
5
|
def preprocess_conditional_directive keyword, target, delimiter, text
|
6
6
|
skip_active = @skipping
|
7
7
|
depth = @conditional_stack.size
|
8
|
-
|
8
|
+
directive_lineno = @lineno
|
9
9
|
result = super
|
10
10
|
return result if @skipping && skip_active
|
11
11
|
drop = @include_replacements.current[:drop] ||= []
|
12
12
|
if (depth_change = @conditional_stack.size - depth) < 0
|
13
13
|
if skip_active
|
14
|
-
drop.push(*(drop.pop..
|
14
|
+
drop.push(*(drop.pop..directive_lineno))
|
15
15
|
else
|
16
|
-
drop <<
|
16
|
+
drop << directive_lineno
|
17
17
|
end
|
18
|
-
elsif depth_change > 0 ||
|
19
|
-
drop <<
|
18
|
+
elsif depth_change > 0 || directive_lineno == @lineno
|
19
|
+
drop << directive_lineno
|
20
20
|
else
|
21
|
-
drop << [
|
21
|
+
drop << [directive_lineno, text]
|
22
22
|
end
|
23
23
|
result
|
24
24
|
end
|
@@ -2,10 +2,8 @@
|
|
2
2
|
|
3
3
|
module Asciidoctor::Reducer
|
4
4
|
module IncludeDirectiveTracker
|
5
|
-
attr_reader :include_replacements
|
6
|
-
attr_writer :source_lines
|
7
|
-
|
8
5
|
def self.extended instance
|
6
|
+
instance.singleton_class.send :attr_reader, :include_replacements
|
9
7
|
instance.instance_variable_set :@include_replacements, ([{}].extend CurrentPosition)
|
10
8
|
instance.instance_variable_set :@x_reducer, {}
|
11
9
|
end
|
@@ -13,14 +11,14 @@ module Asciidoctor::Reducer
|
|
13
11
|
def preprocess_include_directive target, attrlist
|
14
12
|
@x_reducer[:include_directive_line] = %(include::#{target}[#{attrlist}])
|
15
13
|
@x_reducer[:include_pushed] = false
|
16
|
-
|
14
|
+
directive_lineno = @lineno # we're currently on the include line, which is 1-based
|
17
15
|
result = super
|
18
16
|
unless @x_reducer[:include_pushed]
|
19
17
|
if ((ln = peek_line true)&.end_with? ']') && !(unresolved = ln.start_with? 'Unresolved directive in ') &&
|
20
|
-
|
18
|
+
directive_lineno == @lineno && (unresolved = ln.start_with? 'link:')
|
21
19
|
ln = %(#{ln.slice 0, (ln.length - 1)}role=include])
|
22
20
|
end
|
23
|
-
push_include_replacement
|
21
|
+
push_include_replacement directive_lineno, (unresolved ? [ln] : []), unresolved
|
24
22
|
end
|
25
23
|
@x_reducer.clear
|
26
24
|
result
|
@@ -28,10 +26,10 @@ module Asciidoctor::Reducer
|
|
28
26
|
|
29
27
|
def push_include data, file, path, lineno, attrs
|
30
28
|
@x_reducer[:include_pushed] = true
|
31
|
-
|
29
|
+
directive_lineno = @lineno - 1 # we're below the include line, which is 1-based
|
32
30
|
prev_inc_depth = @include_stack.size
|
33
31
|
result = super
|
34
|
-
push_include_replacement
|
32
|
+
push_include_replacement directive_lineno, (@include_stack.size > prev_inc_depth ? lines : [])
|
35
33
|
result
|
36
34
|
end
|
37
35
|
|
@@ -55,9 +53,8 @@ module Asciidoctor::Reducer
|
|
55
53
|
end
|
56
54
|
|
57
55
|
module CurrentPosition
|
58
|
-
attr_reader :pointer
|
59
|
-
|
60
56
|
def self.extended instance
|
57
|
+
instance.singleton_class.send :attr_reader, :pointer
|
61
58
|
instance.to_end
|
62
59
|
end
|
63
60
|
|
@@ -7,7 +7,8 @@ module Asciidoctor::Reducer
|
|
7
7
|
class Preprocessor < ::Asciidoctor::Extensions::Preprocessor
|
8
8
|
def process doc, reader
|
9
9
|
doc.options[:preserve_conditionals] ?
|
10
|
-
(reader.extend IncludeDirectiveTracker) :
|
10
|
+
(reader.extend IncludeDirectiveTracker) :
|
11
|
+
(reader.extend ConditionalDirectiveTracker, IncludeDirectiveTracker)
|
11
12
|
end
|
12
13
|
end
|
13
14
|
end
|
@@ -19,7 +19,7 @@ module Asciidoctor::Reducer
|
|
19
19
|
end
|
20
20
|
target_lines[idx] = lines if target_lines
|
21
21
|
end
|
22
|
-
|
22
|
+
reduced_source_lines = inc_replacements[0][:lines].flatten
|
23
23
|
if doc.sourcemap
|
24
24
|
logger = ::Asciidoctor::LoggerManager.logger
|
25
25
|
opts = doc.options.merge logger: nil, parse: false, reduced: true
|
@@ -27,13 +27,13 @@ module Asciidoctor::Reducer
|
|
27
27
|
opts[:extension_registry] = ::Asciidoctor::Extensions::Registry.new ext_reg.groups
|
28
28
|
end
|
29
29
|
includes = doc.catalog[:includes]
|
30
|
-
doc = ::Asciidoctor.load
|
30
|
+
doc = ::Asciidoctor.load reduced_source_lines, opts
|
31
31
|
doc.catalog[:includes] = includes
|
32
32
|
doc.parse
|
33
33
|
::Asciidoctor::LoggerManager.logger = logger
|
34
34
|
else
|
35
|
-
|
36
|
-
doc.
|
35
|
+
reduced_source_lines.pop while reduced_source_lines[-1] == ''
|
36
|
+
doc.source_lines.replace reduced_source_lines
|
37
37
|
end
|
38
38
|
end
|
39
39
|
doc
|
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.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Allen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-05-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|
@@ -52,9 +52,9 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 3.11.0
|
55
|
-
description: A tool that reduces
|
56
|
-
|
57
|
-
|
55
|
+
description: A tool that reduces an AsciiDoc document containing preprocessor directives
|
56
|
+
(includes and conditionals) to a single AsciiDoc document by expanding all includes
|
57
|
+
and evaluating all conditionals.
|
58
58
|
email: dan.j.allen@gmail.com
|
59
59
|
executables:
|
60
60
|
- asciidoctor-reducer
|
@@ -97,13 +97,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
97
97
|
version: '0'
|
98
98
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
|
-
- - "
|
100
|
+
- - ">="
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
-
version:
|
102
|
+
version: '0'
|
103
103
|
requirements: []
|
104
104
|
rubygems_version: 3.3.7
|
105
105
|
signing_key:
|
106
106
|
specification_version: 4
|
107
|
-
summary: Reduces
|
108
|
-
|
107
|
+
summary: Reduces an AsciiDoc document containing includes and conditionals to a single
|
108
|
+
AsciiDoc document.
|
109
109
|
test_files: []
|