tocer 3.1.1 → 3.2.0
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
- checksums.yaml.gz.sig +1 -1
- data.tar.gz.sig +2 -4
- data/README.md +39 -8
- data/lib/tocer.rb +1 -0
- data/lib/tocer/builder.rb +13 -1
- data/lib/tocer/cli.rb +36 -7
- data/lib/tocer/identity.rb +1 -1
- data/lib/tocer/parsers/header.rb +2 -4
- data/lib/tocer/runner.rb +32 -0
- data/lib/tocer/writer.rb +1 -1
- metadata +5 -4
- metadata.gz.sig +1 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b7d0d42ffc60ae31c41a13f98571d2aa60b692b
|
4
|
+
data.tar.gz: 2b3ee230d78cb78aaf77664bb2c3e1f0dae61fb5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6cb3b159d8a724a0f6384ae1611d77cd1466b6655be90e1f9ad6f32fea7b4501604b29af09996f921dce886c3382583fe9d6629ccc5fe1b263301d83bd9bb74
|
7
|
+
data.tar.gz: 3b081110b49be864e15c4c4ba06c5596bba1c890e75634e448221aa77c61f91ab416861099f1fb7d5b7e7bd5906273a067d662ff7523845d369b33a23a9ec23e
|
checksums.yaml.gz.sig
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
������}=IG�u�y]�wz����8$E�������x�]�� �,�k&�p�*u
|
data.tar.gz.sig
CHANGED
data/README.md
CHANGED
@@ -35,8 +35,11 @@ Markdown files.
|
|
35
35
|
- Supports Markdown ATX-style headers. Example: `# Header`.
|
36
36
|
- Does not support header suffixes. Example: `# Header #`.
|
37
37
|
- Does not support header prefixes without spaces. Example: `#Header`.
|
38
|
+
- Supports table of contents generation for single or multiple files.
|
39
|
+
- Supports custom label. Default: "# Table of Contents".
|
40
|
+
- Supports whitelist filtering. Default: ".md".
|
38
41
|
- Prepends table of contents to Markdown documents that don't have table of contents.
|
39
|
-
-
|
42
|
+
- Rebuilds Markdown documents that have existing table of contents.
|
40
43
|
|
41
44
|
# Requirements
|
42
45
|
|
@@ -62,22 +65,30 @@ For an insecure install, type the following (not recommended):
|
|
62
65
|
|
63
66
|
## Command Line Interface (CLI)
|
64
67
|
|
65
|
-
From the command line, type: `tocer help`
|
68
|
+
From the command line, type: `tocer --help`
|
66
69
|
|
67
70
|
tocer -c, [--config] # Manage gem configuration.
|
68
71
|
tocer -g, [--generate=PATH] # Generate table of contents.
|
69
72
|
tocer -h, [--help=COMMAND] # Show this message or get help for a command.
|
70
73
|
tocer -v, [--version] # Show gem version.
|
71
74
|
|
72
|
-
|
75
|
+
For specific `--generate` options, run `tocer --help --generate` to see the following:
|
76
|
+
|
77
|
+
-l, [--label=LABEL] # Label
|
78
|
+
# Default: # Table of Contents
|
79
|
+
-w, [--whitelist=one two three] # File whitelist
|
80
|
+
# Default: [".md"]
|
81
|
+
|
82
|
+
To generate the table of contents at a specific position within your Markdown files, add the
|
83
|
+
following lines to your file(s) prior to generation:
|
73
84
|
|
74
85
|
```
|
75
86
|
<!-- Tocer[start] -->
|
76
87
|
<!-- Tocer[finish] -->
|
77
88
|
```
|
78
89
|
|
79
|
-
Alternatively, you can run `tocer -g <
|
80
|
-
will prepend the above to your file, complete with an auto-generated table of contents.
|
90
|
+
Alternatively, you can run `tocer -g <directory>` on files that do not have Tocer support and it
|
91
|
+
will prepend the above to your file(s), complete with an auto-generated table of contents.
|
81
92
|
|
82
93
|
In the case that Tocer has already auto-generated a table of contents for a Markdown file, the
|
83
94
|
existing table of contents has become stale, or placement of the table of contents has changed you
|
@@ -88,20 +99,40 @@ can re-run Tocer on that file to auto-update it with new table of contents.
|
|
88
99
|
If desired, this gem supports global customization via the `~/.tocerrc` file. Order of precedence is
|
89
100
|
determined in the following order (with the last one taking top priority):
|
90
101
|
|
91
|
-
0. Global `~/.tocerrc`.
|
92
|
-
0.
|
102
|
+
0. Global: `~/.tocerrc`.
|
103
|
+
0. Local: `<project_root>/.tocerrc`.
|
104
|
+
0. CLI: `tocer --generate . --label "## Custom Label" --whitelist README.md`
|
93
105
|
|
94
|
-
Any
|
106
|
+
Any settings provided to the CLI during runtime will trump the global setting. The global setting is
|
95
107
|
the weakest of all but great for situations where custom settings should be applied to *all*
|
96
108
|
projects.
|
97
109
|
|
98
110
|
The `~/.tocerrc` uses the following default settings:
|
99
111
|
|
100
112
|
:label: "# Table of Contents"
|
113
|
+
:whitelist: [".md"]
|
101
114
|
|
102
115
|
Each `~/.tocerrc` setting can be configured as follows:
|
103
116
|
|
104
117
|
- `label`: The header label for the table of contents. Default: "# Table of Contents".
|
118
|
+
- `whitelist`: The list of *included* files. Default: ".md".
|
119
|
+
|
120
|
+
There are multiple ways the *whitelist* can be defined. Here are some examples:
|
121
|
+
|
122
|
+
# Use an empty array to include *all* files.
|
123
|
+
:whitelist: []
|
124
|
+
|
125
|
+
# Use an array of wildcards for groups of files with similar extensions:
|
126
|
+
:whitelist:
|
127
|
+
- .md
|
128
|
+
- .mkd
|
129
|
+
- .markdown
|
130
|
+
|
131
|
+
# Use a mix of wild cards and relative paths to customized as necessary:
|
132
|
+
:whitelist:
|
133
|
+
- README.md
|
134
|
+
- docs/*.md
|
135
|
+
- .markdown
|
105
136
|
|
106
137
|
# Tests
|
107
138
|
|
data/lib/tocer.rb
CHANGED
data/lib/tocer/builder.rb
CHANGED
@@ -3,15 +3,21 @@
|
|
3
3
|
module Tocer
|
4
4
|
# Builds a table of contents for a Markdown document.
|
5
5
|
class Builder
|
6
|
+
CODE_BLOCK_PUNCTUATION = "```"
|
7
|
+
|
6
8
|
def initialize lines, label: "# Table of Contents", comment_block: Elements::CommentBlock
|
7
9
|
@lines = lines
|
8
10
|
@label = label
|
9
11
|
@comment_block = comment_block.new
|
10
12
|
@url_count = Hash.new { |hash, key| hash[key] = 0 }
|
13
|
+
@code_block = false
|
11
14
|
end
|
12
15
|
|
13
16
|
def headers
|
14
|
-
lines.select
|
17
|
+
lines.select do |line|
|
18
|
+
toggle_code_block line
|
19
|
+
line.start_with?(Parsers::Header::PUNCTUATION) && !code_block
|
20
|
+
end
|
15
21
|
end
|
16
22
|
|
17
23
|
def build
|
@@ -28,6 +34,12 @@ module Tocer
|
|
28
34
|
private
|
29
35
|
|
30
36
|
attr_reader :lines, :label, :comment_block, :url_count
|
37
|
+
attr_accessor :code_block
|
38
|
+
|
39
|
+
def toggle_code_block line
|
40
|
+
return unless line.start_with? CODE_BLOCK_PUNCTUATION
|
41
|
+
self.code_block = !code_block
|
42
|
+
end
|
31
43
|
|
32
44
|
def acquire_transfomer header
|
33
45
|
if header =~ /\[.+\]\(.+\)/
|
data/lib/tocer/cli.rb
CHANGED
@@ -15,7 +15,8 @@ module Tocer
|
|
15
15
|
|
16
16
|
def self.configuration
|
17
17
|
Runcom::Configuration.new file_name: Identity.file_name, defaults: {
|
18
|
-
label: "# Table of Contents"
|
18
|
+
label: "# Table of Contents",
|
19
|
+
whitelist: %w[.md]
|
19
20
|
}
|
20
21
|
end
|
21
22
|
|
@@ -25,10 +26,26 @@ module Tocer
|
|
25
26
|
|
26
27
|
desc "-g, [--generate=PATH]", "Generate table of contents."
|
27
28
|
map %w[-g --generate] => :generate
|
28
|
-
method_option :label,
|
29
|
+
method_option :label,
|
30
|
+
aliases: "-l",
|
31
|
+
desc: "Label",
|
32
|
+
type: :string,
|
33
|
+
default: configuration.to_h.fetch(:label)
|
34
|
+
method_option :whitelist,
|
35
|
+
aliases: "-w",
|
36
|
+
desc: "File whitelist",
|
37
|
+
type: :array,
|
38
|
+
default: configuration.to_h.fetch(:whitelist)
|
29
39
|
def generate path
|
30
|
-
|
31
|
-
|
40
|
+
configuration = build_configuration path, options.label, options.whitelist
|
41
|
+
runner = build_runner path, configuration
|
42
|
+
files = runner.files
|
43
|
+
|
44
|
+
runner.run
|
45
|
+
return if files.empty?
|
46
|
+
|
47
|
+
say "Processed table of contents for:"
|
48
|
+
files.each { |file| say " #{file}" }
|
32
49
|
end
|
33
50
|
|
34
51
|
desc "-c, [--config]", %(Manage gem configuration ("#{configuration.computed_path}").)
|
@@ -64,9 +81,21 @@ module Tocer
|
|
64
81
|
|
65
82
|
private
|
66
83
|
|
67
|
-
def
|
68
|
-
|
69
|
-
|
84
|
+
def build_configuration path, label, whitelist
|
85
|
+
if Pathname(path).file?
|
86
|
+
warn "[DEPRECATION]: File paths are deprecated, use directory paths instead."
|
87
|
+
self.class.configuration.merge label: label, whitelist: [path]
|
88
|
+
else
|
89
|
+
self.class.configuration.merge label: label, whitelist: whitelist
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def build_runner path, configuration
|
94
|
+
if Pathname(path).file?
|
95
|
+
Runner.new ".", configuration: configuration
|
96
|
+
else
|
97
|
+
Runner.new path, configuration: configuration
|
98
|
+
end
|
70
99
|
end
|
71
100
|
end
|
72
101
|
end
|
data/lib/tocer/identity.rb
CHANGED
data/lib/tocer/parsers/header.rb
CHANGED
@@ -4,16 +4,14 @@ module Tocer
|
|
4
4
|
module Parsers
|
5
5
|
# Represents a Markdown header.
|
6
6
|
class Header
|
7
|
-
|
8
|
-
"#"
|
9
|
-
end
|
7
|
+
PUNCTUATION = "#"
|
10
8
|
|
11
9
|
def initialize markdown
|
12
10
|
@markdown = markdown
|
13
11
|
end
|
14
12
|
|
15
13
|
def prefix
|
16
|
-
String markdown[/#{
|
14
|
+
String markdown[/#{PUNCTUATION}{1,}/]
|
17
15
|
end
|
18
16
|
|
19
17
|
def content
|
data/lib/tocer/runner.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "pathname"
|
4
|
+
|
5
|
+
module Tocer
|
6
|
+
# Generates/updates Table of Contents for files in given path.
|
7
|
+
class Runner
|
8
|
+
def initialize path = "", configuration: {}, writer: Writer
|
9
|
+
@path = Pathname path
|
10
|
+
@configuration = configuration
|
11
|
+
@writer = writer
|
12
|
+
end
|
13
|
+
|
14
|
+
def files
|
15
|
+
return [] unless path.exist?
|
16
|
+
glob = whitelist.empty? ? %(#{path}/**/*) : %(#{path}/**/*{#{whitelist.join ","}})
|
17
|
+
Pathname.glob(glob).select(&:file?)
|
18
|
+
end
|
19
|
+
|
20
|
+
def run
|
21
|
+
files.each { |file| writer.new(file, label: configuration.fetch(:label)).write }
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
attr_reader :path, :configuration, :writer
|
27
|
+
|
28
|
+
def whitelist
|
29
|
+
Array configuration.fetch(:whitelist)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/tocer/writer.rb
CHANGED
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: 3.
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brooke Kuhlmann
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
n/LUZ1dKhIHzfKx1B4+TEIefArObGfkLIDM8+Dq1RX7TF1k81Men7iu4MgE9bYBn
|
31
31
|
3dE+xI3FdB5gWcdWxdtgRCmWjtXeYYyb4z6NQQ==
|
32
32
|
-----END CERTIFICATE-----
|
33
|
-
date: 2016-
|
33
|
+
date: 2016-12-03 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: thor
|
@@ -108,14 +108,14 @@ dependencies:
|
|
108
108
|
requirements:
|
109
109
|
- - "~>"
|
110
110
|
- !ruby/object:Gem::Version
|
111
|
-
version: '8.
|
111
|
+
version: '8.1'
|
112
112
|
type: :development
|
113
113
|
prerelease: false
|
114
114
|
version_requirements: !ruby/object:Gem::Requirement
|
115
115
|
requirements:
|
116
116
|
- - "~>"
|
117
117
|
- !ruby/object:Gem::Version
|
118
|
-
version: '8.
|
118
|
+
version: '8.1'
|
119
119
|
- !ruby/object:Gem::Dependency
|
120
120
|
name: pry
|
121
121
|
requirement: !ruby/object:Gem::Requirement
|
@@ -320,6 +320,7 @@ files:
|
|
320
320
|
- lib/tocer/elements/comment_block.rb
|
321
321
|
- lib/tocer/identity.rb
|
322
322
|
- lib/tocer/parsers/header.rb
|
323
|
+
- lib/tocer/runner.rb
|
323
324
|
- lib/tocer/transformers/link.rb
|
324
325
|
- lib/tocer/transformers/text.rb
|
325
326
|
- lib/tocer/writer.rb
|
metadata.gz.sig
CHANGED