Skip to content

Commit

Permalink
Add Jekyll 3 Support
Browse files Browse the repository at this point in the history
  • Loading branch information
Stargator committed Nov 14, 2015
1 parent a2f2135 commit 9a16133
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 18 deletions.
16 changes: 16 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ language: ruby
cache: bundler
sudo: false
rvm:
- 2.2
- 2.1
- 2.0
- 1.9.3
Expand All @@ -18,3 +19,18 @@ notifications:
email:
on_success: never
on_failure: never

matrix:
exclude:
- rvm: 1.9.3
env: JEKYLL_VERSION=3.0.0
- env: JEKYLL_VERSION=2.4
rvm: 2.1
- rvm: 2.2
env: JEKYLL_VERSION=2.4

env:
matrix:
- ""
- JEKYLL_VERSION=2.4
- JEKYLL_VERSION=3.0.0
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ source 'https://rubygems.org'

# Specify your gem's dependencies in jekyll-paginate.gemspec
gemspec

if ENV["JEKYLL_VERSION"]
gem "jekyll", "~> #{ENV["JEKYLL_VERSION"]}"
end
2 changes: 1 addition & 1 deletion jekyll-paginate.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.add_development_dependency "jekyll", ">= 2.0"
spec.add_development_dependency "jekyll", ">= 2.0", "< 3.0"
spec.add_development_dependency "bundler", "~> 1.5"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec", "~> 3.0"
Expand Down
70 changes: 53 additions & 17 deletions spec/pager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
let(:site) { build_site }

it "determines the correct pagination path for each page" do
expect(described_class.paginate_path(site, 1)).to eql("/index.html")
if Jekyll::VERSION < '3.0.0'
expect(described_class.paginate_path(site, 1)).to eql("/index.html")
else
expect(described_class.paginate_path(site, 1)).to eql("/")
end

expect(described_class.paginate_path(site, 2)).to eql("/page2")
end
end
Expand All @@ -24,7 +29,12 @@
let(:site) { build_site({'paginate_path' => '/blog/page-:num'}) }

it "determines the correct pagination path for each page" do
expect(described_class.paginate_path(site, 1)).to eql("/index.html")
if Jekyll::VERSION < '3.0.0'
expect(described_class.paginate_path(site, 1)).to eql("/index.html")
else
expect(described_class.paginate_path(site, 1)).to eql("/")
end

expect(described_class.paginate_path(site, 2)).to eql("/blog/page-2")
end
end
Expand All @@ -33,7 +43,12 @@
let(:site) { build_site({'paginate_path' => '/blog/page/:num'}) }

it "determines the correct pagination path for each page" do
expect(described_class.paginate_path(site, 1)).to eql("/index.html")
if Jekyll::VERSION < '3.0.0'
expect(described_class.paginate_path(site, 1)).to eql("/index.html")
else
expect(described_class.paginate_path(site, 1)).to eql("/")
end

expect(described_class.paginate_path(site, 2)).to eql("/blog/page/2")
end
end
Expand All @@ -42,7 +57,12 @@
let(:site) { build_site({'paginate_path' => '/contacts/page:num'}) }

it "determines the correct pagination path for each page" do
expect(described_class.paginate_path(site, 1)).to eql("/contacts/index.html")
if Jekyll::VERSION < '3.0.0'
expect(described_class.paginate_path(site, 1)).to eql("/contacts/index.html")
else
expect(described_class.paginate_path(site, 1)).to eql("/contacts/")
end

expect(described_class.paginate_path(site, 2)).to eql("/contacts/page2")
end
end
Expand All @@ -51,7 +71,12 @@
let(:site) { build_site({'paginate_path' => '/contacts/page/:num'}) }

it "determines the correct pagination path for each page" do
expect(described_class.paginate_path(site, 1)).to eql("/contacts/index.html")
if Jekyll::VERSION < '3.0.0'
expect(described_class.paginate_path(site, 1)).to eql("/contacts/index.html")
else
expect(described_class.paginate_path(site, 1)).to eql("/contacts/")
end

expect(described_class.paginate_path(site, 2)).to eql("/contacts/page/2")
end
end
Expand All @@ -74,64 +99,75 @@

context "pagination enabled for 2" do
let(:site) { build_site('paginate' => 2) }
let(:posts) { site.posts }
if Jekyll::VERSION < '3.0.0'
let(:posts) { site.posts }
else
let(:posts) { site.posts.docs }
end

it "report that pagination is enabled" do
expect(described_class.pagination_enabled?(site)).to be_truthy
end

context "with 4 posts" do
let(:posts) { site.posts[1..4] }

if Jekyll::VERSION < '3.0.0'
let(:posts) { site.posts[1..4] }
else
let(:posts) { site.posts.docs[1..4] }
end

it "create first pager" do
pager = described_class.new(site, 1, posts)
expect(pager.posts.size).to eql(2)
expect(pager.total_pages).to eql(2)
expect(pager.previous_page).to be_nil
expect(pager.next_page).to eql(2)
end

it "create second pager" do
pager = described_class.new(site, 2, posts)
expect(pager.posts.size).to eql(2)
expect(pager.total_pages).to eql(2)
expect(pager.previous_page).to eql(1)
expect(pager.next_page).to be_nil
end

it "not create third pager" do
expect { described_class.new(site, 3, posts) }.to raise_error
end

end

context "with 5 posts" do
let(:posts) { site.posts[1..5] }

if Jekyll::VERSION < '3.0.0'
let(:posts) { site.posts[1..5] }
else
let(:posts) { site.posts.docs[1..5] }
end

it "create first pager" do
pager = described_class.new(site, 1, posts)
expect(pager.posts.size).to eql(2)
expect(pager.total_pages).to eql(3)
expect(pager.previous_page).to be_nil
expect(pager.next_page).to eql(2)
end

it "create second pager" do
pager = described_class.new(site, 2, posts)
expect(pager.posts.size).to eql(2)
expect(pager.total_pages).to eql(3)
expect(pager.previous_page).to eql(1)
expect(pager.next_page).to eql(3)
end

it "create third pager" do
pager = described_class.new(site, 3, posts)
expect(pager.posts.size).to eql(1)
expect(pager.total_pages).to eql(3)
expect(pager.previous_page).to eql(2)
expect(pager.next_page).to be_nil
end

it "not create fourth pager" do
expect { described_class.new(site, 4, posts) }.to raise_error(RuntimeError)
end
Expand Down

0 comments on commit 9a16133

Please sign in to comment.