tocer 4.0.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 364451d192c18a68dca94f98111f91bc9497c9a2
4
- data.tar.gz: 8121740b8a7a03151014009133eb1e5187bd8e21
3
+ metadata.gz: c3a5d9b3cbfbd48fe9e33a63d6bb64f835b41d29
4
+ data.tar.gz: 4bf1614edeb7da8332a07551446b0d3b9203f889
5
5
  SHA512:
6
- metadata.gz: 690afd875c906b115a1a2f8e99dba18e4cddd7f22fce0cd6293e2fe30bdcbd344cb13e06ab357c5e6ad87e3415f8ce309a5a713c1fd03aa0d75e29c2f41a0dde
7
- data.tar.gz: 75e09cac2a5c43f65c73ed4e03aa7c920ab2b9e08696237a2d389ca0768c773f19bdba103839217dee2f432408d7876b1c2e54366d77a79c9bd7099926cb6730
6
+ metadata.gz: 10030e97ee6a0f6935483700653a3ac795b7905dfb3a8da3a61d0222a694248260ca6c02ca38923bf1a50d57eab92ba213bf6565de075b82973bea719eab51e0
7
+ data.tar.gz: 00f5d32a47dc85d51323bf50f1af64761728071d212e653acd73e6da2a852e8da28ae78831e9f7a96e2110fbd41ae80d3953161d6fd31021020177f280462201
data/README.md CHANGED
@@ -37,7 +37,7 @@ Markdown files.
37
37
  - Does not support header prefixes without spaces. Example: `#Header`.
38
38
  - Supports table of contents generation for single or multiple files.
39
39
  - Supports custom label. Default: "# Table of Contents".
40
- - Supports whitelist filtering. Default: ".md".
40
+ - Supports whitelist filtering. Default: "README.md".
41
41
  - Prepends table of contents to Markdown documents that don't have table of contents.
42
42
  - Rebuilds Markdown documents that have existing table of contents.
43
43
 
@@ -77,7 +77,7 @@ For specific `--generate` options, run `tocer --help --generate` to see the foll
77
77
  -l, [--label=LABEL] # Label
78
78
  # Default: # Table of Contents
79
79
  -w, [--whitelist=one two three] # File whitelist
80
- # Default: [".md"]
80
+ # Default: ["README.md"]
81
81
 
82
82
  To generate the table of contents at a specific position within your Markdown files, add the
83
83
  following lines to your file(s) prior to generation:
@@ -88,7 +88,8 @@ following lines to your file(s) prior to generation:
88
88
  ```
89
89
 
90
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.
91
+ will prepend the table of contents to your file(s), complete with an auto-generated table of
92
+ contents.
92
93
 
93
94
  In the case that Tocer has already auto-generated a table of contents for a Markdown file, the
94
95
  existing table of contents has become stale, or placement of the table of contents has changed you
@@ -101,38 +102,41 @@ determined in the following order (with the last one taking top priority):
101
102
 
102
103
  0. Global: `~/.tocerrc`.
103
104
  0. Local: `<project_root>/.tocerrc`.
104
- 0. CLI: `tocer --generate . --label "## Custom Label" --whitelist README.md`
105
+ 0. CLI: `tocer --generate . --label "## Custom Label" --whitelist CHANGES.md`
105
106
 
106
- Any settings provided to the CLI during runtime will trump the global setting. The global setting is
107
- the weakest of all but great for situations where custom settings should be applied to *all*
108
- projects.
107
+ Settings provided to the CLI during runtime will trump the global setting. The global settings are
108
+ weakest of all but great for situations where custom settings should be applied to *all* projects.
109
109
 
110
- The `~/.tocerrc` uses the following default settings:
110
+ The `~/.tocerrc` file uses the following default settings:
111
111
 
112
112
  :label: "# Table of Contents"
113
- :whitelist: [".md"]
113
+ :whitelist: ["README.md"]
114
114
 
115
115
  Each `~/.tocerrc` setting can be configured as follows:
116
116
 
117
117
  - `label`: The header label for the table of contents. Default: "# Table of Contents".
118
- - `whitelist`: The list of *included* files. Default: ".md".
118
+ - `whitelist`: The list of *included* files. Default: "*.md".
119
119
 
120
120
  There are multiple ways the *whitelist* can be defined. Here are some examples:
121
121
 
122
- # Use an empty array to include *all* files.
122
+ # Use an empty array to ignore all files (a key with with no value would work too).
123
123
  :whitelist: []
124
124
 
125
125
  # Use an array of wildcards for groups of files with similar extensions:
126
126
  :whitelist:
127
- - .md
128
- - .mkd
129
- - .markdown
127
+ - *.md
128
+ - *.mkd
129
+ - *.markdown
130
130
 
131
- # Use a mix of wild cards and relative paths to customized as necessary:
131
+ # Use a mix of wild cards and relative names/paths to customized as necessary:
132
132
  :whitelist:
133
133
  - README.md
134
134
  - docs/*.md
135
- - .markdown
135
+ - *.markdown
136
+
137
+ # Use a recursive glob to traverse and update all sub-directories:
138
+ :whitelist:
139
+ - **/*.md
136
140
 
137
141
  # Tests
138
142
 
@@ -144,9 +148,9 @@ To test, run:
144
148
 
145
149
  Read [Semantic Versioning](http://semver.org) for details. Briefly, it means:
146
150
 
147
- - Patch (x.y.Z) - Incremented for small, backwards compatible, bug fixes.
148
- - Minor (x.Y.z) - Incremented for new, backwards compatible, public API enhancements/fixes.
149
151
  - Major (X.y.z) - Incremented for any backwards incompatible public API changes.
152
+ - Minor (x.Y.z) - Incremented for new, backwards compatible, public API enhancements/fixes.
153
+ - Patch (x.y.Z) - Incremented for small, backwards compatible, bug fixes.
150
154
 
151
155
  # Code of Conduct
152
156
 
@@ -2,9 +2,18 @@
2
2
 
3
3
  module Tocer
4
4
  # Builds a table of contents for a Markdown document.
5
+ # :reek:TooManyInstanceVariables
5
6
  class Builder
6
7
  CODE_BLOCK_PUNCTUATION = "```"
7
8
 
9
+ def self.transformer header
10
+ if header.match?(/\[.+\]\(.+\)/)
11
+ Transformers::Link.new header
12
+ else
13
+ Transformers::Text.new header
14
+ end
15
+ end
16
+
8
17
  def initialize lines, label: "# Table of Contents", comment_block: Elements::CommentBlock
9
18
  @lines = lines
10
19
  @label = label
@@ -41,22 +50,16 @@ module Tocer
41
50
  self.code_block = !code_block
42
51
  end
43
52
 
44
- def acquire_transfomer header
45
- if header.match?(/\[.+\]\(.+\)/)
46
- Transformers::Link.new header
47
- else
48
- Transformers::Text.new header
49
- end
50
- end
51
-
52
53
  def url_suffix url
53
- url_count[url].zero? ? "" : url_count[url]
54
+ count = url_count[url]
55
+ count.zero? ? "" : count
54
56
  end
55
57
 
56
58
  def transform header
57
- transformer = acquire_transfomer header
58
- link = transformer.transform url_suffix: url_suffix(transformer.url)
59
- url_count[transformer.url] += 1
59
+ transformer = self.class.transformer header
60
+ url = transformer.url
61
+ link = transformer.transform url_suffix: url_suffix(url)
62
+ url_count[url] += 1
60
63
  link
61
64
  end
62
65
 
@@ -16,7 +16,7 @@ module Tocer
16
16
  def self.configuration
17
17
  Runcom::Configuration.new file_name: Identity.file_name, defaults: {
18
18
  label: "# Table of Contents",
19
- whitelist: %w[.md]
19
+ whitelist: ["README.md"]
20
20
  }
21
21
  end
22
22
 
@@ -36,13 +36,15 @@ module Tocer
36
36
  desc: "File whitelist",
37
37
  type: :array,
38
38
  default: configuration.to_h.fetch(:whitelist)
39
- def generate path
40
- configuration = build_configuration path, options.label, options.whitelist
41
- runner = build_runner path, configuration
39
+ # :reek:TooManyStatements
40
+ def generate path = "."
41
+ configuration = self.class.configuration.merge label: options.label,
42
+ whitelist: options.whitelist
43
+ runner = Runner.new path, configuration: configuration
42
44
  files = runner.files
43
45
 
44
- runner.run
45
46
  return if files.empty?
47
+ runner.run
46
48
 
47
49
  say "Processed table of contents for:"
48
50
  files.each { |file| say " #{file}" }
@@ -78,24 +80,5 @@ module Tocer
78
80
  def help task = nil
79
81
  say and super
80
82
  end
81
-
82
- private
83
-
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
99
- end
100
83
  end
101
84
  end
@@ -4,6 +4,10 @@ module Tocer
4
4
  module Elements
5
5
  # Represents a table of contents start and finish comment block.
6
6
  class CommentBlock
7
+ def self.index lines, id
8
+ (lines.index { |line| line =~ /\<\!\-\-.*#{Regexp.escape id}.*\-\-\>/ }).to_i
9
+ end
10
+
7
11
  def initialize start_id: "Tocer[start]",
8
12
  finish_id: "Tocer[finish]",
9
13
  message: "Auto-generated, don't remove."
@@ -17,16 +21,16 @@ module Tocer
17
21
  comment start_id, message
18
22
  end
19
23
 
20
- def start_index collection
21
- index collection, start_id
24
+ def start_index lines
25
+ self.class.index lines, start_id
22
26
  end
23
27
 
24
28
  def finish
25
29
  comment finish_id, message
26
30
  end
27
31
 
28
- def finish_index collection
29
- index collection, finish_id
32
+ def finish_index lines
33
+ self.class.index lines, finish_id
30
34
  end
31
35
 
32
36
  private
@@ -36,10 +40,6 @@ module Tocer
36
40
  def comment id, message
37
41
  "<!-- #{id}: #{message} -->"
38
42
  end
39
-
40
- def index collection, id
41
- collection.index { |line| line =~ /\<\!\-\-.*#{Regexp.escape id}.*\-\-\>/ }
42
- end
43
43
  end
44
44
  end
45
45
  end
@@ -12,7 +12,7 @@ module Tocer
12
12
  end
13
13
 
14
14
  def self.version
15
- "4.0.0"
15
+ "5.0.0"
16
16
  end
17
17
 
18
18
  def self.version_label
@@ -5,16 +5,15 @@ require "pathname"
5
5
  module Tocer
6
6
  # Generates/updates Table of Contents for files in given path.
7
7
  class Runner
8
- def initialize path = "", configuration: {}, writer: Writer
8
+ def initialize path = ".", configuration: {}, writer: Writer
9
9
  @path = Pathname path
10
10
  @configuration = configuration
11
11
  @writer = writer
12
12
  end
13
13
 
14
14
  def files
15
- return [] unless path.exist?
16
- glob = whitelist.empty? ? %(#{path}/**/*) : %(#{path}/**/*{#{whitelist.join ","}})
17
- Pathname.glob(glob).select(&:file?)
15
+ return [] unless path.exist? && path.directory? && !whitelist.empty?
16
+ Pathname.glob(%(#{path}/{#{whitelist.join ","}})).select(&:file?)
18
17
  end
19
18
 
20
19
  def run
@@ -26,7 +25,7 @@ module Tocer
26
25
  attr_reader :path, :configuration, :writer
27
26
 
28
27
  def whitelist
29
- Array configuration.fetch(:whitelist)
28
+ Array configuration[:whitelist]
30
29
  end
31
30
  end
32
31
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  module Tocer
4
4
  # Writes table of contents to a Markdown document.
5
+ # :reek:TooManyInstanceVariables
5
6
  class Writer
6
7
  # rubocop:disable Metrics/ParameterLists
7
8
  def initialize file_path,
@@ -10,14 +11,14 @@ module Tocer
10
11
  comment_block: Elements::CommentBlock
11
12
 
12
13
  @file_path = file_path
13
- @file_lines = File.open(file_path).to_a
14
+ @file_lines = File.open(file_path, &:to_a)
14
15
  @label = label
15
16
  @builder = builder
16
17
  setup_indexes comment_block.new, @file_lines
17
18
  end
18
19
 
19
20
  def write
20
- body = start_index ? replace_toc : prepend_toc
21
+ body = start_index.zero? ? prepend_toc : replace_toc
21
22
  File.open(file_path, "w") { |file| file.write body }
22
23
  end
23
24
 
metadata CHANGED
@@ -1,36 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tocer
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
8
8
  autorequire:
9
9
  bindir: bin
10
- cert_chain:
11
- - |
12
- -----BEGIN CERTIFICATE-----
13
- MIIDeDCCAmCgAwIBAgIBATANBgkqhkiG9w0BAQUFADBBMQ8wDQYDVQQDDAZicm9v
14
- a2UxGjAYBgoJkiaJk/IsZAEZFgphbGNoZW1pc3RzMRIwEAYKCZImiZPyLGQBGRYC
15
- aW8wHhcNMTYxMDE5MTY0NDEzWhcNMTcxMDE5MTY0NDEzWjBBMQ8wDQYDVQQDDAZi
16
- cm9va2UxGjAYBgoJkiaJk/IsZAEZFgphbGNoZW1pc3RzMRIwEAYKCZImiZPyLGQB
17
- GRYCaW8wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCgryPL4/IbWDcL
18
- fnqpnoJALqj+ega7hSsvvD8sac57HPNLeKcOmSafFiQLAnTmmE132ZlFc8kyZRVn
19
- zmqSESowO5jd+ggFuy1ySqQJXhwgik04KedKRUjpIDZePrjw+M5UJT1qzKCKL2xI
20
- nx5cOKP1fSWJ1RRu8JhaDeSloGtYMdw2c28wnKPNIsWDood4xhbLcY9IqeISft2e
21
- oTAHTHandHbvt24X3/n67ceNjLBbsVZPXCC1C8C8ccjHjA4Tm2uiFoDwThMcPggg
22
- 90H6fh0vLFcNAobdPEchbge8tWtfmMPz2+C4yklANn81GA+ANsBS1uwx6mxJoMQU
23
- BNVp0aLvAgMBAAGjezB5MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQW
24
- BBRS85Rn1BaqeIONByw4t46DMDMzHDAfBgNVHREEGDAWgRRicm9va2VAYWxjaGVt
25
- aXN0cy5pbzAfBgNVHRIEGDAWgRRicm9va2VAYWxjaGVtaXN0cy5pbzANBgkqhkiG
26
- 9w0BAQUFAAOCAQEAZMb57Y4wdpbX8XxTukEO7VC1pndccUsxdbziGsAOiuHET3Aq
27
- ygLvrfdYrN88/w+qxncW5bxbO3a6UGkuhIFUPM8zRSE/rh6bCcJljTJrExVt42eV
28
- aYCb7WJNsx3eNXHn3uQodq3tD+lmNJzz2bFeT3smGSKEnALBjqorO/2mpDh4FJ3S
29
- 4CcDYsJ1ywep8LDJDBBGdKz9moL+axryzpeTpgTT/fFYFzRzWrURPyDvPOikh9TX
30
- n/LUZ1dKhIHzfKx1B4+TEIefArObGfkLIDM8+Dq1RX7TF1k81Men7iu4MgE9bYBn
31
- 3dE+xI3FdB5gWcdWxdtgRCmWjtXeYYyb4z6NQQ==
32
- -----END CERTIFICATE-----
33
- date: 2017-01-22 00:00:00.000000000 Z
10
+ cert_chain: []
11
+ date: 2017-05-07 00:00:00.000000000 Z
34
12
  dependencies:
35
13
  - !ruby/object:Gem::Dependency
36
14
  name: thor
@@ -52,42 +30,42 @@ dependencies:
52
30
  requirements:
53
31
  - - "~>"
54
32
  - !ruby/object:Gem::Version
55
- version: '5.0'
33
+ version: '5.1'
56
34
  type: :runtime
57
35
  prerelease: false
58
36
  version_requirements: !ruby/object:Gem::Requirement
59
37
  requirements:
60
38
  - - "~>"
61
39
  - !ruby/object:Gem::Version
62
- version: '5.0'
40
+ version: '5.1'
63
41
  - !ruby/object:Gem::Dependency
64
42
  name: refinements
65
43
  requirement: !ruby/object:Gem::Requirement
66
44
  requirements:
67
45
  - - "~>"
68
46
  - !ruby/object:Gem::Version
69
- version: '4.0'
47
+ version: '4.1'
70
48
  type: :runtime
71
49
  prerelease: false
72
50
  version_requirements: !ruby/object:Gem::Requirement
73
51
  requirements:
74
52
  - - "~>"
75
53
  - !ruby/object:Gem::Version
76
- version: '4.0'
54
+ version: '4.1'
77
55
  - !ruby/object:Gem::Dependency
78
56
  name: runcom
79
57
  requirement: !ruby/object:Gem::Requirement
80
58
  requirements:
81
59
  - - "~>"
82
60
  - !ruby/object:Gem::Version
83
- version: '0.5'
61
+ version: '0.6'
84
62
  type: :runtime
85
63
  prerelease: false
86
64
  version_requirements: !ruby/object:Gem::Requirement
87
65
  requirements:
88
66
  - - "~>"
89
67
  - !ruby/object:Gem::Version
90
- version: '0.5'
68
+ version: '0.6'
91
69
  - !ruby/object:Gem::Dependency
92
70
  name: rake
93
71
  requirement: !ruby/object:Gem::Requirement
@@ -102,6 +80,20 @@ dependencies:
102
80
  - - "~>"
103
81
  - !ruby/object:Gem::Version
104
82
  version: '12.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: gemsmith
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '9.4'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '9.4'
105
97
  - !ruby/object:Gem::Dependency
106
98
  name: pry
107
99
  requirement: !ruby/object:Gem::Requirement
@@ -206,14 +198,14 @@ dependencies:
206
198
  requirements:
207
199
  - - "~>"
208
200
  - !ruby/object:Gem::Version
209
- version: '3.5'
201
+ version: '3.6'
210
202
  type: :development
211
203
  prerelease: false
212
204
  version_requirements: !ruby/object:Gem::Requirement
213
205
  requirements:
214
206
  - - "~>"
215
207
  - !ruby/object:Gem::Version
216
- version: '3.5'
208
+ version: '3.6'
217
209
  - !ruby/object:Gem::Dependency
218
210
  name: guard-rspec
219
211
  requirement: !ruby/object:Gem::Requirement
@@ -234,42 +226,42 @@ dependencies:
234
226
  requirements:
235
227
  - - "~>"
236
228
  - !ruby/object:Gem::Version
237
- version: '0.0'
229
+ version: '0.1'
238
230
  type: :development
239
231
  prerelease: false
240
232
  version_requirements: !ruby/object:Gem::Requirement
241
233
  requirements:
242
234
  - - "~>"
243
235
  - !ruby/object:Gem::Version
244
- version: '0.0'
236
+ version: '0.1'
245
237
  - !ruby/object:Gem::Dependency
246
238
  name: reek
247
239
  requirement: !ruby/object:Gem::Requirement
248
240
  requirements:
249
241
  - - "~>"
250
242
  - !ruby/object:Gem::Version
251
- version: '4.5'
243
+ version: '4.6'
252
244
  type: :development
253
245
  prerelease: false
254
246
  version_requirements: !ruby/object:Gem::Requirement
255
247
  requirements:
256
248
  - - "~>"
257
249
  - !ruby/object:Gem::Version
258
- version: '4.5'
250
+ version: '4.6'
259
251
  - !ruby/object:Gem::Dependency
260
252
  name: rubocop
261
253
  requirement: !ruby/object:Gem::Requirement
262
254
  requirements:
263
255
  - - "~>"
264
256
  - !ruby/object:Gem::Version
265
- version: '0.47'
257
+ version: '0.48'
266
258
  type: :development
267
259
  prerelease: false
268
260
  version_requirements: !ruby/object:Gem::Requirement
269
261
  requirements:
270
262
  - - "~>"
271
263
  - !ruby/object:Gem::Version
272
- version: '0.47'
264
+ version: '0.48'
273
265
  - !ruby/object:Gem::Dependency
274
266
  name: codeclimate-test-reporter
275
267
  requirement: !ruby/object:Gem::Requirement
@@ -327,7 +319,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
327
319
  version: '0'
328
320
  requirements: []
329
321
  rubyforge_project:
330
- rubygems_version: 2.6.9
322
+ rubygems_version: 2.6.12
331
323
  signing_key:
332
324
  specification_version: 4
333
325
  summary: A command line interface for generating table of contents for Markdown files.
@@ -1 +0,0 @@
1
- ��|��JD��0�3���v�o��.OtH�ԊX�v_�����A�ˋb
data.tar.gz.sig DELETED
@@ -1,2 +0,0 @@
1
- N�^}�7~�
2
- �4�
metadata.gz.sig DELETED
Binary file