asciidoctor-list-content 0.1.1 → 0.1.2

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/bin/list-content +74 -60
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 10f4720470db26b90ba32f652524acba57e3970da6890497f9e43cac515fa2fc
4
- data.tar.gz: 953804b4375bbc24f19e0b452b5e5640ee07861bd1192bc2a64ad912baba49fa
3
+ metadata.gz: d159dbea869af6eea5834a4b8d3b92f39034dce7090cff97c1cd8e1c9585757e
4
+ data.tar.gz: 9769823625e20bffa86d71b58bd787a8b5e5e0a2765a12449af492e537f18fcb
5
5
  SHA512:
6
- metadata.gz: 8a4f37f62eb062aa4d1d63710813eeb289cec6a9df03a97cbd4b36089338e91f974b2661c97093992c47233a09f4b384ae6fd56c3a6e03034dc206b88d346725
7
- data.tar.gz: 05236dd26b112092ebf4c785074ab0b3aa56b7617663ff10cb8d19179971f2062f13c67e2bba2d3c3a7d5d119201134ce3c43106bdef1308197e76a7206ba809
6
+ metadata.gz: 184791ac163885f54292b2e6c6e37aea1bf9dcaf4266d646a549cee5009c7693ce0571a46f502addfff5afcac7ee838cba1c359469551aad1a5ed0a3446383dc
7
+ data.tar.gz: 9c2b3ac3154a434104567fdafee85d0693324c1335efba62a29e8b6553af30878dbeefe1a294c194144182ffb24294278f4c58ce9c4130a8e1b12e155b2af9d1
data/README.md CHANGED
@@ -48,6 +48,6 @@ gem install asciidoctor-list-content
48
48
 
49
49
  ## Copyright
50
50
 
51
- Copyright © 2022, 2025 Jaromir Hradilek
51
+ Copyright © 2022, 2026 Jaromir Hradilek
52
52
 
53
53
  This program is free software, released under the terms of the MIT license. It is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
data/bin/list-content CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  # list-content.rb - list content included in supplied AsciiDoc files
4
- # Copyright (C) 2022 Jaromir Hradilek
4
+ # Copyright (C) 2022, 2026 Jaromir Hradilek
5
5
 
6
6
  # MIT License
7
7
  #
@@ -29,7 +29,7 @@ require 'pathname'
29
29
  require 'optparse'
30
30
 
31
31
  # Set the script name and version:
32
- VERSION = '0.1.1'
32
+ VERSION = '0.1.2'
33
33
  NAME = File.basename($0)
34
34
 
35
35
  # Set the current working directory as the defualt starting point for
@@ -77,8 +77,8 @@ op = OptionParser.new do |opts|
77
77
  end
78
78
 
79
79
  opts.on('-r', '--relative-to=DIR', 'print file paths relative to DIR') do |value|
80
- abort "Directory does not exist: #{dir}" if not File.exist?(value)
81
- abort "Not a directory: #{dir}" if not File.directory?(value)
80
+ abort "#{NAME}: Directory does not exist: #{dir}" if not File.exist?(value)
81
+ abort "#{NAME}: Not a directory: #{dir}" if not File.directory?(value)
82
82
  relpath = Pathname.new(File.expand_path(value))
83
83
  end
84
84
 
@@ -94,68 +94,82 @@ op = OptionParser.new do |opts|
94
94
  end
95
95
 
96
96
  # Parse command-line options and return the remaining arguments:
97
- args = op.parse!
97
+ begin
98
+ args = op.parse!
99
+ rescue OptionParser::InvalidArgument, OptionParser::InvalidOption,
100
+ OptionParser::AmbiguousOption, OptionParser::MissingArgument => error
101
+ abort "#{NAME}: #{error.message}"
102
+ end
98
103
 
99
104
  # Verify the number of supplied command-line arguments:
100
- abort "Invalid number of arguments" if args.length < 1
101
-
102
- # Process each supplied file:
103
- args.each do |file|
104
- # Verify that the supplied file exists and is readable:
105
- abort "File does not exist: #{file}" if not File.exist?(file)
106
- abort "Not a file: #{file}" if not File.file?(file)
107
- abort "File not readable: #{file}" if not File.readable?(file)
108
-
109
- # Get the adjusted relative path to the supplied file:
110
- path = Pathname.new(File.realpath(file)).relative_path_from(relpath)
111
-
112
- # Parse the supplied file:
113
- doc = Asciidoctor.load_file(file, doctype: :book, safe: :safe, catalog_assets: true)
114
-
115
- # Print the list of all included files:
116
- doc.catalog[:includes].each do |item, _|
117
- # Get the adjusted relative path to the included file:
118
- include = Pathname.new(File.realpath(File.join(File.dirname(file), "#{item}.adoc"))).relative_path_from(relpath)
119
-
120
- # Print the name of the parent file if requested:
121
- print "#{path}#{delimiter}" if with_filename
122
-
123
- # Print the content type from the file prefix if requested:
124
- if with_prefix
125
- case include.basename.to_s
126
- when /^con_/
127
- type = 'CONCEPT'
128
- when /^proc_/
129
- type = 'PROCEDURE'
130
- when /^ref_/
131
- type = 'REFERENCE'
132
- when /^assembly_/
133
- type = 'ASSEMBLY'
134
- else
135
- type = 'NONE'
105
+ abort "#{NAME}: Invalid number of arguments" if args.length < 1
106
+
107
+ begin
108
+ # Process each supplied file:
109
+ args.each do |file|
110
+ # Verify that the supplied file exists and is readable:
111
+ abort "#{NAME}: File does not exist: #{file}" if not File.exist?(file)
112
+ abort "#{NAME}: Not a file: #{file}" if not File.file?(file)
113
+ abort "#{NAME}: File not readable: #{file}" if not File.readable?(file)
114
+
115
+ # Get the adjusted relative path to the supplied file:
116
+ path = Pathname.new(File.realpath(file)).relative_path_from(relpath)
117
+
118
+ # Parse the supplied file:
119
+ doc = Asciidoctor.load_file(file, doctype: :book, safe: :unsafe, catalog_assets: true)
120
+
121
+ # Print the list of all included files:
122
+ doc.catalog[:includes].each do |item, _|
123
+ # Start composing the resulting output:
124
+ result = ''
125
+
126
+ # Get the adjusted relative path to the included file:
127
+ include = Pathname.new(File.realpath(File.join(File.dirname(file), "#{item}.adoc"))).relative_path_from(relpath)
128
+
129
+ # Print the name of the parent file if requested:
130
+ result << "#{path}#{delimiter}" if with_filename
131
+
132
+ # Print the content type from the file prefix if requested:
133
+ if with_prefix
134
+ case include.basename.to_s
135
+ when /^con[_-]/
136
+ type = 'CONCEPT'
137
+ when /^proc[_-]/
138
+ type = 'PROCEDURE'
139
+ when /^ref[_-]/
140
+ type = 'REFERENCE'
141
+ when /^assembly[_-]/
142
+ type = 'ASSEMBLY'
143
+ when /^snip[_-]/
144
+ type = 'SNIPPET'
145
+ else
146
+ type = 'NONE'
147
+ end
148
+ result << "#{type}#{delimiter}"
136
149
  end
137
- print "#{type}#{delimiter}"
138
- end
139
150
 
140
- # Print the conent type from the related attribute if requested:
141
- if with_attribute
142
- type = File.read(include)[/^:_content-type: (.*)$/,1]
143
- type = 'NONE' if not type
144
- print "#{type}#{delimiter}"
145
- end
151
+ # Print the conent type from the related attribute if requested:
152
+ if with_attribute
153
+ type = File.read(include)[/^:_(?:mod-docs-content|content|module)-type: (.*)$/,1]
154
+ type = 'NONE' if not type
155
+ result << "#{type}#{delimiter}"
156
+ end
146
157
 
147
- # Print the name of the included file:
148
- puts include
149
- end
158
+ # Print the name of the included file:
159
+ puts result << include.to_s
160
+ end
150
161
 
151
- # Skip listing images if not requested:
152
- next unless images
162
+ # Skip listing images if not requested:
163
+ next unless images
153
164
 
154
- # Print the list of all included images:
155
- doc.catalog[:images].each do |image|
156
- print "#{path}#{delimiter}" if with_filename
157
- print "IMAGE#{delimiter}" if with_prefix
158
- print "IMAGE#{delimiter}" if with_attribute
159
- puts Pathname.new(File.realpath(File.join(File.dirname(file), image.imagesdir || '', image.target))).relative_path_from(relpath)
165
+ # Print the list of all included images:
166
+ doc.catalog[:images].each do |image|
167
+ print "#{path}#{delimiter}" if with_filename
168
+ print "IMAGE#{delimiter}" if with_prefix
169
+ print "IMAGE#{delimiter}" if with_attribute
170
+ puts Pathname.new(File.realpath(File.join(File.dirname(file), image.imagesdir || '', image.target))).relative_path_from(relpath)
171
+ end
160
172
  end
173
+ rescue Interrupt
174
+ exit 130
161
175
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-list-content
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jaromir Hradilek
@@ -63,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
63
  - !ruby/object:Gem::Version
64
64
  version: '0'
65
65
  requirements: []
66
- rubygems_version: 3.6.7
66
+ rubygems_version: 4.0.10
67
67
  specification_version: 4
68
68
  summary: List files included in an AsciiDoc document
69
69
  test_files: []