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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/bin/list-content +74 -60
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d159dbea869af6eea5834a4b8d3b92f39034dce7090cff97c1cd8e1c9585757e
|
|
4
|
+
data.tar.gz: 9769823625e20bffa86d71b58bd787a8b5e5e0a2765a12449af492e537f18fcb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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,
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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
|
-
|
|
148
|
-
|
|
149
|
-
|
|
158
|
+
# Print the name of the included file:
|
|
159
|
+
puts result << include.to_s
|
|
160
|
+
end
|
|
150
161
|
|
|
151
|
-
|
|
152
|
-
|
|
162
|
+
# Skip listing images if not requested:
|
|
163
|
+
next unless images
|
|
153
164
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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.
|
|
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:
|
|
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: []
|