asciidoctor-list-content 0.1.1
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 +7 -0
- data/AUTHORS +1 -0
- data/LICENSE +21 -0
- data/README.md +53 -0
- data/TODO +0 -0
- data/bin/list-content +161 -0
- metadata +69 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 10f4720470db26b90ba32f652524acba57e3970da6890497f9e43cac515fa2fc
|
4
|
+
data.tar.gz: 953804b4375bbc24f19e0b452b5e5640ee07861bd1192bc2a64ad912baba49fa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8a4f37f62eb062aa4d1d63710813eeb289cec6a9df03a97cbd4b36089338e91f974b2661c97093992c47233a09f4b384ae6fd56c3a6e03034dc206b88d346725
|
7
|
+
data.tar.gz: 05236dd26b112092ebf4c785074ab0b3aa56b7617663ff10cb8d19179971f2062f13c67e2bba2d3c3a7d5d119201134ce3c43106bdef1308197e76a7206ba809
|
data/AUTHORS
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Jaromir Hradilek <jhradilek@gmail.com>
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (C) 2024, 2025 Jaromir Hradilek
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a
|
6
|
+
copy of this software and associated documentation files (the "Software"),
|
7
|
+
to deal in the Software without restriction, including without limitation
|
8
|
+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
9
|
+
and/or sell copies of the Software, and to permit persons to whom the
|
10
|
+
Software is furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
20
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
21
|
+
DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# list-content
|
2
|
+
|
3
|
+
`list-content` is a simple script that parses an AsciiDoc file and prints all files included in it to standard output.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install the `asciidoctor-list-content` Ruby gem:
|
8
|
+
|
9
|
+
```console
|
10
|
+
gem install asciidoctor-list-content
|
11
|
+
```
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
* List all AsciiDoc files included in the specified file:
|
16
|
+
|
17
|
+
```console
|
18
|
+
list-content main.adoc
|
19
|
+
```
|
20
|
+
|
21
|
+
By default, the files are listed with the path relative to the current working directory. To make the paths relative to a different directory, specify the `--relative-to` or `-r` command-line option:
|
22
|
+
|
23
|
+
```console
|
24
|
+
list-content --relative-to ../../../ main.adoc
|
25
|
+
```
|
26
|
+
* Include the name of the specified file on each output line:
|
27
|
+
|
28
|
+
```console
|
29
|
+
list-content --with-filename main.adoc
|
30
|
+
```
|
31
|
+
|
32
|
+
This is especially useful if you are running the script of multiple files at the same time:
|
33
|
+
|
34
|
+
```console
|
35
|
+
list-content --with-filename */main.adoc
|
36
|
+
```
|
37
|
+
|
38
|
+
By default, the script uses a colon followed by a single space as the separator. If you plan to save the output as a CSV file, specify the `--delimiter` or `-d` command-line option:
|
39
|
+
|
40
|
+
```console
|
41
|
+
list-content --with-filename --delimiter ',' */main.adoc
|
42
|
+
```
|
43
|
+
* For a complete list of available options, run the script with the `--help` or `-h` command-line option:
|
44
|
+
|
45
|
+
```console
|
46
|
+
list-content --help
|
47
|
+
```
|
48
|
+
|
49
|
+
## Copyright
|
50
|
+
|
51
|
+
Copyright © 2022, 2025 Jaromir Hradilek
|
52
|
+
|
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/TODO
ADDED
File without changes
|
data/bin/list-content
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# list-content.rb - list content included in supplied AsciiDoc files
|
4
|
+
# Copyright (C) 2022 Jaromir Hradilek
|
5
|
+
|
6
|
+
# MIT License
|
7
|
+
#
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
9
|
+
# a copy of this software and associated documentation files (the "Soft-
|
10
|
+
# ware"), to deal in the Software without restriction, including without
|
11
|
+
# limitation the rights to use, copy, modify, merge, publish, distribute,
|
12
|
+
# sublicense, and/or sell copies of the Software, and to permit persons to
|
13
|
+
# whom the Software is furnished to do so, subject to the following condi-
|
14
|
+
# tions:
|
15
|
+
#
|
16
|
+
# The above copyright notice and this permission notice shall be included
|
17
|
+
# in all copies or substantial portions of the Software.
|
18
|
+
#
|
19
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
20
|
+
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABI-
|
21
|
+
# LITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
22
|
+
# SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
|
23
|
+
# OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
24
|
+
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
25
|
+
# OTHER DEALINGS IN THE SOFTWARE.
|
26
|
+
|
27
|
+
require 'asciidoctor'
|
28
|
+
require 'pathname'
|
29
|
+
require 'optparse'
|
30
|
+
|
31
|
+
# Set the script name and version:
|
32
|
+
VERSION = '0.1.1'
|
33
|
+
NAME = File.basename($0)
|
34
|
+
|
35
|
+
# Set the current working directory as the defualt starting point for
|
36
|
+
# relative paths:
|
37
|
+
relpath = Pathname.new(Dir.pwd)
|
38
|
+
|
39
|
+
# Do not list images by default:
|
40
|
+
images = false
|
41
|
+
|
42
|
+
# Do not include the main file in the output by default:
|
43
|
+
with_filename = false
|
44
|
+
|
45
|
+
# Do not include the content type determined from the file prefix in the output by default:
|
46
|
+
with_prefix = false
|
47
|
+
|
48
|
+
# Do not include the content type determined from the attribute in the output by default:
|
49
|
+
with_attribute = false
|
50
|
+
|
51
|
+
# Use colon as a field delimiter by default:
|
52
|
+
delimiter = ': '
|
53
|
+
|
54
|
+
# Configure the option parser:
|
55
|
+
op = OptionParser.new do |opts|
|
56
|
+
opts.banner = "Usage: #{NAME} [OPTION...] FILE...\n"
|
57
|
+
opts.banner += " #{NAME} -h|-v\n\n"
|
58
|
+
|
59
|
+
opts.on('-i', '--images', 'list included images in addition to included files') do
|
60
|
+
images = true
|
61
|
+
end
|
62
|
+
|
63
|
+
opts.on('-f', '--with-filename', 'include the name of the main file in the output') do
|
64
|
+
with_filename = true
|
65
|
+
end
|
66
|
+
|
67
|
+
opts.on('-t', '--with-prefix-type', 'include the content type determined from the file prefix in the output') do
|
68
|
+
with_prefix = true
|
69
|
+
end
|
70
|
+
|
71
|
+
opts.on('-T', '--with-attribute-type', 'include the content type determined from the attribute in the output') do
|
72
|
+
with_attribute = true
|
73
|
+
end
|
74
|
+
|
75
|
+
opts.on('-d', '--delimiter=STRING', "use STRING instead of '#{delimiter}' for field delimiter") do |value|
|
76
|
+
delimiter = value
|
77
|
+
end
|
78
|
+
|
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)
|
82
|
+
relpath = Pathname.new(File.expand_path(value))
|
83
|
+
end
|
84
|
+
|
85
|
+
opts.on('-h', '--help', 'display this help and exit') do
|
86
|
+
puts op
|
87
|
+
exit
|
88
|
+
end
|
89
|
+
|
90
|
+
opts.on('-v', '--version', 'display the version and exit') do
|
91
|
+
puts "#{NAME} #{VERSION}"
|
92
|
+
exit
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# Parse command-line options and return the remaining arguments:
|
97
|
+
args = op.parse!
|
98
|
+
|
99
|
+
# 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'
|
136
|
+
end
|
137
|
+
print "#{type}#{delimiter}"
|
138
|
+
end
|
139
|
+
|
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
|
146
|
+
|
147
|
+
# Print the name of the included file:
|
148
|
+
puts include
|
149
|
+
end
|
150
|
+
|
151
|
+
# Skip listing images if not requested:
|
152
|
+
next unless images
|
153
|
+
|
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)
|
160
|
+
end
|
161
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: asciidoctor-list-content
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jaromir Hradilek
|
8
|
+
bindir: bin
|
9
|
+
cert_chain: []
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: asciidoctor
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '2.0'
|
19
|
+
- - ">="
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.0.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - "~>"
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '2.0'
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: 2.0.0
|
32
|
+
description: A simple script that parses a supplied AsciiDoc file and prints all files
|
33
|
+
included in it to standard output.
|
34
|
+
email: jhradilek@gmail.com
|
35
|
+
executables:
|
36
|
+
- list-content
|
37
|
+
extensions: []
|
38
|
+
extra_rdoc_files: []
|
39
|
+
files:
|
40
|
+
- AUTHORS
|
41
|
+
- LICENSE
|
42
|
+
- README.md
|
43
|
+
- TODO
|
44
|
+
- bin/list-content
|
45
|
+
homepage: https://github.com/jhradilek/asciidoctor-list-content
|
46
|
+
licenses:
|
47
|
+
- MIT
|
48
|
+
metadata:
|
49
|
+
homepage_uri: https://github.com/jhradilek/asciidoctor-list-content
|
50
|
+
bug_tracker_uri: https://github.com/jhradilek/asciidoctor-list-content/issues
|
51
|
+
documentation_uri: https://github.com/jhradilek/asciidoctor-list-content/blob/main/README.md
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 3.0.0
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubygems_version: 3.6.7
|
67
|
+
specification_version: 4
|
68
|
+
summary: List files included in an AsciiDoc document
|
69
|
+
test_files: []
|