Skip to content

Commit

Permalink
Merge pull request #22 from toshimaru/test-upgrade-guide
Browse files Browse the repository at this point in the history
v0.3 Release / Nested Toc Support / Drop jekyll2 Support
  • Loading branch information
toshimaru authored Jul 20, 2017
2 parents 63495df + e553271 commit 64e1bea
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 38 deletions.
12 changes: 5 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@ cache: bundler
rvm:
- 2.1
- 2.2
- 2.3.1
- 2.4.0
- 2.3.4
- 2.4.1
# gemfile is generated by appraisal
gemfile:
- gemfiles/jekyll_3.5.gemfile
- gemfiles/jekyll_3.4.gemfile
- gemfiles/jekyll_3.3.gemfile
- gemfiles/jekyll_3.2.gemfile
- gemfiles/jekyll_3.1.gemfile
- gemfiles/jekyll_3.gemfile
- gemfiles/jekyll_2.gemfile
matrix:
exclude:
- rvm: 2.4.0
gemfile: gemfiles/jekyll_2.gemfile
addons:
code_climate:
repo_token: 6b81e393ea6ad38560386f650ea2fb0e57a7beb5e20f8c8364fabee30d5bff07
after_success:
- bundle exec codeclimate-test-reporter
4 changes: 4 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
appraise "jekyll-3.5" do
gem "jekyll", "3.5.1"
end

appraise "jekyll-3.4" do
gem "jekyll", "3.4.3"
end
Expand Down
28 changes: 21 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,33 @@ location with the `toc_only` filter.

jekyll-toc generates Unordered List. The final output is as follows.

**Heads-up**: As of v0.3, nested toc has been supported. If you update jekyll-toc from 0.2 to 0.3, please check [upgrade guide](https://github.com/toshimaru/jekyll-toc/wiki/0.3-Upgrade-Guide)

```html
<ul class="section-nav">
<li class="toc-entry toc-h1"><a href="#heading1">Heading.1</a></li>
<li class="toc-entry toc-h2"><a href="#heading2-1">Heading.2-1</a></li>
<li class="toc-entry toc-h2"><a href="#heading2-2">Heading.2-2</a></li>
<li class="toc-entry toc-h3"><a href="#heading3">Heading.3</a></li>
<li class="toc-entry toc-h2"><a href="#heading2-3">Heading.2-3</a></li>
<li class="toc-entry toc-h1"><a href="#heading1">Heading.1</a>
<ul>
<li class="toc-entry toc-h2"><a href="#heading1-1">Heading.1-1</a></li>
<li class="toc-entry toc-h2"><a href="#heading1-2">Heading.1-2</a></li>
</ul>
</li>
<li class="toc-entry toc-h1"><a href="#heading2">Heading.2</a>
<ul>
<li class="toc-entry toc-h2"><a href="#heading2-1">Heading.2-1</a>
<ul>
<li class="toc-entry toc-h3"><a href="#heading2-1-1">Heading.2-1-1</a></li>
<li class="toc-entry toc-h3"><a href="#heading2-1-2">Heading.2-1-2</a></li>
</ul>
</li>
<li class="toc-entry toc-h2"><a href="#heading2-2">Heading.2-2</a></li>
</ul>
</li>
</ul>
```

It looks like the image below.

![screenshot](https://cloud.githubusercontent.com/assets/803398/5722561/7f59e8aa-9b80-11e4-9ee5-27a15192ee83.png)
![screenshot](https://user-images.githubusercontent.com/803398/28401295-0dcfb7ca-6d54-11e7-892b-2f2e6ca755a7.png)

## CSS Styling

Expand All @@ -105,7 +119,7 @@ The toc can be modified with CSS. The sample CSS is the following.
}
```

![screenshot](https://cloud.githubusercontent.com/assets/803398/5723662/f0bc84c8-9b88-11e4-986c-90608ca88184.png)
![screen shot](https://user-images.githubusercontent.com/803398/28401455-0ba60868-6d55-11e7-8159-0ae7591aee66.png)

Each TOC `li` entry has two CSS classes for further styling.
The general `toc-entry` is applied to all `li` elements in the `ul.section-nav`.
Expand Down
7 changes: 7 additions & 0 deletions gemfiles/jekyll_3.5.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "jekyll", "3.5.1"

gemspec :path => "../"
31 changes: 18 additions & 13 deletions jekyll-toc.gemspec
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
lib = File.expand_path("../lib", __FILE__)
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "version"
require 'version'

Gem::Specification.new do |spec|
spec.name = 'jekyll-toc'
spec.version = JekyllToc::VERSION
spec.summary = "Jekyll Table of Contents plugin"
spec.description = "A liquid filter plugin for Jekyll which generates a table of contents."
spec.authors = ["Toshimaru", 'torbjoernk']
spec.summary = 'Jekyll Table of Contents plugin'
spec.description = 'A liquid filter plugin for Jekyll which generates a table of contents.'
spec.authors = %w(toshimaru torbjoernk)
spec.email = '[email protected]'
spec.files = `git ls-files -z`.split("\x0")
spec.homepage = 'https://github.com/toshimaru/jekyll-toc'
spec.license = 'MIT'
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]
spec.require_paths = ['lib']

spec.required_ruby_version = ">= 2.1.0"
spec.post_install_message = %q(As of jekyll-toc 0.3, nested toc is supported! Please make sure your toc is not broken after update jekyll-toc.
spec.add_runtime_dependency "nokogiri", "~> 1.6"
For more info: https://github.com/toshimaru/jekyll-toc/wiki/0.3-Upgrade-Guide)

spec.add_development_dependency 'minitest', "~> 5.0"
spec.add_development_dependency "appraisal"
spec.add_development_dependency "codeclimate-test-reporter", "~> 1.0"
spec.add_development_dependency "jekyll", ">= 2.0"
spec.add_development_dependency "rake"
spec.required_ruby_version = '>= 2.1.0'

spec.add_runtime_dependency 'nokogiri', '~> 1.6'

spec.add_development_dependency 'appraisal'
spec.add_development_dependency 'codeclimate-test-reporter', '~> 1.0'
spec.add_development_dependency 'jekyll', '>= 3.0'
spec.add_development_dependency 'minitest', '~> 5.0'
spec.add_development_dependency 'pry'
spec.add_development_dependency 'rake'
end
2 changes: 1 addition & 1 deletion lib/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module JekyllToc
VERSION = '0.3.0.pre1'
VERSION = '0.3.0'.freeze
end
5 changes: 3 additions & 2 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
require 'simplecov'
SimpleCov.start

require 'jekyll'
require 'minitest/autorun'
require 'jekyll'
require 'jekyll-toc'

SIMPLE_HTML = <<HTML
SIMPLE_HTML = <<-HTML
<h1>Simple H1</h1>
<h2>Simple H2</h2>
<h3>Simple H3</h3>
Expand Down
5 changes: 2 additions & 3 deletions test/test_inject_anchors_filter.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require 'test_helper'
require_relative '../lib/jekyll-toc'

class TestTOCOnlyFilter < Minitest::Test
class TestInjectAnchorsFilter < Minitest::Test
include TestHelpers

def setup
Expand All @@ -11,7 +10,7 @@ def setup
def test_injects_anchors_into_content
html = @parser.inject_anchors_into_html

assert_match(/<a id="simple\-h1" class="anchor" href="#simple\-h1" aria\-hidden="true"><span.*span><\/a>Simple H1/, html)
assert_match(%r{<a id="simple-h1" class="anchor" href="#simple-h1" aria-hidden="true"><span.*span></a>Simple H1}, html)
end

def test_does_not_inject_toc
Expand Down
17 changes: 14 additions & 3 deletions test/test_toc_filter.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
require 'test_helper'
require_relative '../lib/jekyll-toc'


class TestTOCFilter < Minitest::Test
include TestHelpers
Expand All @@ -12,7 +10,20 @@ def setup
def test_injects_anchors
html = @parser.toc

assert_match(/<a id="simple\-h1" class="anchor" href="#simple\-h1" aria\-hidden="true"><span.*span><\/a>Simple H1/, html)
assert_match(%r{<a id="simple-h1" class="anchor" href="#simple-h1" aria-hidden="true"><span.*span></a>Simple H1}, html)
end

def test_nested_toc
doc = Nokogiri::HTML(@parser.toc)
nested_h6_text = doc.css('ul.section-nav')
.css('li.toc-h1')
.css('li.toc-h2')
.css('li.toc-h3')
.css('li.toc-h4')
.css('li.toc-h5')
.css('li.toc-h6')
.text
assert_equal('Simple H6', nested_h6_text)
end

def test_injects_toc_container
Expand Down
3 changes: 1 addition & 2 deletions test/test_toc_only_filter.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'test_helper'
require_relative '../lib/jekyll-toc'

class TestTOCOnlyFilter < Minitest::Test
include TestHelpers
Expand All @@ -17,6 +16,6 @@ def test_injects_toc_container
def test_does_not_return_content
html = @parser.build_toc

assert_nil(/<h1>Simple H1<\/h1>/ =~ html)
assert_nil(%r{<h1>Simple H1</h1>} =~ html)
end
end

0 comments on commit 64e1bea

Please sign in to comment.