jekyll-toc 0.5.0 → 0.5.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ccc2bf0183085116ed9d1f513b7006f97d30780a
4
- data.tar.gz: 2a2394cff59db848efea4239281b763159a5fd47
3
+ metadata.gz: 11249e86a5122f8c2d20eda3c017fa0153c46751
4
+ data.tar.gz: 119d8a76ead5a7bea7bd16b481eb86a66320c099
5
5
  SHA512:
6
- metadata.gz: 03f41351429eacc75d2ac58e914c5f9256fca8e6d2a51dc8462741572b6b7237e5acd558e3b452ad44731f3ed638ece80eea459c998ff831f96f9fefac2320ae
7
- data.tar.gz: baa6fc7fa6a808a1438ba02b9d0fac540642ed2bbc3555d9feeb54f6dcd6ac1f10f06da61413cdb82cfcef94b59e62ea516085cbc1c157349b933a5872521cdb
6
+ metadata.gz: 944f866279b98691b4d04b6bd9426044c7e635abbdf44edfc1ff583ed48371c739d6abc9dfa9d1fb5d15e244fcbc681957a9680339eb9c8a52093f4a559a7045
7
+ data.tar.gz: 13f140512b05717447141aa80303837e9b7d6fab395bfb116fc922eebd3357fbed002aca1829d1af1d96f52877ed772f07bfbc7e8276800a1784748ba79e65b5
data/lib/jekyll-toc.rb CHANGED
@@ -33,7 +33,7 @@ module Jekyll
33
33
  end
34
34
 
35
35
  def toc_config
36
- @context.registers[:site].config["toc"]
36
+ @context.registers[:site].config["toc"] || {}
37
37
  end
38
38
  end
39
39
  end
@@ -11,7 +11,7 @@ module Jekyll
11
11
 
12
12
  def initialize(html, options = {})
13
13
  @doc = Nokogiri::HTML::DocumentFragment.parse(html)
14
- options = DEFAULT_CONFIG.merge(options)
14
+ options = generate_option_hash(options)
15
15
  @toc_levels = options["min_level"]..options["max_level"]
16
16
  @entries = parse_content
17
17
  end
@@ -116,6 +116,12 @@ module Jekyll
116
116
  def toc_headings
117
117
  @toc_levels.map { |level| "h#{level}" }.join(",")
118
118
  end
119
+
120
+ def generate_option_hash(options)
121
+ DEFAULT_CONFIG.merge(options)
122
+ rescue TypeError
123
+ DEFAULT_CONFIG
124
+ end
119
125
  end
120
126
  end
121
127
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module JekyllToc
2
- VERSION = '0.5.0'.freeze
2
+ VERSION = '0.5.1'.freeze
3
3
  end
@@ -0,0 +1,38 @@
1
+ require 'test_helper'
2
+
3
+ class TestOptionError < Minitest::Test
4
+ BASE_HTML = "<h1>h1</h1>"
5
+ EXPECTED_HTML = <<-HTML
6
+ <ul class="section-nav">
7
+ <li class="toc-entry toc-h1"><a href="#h1">h1</a></li>
8
+ </ul>
9
+ HTML
10
+
11
+ def test_option_is_nil
12
+ parser = Jekyll::TableOfContents::Parser.new(BASE_HTML, nil)
13
+ doc = Nokogiri::HTML(parser.toc)
14
+ expected = EXPECTED_HTML
15
+ assert_equal(expected, doc.css('ul.section-nav').to_s)
16
+ end
17
+
18
+ def test_option_is_epmty_string
19
+ parser = Jekyll::TableOfContents::Parser.new(BASE_HTML, "")
20
+ doc = Nokogiri::HTML(parser.toc)
21
+ expected = EXPECTED_HTML
22
+ assert_equal(expected, doc.css('ul.section-nav').to_s)
23
+ end
24
+
25
+ def test_option_is_string
26
+ parser = Jekyll::TableOfContents::Parser.new(BASE_HTML, "string")
27
+ doc = Nokogiri::HTML(parser.toc)
28
+ expected = EXPECTED_HTML
29
+ assert_equal(expected, doc.css('ul.section-nav').to_s)
30
+ end
31
+
32
+ def test_option_is_array
33
+ parser = Jekyll::TableOfContents::Parser.new(BASE_HTML, [])
34
+ doc = Nokogiri::HTML(parser.toc)
35
+ expected = EXPECTED_HTML
36
+ assert_equal(expected, doc.css('ul.section-nav').to_s)
37
+ end
38
+ end
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.5.0
4
+ version: 0.5.1
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: 2017-12-27 00:00:00.000000000 Z
12
+ date: 2017-12-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -136,6 +136,7 @@ files:
136
136
  - test/test_helper.rb
137
137
  - test/test_inject_anchors_filter.rb
138
138
  - test/test_kramdown_list.rb
139
+ - test/test_option_error.rb
139
140
  - test/test_toc_filter.rb
140
141
  - test/test_toc_only_filter.rb
141
142
  - test/test_various_toc_html.rb
@@ -167,6 +168,7 @@ test_files:
167
168
  - test/test_helper.rb
168
169
  - test/test_inject_anchors_filter.rb
169
170
  - test/test_kramdown_list.rb
171
+ - test/test_option_error.rb
170
172
  - test/test_toc_filter.rb
171
173
  - test/test_toc_only_filter.rb
172
174
  - test/test_various_toc_html.rb