tocbot 0.1.0 → 0.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
- data/CHANGELOG.md +21 -0
- data/README.md +33 -16
- data/TOCBot.gemspec +3 -0
- data/exe/tocbot +13 -0
- data/lib/TOCBot.rb +30 -4
- data/lib/TOCBot/version.rb +1 -1
- data/testing/tocbot +13 -0
- metadata +31 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1933941f9999a3850a2216845b4cb8dfe01736d42682657fe2806d6153808a9e
|
4
|
+
data.tar.gz: 396434e53f923a8846aa7530780b8c5bd44df69e7c610c99313158c4fd032313
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6c11c7682c8101edcfbc448df64827239ab2d6d3bf71d467c03baba66e5615c22678470b5655e2e9b593852dbfc9e80e998291058aa985d86bf790a59169003
|
7
|
+
data.tar.gz: d11ea043bd667213705c1539fbd3e9193fe9dd6fd0b2c0823b66d844b9f9c3d90b62cab34bdb5652e246a35c0b7493295cfc5288acafe79d304b53a03130ec74
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
|
6
|
+
This changelog was automatically generated using [Sonny](https://github.com/WolfSoftware/sonny) by [Wolf Software](https://github.com/WolfSoftware)
|
7
|
+
|
8
|
+
### [v0.2.0](https://github.com/WolfSoftware/tocbot/compare/v0.1.0...master)
|
9
|
+
|
10
|
+
> Released on February, 4th 2020
|
11
|
+
|
12
|
+
- Fix rubocop errors generated by travis [`[e5be94d]`](https://github.com/WolfSoftware/tocbot/commit/e5be94df144e1ebf5f53cb0337fd71880d6ddd98) [`[TGWolf]`](https://github.com/TGWolf)
|
13
|
+
|
14
|
+
- Added user specified separators, user specified starting level and user specified depth (To-Do list) [`[ad458e3]`](https://github.com/WolfSoftware/tocbot/commit/ad458e3a780eb86e1fb52368388b228e985584ca) [`[TGWolf]`](https://github.com/TGWolf)
|
15
|
+
|
16
|
+
### [v0.1.0](https://github.com/WolfSoftware/tocbot/releases/v0.1.0)
|
17
|
+
|
18
|
+
> Released on February, 3rd 2020
|
19
|
+
|
20
|
+
- initial: Initial commit [`[7407fa4]`](https://github.com/WolfSoftware/tocbot/commit/7407fa482ee6cc04a6075dc1ee9417390c1e295e) [`[TGWolf]`](https://github.com/TGWolf)
|
21
|
+
|
data/README.md
CHANGED
@@ -12,24 +12,27 @@
|
|
12
12
|
<a name="tocbot"></a>
|
13
13
|
# TOCBot
|
14
14
|
|
15
|
-
<!--
|
15
|
+
<!--TOCBot-->
|
16
16
|
* [TOCBot](#tocbot)
|
17
17
|
* [Introduction](#introduction)
|
18
18
|
* [Installation](#installation)
|
19
|
-
* [
|
20
|
-
* [
|
19
|
+
* [Command Line Usage](#command-line-usage)
|
20
|
+
* [Basic Usage](#basic-usage)
|
21
|
+
* [Advanced Usage](#advanced-usage)
|
21
22
|
* [Contributing to TOCBot](#contributing-to-tocbot)
|
22
23
|
* [Setup](#setup)
|
23
24
|
* [Testing](#testing)
|
24
25
|
* [To-Do List](#to-do-list)
|
25
|
-
<!--
|
26
|
+
<!--TOCBot-->
|
26
27
|
|
27
28
|
<a name="introduction"></a>
|
28
29
|
## Introduction
|
29
30
|
|
30
|
-
TOCBot is a Table of Content (TOC) creation robot. It works by reading a markdown file and identifying all of the headers
|
31
|
+
TOCBot is a Table of Content (TOC) creation robot. It works by reading a markdown file and identifying all of the headers and creating a table of contents based on those headers.
|
31
32
|
|
32
|
-
|
33
|
+
Default it includes all levels (# = level 1, ## = level 2, etc), and will include headers up to 5 levels deep.
|
34
|
+
|
35
|
+
It will insert the table of contents between the separators that are placed in the file. The default separator is <!--TOCBot-->.
|
33
36
|
|
34
37
|
> There must be TWO separators, one to open the table of contents and one to close it.
|
35
38
|
|
@@ -44,8 +47,19 @@ Installing TOCBot is very simple, just execute the following command.
|
|
44
47
|
gem install tocbot
|
45
48
|
```
|
46
49
|
|
50
|
+
<a name="command-line-usage"></a>
|
51
|
+
## Command Line Usage
|
52
|
+
|
53
|
+
| Option | Purpose | Default Value |
|
54
|
+
| ------ | ------- |:-------------:|
|
55
|
+
| -h or --help | Show the help message | N/A |
|
56
|
+
| -d or --depth | How many levels deep to add to the TOC. | 5 |
|
57
|
+
| -f or --filename | The name of the file to process. | README.md |
|
58
|
+
| -l or --level | The level of heading to start with. | 1 |
|
59
|
+
| -s or --separator | The separator used to show where to insert the TOC. | <!--TOCBot--> |
|
60
|
+
|
47
61
|
<a name="basic-usage"></a>
|
48
|
-
|
62
|
+
### Basic Usage
|
49
63
|
|
50
64
|
You can execute TOCBot by simple running
|
51
65
|
|
@@ -53,13 +67,15 @@ You can execute TOCBot by simple running
|
|
53
67
|
tocbot
|
54
68
|
```
|
55
69
|
|
56
|
-
<a name="
|
57
|
-
###
|
70
|
+
<a name="advanced-usage"></a>
|
71
|
+
### Advanced Usage
|
58
72
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
73
|
+
Start with level 2 headers (exclude all level 1 headers), and only include 3 levels of headers.
|
74
|
+
|
75
|
+
```
|
76
|
+
tocbot -s 2 -d 3
|
77
|
+
```
|
78
|
+
> The depth is measures from the start so the above example will include header levels 2, 3 & 4.
|
63
79
|
|
64
80
|
<a name="contributing-to-tocbot"></a>
|
65
81
|
## Contributing to TOCBot
|
@@ -82,6 +98,7 @@ For further information please refer to the [contributing](https://github.com/Wo
|
|
82
98
|
<a name="to-do-list"></a>
|
83
99
|
## To-Do List
|
84
100
|
|
85
|
-
- [
|
86
|
-
- [
|
87
|
-
- [
|
101
|
+
- [X] Allow users to specify the separator
|
102
|
+
- [X] Allow users to specify how deep into the headers to go
|
103
|
+
- [X] Allow users to specify levels to skip
|
104
|
+
|
data/TOCBot.gemspec
CHANGED
@@ -22,4 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency 'bundler', '>= 1.17', '< 3.0'
|
23
23
|
spec.add_development_dependency 'rake', '~> 10.0'
|
24
24
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
25
|
+
spec.add_development_dependency 'tty-spinner', '~> 0.9.0'
|
26
|
+
|
27
|
+
spec.add_runtime_dependency 'tty-spinner', '~> 0.9.0'
|
25
28
|
end
|
data/exe/tocbot
CHANGED
@@ -36,9 +36,22 @@ def process_arguments
|
|
36
36
|
puts opts
|
37
37
|
exit(1)
|
38
38
|
end
|
39
|
+
|
40
|
+
opts.on('-d', '--depth number', 'How many levels deep to add to the TOC. [default: 5]') do |depth|
|
41
|
+
options[:depth] = depth.to_i
|
42
|
+
end
|
43
|
+
|
39
44
|
opts.on('-f', '--filename string', 'The name of the file to process. [default: README.md]') do |filename|
|
40
45
|
options[:filename] = filename
|
41
46
|
end
|
47
|
+
|
48
|
+
opts.on('-l', '--level number', 'The level of heading to start with. [default: 1]') do |level|
|
49
|
+
options[:level] = level.to_i
|
50
|
+
end
|
51
|
+
|
52
|
+
opts.on('-s', '--separator string', 'The separator used to show where to insert the TOC. [default: <!--TOCBot-->]') do |separator|
|
53
|
+
options[:separator] = separator
|
54
|
+
end
|
42
55
|
end
|
43
56
|
|
44
57
|
begin
|
data/lib/TOCBot.rb
CHANGED
@@ -1,13 +1,19 @@
|
|
1
1
|
require 'TOCBot/version'
|
2
2
|
|
3
|
+
require 'tty-spinner'
|
4
|
+
|
3
5
|
#
|
4
6
|
# To follow
|
5
7
|
#
|
6
8
|
class TOCBot
|
7
9
|
def initialize(options = {})
|
8
|
-
@separator = '<!--
|
10
|
+
@separator = '<!--TOCBot-->'
|
11
|
+
@level = 1
|
12
|
+
@depth = 5
|
9
13
|
|
10
14
|
@separator = options[:separator] unless options[:separator].nil?
|
15
|
+
@level = options[:level].to_i unless options[:level].nil?
|
16
|
+
@depth = options[:depth].to_i unless options[:depth].nil?
|
11
17
|
end
|
12
18
|
|
13
19
|
def load_file(filename)
|
@@ -78,14 +84,21 @@ class TOCBot
|
|
78
84
|
next if line.start_with?('<a name="')
|
79
85
|
|
80
86
|
if line.scan(/^\#{1,}.*/m).size.positive?
|
87
|
+
|
81
88
|
m = line.match(/^(\#{1,})(.*)/)
|
82
89
|
hashes = m[1].length
|
83
90
|
text = m[2].strip
|
84
91
|
|
85
|
-
|
92
|
+
if hashes >= @level
|
93
|
+
hashes = hashes - @level + 1
|
86
94
|
|
87
|
-
|
88
|
-
|
95
|
+
if hashes <= @depth
|
96
|
+
link = text.gsub(/ /, '-').downcase
|
97
|
+
|
98
|
+
toc << ' ' * (hashes - 1) + "* [#{text}](##{link})"
|
99
|
+
processed << "<a name=\"#{link}\"></a>"
|
100
|
+
end
|
101
|
+
end
|
89
102
|
end
|
90
103
|
|
91
104
|
#
|
@@ -97,10 +110,23 @@ class TOCBot
|
|
97
110
|
end
|
98
111
|
|
99
112
|
def process_file(filename)
|
113
|
+
spinners = TTY::Spinner::Multi.new("[:spinner] TOCBot is generating your Table of Contents (TOC) (Start Level: #{@level}, Depth: #{@depth})")
|
114
|
+
|
115
|
+
sp1 = spinners.register '[:spinner] Loading File'
|
116
|
+
sp2 = spinners.register '[:spinner] Processing File'
|
117
|
+
sp3 = spinners.register '[:spinner] Writing File'
|
118
|
+
|
119
|
+
sp1.auto_spin
|
120
|
+
sp2.auto_spin
|
121
|
+
sp3.auto_spin
|
122
|
+
|
100
123
|
lines = load_file(filename)
|
124
|
+
sp1.success
|
101
125
|
|
102
126
|
processed, toc = process_lines(lines)
|
127
|
+
sp2.success
|
103
128
|
|
104
129
|
write_file(filename, processed, toc)
|
130
|
+
sp3.success
|
105
131
|
end
|
106
132
|
end
|
data/lib/TOCBot/version.rb
CHANGED
data/testing/tocbot
CHANGED
@@ -39,9 +39,22 @@ def process_arguments
|
|
39
39
|
puts opts
|
40
40
|
exit(1)
|
41
41
|
end
|
42
|
+
|
43
|
+
opts.on('-d', '--depth number', 'How many levels deep to add to the TOC. [default: 5]') do |depth|
|
44
|
+
options[:depth] = depth.to_i
|
45
|
+
end
|
46
|
+
|
42
47
|
opts.on('-f', '--filename string', 'The name of the file to process. [default: README.md]') do |filename|
|
43
48
|
options[:filename] = filename
|
44
49
|
end
|
50
|
+
|
51
|
+
opts.on('-l', '--level number', 'The level of heading to start with. [default: 1]') do |level|
|
52
|
+
options[:level] = level.to_i
|
53
|
+
end
|
54
|
+
|
55
|
+
opts.on('-s', '--separator string', 'The separator used to show where to insert the TOC. [default: <!--TOCBot-->]') do |separator|
|
56
|
+
options[:separator] = separator
|
57
|
+
end
|
45
58
|
end
|
46
59
|
|
47
60
|
begin
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tocbot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Gurney aka Wolf
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-02-
|
11
|
+
date: 2020-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -58,6 +58,34 @@ dependencies:
|
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '3.0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: tty-spinner
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 0.9.0
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 0.9.0
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: tty-spinner
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 0.9.0
|
82
|
+
type: :runtime
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 0.9.0
|
61
89
|
description: A gem for automatically generating a table of contents in a markdown
|
62
90
|
file.
|
63
91
|
email:
|
@@ -72,6 +100,7 @@ files:
|
|
72
100
|
- ".rspec"
|
73
101
|
- ".rubocop.yml"
|
74
102
|
- ".travis.yml"
|
103
|
+
- CHANGELOG.md
|
75
104
|
- CODEOWNERS
|
76
105
|
- CONTRIBUTING.md
|
77
106
|
- Gemfile
|