asciidoctor-reducer 1.0.0.alpha.4 → 1.0.0.alpha.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 28c5a3097f098dfdcbbc424988e182c7acbab7d7c75e3c9e2db5794e029bac71
4
- data.tar.gz: 74202ca198cc1503a1b0db4e0a2a874d767eb04928e162f3f2c5922a94e1823f
3
+ metadata.gz: 8e5bfad3f3b343a1fd2741938d31812feac3218e8b6998d43b3614b6800874b0
4
+ data.tar.gz: 443bcb83342bb51cf3537b9b5cba497b7a1f5340eb7e7fb0956e85746344f917
5
5
  SHA512:
6
- metadata.gz: d2610fb6c16abd5a154c91afc7497c268c221891bb184114afecf1d5a514dd03a738677e0faff1041d8214b2cf051bda07735d2fbe07a5b0dc6a9c3ac05275b6
7
- data.tar.gz: 996d453168c7701e1f6f84e63fcda510d99ef6c18a7c89196edcae233114e007b525bd3ffb9b10b9c93940391ff2e9395e990562e0181051c27bacb1a7ef03c4
6
+ metadata.gz: b52ca3132349b059d672bab08dd1b1c5a2586d88e8f4f31eb8d2ae7f0f9891917f0ee0cd46bd63826e7127cb8a64fda650bc5a13815760d299c06c6e5181e02b
7
+ data.tar.gz: 6bdb49618d5adb7b1ce702d266ee8d6a229545b6ca8676931083df9362b21aaedabf539c7d1c4ea5c2fabecbb25426a9bcc140d80ffce93cd9b6da52bdc0e4cd
data/CHANGELOG.adoc CHANGED
@@ -4,6 +4,19 @@
4
4
  This document provides a high-level view of the changes to the Asciidoctor Reducer by 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.0.alpha.5 (2022-02-06) - @mojavelinux
8
+
9
+ === Changed
10
+
11
+ * Removing trailing empty lines after reducing when sourcemap is not enabled
12
+ * Remove unnecessary override of lineno in preprocess_include_directive override
13
+ * Simplify how include replacement target is tracked
14
+ * Classify extensions in group named `:reducer`
15
+
16
+ === Fixed
17
+
18
+ * Suppress log messages when reloading document (#14)
19
+
7
20
  == 1.0.0.alpha.4 (2022-02-03) - @mojavelinux
8
21
 
9
22
  === Fixed
@@ -57,3 +70,7 @@ Initial release.
57
70
  === Details
58
71
 
59
72
  {url-repo}/releases/tag/v1.0.0.alpha.4[git tag]
73
+
74
+ === Details
75
+
76
+ {url-repo}/releases/tag/v1.0.0.alpha.5[git tag]
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.alpha.4, 2022-02-03
3
+ v1.0.0.alpha.5, 2022-02-06
4
4
  :idprefix:
5
5
  :idseparator: -
6
6
  ifndef::env-github[:icons: font]
@@ -6,8 +6,9 @@ module Asciidoctor::Reducer
6
6
  attr_reader :x_include_replacements
7
7
 
8
8
  def self.extended instance
9
- instance.instance_variable_set :@x_include_replacements, ([{ drop: [] }].extend CurrentPointer)
10
- instance.instance_variable_set :@x_parents, [0]
9
+ instance.instance_variable_set :@x_include_replacements, ([{ drop: [] }].extend CurrentPosition)
10
+ instance.instance_variable_set :@x_include_directive_line, nil
11
+ instance.instance_variable_set :@x_include_pushed, nil
11
12
  end
12
13
 
13
14
  def preprocess_conditional_directive keyword, target, delimiter, text
@@ -34,71 +35,58 @@ module Asciidoctor::Reducer
34
35
 
35
36
  def preprocess_include_directive target, attrlist
36
37
  @x_include_directive_line = %(include::#{target}[#{attrlist}])
37
- @x_push_include_called = false
38
+ @x_include_pushed = false
38
39
  inc_lineno = @lineno - 1 # we're currently on the include line, which is 1-based
39
40
  result = super
40
- return result if @x_push_include_called
41
- parent_depth = (parents = @x_parents).length
42
- # depth change is guaranteed to be >= 0 under normal conditions
43
- unless @include_stack.length < parent_depth
44
- parents << @x_include_replacements.length.pred
45
- parent_depth += 1
41
+ if @x_include_pushed
42
+ @x_include_directive_line = @x_include_pushed = nil
43
+ return result
46
44
  end
47
45
  inc_lines = ((line = lines[0].to_s).start_with? 'Unresolved directive in ') && (line.end_with? ']') ? [line] : []
48
- push_include_replacement inc_lines, parent_depth, inc_lineno
46
+ push_include_replacement inc_lineno, inc_lines
47
+ @x_include_directive_line = @x_include_pushed = nil
49
48
  result
50
49
  end
51
50
 
52
51
  def push_include data, file, path, lineno, attrs
53
- @x_push_include_called = true
52
+ @x_include_pushed = true
54
53
  inc_lineno = @lineno - 2 # we're below the include line, which is 1-based
55
54
  prev_inc_depth = @include_stack.length
56
- # Q: can we do this without resetting the lineno?
57
- lineno = 1 # rubocop:disable Lint/ShadowedArgument
58
55
  result = super
59
- parent_depth = (parents = @x_parents).length
60
- # push_include did not push to the stack
61
- if (inc_depth = @include_stack.length) == prev_inc_depth
62
- depth_change = inc_depth - (parent_depth - 1)
63
- else
64
- depth_change = inc_depth - parent_depth
65
- inc_lines = lines
66
- end
67
- if depth_change > 0
68
- parents << @x_include_replacements.length.pred
69
- parent_depth += 1
70
- elsif depth_change < 0
71
- parent_depth -= (parents.slice! parent_depth + depth_change, -depth_change).length
72
- end
73
- push_include_replacement inc_lines, parent_depth, inc_lineno
56
+ inc_lines = lines if @include_stack.length > prev_inc_depth
57
+ push_include_replacement inc_lineno, inc_lines
74
58
  result
75
59
  end
76
60
 
77
61
  def pop_include
78
- @x_include_replacements.current = @x_include_replacements[@x_include_replacements.current[:into] || 0]
62
+ @x_include_replacements.pos = @x_include_replacements.current[:into] unless @x_include_pushed
79
63
  super
80
64
  end
81
65
 
82
66
  private
83
67
 
84
- def push_include_replacement inc_lines, parent_depth, inc_lineno
68
+ def push_include_replacement inc_lineno, inc_lines
85
69
  @x_include_replacements << {
70
+ into: @x_include_replacements.pos,
71
+ lineno: inc_lineno,
72
+ line: @x_include_directive_line,
86
73
  lines: inc_lines || [],
87
74
  drop: [],
88
- into: @x_parents[parent_depth - 1],
89
- index: inc_lineno,
90
- replace: @x_include_directive_line,
91
75
  }
92
- @x_include_replacements.current = @x_include_replacements[-1] if inc_lines
76
+ @x_include_replacements.pos = @x_include_replacements.length - 1 if inc_lines
93
77
  nil
94
78
  end
95
79
  end
96
80
 
97
- module CurrentPointer
98
- attr_accessor :current
81
+ module CurrentPosition
82
+ attr_accessor :pos
99
83
 
100
84
  def self.extended instance
101
- instance.current = instance[-1]
85
+ instance.pos = instance.length - 1
86
+ end
87
+
88
+ def current
89
+ self[@pos]
102
90
  end
103
91
  end
104
92
  end
@@ -4,14 +4,13 @@ module Asciidoctor::Reducer
4
4
  class TreeProcessor < ::Asciidoctor::Extensions::TreeProcessor
5
5
  def process doc
6
6
  return if doc.options[:reduced]
7
- inc_replacements = doc.reader.x_include_replacements
8
- unless inc_replacements.length == 1 && inc_replacements[0][:drop].empty?
7
+ unless (inc_replacements = doc.reader.x_include_replacements).length == 1 && inc_replacements[0][:drop].empty?
9
8
  inc_replacements[0][:lines] = doc.source_lines.dup
10
9
  inc_replacements.reverse_each do |it|
11
10
  if (into = it[:into])
12
11
  target_lines = inc_replacements[into][:lines]
13
12
  # adds extra bit of assurance that we're replacing the correct line
14
- next unless target_lines[(index = it[:index])] == it[:replace]
13
+ next unless target_lines[(index = it[:lineno])] == it[:line]
15
14
  end
16
15
  lines = it[:lines]
17
16
  unless (drop = it[:drop]).empty?
@@ -21,9 +20,11 @@ module Asciidoctor::Reducer
21
20
  end
22
21
  source_lines = inc_replacements[0][:lines].flatten
23
22
  if doc.sourcemap
24
- # WARNING: if include directives remain that can still be resolved, the sourcemap won't match the source lines
25
- doc = ::Asciidoctor.load source_lines, (doc.options.merge reduced: true)
23
+ logger = ::Asciidoctor::LoggerManager.logger
24
+ doc = ::Asciidoctor.load source_lines, (doc.options.merge logger: false, reduced: true)
25
+ ::Asciidoctor::LoggerManager.logger = logger
26
26
  else
27
+ source_lines.pop while (last = source_lines[-1]) && last.empty?
27
28
  doc.reader.source_lines = source_lines
28
29
  end
29
30
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Asciidoctor
4
4
  module Reducer
5
- VERSION = '1.0.0.alpha.4'
5
+ VERSION = '1.0.0.alpha.5'
6
6
  end
7
7
  end
@@ -3,7 +3,7 @@
3
3
  require 'asciidoctor'
4
4
  require_relative 'reducer/extensions'
5
5
 
6
- Asciidoctor::Extensions.register do
6
+ Asciidoctor::Extensions.register :reducer do
7
7
  preprocessor Asciidoctor::Reducer::Preprocessor
8
8
  tree_processor Asciidoctor::Reducer::TreeProcessor
9
9
  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.alpha.4
4
+ version: 1.0.0.alpha.5
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-02-03 00:00:00.000000000 Z
11
+ date: 2022-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor