asciidoctor-reducer 1.0.1 → 1.0.3

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: '042939f0b251163208b57a67bed8a7b16d15d0972a616e67c171b8462a5ae61b'
4
- data.tar.gz: 9065fc1b7a742f057441f873956883e6c87ba88afb1984496c821f378e666e2b
3
+ metadata.gz: 61484f3684d8fdfc67590e300484c52e9a2bdf14cd9e46a7a59c8bd7926836ba
4
+ data.tar.gz: 5a7327b41a1c2a33ecbec9288e7eb155d2757e9a94cbd64da3497caaab89e3b8
5
5
  SHA512:
6
- metadata.gz: 53e3e2cd52cf60ff810b93c5409cf521c1e5509106c8cece15ac89262d5a7d0ac998b2369ebb1cd8854675de930ea3a2f10c762bf072f758db663f3b6e7aa0ed
7
- data.tar.gz: 1785df7825bd0fb902dd619bf42b2de90360acdf975f3356ca5ad8ed7b65a32c71c8824b51b966aecce774078d14d5c6dcdf281d899eb6f54e61307dbec0b0ce
6
+ metadata.gz: de7ead3ed1f79256653758038bc1b313a01deaeeba2295f042ba21c7af9d8125581a938dbeceebe6caaec952412a1e84dfbe2eb6f1f8aecfbc45d87a38d69de1
7
+ data.tar.gz: 979950581b012e1c46c035bcf30941502800e6c921ba0612167d60accec9ba1efd25cce729877d85f1944d1336f4bb6290fa1581096e9a4f73f66250547bac88
data/CHANGELOG.adoc CHANGED
@@ -4,6 +4,30 @@
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.0.3 (2022-09-22) - @mojavelinux
8
+
9
+ === Changed
10
+
11
+ * Log error message if program cannot locate include directive to reduce (indicates a probable logic error in the program)
12
+
13
+ === Fixed
14
+
15
+ * Reduce preprocessor directives in file included by include directive with `leveloffset` attribute (#45)
16
+
17
+ === Details
18
+
19
+ {url-repo}/releases/tag/v1.0.3[git tag] | {url-repo}/compare/v1.0.2\...v1.0.3[full diff]
20
+
21
+ == 1.0.2 (2022-05-09) - @mojavelinux
22
+
23
+ === Fixed
24
+
25
+ * Replace include and conditional directives inside a file that has been included partially (i.e., has an offset) (#43)
26
+
27
+ === Details
28
+
29
+ {url-repo}/releases/tag/v1.0.2[git tag] | {url-repo}/compare/v1.0.1\...v1.0.2[full diff]
30
+
7
31
  == 1.0.1 (2022-05-08) - @mojavelinux
8
32
 
9
33
  === 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.1, 2022-05-08
3
+ v1.0.3, 2022-09-22
4
4
  :idprefix:
5
5
  :idseparator: -
6
6
  ifndef::env-github[:icons: font]
@@ -260,6 +260,45 @@ Here's an example of that comment:
260
260
 
261
261
  When a document that contains the magic comment is converted, the include mapper reads the comma-separated paths in the value and loads them into the includes table of the document catalog.
262
262
 
263
+ == Reduce files in a GitHub repository
264
+
265
+ It's well known that the AsciiDoc preview on GitHub does not support the include directive.
266
+ With the help of GitHub Actions, Asciidoctor Reducer is ready-made to solve this problem.
267
+
268
+ In order to set up this automated process, you need to first rename the source file to make room for the reduced file.
269
+ Let's call the source file [.path]_README-source.adoc_ and the reduced file [.path]_README.adoc_.
270
+
271
+ Next, create a GitHub Actions workflow file named [.path]_.github/workflows/reduce-readme.yml_ and populate it with the following contents:
272
+
273
+ ..github/workflows/reduce-readme.yml
274
+ [,yaml]
275
+ ----
276
+ name: Reduce README
277
+ on:
278
+ push:
279
+ paths:
280
+ - README-source.adoc
281
+ branches: ['**']
282
+ jobs:
283
+ build:
284
+ runs-on: ubuntu-latest
285
+ steps:
286
+ - name: Checkout Repository
287
+ uses: actions/checkout@v2
288
+ - name: Install Asciidoctor Reducer
289
+ run: sudo gem install asciidoctor-reducer
290
+ - name: Reduce README
291
+ run: asciidoctor-reducer -o README.adoc README-source.adoc
292
+ - name: Commit and Push README
293
+ uses: EndBug/add-and-commit@v9
294
+ with:
295
+ add: README.adoc
296
+ ----
297
+
298
+ Now, each time you modify, commit, and push the [.path]_README-source.adoc_ file, the GitHub Action workflow will run, reduce that file, and push the reduced file back to the repository as [.path]_README.adoc_.
299
+
300
+ If you want to trigger the workflow on changes to other files as well, add those paths or path patterns to the value of the `paths` key.
301
+
263
302
  == Development
264
303
 
265
304
  Follow the instructions below to learn how to help develop the project or test-drive the development version.
@@ -8,7 +8,9 @@ module Asciidoctor::Reducer
8
8
  directive_lineno = @lineno
9
9
  result = super
10
10
  return result if @skipping && skip_active
11
- drop = @include_replacements.current[:drop] ||= []
11
+ curr_inc_replacement = @include_replacements.current
12
+ drop = curr_inc_replacement[:drop] ||= []
13
+ directive_lineno -= (curr_inc_replacement[:offset] ||= 0)
12
14
  if (depth_change = @conditional_stack.size - depth) < 0
13
15
  if skip_active
14
16
  drop.push(*(drop.pop..directive_lineno))
@@ -18,7 +18,7 @@ module Asciidoctor::Reducer
18
18
  directive_lineno == @lineno && (unresolved = ln.start_with? 'link:')
19
19
  ln = %(#{ln.slice 0, (ln.length - 1)}role=include])
20
20
  end
21
- push_include_replacement directive_lineno, (unresolved ? [ln] : []), unresolved
21
+ push_include_replacement directive_lineno, (unresolved ? [ln] : []), 0, unresolved
22
22
  end
23
23
  @x_reducer.clear
24
24
  result
@@ -28,8 +28,13 @@ module Asciidoctor::Reducer
28
28
  @x_reducer[:include_pushed] = true
29
29
  directive_lineno = @lineno - 1 # we're below the include line, which is 1-based
30
30
  prev_inc_depth = @include_stack.size
31
+ offset = lineno > 1 ? lineno - 1 : 0
31
32
  result = super
32
- push_include_replacement directive_lineno, (@include_stack.size > prev_inc_depth ? lines : [])
33
+ if @include_stack.size > prev_inc_depth
34
+ inc_lines = lines
35
+ offset -= 2 if (attrs.key? 'leveloffset') && (inc_lines[0].start_with? ':leveloffset: ') && inc_lines[1]&.empty?
36
+ end
37
+ push_include_replacement directive_lineno, inc_lines || [], offset
33
38
  result
34
39
  end
35
40
 
@@ -40,12 +45,13 @@ module Asciidoctor::Reducer
40
45
 
41
46
  private
42
47
 
43
- def push_include_replacement lineno, lines, unresolved = false
48
+ def push_include_replacement lineno, lines, offset, unresolved = false
44
49
  (inc_replacements = @include_replacements) << {
45
50
  into: inc_replacements.pointer,
46
- lineno: lineno,
51
+ lineno: lineno - (inc_replacements.current[:offset] ||= 0),
47
52
  line: @x_reducer[:include_directive_line],
48
53
  lines: lines,
54
+ offset: offset,
49
55
  }
50
56
  inc_replacements.to_end unless unresolved || lines.empty?
51
57
  nil
@@ -8,8 +8,12 @@ module Asciidoctor::Reducer
8
8
  inc_replacements.reverse_each do |it|
9
9
  if (into = it[:into])
10
10
  target_lines = inc_replacements[into][:lines]
11
- # adds extra bit of assurance that we're replacing the correct line
12
- next unless target_lines[(idx = it[:lineno] - 1)] == it[:line]
11
+ # adds extra assurance that the program is replacing the correct line
12
+ unless target_lines[(idx = it[:lineno] - 1)] == it[:line]
13
+ msg = %(include directive to reduce not found; expected: "#{it[:line]}"; got: "#{target_lines[idx]}")
14
+ doc.logger.error msg
15
+ next
16
+ end
13
17
  end
14
18
  lines = it[:lines]
15
19
  unless (drop = it[:drop] || []).empty?
@@ -21,7 +25,7 @@ module Asciidoctor::Reducer
21
25
  end
22
26
  reduced_source_lines = inc_replacements[0][:lines].flatten
23
27
  if doc.sourcemap
24
- logger = ::Asciidoctor::LoggerManager.logger
28
+ logger = doc.logger
25
29
  opts = doc.options.merge logger: nil, parse: false, reduced: true
26
30
  if (ext_reg = opts[:extension_registry])
27
31
  opts[:extension_registry] = ::Asciidoctor::Extensions::Registry.new ext_reg.groups
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Asciidoctor
4
4
  module Reducer
5
- VERSION = '1.0.1'
5
+ VERSION = '1.0.3'
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.1
4
+ version: 1.0.3
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-05-08 00:00:00.000000000 Z
11
+ date: 2022-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor