tocbot 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8bcafde7a6c86b83780bfcc5631889dbd0b9309114aa9425661213f2875ab8b5
4
+ data.tar.gz: d715becc5115b56732253279ef2f6bd5c33b42e05e5873294f05c4f4518cd9d2
5
+ SHA512:
6
+ metadata.gz: 79234107e404d2a920d7abd26dd089f46295d88fbec7853876effc8382a0f313599005f6cfe1bfb60dff5ff5cf2ff12f47218e81435ae9f3b1a602e4e3a58658
7
+ data.tar.gz: 678bcde4a2160fe77c1ddc86fb0af999f31c9d9daff0c48a1db00f3073ffc44a347d792d937f589af8e69405e4f02373db5c740aaee8627b4447ebeb02f12343
data/.gitattributes ADDED
@@ -0,0 +1,2 @@
1
+ # Just override github
2
+ * linguist-language=Ruby
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ .idea
2
+ ab-results*
3
+
4
+ /.bundle/
5
+ /.yardoc
6
+ /_yardoc/
7
+ /coverage/
8
+ /doc/
9
+ /pkg/
10
+ /spec/reports/
11
+ /tmp/
12
+
13
+ /Gemfile.lock
14
+
15
+ *.gem
16
+
17
+ # rspec failure tracking
18
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,53 @@
1
+ Layout/IndentationWidth:
2
+ Width: 4
3
+
4
+ Layout/LineLength:
5
+ Enabled: false
6
+
7
+ Metrics/AbcSize:
8
+ Enabled: false
9
+
10
+ Metrics/BlockLength:
11
+ Enabled: false
12
+
13
+ Metrics/ClassLength:
14
+ Enabled: false
15
+
16
+ Metrics/CyclomaticComplexity:
17
+ Enabled: false
18
+
19
+ Metrics/MethodLength:
20
+ Enabled: false
21
+
22
+ Metrics/PerceivedComplexity:
23
+ Enabled: false
24
+
25
+ Naming/FileName:
26
+ Enabled: false
27
+
28
+ Style/FrozenStringLiteralComment:
29
+ Enabled: false
30
+
31
+ Style/HashSyntax:
32
+ Enabled: false
33
+
34
+ Style/PercentLiteralDelimiters:
35
+ Enabled: false
36
+
37
+ Style/RaiseArgs:
38
+ EnforcedStyle: compact
39
+
40
+ Style/RedundantBegin:
41
+ Enabled: false
42
+
43
+ Style/RedundantReturn:
44
+ Enabled: false
45
+
46
+ Style/SpecialGlobalVars:
47
+ Enabled: false
48
+
49
+ Style/WordArray:
50
+ EnforcedStyle: brackets
51
+
52
+ Style/RedundantPercentQ:
53
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,69 @@
1
+ matrix:
2
+ include:
3
+ - language: ruby
4
+ name: Bundler (rvm 2.4 & bundler 1.17.3)
5
+ rvm: 2.4
6
+ before_install:
7
+ - gem install bundler -v 1.17.3
8
+ - language: ruby
9
+ name: Bundler (rvm 2.4 & bundler 2.0.1)
10
+ rvm: 2.4
11
+ before_install:
12
+ - gem install bundler -v 2.0.1
13
+ - language: ruby
14
+ name: Bundler (rvm 2.5 & bundler 2.0.1)
15
+ rvm: 2.5
16
+ before_install:
17
+ - gem install bundler -v 2.0.1
18
+ - language: ruby
19
+ name: Bundler (rvm 2.6 & bundler 2.0.1)
20
+ rvm: 2.6
21
+ before_install:
22
+ - gem install bundler -v 2.0.1
23
+ - language: ruby
24
+ name: Rubocop (rvm 2.4)
25
+ env: SKIP_INTERPRETER=true
26
+ rvm: 2.4
27
+ before_install:
28
+ - git clone https://github.com/TravisToolbox/rubocop-travis.git
29
+ install:
30
+ - "./rubocop-travis/install.sh"
31
+ script:
32
+ - "./rubocop-travis/scan.sh"
33
+ - language: ruby
34
+ name: Rubocop (rvm 2.5)
35
+ env: SKIP_INTERPRETER=true
36
+ rvm: 2.5
37
+ before_install:
38
+ - git clone https://github.com/TravisToolbox/rubocop-travis.git
39
+ install:
40
+ - "./rubocop-travis/install.sh"
41
+ script:
42
+ - "./rubocop-travis/scan.sh"
43
+ - language: ruby
44
+ name: Rubocop (rvm 2.6)
45
+ env: SKIP_INTERPRETER=true
46
+ rvm: 2.6
47
+ before_install:
48
+ - git clone https://github.com/TravisToolbox/rubocop-travis.git
49
+ install:
50
+ - "./rubocop-travis/install.sh"
51
+ script:
52
+ - "./rubocop-travis/scan.sh"
53
+ - language: ruby
54
+ name: Link Checking (rvm 2.6)
55
+ rvm: 2.6
56
+ env:
57
+ - WHITELIST="https://img.shields.io"
58
+ - EXCLUDE_FILES="CHANGELOG.md"
59
+ before_install:
60
+ - mkdir travis
61
+ - git clone https://github.com/TravisToolbox/awesomebot-travis.git travis/awesomebot
62
+ install:
63
+ - "./travis/awesomebot/install.sh"
64
+ script:
65
+ - "./travis/awesomebot/scan.sh"
66
+ notifications:
67
+ email: false
68
+ slack:
69
+ secure: bXmFXEcNFh3o+t9fSu4Aa3m7rB/S3Wyiqhhw0am5Ijw8Cki49iao8SlLNz+3ykYi04GYYyDVPwMK61JGERBaqRaPmkdluCMkK1/qYTrOcb/YmOK9ssQKn0bFfWLpt9nRKuKSRjsYEcZ2ygNjUCFitX2Pqwlxqe1uqzloakIzxf1m6dux8SBV64T8okXIcfSlPOoB2tqGwAMpHAGdCMMnpYs50c8NSlYsoKlWTs5hI1sVuIhbBkI1AKPv/kzOzr7tZrlEgFmSb5RF9KvSWFWyb2++6P5uUpuESIOZehg2Ui+gysMBlqnFHbNBZOfKKkhO0/1Jy2CF/JSIDsM0mCzIFvSuYgqyb6gm+vFf/wRvBASsd2JW034sJ5HjmQjUz+lAf89dh5/Z8petcOmo8AawZcjzKTlgUFlJUN1j1ueSU4yRa6gVDK0XsjwbOTfk61aTTSBtZkwho5beYRzaHC7UswSMTHkxQT1vX+NltgAK5gMegVb03v/BqZWpBCQtkVz6SBmZEmacrHXo6l6oYbohMUKbin4BzG/I726PrsEsRCn0lrDC4MeJFGdG2gdB6xNyDyLndKztV3pjFErJh9CmMyKF7RXjE+MK6xblJofg9Xw17fIoaUpvaCct65HuuO7eE2OONqRIS2ySc3ID3n8U3Szcf/ljo109tyMXMd71LH0=
data/CODEOWNERS ADDED
@@ -0,0 +1,7 @@
1
+ # The codeowners file:
2
+ #
3
+ # For more information please read: https://help.github.com/articles/about-codeowners/
4
+
5
+ # These owners will be the default owners for everything in
6
+ # the repo. Unless a later match takes precedence,
7
+ * @WolfSoftware/reviewers
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,3 @@
1
+ # Contributing
2
+
3
+ Please refer to the [contributing](https://github.com/WolfSoftware/contributing) documentation.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in slackit.gemspec
6
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,25 @@
1
+ The MIT License (MIT)
2
+ =====================
3
+
4
+ Copyright © `2009-2020` `Wolf Software Limited`
5
+
6
+ Permission is hereby granted, free of charge, to any person
7
+ obtaining a copy of this software and associated documentation
8
+ files (the “Software”), to deal in the Software without
9
+ restriction, including without limitation the rights to use,
10
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the
12
+ Software is furnished to do so, subject to the following
13
+ conditions:
14
+
15
+ The above copyright notice and this permission notice shall be
16
+ included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25
+ OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,87 @@
1
+ [![Build Status](https://img.shields.io/travis/WolfSoftware/tocbot/master?style=for-the-badge&logo=travis)](https://travis-ci.org/WolfSoftware/tocbot)
2
+ [![Software License](https://img.shields.io/badge/license-MIT-blue?style=for-the-badge)](LICENSE.md)
3
+ [![Release](https://img.shields.io/github/release/WolfSoftware/tocbot?color=blue&style=for-the-badge&logo=github&label=Latest%20Release)](https://github.com/WolfSoftware/tocbot/releases/latest)
4
+ [![Last Release](https://img.shields.io/github/release-date/WolfSoftware/tocbot?color=blue&style=for-the-badge&logo=github)](https://github.com/WolfSoftware/tocbot/releases/latest)
5
+ [![Github commits (since latest release)](https://img.shields.io/github/commits-since/WolfSoftware/tocbot/latest?color=blue&style=for-the-badge&logo=github)](https://github.com/WolfSoftware/tocbot/commits)
6
+ [![Last Commit](https://img.shields.io/github/last-commit/WolfSoftware/tocbot?color=blue&style=for-the-badge&logo=github)](https://github.com/WolfSoftware/tocbot/commits/master)
7
+ [![Code Size](https://img.shields.io/github/languages/code-size/WolfSoftware/tocbot?color=blue&style=for-the-badge&logo=github)](#)
8
+ [![Repo Size](https://img.shields.io/github/repo-size/WolfSoftware/tocbot?color=blue&style=for-the-badge&logo=github)](#)
9
+ [![Contributors](https://img.shields.io/github/contributors/WolfSoftware/tocbot?color=blue&style=for-the-badge&logo=github)](https://github.com/WolfSoftware/tocbot/graphs/contributors)
10
+ [![WolfSoftware](https://img.shields.io/badge/Created%20By-Wolf%20Software%20Ltd.-blue?style=for-the-badge)](https://github.com/WolfSoftware)
11
+
12
+ <a name="tocbot"></a>
13
+ # TOCBot
14
+
15
+ <!--TOC-->
16
+ * [TOCBot](#tocbot)
17
+ * [Introduction](#introduction)
18
+ * [Installation](#installation)
19
+ * [Basic Usage](#basic-usage)
20
+ * [Command Line Usage](#command-line-usage)
21
+ * [Contributing to TOCBot](#contributing-to-tocbot)
22
+ * [Setup](#setup)
23
+ * [Testing](#testing)
24
+ * [To-Do List](#to-do-list)
25
+ <!--TOC-->
26
+
27
+ <a name="introduction"></a>
28
+ ## Introduction
29
+
30
+ TOCBot is a Table of Content (TOC) creation robot. It works by reading a markdown file and identifying all of the headers (currently up to 5 levels deep) and creating a table of contents based on those headers.
31
+
32
+ It will insert the table of contents between the separators that are placed in the file. The current separator is <!--TOC-->.
33
+
34
+ > There must be TWO separators, one to open the table of contents and one to close it.
35
+
36
+ TOCBot will also add links above each header in order to make the Table of Contents clickable.
37
+
38
+ <a name="installation"></a>
39
+ ## Installation
40
+
41
+ Installing TOCBot is very simple, just execute the following command.
42
+
43
+ ```
44
+ gem install tocbot
45
+ ```
46
+
47
+ <a name="basic-usage"></a>
48
+ ## Basic Usage
49
+
50
+ You can execute TOCBot by simple running
51
+
52
+ ```
53
+ tocbot
54
+ ```
55
+
56
+ <a name="command-line-usage"></a>
57
+ ### Command Line Usage
58
+
59
+ | Option | Purpose | Default Value |
60
+ | ------ | ------- |:-------------:|
61
+ | -h or --help | Show the help message | N/A |
62
+ | -f or --filename | The name of the file to process. | README.md |
63
+
64
+ <a name="contributing-to-tocbot"></a>
65
+ ## Contributing to TOCBot
66
+
67
+ <a name="setup"></a>
68
+ ### Setup
69
+
70
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
71
+
72
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will
73
+ create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
74
+
75
+ <a name="testing"></a>
76
+ ### Testing
77
+
78
+ For local testing make sure that you run `bundle exec rspec spec` and then `rake install` to install the gem locally.
79
+
80
+ For further information please refer to the [contributing](https://github.com/WolfSoftware/contributing) documentation.
81
+
82
+ <a name="to-do-list"></a>
83
+ ## To-Do List
84
+
85
+ - [ ] Allow users to specify the separator
86
+ - [ ] Allow users to specify how deep into the headers to go
87
+ - [ ] Allow users to specify levels to skip
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/TOCBot.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'TOCBot/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'tocbot'
7
+ spec.version = TOCBot::VERSION
8
+ spec.authors = ['Tim Gurney aka Wolf']
9
+ spec.email = ['wolf@tgwolf.com']
10
+
11
+ spec.summary = %q{An automated TOC creation not.}
12
+ spec.description = %q{A gem for automatically generating a table of contents in a markdown file.}
13
+ spec.homepage = 'https://github.com/WolfSoftware/tocbot'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_development_dependency 'bundler', '>= 1.17', '< 3.0'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'rspec', '~> 3.0'
25
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'TOCBot'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/tocbot ADDED
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'tocbot'
5
+
6
+ # -------------------------------------------------------------------------------- #
7
+ # This function will take the input arguments and then passes them to TOCBot. #
8
+ # -------------------------------------------------------------------------------- #
9
+
10
+ def send_to_tocbot(options)
11
+ begin
12
+ toc = TOCBot.new(options)
13
+ toc.process_file(options[:filename])
14
+ rescue StandardError => e
15
+ puts "Error: #{e}"
16
+ exit(1)
17
+ end
18
+ end
19
+
20
+ # -------------------------------------------------------------------------------- #
21
+ # This function will process the input from the command line and work out what it #
22
+ # is that the user wants to see. #
23
+ # #
24
+ # This is the main processing function where all the processing logic is handled. #
25
+ # -------------------------------------------------------------------------------- #
26
+
27
+ def process_arguments
28
+ options = { :filename => 'README.md' }
29
+ # Enforce the presence of
30
+ mandatory = %I[filename]
31
+
32
+ optparse = OptionParser.new do |opts|
33
+ opts.banner = "Usage: #{$PROGRAM_NAME}"
34
+
35
+ opts.on('-h', '--help', 'Display this screen') do
36
+ puts opts
37
+ exit(1)
38
+ end
39
+ opts.on('-f', '--filename string', 'The name of the file to process. [default: README.md]') do |filename|
40
+ options[:filename] = filename
41
+ end
42
+ end
43
+
44
+ begin
45
+ optparse.parse!
46
+ missing = mandatory.select { |param| options[param].nil? }
47
+ raise OptionParser::MissingArgument.new(missing.join(', ')) unless missing.empty?
48
+ rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e
49
+ puts e.to_s
50
+ puts optparse
51
+ exit
52
+ end
53
+
54
+ exit 0 if send_to_tocbot(options)
55
+
56
+ exit 1
57
+ end
58
+
59
+ # -------------------------------------------------------------------------------- #
60
+ # Main() #
61
+ # -------------------------------------------------------------------------------- #
62
+ # The main function where all of the heavy lifting and script config is done. #
63
+ # -------------------------------------------------------------------------------- #
64
+
65
+ def main
66
+ process_arguments
67
+ end
68
+
69
+ main
70
+
71
+ # -------------------------------------------------------------------------------- #
72
+ # End of Script #
73
+ # -------------------------------------------------------------------------------- #
74
+ # This is the end - nothing more to see here. #
75
+ # -------------------------------------------------------------------------------- #
@@ -0,0 +1,3 @@
1
+ class TOCBot
2
+ VERSION = '0.1.0'.freeze
3
+ end
data/lib/TOCBot.rb ADDED
@@ -0,0 +1,106 @@
1
+ require 'TOCBot/version'
2
+
3
+ #
4
+ # To follow
5
+ #
6
+ class TOCBot
7
+ def initialize(options = {})
8
+ @separator = '<!--TOC-->'
9
+
10
+ @separator = options[:separator] unless options[:separator].nil?
11
+ end
12
+
13
+ def load_file(filename)
14
+ lines = []
15
+
16
+ begin
17
+ lines = File.readlines(filename).each(&:chomp!)
18
+ rescue SystemCallError
19
+ raise StandardError.new("Failed to open file #{filename} for reading")
20
+ end
21
+ return lines
22
+ end
23
+
24
+ def write_file(filename, processed, toc_list, permissions = 0o0644)
25
+ toc_done = false
26
+
27
+ begin
28
+ File.open(filename, 'w') do |f|
29
+ processed.each do |line|
30
+ f.puts line
31
+
32
+ next unless line == @separator && !toc_done
33
+
34
+ toc_list.each do |toc|
35
+ f.puts toc
36
+ end
37
+ toc_done = true
38
+ end
39
+ f.chmod(permissions)
40
+ end
41
+ rescue SystemCallError
42
+ raise StandardError.new("Failed to open file #{filename} for writing")
43
+ end
44
+ end
45
+
46
+ def process_lines(lines)
47
+ processed = []
48
+ toc = []
49
+
50
+ skip_code_block = false
51
+ strip_existing_toc = false
52
+ lines.each do |line|
53
+ line = line.strip
54
+
55
+ #
56
+ # Identify code blocks and ignore the contents
57
+ #
58
+ skip_code_block = !skip_code_block if line.start_with?('```')
59
+
60
+ if skip_code_block
61
+ processed << line
62
+ next
63
+ end
64
+
65
+ #
66
+ # Identify open/closing <!--TOC--> tags
67
+ #
68
+ strip_existing_toc = !strip_existing_toc if line == @separator
69
+
70
+ #
71
+ # Skip over effectively removing the existing TOC
72
+ #
73
+ next if strip_existing_toc && line.downcase != @separator.downcase
74
+
75
+ #
76
+ # Strip out relative links
77
+ #
78
+ next if line.start_with?('<a name="')
79
+
80
+ if line.scan(/^\#{1,}.*/m).size.positive?
81
+ m = line.match(/^(\#{1,})(.*)/)
82
+ hashes = m[1].length
83
+ text = m[2].strip
84
+
85
+ link = text.gsub(/ /, '-').downcase
86
+
87
+ toc << ' ' * (hashes - 1) + "* [#{text}](##{link})"
88
+ processed << "<a name=\"#{link}\"></a>"
89
+ end
90
+
91
+ #
92
+ # Add the line to array - but also process it to see if it needs to go into the TOC
93
+ #
94
+ processed << line
95
+ end
96
+ return processed, toc
97
+ end
98
+
99
+ def process_file(filename)
100
+ lines = load_file(filename)
101
+
102
+ processed, toc = process_lines(lines)
103
+
104
+ write_file(filename, processed, toc)
105
+ end
106
+ end
@@ -0,0 +1,5 @@
1
+ RSpec.describe TOCBot do
2
+ it 'has a version number' do
3
+ expect(TOCBot::VERSION).not_to be nil
4
+ end
5
+ end
@@ -0,0 +1,14 @@
1
+ require 'bundler/setup'
2
+ require 'TOCBot'
3
+
4
+ RSpec.configure do |config|
5
+ # Enable flags like --only-failures and --next-failure
6
+ config.example_status_persistence_file_path = '.rspec_status'
7
+
8
+ # Disable RSpec exposing methods globally on `Module` and `main`
9
+ config.disable_monkey_patching!
10
+
11
+ config.expect_with :rspec do |c|
12
+ c.syntax = :expect
13
+ end
14
+ end
data/testing/tocbot ADDED
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift('./lib')
4
+
5
+ require 'bundler/setup'
6
+ require 'optparse'
7
+ require 'tocbot'
8
+
9
+ # -------------------------------------------------------------------------------- #
10
+ # This function will take the input arguments and then passes them to TOCBot. #
11
+ # -------------------------------------------------------------------------------- #
12
+
13
+ def send_to_tocbot(options)
14
+ begin
15
+ toc = TOCBot.new(options)
16
+ toc.process_file(options[:filename])
17
+ rescue StandardError => e
18
+ puts "Error: #{e}"
19
+ exit(1)
20
+ end
21
+ end
22
+
23
+ # -------------------------------------------------------------------------------- #
24
+ # This function will process the input from the command line and work out what it #
25
+ # is that the user wants to see. #
26
+ # #
27
+ # This is the main processing function where all the processing logic is handled. #
28
+ # -------------------------------------------------------------------------------- #
29
+
30
+ def process_arguments
31
+ options = { :filename => 'README.md' }
32
+ # Enforce the presence of
33
+ mandatory = %I[filename]
34
+
35
+ optparse = OptionParser.new do |opts|
36
+ opts.banner = "Usage: #{$PROGRAM_NAME}"
37
+
38
+ opts.on('-h', '--help', 'Display this screen') do
39
+ puts opts
40
+ exit(1)
41
+ end
42
+ opts.on('-f', '--filename string', 'The name of the file to process. [default: README.md]') do |filename|
43
+ options[:filename] = filename
44
+ end
45
+ end
46
+
47
+ begin
48
+ optparse.parse!
49
+ missing = mandatory.select { |param| options[param].nil? }
50
+ raise OptionParser::MissingArgument.new(missing.join(', ')) unless missing.empty?
51
+ rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e
52
+ puts e.to_s
53
+ puts optparse
54
+ exit
55
+ end
56
+
57
+ exit 0 if send_to_tocbot(options)
58
+
59
+ exit 1
60
+ end
61
+
62
+ # -------------------------------------------------------------------------------- #
63
+ # Main() #
64
+ # -------------------------------------------------------------------------------- #
65
+ # The main function where all of the heavy lifting and script config is done. #
66
+ # -------------------------------------------------------------------------------- #
67
+
68
+ def main
69
+ process_arguments
70
+ end
71
+
72
+ main
73
+
74
+ # -------------------------------------------------------------------------------- #
75
+ # End of Script #
76
+ # -------------------------------------------------------------------------------- #
77
+ # This is the end - nothing more to see here. #
78
+ # -------------------------------------------------------------------------------- #
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tocbot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tim Gurney aka Wolf
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-02-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '3.0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '1.17'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '3.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: rake
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '10.0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '10.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '3.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '3.0'
61
+ description: A gem for automatically generating a table of contents in a markdown
62
+ file.
63
+ email:
64
+ - wolf@tgwolf.com
65
+ executables:
66
+ - tocbot
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - ".gitattributes"
71
+ - ".gitignore"
72
+ - ".rspec"
73
+ - ".rubocop.yml"
74
+ - ".travis.yml"
75
+ - CODEOWNERS
76
+ - CONTRIBUTING.md
77
+ - Gemfile
78
+ - LICENSE.md
79
+ - README.md
80
+ - Rakefile
81
+ - TOCBot.gemspec
82
+ - bin/console
83
+ - bin/setup
84
+ - exe/tocbot
85
+ - lib/TOCBot.rb
86
+ - lib/TOCBot/version.rb
87
+ - spec/TOCBot_spec.rb
88
+ - spec/spec_helper.rb
89
+ - testing/tocbot
90
+ homepage: https://github.com/WolfSoftware/tocbot
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubygems_version: 3.1.2
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: An automated TOC creation not.
113
+ test_files: []