tocer 15.1.2 → 16.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.adoc +37 -18
- data/lib/tocer/builder.rb +1 -1
- data/lib/tocer/cli/actions/label.rb +25 -0
- data/lib/tocer/cli/actions/pattern.rb +25 -0
- data/lib/tocer/cli/actions/root.rb +25 -0
- data/lib/tocer/cli/commands/upsert.rb +35 -0
- data/lib/tocer/cli/shell.rb +19 -16
- data/lib/tocer/configuration/contract.rb +16 -0
- data/lib/tocer/configuration/defaults.yml +3 -3
- data/lib/tocer/configuration/model.rb +13 -0
- data/lib/tocer/container.rb +16 -2
- data/lib/tocer/rake/register.rb +2 -2
- data/lib/tocer/runner.rb +12 -7
- data/lib/tocer/writer.rb +1 -1
- data/tocer.gemspec +10 -7
- data.tar.gz.sig +0 -0
- metadata +61 -22
- metadata.gz.sig +0 -0
- data/lib/tocer/cli/actions/config.rb +0 -33
- data/lib/tocer/cli/actions/container.rb +0 -19
- data/lib/tocer/cli/actions/import.rb +0 -11
- data/lib/tocer/cli/actions/insert.rb +0 -25
- data/lib/tocer/cli/parser.rb +0 -35
- data/lib/tocer/cli/parsers/core.rb +0 -74
- data/lib/tocer/cli/parsers/flag.rb +0 -52
- data/lib/tocer/configuration/content.rb +0 -22
- data/lib/tocer/configuration/loader.rb +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 832f39f67b1d9fc4b4be22d308e7526cb16e2b7a4f352102e79636fc1e8299c9
|
4
|
+
data.tar.gz: 5c7f2a4671d6b2b3f83dad7188d0e75b636911bfb9adc293996c9446d058f5f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: adbd726db1d8b5dfe370c0436173513189fc730390e2b8dca8dac953aeea15d852425ddb35b7e74b9d7f36fa8ddcf9d501fc8210503538f46b2eaf34145d938a
|
7
|
+
data.tar.gz: dc21ad6f148f3d1e9566fd842aeee2d9ce48db4a4a0c94b95f601709a2c9b6a9335563f52d18066c443b15d0dd85e68bc55d3a970e4a2879f492ecd64b3c7784
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/README.adoc
CHANGED
@@ -28,13 +28,29 @@ toc::[]
|
|
28
28
|
|
29
29
|
== Setup
|
30
30
|
|
31
|
-
To install, run:
|
31
|
+
To install _with_ security, run:
|
32
|
+
|
33
|
+
[source,bash]
|
34
|
+
----
|
35
|
+
# 💡 Skip this line if you already have the public certificate installed.
|
36
|
+
gem cert --add <(curl --compressed --location https://alchemists.io/gems.pem)
|
37
|
+
gem install tocer --trust-policy HighSecurity
|
38
|
+
----
|
39
|
+
|
40
|
+
To install _without_ security, run:
|
32
41
|
|
33
42
|
[source,bash]
|
34
43
|
----
|
35
44
|
gem install tocer
|
36
45
|
----
|
37
46
|
|
47
|
+
You can also add the gem directly to your project:
|
48
|
+
|
49
|
+
[source,bash]
|
50
|
+
----
|
51
|
+
bundle add tocer
|
52
|
+
----
|
53
|
+
|
38
54
|
== Usage
|
39
55
|
|
40
56
|
=== Command Line Interface (CLI)
|
@@ -42,15 +58,18 @@ gem install tocer
|
|
42
58
|
From the command line, run: `tocer --help`
|
43
59
|
|
44
60
|
....
|
45
|
-
USAGE
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
61
|
+
USAGE
|
62
|
+
tocer [OPTIONS]
|
63
|
+
tocer COMMAND [OPTIONS]
|
64
|
+
|
65
|
+
OPTIONS
|
66
|
+
-v, --version Show version.
|
67
|
+
-h, --help [COMMAND] Show this message.
|
68
|
+
|
69
|
+
COMMANDS
|
70
|
+
config Manage configuration.
|
71
|
+
Path is dynamic per current directory.
|
72
|
+
upsert Update/insert table of contents.
|
54
73
|
....
|
55
74
|
|
56
75
|
To generate the table of contents at a specific position within your Markdown files, add the
|
@@ -77,10 +96,10 @@ The default configuration is as follows:
|
|
77
96
|
|
78
97
|
[source,yaml]
|
79
98
|
----
|
80
|
-
|
81
|
-
:
|
99
|
+
label: "## Table of Contents"
|
100
|
+
patterns:
|
82
101
|
- "README.md"
|
83
|
-
|
102
|
+
root_dir: "."
|
84
103
|
----
|
85
104
|
|
86
105
|
Feel free to take this default configuration, modify, and save as your own custom
|
@@ -89,7 +108,7 @@ Feel free to take this default configuration, modify, and save as your own custo
|
|
89
108
|
The `configuration.yml` file can be configured as follows:
|
90
109
|
|
91
110
|
* `label`: The header label for the table of contents.
|
92
|
-
* `
|
111
|
+
* `patterns`: The list of included files.
|
93
112
|
* `root_dir`: The root path to use for processing files.
|
94
113
|
|
95
114
|
There are multiple ways the include list can be defined. Here are some examples:
|
@@ -97,22 +116,22 @@ There are multiple ways the include list can be defined. Here are some examples:
|
|
97
116
|
[source,yaml]
|
98
117
|
----
|
99
118
|
# Use an empty array to ignore all files:
|
100
|
-
:
|
119
|
+
:patterns: []
|
101
120
|
|
102
121
|
# Use an array of wildcards for groups of files with similar extensions:
|
103
|
-
:
|
122
|
+
:patterns:
|
104
123
|
- "*.md"
|
105
124
|
- "*.mkd"
|
106
125
|
- "*.markdown"
|
107
126
|
|
108
127
|
# Use a mix of wild cards and relative names/paths to customized as necessary:
|
109
|
-
:
|
128
|
+
:patterns:
|
110
129
|
- "README.md"
|
111
130
|
- "docs/*.md"
|
112
131
|
- "*.markdown"
|
113
132
|
|
114
133
|
# Use a recursive glob to traverse and update all sub-directories:
|
115
|
-
:
|
134
|
+
:patterns:
|
116
135
|
- "**/*.md"
|
117
136
|
----
|
118
137
|
|
data/lib/tocer/builder.rb
CHANGED
@@ -20,7 +20,7 @@ module Tocer
|
|
20
20
|
|
21
21
|
def unbuildable?(lines) = comment_block.empty?(lines) && headers(lines).empty?
|
22
22
|
|
23
|
-
def call lines, label:
|
23
|
+
def call lines, label: Container[:configuration].label
|
24
24
|
return "" if headers(lines).empty?
|
25
25
|
|
26
26
|
url_count.clear
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "refinements/structs"
|
4
|
+
require "sod"
|
5
|
+
|
6
|
+
module Tocer
|
7
|
+
module CLI
|
8
|
+
module Actions
|
9
|
+
# Stores table of contents label.
|
10
|
+
class Label < Sod::Action
|
11
|
+
include Import[:inputs]
|
12
|
+
|
13
|
+
using Refinements::Structs
|
14
|
+
|
15
|
+
description "Set label."
|
16
|
+
|
17
|
+
on %w[-l --label], argument: "[TEXT]"
|
18
|
+
|
19
|
+
default { Container[:configuration].label }
|
20
|
+
|
21
|
+
def call(label = default) = inputs.merge!(label:)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "refinements/structs"
|
4
|
+
require "sod"
|
5
|
+
|
6
|
+
module Tocer
|
7
|
+
module CLI
|
8
|
+
module Actions
|
9
|
+
# Stores table of contents file patterns.
|
10
|
+
class Pattern < Sod::Action
|
11
|
+
include Import[:inputs]
|
12
|
+
|
13
|
+
using Refinements::Structs
|
14
|
+
|
15
|
+
description "Set file patterns."
|
16
|
+
|
17
|
+
on %w[-p --patterns], argument: "[a,b,c]"
|
18
|
+
|
19
|
+
default { Container[:configuration].patterns }
|
20
|
+
|
21
|
+
def call(patterns = default) = inputs.merge! patterns: Array(patterns)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "refinements/structs"
|
4
|
+
require "sod"
|
5
|
+
|
6
|
+
module Tocer
|
7
|
+
module CLI
|
8
|
+
module Actions
|
9
|
+
# Stores table of contents root path.
|
10
|
+
class Root < Sod::Action
|
11
|
+
include Import[:inputs]
|
12
|
+
|
13
|
+
using Refinements::Structs
|
14
|
+
|
15
|
+
description "Set root directory."
|
16
|
+
|
17
|
+
on %w[-r --root], argument: "[PATH]"
|
18
|
+
|
19
|
+
default { Container[:configuration].root_dir }
|
20
|
+
|
21
|
+
def call(path = default) = inputs.merge! root_dir: Pathname(path)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "pathname"
|
4
|
+
require "refinements/structs"
|
5
|
+
require "sod"
|
6
|
+
|
7
|
+
module Tocer
|
8
|
+
module CLI
|
9
|
+
module Commands
|
10
|
+
# Stores table of contents root path.
|
11
|
+
class Upsert < Sod::Command
|
12
|
+
include Import[:inputs, :kernel]
|
13
|
+
|
14
|
+
handle "upsert"
|
15
|
+
|
16
|
+
description "Update/insert table of contents."
|
17
|
+
|
18
|
+
on Actions::Root
|
19
|
+
on Actions::Label
|
20
|
+
on Actions::Pattern
|
21
|
+
|
22
|
+
def initialize(runner: Runner.new, **)
|
23
|
+
super(**)
|
24
|
+
@runner = runner
|
25
|
+
end
|
26
|
+
|
27
|
+
def call = runner.call inputs
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
attr_reader :runner
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/tocer/cli/shell.rb
CHANGED
@@ -1,36 +1,39 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "
|
3
|
+
require "sod"
|
4
4
|
|
5
5
|
module Tocer
|
6
6
|
module CLI
|
7
7
|
# The main Command Line Interface (CLI) object.
|
8
8
|
class Shell
|
9
|
-
include
|
9
|
+
include Import[:defaults_path, :xdg_config, :specification]
|
10
10
|
|
11
|
-
def initialize(
|
11
|
+
def initialize(context: Sod::Context, dsl: Sod, **)
|
12
12
|
super(**)
|
13
|
-
@
|
13
|
+
@context = context
|
14
|
+
@dsl = dsl
|
14
15
|
end
|
15
16
|
|
16
|
-
def call
|
17
|
-
act_on parser.call(arguments)
|
18
|
-
rescue OptionParser::ParseError => error
|
19
|
-
puts error.message
|
20
|
-
end
|
17
|
+
def call(...) = cli.call(...)
|
21
18
|
|
22
19
|
private
|
23
20
|
|
24
|
-
attr_reader :
|
21
|
+
attr_reader :context, :dsl
|
22
|
+
|
23
|
+
def cli
|
24
|
+
context = build_context
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
else logger.any { parser.to_s }
|
26
|
+
dsl.new :tocer, banner: specification.banner do
|
27
|
+
on(Sod::Prefabs::Commands::Config, context:)
|
28
|
+
on Commands::Upsert
|
29
|
+
on(Sod::Prefabs::Actions::Version, context:)
|
30
|
+
on Sod::Prefabs::Actions::Help, self
|
32
31
|
end
|
33
32
|
end
|
33
|
+
|
34
|
+
def build_context
|
35
|
+
context[defaults_path:, xdg_config:, version_label: specification.labeled_version]
|
36
|
+
end
|
34
37
|
end
|
35
38
|
end
|
36
39
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "dry/schema"
|
4
|
+
require "etcher"
|
5
|
+
|
6
|
+
Dry::Schema.load_extensions :monads
|
7
|
+
|
8
|
+
module Tocer
|
9
|
+
module Configuration
|
10
|
+
Contract = Dry::Schema.Params do
|
11
|
+
required(:label).filled :string
|
12
|
+
required(:patterns).array :string
|
13
|
+
required(:root_dir).filled Etcher::Types::Pathname
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
2
|
-
:
|
1
|
+
label: "## Table of Contents"
|
2
|
+
patterns:
|
3
3
|
- "README.md"
|
4
|
-
|
4
|
+
root_dir: "."
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tocer
|
4
|
+
module Configuration
|
5
|
+
# Defines the content of the configuration for use throughout the gem.
|
6
|
+
Model = Struct.new :label, :root_dir, :patterns do
|
7
|
+
def initialize(**)
|
8
|
+
super
|
9
|
+
self[:patterns] = Array patterns
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/tocer/container.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
require "cogger"
|
4
4
|
require "dry-container"
|
5
|
+
require "etcher"
|
6
|
+
require "runcom"
|
5
7
|
require "spek"
|
6
8
|
|
7
9
|
module Tocer
|
@@ -9,9 +11,21 @@ module Tocer
|
|
9
11
|
module Container
|
10
12
|
extend Dry::Container::Mixin
|
11
13
|
|
12
|
-
register
|
14
|
+
register :configuration do
|
15
|
+
self[:defaults].add_loader(Etcher::Loaders::YAML.new(self[:xdg_config].active))
|
16
|
+
.then { |registry| Etcher.call registry }
|
17
|
+
end
|
18
|
+
|
19
|
+
register :defaults do
|
20
|
+
Etcher::Registry.new(contract: Configuration::Contract, model: Configuration::Model)
|
21
|
+
.add_loader(Etcher::Loaders::YAML.new(self[:defaults_path]))
|
22
|
+
end
|
23
|
+
|
24
|
+
register(:inputs, memoize: true) { self[:configuration].dup }
|
25
|
+
register(:defaults_path) { Pathname(__dir__).join("configuration/defaults.yml") }
|
26
|
+
register(:xdg_config) { Runcom::Config.new "tocer/configuration.yml" }
|
13
27
|
register(:specification) { Spek::Loader.call "#{__dir__}/../../tocer.gemspec" }
|
14
28
|
register(:kernel) { Kernel }
|
15
|
-
register(:logger) { Cogger
|
29
|
+
register(:logger) { Cogger.new formatter: :emoji }
|
16
30
|
end
|
17
31
|
end
|
data/lib/tocer/rake/register.rb
CHANGED
@@ -19,8 +19,8 @@ module Tocer
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def call
|
22
|
-
desc "Insert
|
23
|
-
task :toc, %i[label
|
22
|
+
desc "Update/Insert Table of Contents"
|
23
|
+
task :toc, %i[label patterns] do |_task, arguments|
|
24
24
|
runner.call configuration.merge(arguments.to_h)
|
25
25
|
end
|
26
26
|
end
|
data/lib/tocer/runner.rb
CHANGED
@@ -5,18 +5,23 @@ require "refinements/pathnames"
|
|
5
5
|
module Tocer
|
6
6
|
# Generates/updates Table of Contents for files in root path.
|
7
7
|
class Runner
|
8
|
+
include Import[:kernel]
|
9
|
+
|
8
10
|
using Refinements::Pathnames
|
9
11
|
|
10
|
-
def initialize
|
12
|
+
def initialize(writer: Writer.new, **)
|
13
|
+
super(**)
|
11
14
|
@writer = writer
|
12
15
|
end
|
13
16
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
# :reek:FeatureEnvy
|
18
|
+
def call configuration
|
19
|
+
configuration.root_dir
|
20
|
+
.files(%({#{configuration.patterns.join ","}}))
|
21
|
+
.each do |path|
|
22
|
+
kernel.puts " #{path}"
|
23
|
+
writer.call path, label: configuration.label
|
24
|
+
end
|
20
25
|
end
|
21
26
|
|
22
27
|
private
|
data/lib/tocer/writer.rb
CHANGED
@@ -24,7 +24,7 @@ module Tocer
|
|
24
24
|
@builder = builder
|
25
25
|
end
|
26
26
|
|
27
|
-
def call path, label:
|
27
|
+
def call path, label: Container[:configuration].label
|
28
28
|
path.rewrite do |body|
|
29
29
|
lines = body.each_line.to_a
|
30
30
|
builder.prependable?(lines) ? prepend(lines, label) : replace(lines, label)
|
data/tocer.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "tocer"
|
5
|
-
spec.version = "
|
5
|
+
spec.version = "16.0.0"
|
6
6
|
spec.authors = ["Brooke Kuhlmann"]
|
7
7
|
spec.email = ["brooke@alchemists.io"]
|
8
8
|
spec.homepage = "https://alchemists.io/projects/tocer"
|
9
|
-
spec.summary = "A command line interface for generating table of contents
|
9
|
+
spec.summary = "A command line interface for generating Markdown table of contents."
|
10
10
|
spec.license = "Hippocratic-2.1"
|
11
11
|
|
12
12
|
spec.metadata = {
|
@@ -23,13 +23,16 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.cert_chain = [Gem.default_cert_path]
|
24
24
|
|
25
25
|
spec.required_ruby_version = "~> 3.2"
|
26
|
-
spec.add_dependency "cogger", "~> 0.
|
26
|
+
spec.add_dependency "cogger", "~> 0.10"
|
27
27
|
spec.add_dependency "core", "~> 0.1"
|
28
28
|
spec.add_dependency "dry-container", "~> 0.11"
|
29
|
-
spec.add_dependency "
|
30
|
-
spec.add_dependency "
|
31
|
-
spec.add_dependency "
|
32
|
-
spec.add_dependency "
|
29
|
+
spec.add_dependency "dry-schema", "~> 1.13"
|
30
|
+
spec.add_dependency "etcher", "~> 0.2"
|
31
|
+
spec.add_dependency "infusible", "~> 2.0"
|
32
|
+
spec.add_dependency "refinements", "~> 11.0"
|
33
|
+
spec.add_dependency "runcom", "~> 10.0"
|
34
|
+
spec.add_dependency "sod", "~> 0.0"
|
35
|
+
spec.add_dependency "spek", "~> 2.0"
|
33
36
|
spec.add_dependency "zeitwerk", "~> 2.6"
|
34
37
|
|
35
38
|
spec.bindir = "exe"
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tocer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 16.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brooke Kuhlmann
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
3n5C8/6Zh9DYTkpcwPSuIfAga6wf4nXc9m6JAw8AuMLaiWN/r/2s4zJsUHYERJEu
|
36
36
|
gZGm4JqtuSg8pYjPeIJxS960owq+SfuC+jxqmRA54BisFCv/0VOJi7tiJVY=
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date: 2023-
|
38
|
+
date: 2023-06-16 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: cogger
|
@@ -43,14 +43,14 @@ dependencies:
|
|
43
43
|
requirements:
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: '0.
|
46
|
+
version: '0.10'
|
47
47
|
type: :runtime
|
48
48
|
prerelease: false
|
49
49
|
version_requirements: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
51
|
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '0.
|
53
|
+
version: '0.10'
|
54
54
|
- !ruby/object:Gem::Dependency
|
55
55
|
name: core
|
56
56
|
requirement: !ruby/object:Gem::Requirement
|
@@ -79,22 +79,64 @@ dependencies:
|
|
79
79
|
- - "~>"
|
80
80
|
- !ruby/object:Gem::Version
|
81
81
|
version: '0.11'
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: dry-schema
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '1.13'
|
89
|
+
type: :runtime
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '1.13'
|
96
|
+
- !ruby/object:Gem::Dependency
|
97
|
+
name: etcher
|
98
|
+
requirement: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0.2'
|
103
|
+
type: :runtime
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0.2'
|
82
110
|
- !ruby/object:Gem::Dependency
|
83
111
|
name: infusible
|
84
112
|
requirement: !ruby/object:Gem::Requirement
|
85
113
|
requirements:
|
86
114
|
- - "~>"
|
87
115
|
- !ruby/object:Gem::Version
|
88
|
-
version: '
|
116
|
+
version: '2.0'
|
89
117
|
type: :runtime
|
90
118
|
prerelease: false
|
91
119
|
version_requirements: !ruby/object:Gem::Requirement
|
92
120
|
requirements:
|
93
121
|
- - "~>"
|
94
122
|
- !ruby/object:Gem::Version
|
95
|
-
version: '
|
123
|
+
version: '2.0'
|
96
124
|
- !ruby/object:Gem::Dependency
|
97
125
|
name: refinements
|
126
|
+
requirement: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - "~>"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '11.0'
|
131
|
+
type: :runtime
|
132
|
+
prerelease: false
|
133
|
+
version_requirements: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '11.0'
|
138
|
+
- !ruby/object:Gem::Dependency
|
139
|
+
name: runcom
|
98
140
|
requirement: !ruby/object:Gem::Requirement
|
99
141
|
requirements:
|
100
142
|
- - "~>"
|
@@ -108,33 +150,33 @@ dependencies:
|
|
108
150
|
- !ruby/object:Gem::Version
|
109
151
|
version: '10.0'
|
110
152
|
- !ruby/object:Gem::Dependency
|
111
|
-
name:
|
153
|
+
name: sod
|
112
154
|
requirement: !ruby/object:Gem::Requirement
|
113
155
|
requirements:
|
114
156
|
- - "~>"
|
115
157
|
- !ruby/object:Gem::Version
|
116
|
-
version: '
|
158
|
+
version: '0.0'
|
117
159
|
type: :runtime
|
118
160
|
prerelease: false
|
119
161
|
version_requirements: !ruby/object:Gem::Requirement
|
120
162
|
requirements:
|
121
163
|
- - "~>"
|
122
164
|
- !ruby/object:Gem::Version
|
123
|
-
version: '
|
165
|
+
version: '0.0'
|
124
166
|
- !ruby/object:Gem::Dependency
|
125
167
|
name: spek
|
126
168
|
requirement: !ruby/object:Gem::Requirement
|
127
169
|
requirements:
|
128
170
|
- - "~>"
|
129
171
|
- !ruby/object:Gem::Version
|
130
|
-
version: '
|
172
|
+
version: '2.0'
|
131
173
|
type: :runtime
|
132
174
|
prerelease: false
|
133
175
|
version_requirements: !ruby/object:Gem::Requirement
|
134
176
|
requirements:
|
135
177
|
- - "~>"
|
136
178
|
- !ruby/object:Gem::Version
|
137
|
-
version: '
|
179
|
+
version: '2.0'
|
138
180
|
- !ruby/object:Gem::Dependency
|
139
181
|
name: zeitwerk
|
140
182
|
requirement: !ruby/object:Gem::Requirement
|
@@ -164,17 +206,14 @@ files:
|
|
164
206
|
- exe/tocer
|
165
207
|
- lib/tocer.rb
|
166
208
|
- lib/tocer/builder.rb
|
167
|
-
- lib/tocer/cli/actions/
|
168
|
-
- lib/tocer/cli/actions/
|
169
|
-
- lib/tocer/cli/actions/
|
170
|
-
- lib/tocer/cli/
|
171
|
-
- lib/tocer/cli/parser.rb
|
172
|
-
- lib/tocer/cli/parsers/core.rb
|
173
|
-
- lib/tocer/cli/parsers/flag.rb
|
209
|
+
- lib/tocer/cli/actions/label.rb
|
210
|
+
- lib/tocer/cli/actions/pattern.rb
|
211
|
+
- lib/tocer/cli/actions/root.rb
|
212
|
+
- lib/tocer/cli/commands/upsert.rb
|
174
213
|
- lib/tocer/cli/shell.rb
|
175
|
-
- lib/tocer/configuration/
|
214
|
+
- lib/tocer/configuration/contract.rb
|
176
215
|
- lib/tocer/configuration/defaults.yml
|
177
|
-
- lib/tocer/configuration/
|
216
|
+
- lib/tocer/configuration/model.rb
|
178
217
|
- lib/tocer/container.rb
|
179
218
|
- lib/tocer/elements/comment_block.rb
|
180
219
|
- lib/tocer/import.rb
|
@@ -212,8 +251,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
212
251
|
- !ruby/object:Gem::Version
|
213
252
|
version: '0'
|
214
253
|
requirements: []
|
215
|
-
rubygems_version: 3.4.
|
254
|
+
rubygems_version: 3.4.14
|
216
255
|
signing_key:
|
217
256
|
specification_version: 4
|
218
|
-
summary: A command line interface for generating table of contents
|
257
|
+
summary: A command line interface for generating Markdown table of contents.
|
219
258
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|
@@ -1,33 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Tocer
|
4
|
-
module CLI
|
5
|
-
module Actions
|
6
|
-
# Handles the config action.
|
7
|
-
class Config
|
8
|
-
include Tocer::Import[:kernel, :logger]
|
9
|
-
|
10
|
-
def initialize(client: Configuration::Loader::CLIENT, **)
|
11
|
-
super(**)
|
12
|
-
@client = client
|
13
|
-
end
|
14
|
-
|
15
|
-
def call selection
|
16
|
-
case selection
|
17
|
-
when :edit then edit
|
18
|
-
when :view then view
|
19
|
-
else logger.error { "Invalid configuration selection: #{selection}." }
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
attr_reader :client
|
26
|
-
|
27
|
-
def edit = kernel.system("$EDITOR #{client.current}")
|
28
|
-
|
29
|
-
def view = kernel.system("cat #{client.current}")
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "dry/container"
|
4
|
-
|
5
|
-
module Tocer
|
6
|
-
module CLI
|
7
|
-
module Actions
|
8
|
-
# Provides a single container with application and action specific dependencies.
|
9
|
-
module Container
|
10
|
-
extend Dry::Container::Mixin
|
11
|
-
|
12
|
-
merge Tocer::Container
|
13
|
-
|
14
|
-
register(:config) { Config.new }
|
15
|
-
register(:insert) { Insert.new }
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Tocer
|
4
|
-
module CLI
|
5
|
-
module Actions
|
6
|
-
# Handles the insert action.
|
7
|
-
class Insert
|
8
|
-
include Tocer::Import[:logger]
|
9
|
-
|
10
|
-
def initialize(runner: Runner.new, **)
|
11
|
-
super(**)
|
12
|
-
@runner = runner
|
13
|
-
end
|
14
|
-
|
15
|
-
def call configuration
|
16
|
-
runner.call(configuration) { |path| logger.info { " #{path}" } }
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
attr_reader :runner
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
data/lib/tocer/cli/parser.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "core"
|
4
|
-
require "optparse"
|
5
|
-
|
6
|
-
module Tocer
|
7
|
-
module CLI
|
8
|
-
# Assembles and parses all Command Line Interface (CLI) options.
|
9
|
-
class Parser
|
10
|
-
include Import[:configuration]
|
11
|
-
|
12
|
-
CLIENT = OptionParser.new nil, 40, " "
|
13
|
-
SECTIONS = [Parsers::Core, Parsers::Flag].freeze # Order matters.
|
14
|
-
|
15
|
-
def initialize(sections: SECTIONS, client: CLIENT, **)
|
16
|
-
super(**)
|
17
|
-
@sections = sections
|
18
|
-
@client = client
|
19
|
-
@configuration_duplicate = configuration.dup
|
20
|
-
end
|
21
|
-
|
22
|
-
def call arguments = Core::EMPTY_ARRAY
|
23
|
-
sections.each { |parser| parser.call configuration_duplicate, client: }
|
24
|
-
client.parse arguments
|
25
|
-
configuration_duplicate.freeze
|
26
|
-
end
|
27
|
-
|
28
|
-
def to_s = client.to_s
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
attr_reader :sections, :client, :configuration_duplicate
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,74 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "core"
|
4
|
-
require "refinements/structs"
|
5
|
-
|
6
|
-
module Tocer
|
7
|
-
module CLI
|
8
|
-
module Parsers
|
9
|
-
# Handles parsing of Command Line Interface (CLI) core options.
|
10
|
-
class Core
|
11
|
-
include Import[:specification]
|
12
|
-
|
13
|
-
using Refinements::Structs
|
14
|
-
|
15
|
-
def self.call(...) = new(...).call
|
16
|
-
|
17
|
-
def initialize(configuration = Container[:configuration], client: Parser::CLIENT, **)
|
18
|
-
super(**)
|
19
|
-
@configuration = configuration
|
20
|
-
@client = client
|
21
|
-
end
|
22
|
-
|
23
|
-
def call arguments = ::Core::EMPTY_ARRAY
|
24
|
-
client.banner = specification.labeled_summary
|
25
|
-
client.separator "\nUSAGE:\n"
|
26
|
-
collate
|
27
|
-
client.parse arguments
|
28
|
-
configuration
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
attr_reader :configuration, :client
|
34
|
-
|
35
|
-
def collate = private_methods.sort.grep(/add_/).each { |method| __send__ method }
|
36
|
-
|
37
|
-
def add_config
|
38
|
-
client.on(
|
39
|
-
"-c",
|
40
|
-
"--config ACTION",
|
41
|
-
%i[edit view],
|
42
|
-
"Manage gem configuration: edit or view."
|
43
|
-
) do |action|
|
44
|
-
configuration.merge! action_config: action
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def add_insert
|
49
|
-
root_dir = configuration.root_dir
|
50
|
-
|
51
|
-
client.on(
|
52
|
-
"-i",
|
53
|
-
"--insert [PATH]",
|
54
|
-
%(Insert/update table of contents. Default: "#{root_dir}".)
|
55
|
-
) do |path|
|
56
|
-
configuration.merge! action_insert: true, root_dir: path || root_dir
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def add_version
|
61
|
-
client.on "-v", "--version", "Show gem version." do
|
62
|
-
configuration.merge! action_version: true
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def add_help
|
67
|
-
client.on "-h", "--help", "Show this message." do
|
68
|
-
configuration.merge! action_help: true
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "core"
|
4
|
-
require "refinements/structs"
|
5
|
-
|
6
|
-
module Tocer
|
7
|
-
module CLI
|
8
|
-
module Parsers
|
9
|
-
# Handles parsing of Command Line Interface (CLI) flags.
|
10
|
-
class Flag
|
11
|
-
using Refinements::Structs
|
12
|
-
|
13
|
-
def self.call(...) = new(...).call
|
14
|
-
|
15
|
-
def initialize configuration = Container[:configuration], client: Parser::CLIENT
|
16
|
-
@configuration = configuration
|
17
|
-
@client = client
|
18
|
-
end
|
19
|
-
|
20
|
-
def call arguments = ::Core::EMPTY_ARRAY
|
21
|
-
client.separator "\nOPTIONS:\n"
|
22
|
-
private_methods.sort.grep(/add_/).each { |method| __send__ method }
|
23
|
-
client.parse arguments
|
24
|
-
configuration
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
attr_reader :configuration, :client
|
30
|
-
|
31
|
-
def add_label
|
32
|
-
client.on(
|
33
|
-
"--label [LABEL]",
|
34
|
-
%(Add label. Default: "#{configuration.label}".)
|
35
|
-
) do |value|
|
36
|
-
configuration.merge! label: value if value
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def add_include
|
41
|
-
client.on(
|
42
|
-
"--includes [a,b,c]",
|
43
|
-
Array,
|
44
|
-
%(Add include patterns. Default: #{configuration.includes}.)
|
45
|
-
) do |items|
|
46
|
-
configuration.merge! includes: items if items
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Tocer
|
4
|
-
module Configuration
|
5
|
-
# Defines the content of the configuration for use throughout the gem.
|
6
|
-
Content = Struct.new(
|
7
|
-
:action_config,
|
8
|
-
:action_help,
|
9
|
-
:action_insert,
|
10
|
-
:action_version,
|
11
|
-
:includes,
|
12
|
-
:label,
|
13
|
-
:root_dir,
|
14
|
-
keyword_init: true
|
15
|
-
) do
|
16
|
-
def initialize *arguments
|
17
|
-
super
|
18
|
-
freeze
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "pathname"
|
4
|
-
require "refinements/structs"
|
5
|
-
require "runcom"
|
6
|
-
require "yaml"
|
7
|
-
|
8
|
-
module Tocer
|
9
|
-
module Configuration
|
10
|
-
# Represents the fully assembled Command Line Interface (CLI) configuration.
|
11
|
-
class Loader
|
12
|
-
using Refinements::Structs
|
13
|
-
|
14
|
-
DEFAULTS = YAML.load_file(Pathname(__dir__).join("defaults.yml")).freeze
|
15
|
-
CLIENT = Runcom::Config.new "tocer/configuration.yml", defaults: DEFAULTS
|
16
|
-
|
17
|
-
def self.call = new.call
|
18
|
-
|
19
|
-
def self.with_defaults = new(client: DEFAULTS)
|
20
|
-
|
21
|
-
def initialize content: Content.new, client: CLIENT
|
22
|
-
@content = content
|
23
|
-
@client = client
|
24
|
-
end
|
25
|
-
|
26
|
-
def call = content.merge(**client.to_h)
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
attr_reader :content, :client
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|