jekyll-toc 0.11.0 → 0.12.0.rc1

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
  SHA256:
3
- metadata.gz: afa3ea6b7c656558ab8ac87171d113867f0c720a5917d4a057b7754c0f2b1516
4
- data.tar.gz: 5309a5224a0e925d3993024736821e29d2605fc74c003e9e412ab0af9a26c869
3
+ metadata.gz: be220b1646e71d971f92efb0d26f1dc8774a503d8607d8762b54f9402e1606fa
4
+ data.tar.gz: 79701301568dc4bedf7a7658ccc7dd618b16018e7befecea758f7298044187ed
5
5
  SHA512:
6
- metadata.gz: 0a51b5ea083c92d3cf6842f4d4ab5ec41c8da3425ec8f64c1938933f2e43514eaebd9731a59742bac191990e47318bd72104b92cf8611a97d3858d21c390db74
7
- data.tar.gz: 34b863397e58393a41d567a412a84676ac125fa5ad3465a509114ad0b965f3d440ef3a730f81d96313b6f76beb3c8529a610702ca667489fa012fd4dfd76125d
6
+ metadata.gz: 5248660f0d76d3afbee5d9e4316f63896a44766326c73ad7feeff23ca977bd147722a457ee21b2022048cc6cc1b93837048f48de5518bce71bfc71cf6e647308
7
+ data.tar.gz: a6e2f104e4334909dbe70fdbca80123b644965f3c2599c55a09575461f5f9e769a5274ae3627b78cde91203daa9f65c98168d868322f2335386f5d0aacafc77c
@@ -20,4 +20,3 @@ Metrics/ClassLength:
20
20
 
21
21
  Style/FileName:
22
22
  Enabled: false
23
-
data/README.md CHANGED
@@ -12,6 +12,7 @@
12
12
  - [1. Basic Usage](#1-basic-usage)
13
13
  - [2. Advanced Usage](#2-advanced-usage)
14
14
  - [Generated HTML](#generated-html)
15
+ - [Default Configuration](#default-configuration)
15
16
  - [Customization](#customization)
16
17
  - [Skip TOC](#skip-toc)
17
18
  - [Skip TOC Section](#skip-toc-section)
@@ -112,6 +113,19 @@ jekyll-toc generates an unordered list. The HTML output is as follows.
112
113
 
113
114
  ![screenshot](https://user-images.githubusercontent.com/803398/28401295-0dcfb7ca-6d54-11e7-892b-2f2e6ca755a7.png)s
114
115
 
116
+ ## Default Configuration
117
+
118
+ ```yml
119
+ toc:
120
+ min_level: 1
121
+ max_level: 6
122
+ no_toc_section_class: no_toc_section
123
+ list_class: section-nav
124
+ sublist_class: ''
125
+ item_class: toc-entry
126
+ item_prefix: toc-
127
+ ```
128
+
115
129
  ## Customization
116
130
 
117
131
  ### Skip TOC
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'nokogiri'
4
+ require 'table_of_contents/configuration'
4
5
  require 'table_of_contents/parser'
5
6
 
6
7
  module Jekyll
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module TableOfContents
5
+ # jekyll-toc configuration class
6
+ class Configuration
7
+ attr_accessor :toc_levels, :no_toc_section_class, :list_class, :sublist_class, :item_class, :item_prefix
8
+
9
+ DEFAULT_CONFIG = {
10
+ 'min_level' => 1,
11
+ 'max_level' => 6,
12
+ 'no_toc_section_class' => 'no_toc_section',
13
+ 'list_class' => 'section-nav',
14
+ 'sublist_class' => '',
15
+ 'item_class' => 'toc-entry',
16
+ 'item_prefix' => 'toc-'
17
+ }.freeze
18
+
19
+ def initialize(options)
20
+ options = generate_option_hash(options)
21
+
22
+ @toc_levels = options['min_level']..options['max_level']
23
+ @no_toc_section_class = options['no_toc_section_class']
24
+ @list_class = options['list_class']
25
+ @sublist_class = options['sublist_class']
26
+ @item_class = options['item_class']
27
+ @item_prefix = options['item_prefix']
28
+ end
29
+
30
+ private
31
+
32
+ def generate_option_hash(options)
33
+ DEFAULT_CONFIG.merge(options)
34
+ rescue TypeError
35
+ DEFAULT_CONFIG
36
+ end
37
+ end
38
+ end
39
+ end
@@ -7,25 +7,9 @@ module Jekyll
7
7
  NO_TOC_CLASS_NAME = 'no_toc'
8
8
  PUNCTUATION_REGEXP = /[^\p{Word}\- ]/u
9
9
 
10
- DEFAULT_CONFIG = {
11
- 'no_toc_section_class' => 'no_toc_section',
12
- 'min_level' => 1,
13
- 'max_level' => 6,
14
- 'list_class' => 'section-nav',
15
- 'sublist_class' => '',
16
- 'item_class' => 'toc-entry',
17
- 'item_prefix' => 'toc-'
18
- }.freeze
19
-
20
10
  def initialize(html, options = {})
21
11
  @doc = Nokogiri::HTML::DocumentFragment.parse(html)
22
- options = generate_option_hash(options)
23
- @toc_levels = options['min_level']..options['max_level']
24
- @no_toc_section_class = options['no_toc_section_class']
25
- @list_class = options['list_class']
26
- @sublist_class = options['sublist_class']
27
- @item_class = options['item_class']
28
- @item_prefix = options['item_prefix']
12
+ @configuration = Configuration.new(options)
29
13
  @entries = parse_content
30
14
  end
31
15
 
@@ -34,7 +18,7 @@ module Jekyll
34
18
  end
35
19
 
36
20
  def build_toc
37
- %(<ul class="#{@list_class}">\n#{build_toc_list(@entries)}</ul>)
21
+ %(<ul class="#{@configuration.list_class}">\n#{build_toc_list(@entries)}</ul>)
38
22
  end
39
23
 
40
24
  def inject_anchors_into_html
@@ -86,7 +70,7 @@ module Jekyll
86
70
  entry = entries[i]
87
71
  if entry[:h_num] == min_h_num
88
72
  # If the current entry should not be indented in the list, add the entry to the list
89
- toc_list << %(<li class="#{@item_class} #{@item_prefix}#{entry[:node_name]}"><a href="##{entry[:id]}">#{entry[:text]}</a>)
73
+ toc_list << %(<li class="#{@configuration.item_class} #{@configuration.item_prefix}#{entry[:node_name]}"><a href="##{entry[:id]}">#{entry[:text]}</a>)
90
74
  # If the next entry should be indented in the list, generate a sublist
91
75
  next_i = i + 1
92
76
  if next_i < entries.count && entries[next_i][:h_num] > min_h_num
@@ -120,29 +104,23 @@ module Jekyll
120
104
  end
121
105
 
122
106
  def toc_headings
123
- @toc_levels.map { |level| "h#{level}" }.join(',')
107
+ @configuration.toc_levels.map { |level| "h#{level}" }.join(',')
124
108
  end
125
109
 
126
110
  def toc_headings_in_no_toc_section
127
- if @no_toc_section_class.is_a? Array
128
- @no_toc_section_class.map { |cls| toc_headings_within(cls) }.join(',')
111
+ if @configuration.no_toc_section_class.is_a? Array
112
+ @configuration.no_toc_section_class.map { |cls| toc_headings_within(cls) }.join(',')
129
113
  else
130
- toc_headings_within(@no_toc_section_class)
114
+ toc_headings_within(@configuration.no_toc_section_class)
131
115
  end
132
116
  end
133
117
 
134
118
  def toc_headings_within(class_name)
135
- @toc_levels.map { |level| ".#{class_name} h#{level}" }.join(',')
136
- end
137
-
138
- def generate_option_hash(options)
139
- DEFAULT_CONFIG.merge(options)
140
- rescue TypeError
141
- DEFAULT_CONFIG
119
+ @configuration.toc_levels.map { |level| ".#{class_name} h#{level}" }.join(',')
142
120
  end
143
121
 
144
122
  def ul_attributes
145
- @ul_attributes ||= @sublist_class.empty? ? '' : %( class="#{@sublist_class}")
123
+ @ul_attributes ||= @configuration.sublist_class.empty? ? '' : %( class="#{@configuration.sublist_class}")
146
124
  end
147
125
  end
148
126
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllToc
4
- VERSION = '0.11.0'
4
+ VERSION = '0.12.0.rc1'
5
5
  end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class TestConfiguration < Minitest::Test
6
+ def test_default_conf1guration
7
+ configuration = Jekyll::TableOfContents::Configuration.new({})
8
+
9
+ assert_equal configuration.toc_levels, 1..6
10
+ assert_equal configuration.no_toc_section_class, 'no_toc_section'
11
+ assert_equal configuration.list_class, 'section-nav'
12
+ assert_equal configuration.sublist_class, ''
13
+ assert_equal configuration.item_class, 'toc-entry'
14
+ assert_equal configuration.item_prefix, 'toc-'
15
+ end
16
+
17
+ def test_type_error
18
+ configuration = Jekyll::TableOfContents::Configuration.new('TypeError!')
19
+
20
+ assert_equal configuration.toc_levels, 1..6
21
+ assert_equal configuration.no_toc_section_class, 'no_toc_section'
22
+ assert_equal configuration.list_class, 'section-nav'
23
+ assert_equal configuration.sublist_class, ''
24
+ assert_equal configuration.item_class, 'toc-entry'
25
+ assert_equal configuration.item_prefix, 'toc-'
26
+ end
27
+ end
@@ -5,11 +5,11 @@ require 'test_helper'
5
5
  class TestTableOfContentsFilter < Minitest::Test
6
6
  include Jekyll::TableOfContentsFilter
7
7
 
8
- DUMMY_HTML = "<div>Dummy HTML Content</div>"
9
-
8
+ DUMMY_HTML = '<div>Dummy HTML Content</div>'
9
+
10
10
  def setup
11
11
  stubbed_context = Struct.new(:registers)
12
- @context = stubbed_context.new(page: "xxx")
12
+ @context = stubbed_context.new(page: 'xxx')
13
13
  @context
14
14
  end
15
15
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-toc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - toshimaru
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-03-24 00:00:00.000000000 Z
12
+ date: 2019-03-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -157,6 +157,7 @@ files:
157
157
  - gemfiles/jekyll_3.8.gemfile
158
158
  - jekyll-toc.gemspec
159
159
  - lib/jekyll-toc.rb
160
+ - lib/table_of_contents/configuration.rb
160
161
  - lib/table_of_contents/parser.rb
161
162
  - lib/version.rb
162
163
  - test/parser/test_inject_anchors_filter.rb
@@ -164,6 +165,7 @@ files:
164
165
  - test/parser/test_toc_filter.rb
165
166
  - test/parser/test_toc_only_filter.rb
166
167
  - test/parser/test_various_toc_html.rb
168
+ - test/test_configuration.rb
167
169
  - test/test_helper.rb
168
170
  - test/test_jekyll-toc.rb
169
171
  - test/test_kramdown_list.rb
@@ -182,9 +184,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
182
184
  version: '2.3'
183
185
  required_rubygems_version: !ruby/object:Gem::Requirement
184
186
  requirements:
185
- - - ">="
187
+ - - ">"
186
188
  - !ruby/object:Gem::Version
187
- version: '0'
189
+ version: 1.3.1
188
190
  requirements: []
189
191
  rubygems_version: 3.0.3
190
192
  signing_key:
@@ -196,6 +198,7 @@ test_files:
196
198
  - test/parser/test_toc_filter.rb
197
199
  - test/parser/test_toc_only_filter.rb
198
200
  - test/parser/test_various_toc_html.rb
201
+ - test/test_configuration.rb
199
202
  - test/test_helper.rb
200
203
  - test/test_jekyll-toc.rb
201
204
  - test/test_kramdown_list.rb