asciidoctor-reducer 1.0.0-beta.1 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ba34a52b145d4aec9db42e4149f7bbdf29897657f99d6b446d05510e0d193835
4
- data.tar.gz: 71c60fcd5c4a1b1dc403885c3b47816b23917c755a9c4c3e6d40d0305fdae35a
3
+ metadata.gz: '042939f0b251163208b57a67bed8a7b16d15d0972a616e67c171b8462a5ae61b'
4
+ data.tar.gz: 9065fc1b7a742f057441f873956883e6c87ba88afb1984496c821f378e666e2b
5
5
  SHA512:
6
- metadata.gz: 31c60803245045f362a162771cba785a2b11e2d65e504b0a06a220c9b22b9376a6c0f2e1b26ad580af9db2bff2c94d99502b7c4a065032a006dc0f409bb737c2
7
- data.tar.gz: c1e960d7705de5cbb26fdb4cadd54fdbefaaf77617f9f4ac9f43ffbefb5089a2ae96af2d34be3333d43b404bba158e029e678d889c8410b7548e7eebbf343e4b
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 high-level view of the changes to the Asciidoctor Reducer by release.
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.0-beta.1, 2022-04-21
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 that contains includes to a single AsciiDoc document by expanding any includes reachable from the parent document.
20
- The tool also applies preprocessor conditionals (unless the option to preserve them is specified), leaving behind only the selected lines.
21
- If the document does not contain any preprocessor directives, the tool returns the original source.
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 --pre
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.
@@ -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 a composite AsciiDoc document containing includes and conditionals to a single AsciiDoc document.'
11
- s.description = 'A tool that reduces a composite AsciiDoc document containing preprocessor directives (includes and conditionals) to a single AsciiDoc document by expanding the includes and applying the conditionals.'
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
- Reduces a composite AsciiDoc document containing includes and conditionals to a single AsciiDoc document.
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
- cond_lineno = @lineno
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..cond_lineno))
14
+ drop.push(*(drop.pop..directive_lineno))
15
15
  else
16
- drop << cond_lineno
16
+ drop << directive_lineno
17
17
  end
18
- elsif depth_change > 0 || cond_lineno == @lineno
19
- drop << cond_lineno
18
+ elsif depth_change > 0 || directive_lineno == @lineno
19
+ drop << directive_lineno
20
20
  else
21
- drop << [cond_lineno, text]
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
- inc_lineno = @lineno # we're currently on the include line, which is 1-based
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
- inc_lineno == @lineno && (unresolved = ln.start_with? 'link:')
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 inc_lineno, (unresolved ? [ln] : []), unresolved
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
- inc_lineno = @lineno - 1 # we're below the include line, which is 1-based
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 inc_lineno, (@include_stack.size > prev_inc_depth ? lines : [])
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) : (reader.extend ConditionalDirectiveTracker, 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
- source_lines = inc_replacements[0][:lines].flatten
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 source_lines, opts
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
- source_lines.pop while (source_lines[-1] || :eof).empty?
36
- doc.reader.source_lines = source_lines
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Asciidoctor
4
4
  module Reducer
5
- VERSION = '1.0.0-beta.1'
5
+ VERSION = '1.0.1'
6
6
  end
7
7
  end
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.0-beta.1
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-04-21 00:00:00.000000000 Z
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 a composite AsciiDoc document containing preprocessor
56
- directives (includes and conditionals) to a single AsciiDoc document by expanding
57
- the includes and applying the conditionals.
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: 1.3.1
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 a composite AsciiDoc document containing includes and conditionals
108
- to a single AsciiDoc document.
107
+ summary: Reduces an AsciiDoc document containing includes and conditionals to a single
108
+ AsciiDoc document.
109
109
  test_files: []