asciidoctor-reducer 1.0.2 → 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: b5316a1e0a22871599401171fc8f5104e4a03cf09598eacee8670153354e6050
4
- data.tar.gz: 02cc09578b9798e53f3e8a23f81b2e051ef2b6714c39bee99d043a6cbee2acc5
3
+ metadata.gz: 61484f3684d8fdfc67590e300484c52e9a2bdf14cd9e46a7a59c8bd7926836ba
4
+ data.tar.gz: 5a7327b41a1c2a33ecbec9288e7eb155d2757e9a94cbd64da3497caaab89e3b8
5
5
  SHA512:
6
- metadata.gz: a2ef54d4a37f4c1f2205cb191735a1d6462ad271faa75db4ea87305c5ba25f2ba08885057f5c56006703ad745fc2c55928ac0c6db9205e9ee35284fab245f395
7
- data.tar.gz: '0018183fd91c359a67ad0a6e5b60901f5f868bc4223bd9fc27c639eb5fb05a684c938480507a9ff445bdd00ad260ff385c29d68a6359c2498cc6a4d9cee0320a'
6
+ metadata.gz: de7ead3ed1f79256653758038bc1b313a01deaeeba2295f042ba21c7af9d8125581a938dbeceebe6caaec952412a1e84dfbe2eb6f1f8aecfbc45d87a38d69de1
7
+ data.tar.gz: 979950581b012e1c46c035bcf30941502800e6c921ba0612167d60accec9ba1efd25cce729877d85f1944d1336f4bb6290fa1581096e9a4f73f66250547bac88
data/CHANGELOG.adoc CHANGED
@@ -4,6 +4,20 @@
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
+
7
21
  == 1.0.2 (2022-05-09) - @mojavelinux
8
22
 
9
23
  === Fixed
data/README.adoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = {project-name}
2
2
  Dan Allen <https://github.com/mojavelinux[@mojavelinux]>
3
- v1.0.2, 2022-05-09
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.
@@ -30,7 +30,11 @@ module Asciidoctor::Reducer
30
30
  prev_inc_depth = @include_stack.size
31
31
  offset = lineno > 1 ? lineno - 1 : 0
32
32
  result = super
33
- push_include_replacement directive_lineno, (@include_stack.size > prev_inc_depth ? lines : []), offset
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
34
38
  result
35
39
  end
36
40
 
@@ -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 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.2'
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.2
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-09 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