jekyll-toc 0.12.0.rc2 → 0.12.0.rc3

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
  SHA256:
3
- metadata.gz: 6912be740161a70021da9fdcfffcc86c1102b47ca0331fb83dd82ac6c3d9ff3a
4
- data.tar.gz: b643b75ca33642f66054b52de2d3bc94ef6280277ac1afe91afbc5d0b9096f09
3
+ metadata.gz: cbc830ae67f7d9cf7420ededcdd81373c0384544c3622690ba731669cdfd115b
4
+ data.tar.gz: ce7987e81662a5b84b5fba251755c66abef34d78d02ccd1dd5d1f2e7d0e65ceb
5
5
  SHA512:
6
- metadata.gz: 26e96485ad84ea72849fde58ff33ced713b3ea962f56dc9ed09caf4ee85c2abff1566994126e0c9cb3f4d56f1d2e7b4638b26ae6e90c0cf9c56405f1b765ef2f
7
- data.tar.gz: 714d5b7e4973f32d08e2a8689240ee3f372ca6bb7e983122ffca009db47bf175d8df8e3e21cd6c4a74b225ede5e480c2fe48fbec1cb030a2a3dcee10d04c423a
6
+ metadata.gz: dc532b059cde9864f956b2f17cea00dcb3c82d51d16377e75ca8a7dff9102b369f77e5b86632d598002893e3ad016f65a52fbf9c165305a64a75baeec5803bb3
7
+ data.tar.gz: 80c83f7eb2bd69be980483560f367f4ae500c37b7321fe7ffaef7e0e947eac6cb40d23bf2346a5f1f5850222e69628f4a946e542ade81c5d8efa46cec3ede0ff
data/README.md CHANGED
@@ -67,7 +67,7 @@ If you'd like separated TOC and content, you can use `toc_only` and `inject_anch
67
67
 
68
68
  #### ~~`toc_only` filter~~
69
69
 
70
- ⚠️ Please use `{% toc %}` instead of `{{ contents | toc_only }}`.
70
+ ⚠️ Please use `{% toc %}` instead of `{{ content | toc_only }}`.
71
71
 
72
72
  Generates the TOC itself as described [below](#generated-html).
73
73
  Mostly useful in cases where the TOC should _not_ be placed immediately
data/lib/jekyll-toc.rb CHANGED
@@ -10,31 +10,33 @@ module Jekyll
10
10
  def render(context)
11
11
  return '' unless context.registers[:page]['toc']
12
12
 
13
- content_html = context.registers[:page].content
14
- ::Jekyll::TableOfContents::Parser.new(content_html).build_toc
13
+ content_html = context.registers[:page]['content']
14
+ toc_config = context.registers[:site].config['toc'] || {}
15
+ TableOfContents::Parser.new(content_html, toc_config).build_toc
15
16
  end
16
17
  end
17
18
 
18
19
  # Jekyll Table of Contents filter plugin
19
20
  module TableOfContentsFilter
21
+ # Deprecated method. Removed in v1.0.
20
22
  def toc_only(html)
21
23
  Jekyll.logger.warn 'Deprecation: toc_only filter is deprecated and will be remove in jekyll-toc v1.0.',
22
24
  'Use `{% toc %}` instead of `{{ contents | toc_only }}`.'
23
25
  return '' unless toc_enabled?
24
26
 
25
- ::Jekyll::TableOfContents::Parser.new(html, toc_config).build_toc
27
+ TableOfContents::Parser.new(html, toc_config).build_toc
26
28
  end
27
29
 
28
30
  def inject_anchors(html)
29
31
  return html unless toc_enabled?
30
32
 
31
- ::Jekyll::TableOfContents::Parser.new(html, toc_config).inject_anchors_into_html
33
+ TableOfContents::Parser.new(html, toc_config).inject_anchors_into_html
32
34
  end
33
35
 
34
36
  def toc(html)
35
37
  return html unless toc_enabled?
36
38
 
37
- ::Jekyll::TableOfContents::Parser.new(html, toc_config).toc
39
+ TableOfContents::Parser.new(html, toc_config).toc
38
40
  end
39
41
 
40
42
  private
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllToc
4
- VERSION = '0.12.0.rc2'
4
+ VERSION = '0.12.0.rc3'
5
5
  end
@@ -7,19 +7,46 @@ class TestTableOfContentsFilter < Minitest::Test
7
7
 
8
8
  DUMMY_HTML = '<div>Dummy HTML Content</div>'
9
9
 
10
- def setup
11
- @context = Struct.new(:registers).new(page: { "toc" => false })
12
- end
13
-
14
10
  def test_toc_only
11
+ @context = disable_toc_context
15
12
  assert_empty toc_only(DUMMY_HTML)
16
13
  end
17
14
 
18
15
  def test_inject_anchors
19
- assert_equal inject_anchors(DUMMY_HTML), DUMMY_HTML
16
+ @context = disable_toc_context
17
+ assert_equal DUMMY_HTML, inject_anchors(DUMMY_HTML)
20
18
  end
21
19
 
22
20
  def test_toc
23
- assert_equal toc(DUMMY_HTML), DUMMY_HTML
21
+ @context = disable_toc_context
22
+ assert_equal DUMMY_HTML, toc(DUMMY_HTML)
23
+ end
24
+
25
+ def test_toc_only2
26
+ @context = enable_toc_context
27
+ assert_equal "<ul class=\"section-nav\">\n</ul>", toc_only(DUMMY_HTML)
28
+ end
29
+
30
+ def test_inject_anchors2
31
+ @context = enable_toc_context
32
+ assert_equal DUMMY_HTML, inject_anchors(DUMMY_HTML)
33
+ end
34
+
35
+ def test_toc2
36
+ @context = enable_toc_context
37
+ assert_equal "<ul class=\"section-nav\">\n</ul>#{DUMMY_HTML}", toc(DUMMY_HTML)
38
+ end
39
+
40
+ private
41
+
42
+ def disable_toc_context
43
+ Struct.new(:registers).new(page: { 'toc' => false })
44
+ end
45
+
46
+ def enable_toc_context
47
+ Struct.new(:registers).new(
48
+ page: { 'toc' => true },
49
+ site: Struct.new(:config).new({ 'toc' => false })
50
+ )
24
51
  end
25
52
  end
data/test/test_toc_tag.rb CHANGED
@@ -7,11 +7,15 @@ class TestTableOfContentsTag < Minitest::Test
7
7
 
8
8
  def setup
9
9
  @stubbed_context = Struct.new(:registers)
10
+ @stubbed_context1 = Struct.new(:config)
10
11
  @stubbed_context2 = Struct.new(:toc, :content)
11
12
  end
12
13
 
13
14
  def test_toc_tag
14
- context = @stubbed_context.new(page: @stubbed_context2.new({ 'toc' => false }, '<h1>test</h1>'))
15
+ context = @stubbed_context.new(
16
+ page: @stubbed_context2.new({ 'toc' => false }, '<h1>test</h1>'),
17
+ site: @stubbed_context1.new({ 'toc' => nil })
18
+ )
15
19
  tag = Jekyll::TocTag.parse('toc_tag', '', Tokenizer.new(''), ParseContext.new)
16
20
  assert_equal tag.render(context), "<ul class=\"section-nav\">\n<li class=\"toc-entry toc-h1\"><a href=\"#test\">test</a></li>\n</ul>"
17
21
  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.12.0.rc2
4
+ version: 0.12.0.rc3
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-30 00:00:00.000000000 Z
12
+ date: 2019-03-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri