jekyll-paginate-v2 1.0.0 → 1.1.0
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 +4 -4
- data/README.md +41 -45
- data/Rakefile +16 -0
- data/jekyll-paginate-v2.gemspec +2 -3
- data/lib/jekyll-paginate-v2/pagination.rb +2 -2
- data/lib/jekyll-paginate-v2/paginator.rb +4 -4
- data/lib/jekyll-paginate-v2/utils.rb +6 -7
- data/lib/jekyll-paginate-v2/version.rb +1 -1
- data/spec/defaults_spec.rb +32 -0
- data/spec/paginator_spec.rb +103 -0
- data/spec/spec_helper.rb +31 -0
- data/spec/utils_spec.rb +65 -0
- metadata +12 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80775a1edd643521212d16cdaab6e1c983a0e7dd
|
4
|
+
data.tar.gz: 2fde95bfee813f020993d8076e8ba95897a07017
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 054388632b1064bda7bdb101ef988cb4b3abb28203f674fcf3e69e930c67fab6783fe3c1ce0d672bbd344489095797e119b74517a2039eeb6a12a4fb6c022f61
|
7
|
+
data.tar.gz: 2970a984f3ef365a0ad3ff329793a6ea45a7d1a845e0ed8068e3c4db0f4bf049fe85c725da720f26f79f613ee5fecdd021a3e12c3186dd9c2e9d2bba85308499
|
data/README.md
CHANGED
@@ -1,12 +1,27 @@
|
|
1
1
|
# Jekyll::Paginate V2
|
2
2
|
|
3
|
-
Pagination
|
3
|
+
Pagination gem built specially for Jekyll 3 and newer.
|
4
|
+
https://rubygems.org/gems/jekyll-paginate-v2
|
4
5
|
|
5
|
-
|
6
|
+
Fully backwards compatable and enhanced replacement for the previously built-in [jekyll-paginate gem](https://github.com/jekyll/jekyll-paginate).
|
6
7
|
|
7
|
-
The code was based on the original design of [jekyll-paginate](https://github.com/jekyll/jekyll-paginate) and features were mostly drawn from discussions from the issues pages (especially https://github.com/jekyll/jekyll-paginate/issues/27) and some from the excellent [Octopress::Paginate code](https://github.com/octopress/paginate).
|
8
|
+
The code was based on the original design of [jekyll-paginate](https://github.com/jekyll/jekyll-paginate) and features were mostly drawn from discussions from the issues pages (especially [#27](https://github.com/jekyll/jekyll-paginate/issues/27)) and some from the excellent [Octopress::Paginate code](https://github.com/octopress/paginate).
|
9
|
+
|
10
|
+
:heart:
|
11
|
+
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
```
|
16
|
+
gem install jekyll-paginate-v2
|
17
|
+
```
|
18
|
+
|
19
|
+
Update your [_config.yml](#site-configuration) and [pages](#page-configuration).
|
20
|
+
|
21
|
+
> Although backwards compatible, this gem needs slightly extended [site yml](#site-configuration) configuration and adds miniscule new front-matter for the [paging templates](#page-configuration) configuration elements.
|
22
|
+
|
23
|
+
Now you're ready to run `jekyll serve` and your paginated files should be generated.
|
8
24
|
|
9
|
-
Thanks everybody :heart:
|
10
25
|
|
11
26
|
## Features
|
12
27
|
|
@@ -23,42 +38,20 @@ In addition to all the features offered by the older [jekyll-paginate gem](https
|
|
23
38
|
|
24
39
|
All this while being fully backwards compatible with the old [jekyll-paginate](https://github.com/jekyll/jekyll-paginate) gem (requires minimal additional front-matter, see [page-configuration](#page-configuration)).
|
25
40
|
|
26
|
-
## Installation
|
27
|
-
|
28
|
-
Currently this plugin is in develpment mode and is not yet distributed as a gem (mostly because I don't know how).
|
29
|
-
|
30
|
-
To install, simply copy the `lib\jekyll-paginate-v2.rb` file into the `_plugins` folder under your Jekyll site root.
|
31
|
-
> If the _plugins folder does not exist simply create it.
|
32
|
-
|
33
|
-
Then add the necessary [Site YML](#site-configuration) and [Page](#page-configuration) configuration elements.
|
34
|
-
|
35
|
-
Run `jekyll serve` and you should see the pagination plugin debug messages printed during site generation:
|
36
|
-
|
37
|
-
``` bash
|
38
|
-
Generating...
|
39
|
-
Pagination: found template: pictures/bestof.md
|
40
|
-
Pagination: found template: puffins/list.html
|
41
|
-
Pagination: found template: index.html
|
42
|
-
```
|
43
|
-
|
44
|
-
## Current state
|
45
|
-
|
46
|
-
Currently this code is in dire need of feedback, code review and testing.
|
47
|
-
|
48
|
-
I also would welcome guidance on how to write automated tests for this code so that I can publish it as a Gem.
|
49
|
-
|
50
|
-
Come to think of it, I currently have no idea on how to publish a Gem... :/
|
51
|
-
|
52
|
-
> Don't worry too much about the current structure, this is just the first iteration.
|
53
|
-
> The code is currently a single file `jekyll-paginate-v2.rb` only because it makes it faster to develop and debug. As soon as I and hopefully other people test and green-light the logic I intend to break this code into separate files and distribute as a gem.
|
54
41
|
|
55
42
|
## Contributing
|
56
43
|
|
44
|
+
I currently need testers and people willing to give me feedback and code reviews.
|
45
|
+
|
57
46
|
1. Fork it ( https://github.com/sverrirs/jekyll-paginate-v2/fork )
|
58
47
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
59
48
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
60
|
-
4.
|
61
|
-
5.
|
49
|
+
4. Build the gem locally (`gem build jekyll-paginate-v2.gemspec`)
|
50
|
+
5. Test and verify the gem locally (`gem install ./jekyll-paginate-v2-x.x.x.gem`)
|
51
|
+
6. Push to the branch (`git push origin my-new-feature`)
|
52
|
+
7. Create new Pull Request
|
53
|
+
|
54
|
+
Note: This project uses [semantic versioning](http://semver.org/).
|
62
55
|
|
63
56
|
## Site configuration
|
64
57
|
|
@@ -109,8 +102,11 @@ pagination:
|
|
109
102
|
To enable pagination on a page (i.e. make that page a template for pagination) then simply include the minimal pagination configuration in the page front-matter:
|
110
103
|
|
111
104
|
``` yml
|
105
|
+
---
|
106
|
+
layout: page
|
112
107
|
pagination:
|
113
108
|
enabled: true
|
109
|
+
---
|
114
110
|
```
|
115
111
|
|
116
112
|
Then you can use the normal `paginator.posts` logic to iterate through the posts.
|
@@ -125,17 +121,17 @@ And to display pagination links, simply
|
|
125
121
|
|
126
122
|
``` html
|
127
123
|
{% if paginator.total_pages > 1 %}
|
128
|
-
<ul
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
124
|
+
<ul>
|
125
|
+
{% if paginator.previous_page %}
|
126
|
+
<li>
|
127
|
+
<a href="{{ paginator.previous_page_path | prepend: site.baseurl }}">Newer</a>
|
128
|
+
</li>
|
129
|
+
{% endif %}
|
130
|
+
{% if paginator.next_page %}
|
131
|
+
<li>
|
132
|
+
<a href="{{ paginator.next_page_path | prepend: site.baseurl }}">Older</a>
|
133
|
+
</li>
|
134
|
+
{% endif %}
|
139
135
|
</ul>
|
140
136
|
{% endif %}
|
141
137
|
```
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
#$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), *%w[lib]))
|
5
|
+
#require 'lib/jekyll-paginate-v2/version'
|
6
|
+
|
7
|
+
Rake::TestTask.new do |t|
|
8
|
+
t.libs.push 'lib'
|
9
|
+
t.libs.push 'specs'
|
10
|
+
t.verbose = true
|
11
|
+
t.pattern = "spec/*_spec.rb"
|
12
|
+
t.test_files = FileList['spec/*_spec.rb']
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "Run tests"
|
16
|
+
task :default => [:test]
|
data/jekyll-paginate-v2.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.name = "jekyll-paginate-v2"
|
8
8
|
spec.version = Jekyll::PaginateV2::VERSION
|
9
9
|
spec.platform = Gem::Platform::RUBY
|
10
|
-
spec.date = '2016-11-
|
10
|
+
spec.date = '2016-11-19'
|
11
11
|
spec.authors = ["Sverrir Sigmundarson"]
|
12
12
|
spec.email = ["jekyll@sverrirs.com"]
|
13
13
|
spec.homepage = "https://github.com/sverrirs/jekyll-paginate-v2"
|
@@ -18,11 +18,10 @@ Gem::Specification.new do |spec|
|
|
18
18
|
|
19
19
|
spec.files = `git ls-files -z`.split("\x0")
|
20
20
|
#spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
|
-
|
21
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
24
|
spec.add_development_dependency "jekyll", ">= 3.0"
|
25
25
|
spec.add_development_dependency "bundler", "~> 1.5"
|
26
26
|
spec.add_development_dependency "rake"
|
27
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
28
27
|
end
|
@@ -215,11 +215,11 @@ module Jekyll
|
|
215
215
|
# This .pager member is a built in thing in Jekyll and defines the paginator implementation
|
216
216
|
# Simpy override to use mine
|
217
217
|
(1..total_pages).each do |cur_page_nr|
|
218
|
-
pager = PaginatorV2.new( config, using_posts, cur_page_nr, total_pages, template )
|
218
|
+
pager = PaginatorV2.new( config['per_page'], config['permalink'], using_posts, cur_page_nr, total_pages, template.url )
|
219
219
|
if( cur_page_nr > 1)
|
220
220
|
newpage = Page.new( site, site.source, template.dir, template.name)
|
221
221
|
newpage.pager = pager
|
222
|
-
newpage.dir = Utils.paginate_path(template, cur_page_nr, config)
|
222
|
+
newpage.dir = Utils.paginate_path(template.url, cur_page_nr, config['permalink'])
|
223
223
|
if( config.has_key?('title_suffix'))
|
224
224
|
if( !template.data['title'] )
|
225
225
|
tmp_title = site.config['title']
|
@@ -15,9 +15,9 @@ module Jekyll
|
|
15
15
|
# all_posts - The Array of all the site's Posts.
|
16
16
|
# num_pages - The Integer number of pages or nil if you'd like the number
|
17
17
|
# of pages calculated.
|
18
|
-
def initialize(
|
18
|
+
def initialize(config_per_page, config_permalink, posts, cur_page_nr, num_pages, template_url )
|
19
19
|
@page = cur_page_nr
|
20
|
-
@per_page =
|
20
|
+
@per_page = config_per_page.to_i
|
21
21
|
@total_pages = num_pages
|
22
22
|
|
23
23
|
if @page > @total_pages
|
@@ -30,9 +30,9 @@ module Jekyll
|
|
30
30
|
@total_posts = posts.size
|
31
31
|
@posts = posts[init..offset]
|
32
32
|
@previous_page = @page != 1 ? @page - 1 : nil
|
33
|
-
@previous_page_path = Utils.paginate_path(
|
33
|
+
@previous_page_path = @page != 1 ? Utils.paginate_path(template_url, @previous_page, config_permalink) : nil
|
34
34
|
@next_page = @page != @total_pages ? @page + 1 : nil
|
35
|
-
@next_page_path = Utils.paginate_path(
|
35
|
+
@next_page_path = @page != @total_pages ? Utils.paginate_path(template_url, @next_page, config_permalink) : nil
|
36
36
|
end
|
37
37
|
|
38
38
|
# Convert this Paginator's data to a Hash suitable for use by Liquid.
|
@@ -14,16 +14,15 @@ module Jekyll
|
|
14
14
|
# config - the current configuration in use
|
15
15
|
#
|
16
16
|
# Returns the pagination path as a string
|
17
|
-
def self.paginate_path(
|
17
|
+
def self.paginate_path(template_url, cur_page_nr, permalink_format)
|
18
18
|
return nil if cur_page_nr.nil?
|
19
|
-
return
|
20
|
-
|
21
|
-
|
22
|
-
format = Utils.format_page_number(format, cur_page_nr)
|
19
|
+
return template_url if cur_page_nr <= 1
|
20
|
+
if permalink_format.include?(":num")
|
21
|
+
permalink_format = Utils.format_page_number(permalink_format, cur_page_nr)
|
23
22
|
else
|
24
|
-
raise ArgumentError.new("Invalid pagination path: '#{
|
23
|
+
raise ArgumentError.new("Invalid pagination path: '#{permalink_format}'. It must include ':num'.")
|
25
24
|
end
|
26
|
-
Utils.ensure_leading_slash(
|
25
|
+
Utils.ensure_leading_slash(permalink_format)
|
27
26
|
end #function paginate_path
|
28
27
|
|
29
28
|
# Static: returns a fully formatted string with the current page number if configured
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative 'spec_helper.rb'
|
2
|
+
|
3
|
+
module Jekyll::PaginateV2
|
4
|
+
describe "checking default config" do
|
5
|
+
|
6
|
+
it "should always contain the following keys" do
|
7
|
+
DEFAULT.must_include 'enabled'
|
8
|
+
DEFAULT.must_include 'collection'
|
9
|
+
DEFAULT.must_include 'per_page'
|
10
|
+
DEFAULT.must_include 'permalink'
|
11
|
+
DEFAULT.must_include 'title_suffix'
|
12
|
+
DEFAULT.must_include 'page_num'
|
13
|
+
DEFAULT.must_include 'sort_reverse'
|
14
|
+
DEFAULT.must_include 'sort_field'
|
15
|
+
DEFAULT.must_include 'limit'
|
16
|
+
DEFAULT.size.must_be :>=, 9
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should always contain the following key defaults" do
|
20
|
+
DEFAULT['enabled'].must_equal false
|
21
|
+
DEFAULT['collection'].must_equal 'posts'
|
22
|
+
DEFAULT['per_page'].must_equal 10
|
23
|
+
DEFAULT['permalink'].must_equal '/page:num/'
|
24
|
+
DEFAULT['title_suffix'].must_equal ' - page :num'
|
25
|
+
DEFAULT['page_num'].must_equal 1
|
26
|
+
DEFAULT['sort_reverse'].must_equal false
|
27
|
+
DEFAULT['sort_field'].must_equal 'date'
|
28
|
+
DEFAULT['limit'].must_equal 0
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require_relative 'spec_helper.rb'
|
2
|
+
|
3
|
+
module Jekyll::PaginateV2
|
4
|
+
describe PaginatorV2 do
|
5
|
+
|
6
|
+
it "must include the necessary paginator attributes" do
|
7
|
+
|
8
|
+
pager = PaginatorV2.new(10, "/page:num/", [], 1, 10, "/index.md")
|
9
|
+
|
10
|
+
err = ->{ pager.page }.wont_raise NoMethodError
|
11
|
+
err = ->{ pager.per_page }.wont_raise NoMethodError
|
12
|
+
err = ->{ pager.posts }.wont_raise NoMethodError
|
13
|
+
err = ->{ pager.total_posts }.wont_raise NoMethodError
|
14
|
+
err = ->{ pager.total_pages }.wont_raise NoMethodError
|
15
|
+
err = ->{ pager.previous_page }.wont_raise NoMethodError
|
16
|
+
err = ->{ pager.previous_page_path }.wont_raise NoMethodError
|
17
|
+
err = ->{ pager.next_page }.wont_raise NoMethodError
|
18
|
+
err = ->{ pager.next_page_path }.wont_raise NoMethodError
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
it "must throw an error if the current page number is greater than the total pages" do
|
23
|
+
err = -> { pager = PaginatorV2.new(10, "/page:num/", [], 10, 8, "/index.md") }.must_raise RuntimeError
|
24
|
+
err = -> { pager = PaginatorV2.new(10, "/page:num/", [], 8, 10, "/index.md") }.wont_raise RuntimeError
|
25
|
+
end
|
26
|
+
|
27
|
+
it "must trim the list of posts correctly based on the cur_page_nr and per_page" do
|
28
|
+
# Create a dummy list of posts that is easy to track
|
29
|
+
posts = ['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34','35']
|
30
|
+
|
31
|
+
# Initialize a pager with
|
32
|
+
# 5 posts per page
|
33
|
+
# at page 2 out of 5 pages
|
34
|
+
pager = PaginatorV2.new(5, "/page:num/", posts, 2, 5, "/index.md")
|
35
|
+
|
36
|
+
pager.page.must_equal 2
|
37
|
+
pager.per_page.must_equal 5
|
38
|
+
pager.total_pages.must_equal 5
|
39
|
+
|
40
|
+
pager.total_posts.must_equal 35
|
41
|
+
|
42
|
+
pager.posts.size.must_equal 5
|
43
|
+
pager.posts[0].must_equal '6'
|
44
|
+
pager.posts[4].must_equal '10'
|
45
|
+
|
46
|
+
pager.previous_page.must_equal 1
|
47
|
+
pager.previous_page_path.must_equal '/index.md'
|
48
|
+
pager.next_page.must_equal 3
|
49
|
+
pager.next_page_path.must_equal '/page3/'
|
50
|
+
end
|
51
|
+
|
52
|
+
it "must not create a previous page if we're at first page" do
|
53
|
+
# Create a dummy list of posts that is easy to track
|
54
|
+
posts = ['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34','35']
|
55
|
+
|
56
|
+
# Initialize a pager with
|
57
|
+
# 5 posts per page
|
58
|
+
# at page 2 out of 5 pages
|
59
|
+
pager = PaginatorV2.new(5, "/page:num/", posts, 1, 5, "/index.md")
|
60
|
+
|
61
|
+
pager.page.must_equal 1
|
62
|
+
pager.per_page.must_equal 5
|
63
|
+
pager.total_pages.must_equal 5
|
64
|
+
|
65
|
+
pager.total_posts.must_equal 35
|
66
|
+
|
67
|
+
pager.posts.size.must_equal 5
|
68
|
+
pager.posts[0].must_equal '1'
|
69
|
+
pager.posts[4].must_equal '5'
|
70
|
+
|
71
|
+
pager.previous_page.must_be_nil
|
72
|
+
pager.previous_page_path.must_be_nil
|
73
|
+
pager.next_page.must_equal 2
|
74
|
+
pager.next_page_path.must_equal '/page2/'
|
75
|
+
end
|
76
|
+
|
77
|
+
it "must not create a next page if we're at the final page" do
|
78
|
+
# Create a dummy list of posts that is easy to track
|
79
|
+
posts = ['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34','35']
|
80
|
+
|
81
|
+
# Initialize a pager with
|
82
|
+
# 5 posts per page
|
83
|
+
# at page 2 out of 5 pages
|
84
|
+
pager = PaginatorV2.new(5, "/page:num/", posts, 5, 5, "/index.md")
|
85
|
+
|
86
|
+
pager.page.must_equal 5
|
87
|
+
pager.per_page.must_equal 5
|
88
|
+
pager.total_pages.must_equal 5
|
89
|
+
|
90
|
+
pager.total_posts.must_equal 35
|
91
|
+
|
92
|
+
pager.posts.size.must_equal 5
|
93
|
+
pager.posts[0].must_equal '21'
|
94
|
+
pager.posts[4].must_equal '25'
|
95
|
+
|
96
|
+
pager.previous_page.must_equal 4
|
97
|
+
pager.previous_page_path.must_equal '/page4/'
|
98
|
+
pager.next_page.must_be_nil
|
99
|
+
pager.next_page_path.must_be_nil
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'minitest/spec'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
|
4
|
+
require 'jekyll'
|
5
|
+
require_relative '../lib/jekyll-paginate-v2/defaults'
|
6
|
+
require_relative '../lib/jekyll-paginate-v2/utils'
|
7
|
+
require_relative '../lib/jekyll-paginate-v2/paginator'
|
8
|
+
require_relative '../lib/jekyll-paginate-v2/pagination'
|
9
|
+
|
10
|
+
# From: http://stackoverflow.com/a/32335990/779521
|
11
|
+
module MiniTest
|
12
|
+
module Assertions
|
13
|
+
def refute_raises *exp
|
14
|
+
msg = "#{exp.pop}.\n" if String === exp.last
|
15
|
+
|
16
|
+
begin
|
17
|
+
yield
|
18
|
+
rescue MiniTest::Skip => e
|
19
|
+
return e if exp.include? MiniTest::Skip
|
20
|
+
raise e
|
21
|
+
rescue Exception => e
|
22
|
+
exp = exp.first if exp.size == 1
|
23
|
+
flunk "unexpected exception raised: #{e}"
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
module Expectations
|
29
|
+
infect_an_assertion :refute_raises, :wont_raise
|
30
|
+
end
|
31
|
+
end
|
data/spec/utils_spec.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require_relative 'spec_helper.rb'
|
2
|
+
|
3
|
+
module Jekyll::PaginateV2
|
4
|
+
describe Utils do
|
5
|
+
|
6
|
+
it "should always replace num format with the specified number" do
|
7
|
+
Utils.format_page_number( ":num", 7).must_equal "7"
|
8
|
+
Utils.format_page_number( ":num", 13).must_equal "13"
|
9
|
+
Utils.format_page_number( ":num", -2).must_equal "-2"
|
10
|
+
Utils.format_page_number( ":num", 0).must_equal "0"
|
11
|
+
Utils.format_page_number( ":num", 1000).must_equal "1000"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should always replace num format with the specified number and keep rest of formatting" do
|
15
|
+
Utils.format_page_number( "/page:num/", 7).must_equal "/page7/"
|
16
|
+
Utils.format_page_number( "/page:num/", 50).must_equal "/page50/"
|
17
|
+
Utils.format_page_number( "/page:num/", -5).must_equal "/page-5/"
|
18
|
+
|
19
|
+
Utils.format_page_number( "/car/:num/", 1).must_equal "/car/1/"
|
20
|
+
Utils.format_page_number( "/car/:num", 1).must_equal "/car/1"
|
21
|
+
Utils.format_page_number( "car/:num", 1).must_equal "car/1"
|
22
|
+
Utils.format_page_number( "/car//:num", 1).must_equal "/car//1"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "make sure there is a leading slash in path" do
|
26
|
+
Utils.ensure_leading_slash("path/to/file/wow").must_equal "/path/to/file/wow"
|
27
|
+
Utils.ensure_leading_slash("/no/place/wow/").must_equal "/no/place/wow/"
|
28
|
+
Utils.ensure_leading_slash("/no").must_equal "/no"
|
29
|
+
Utils.ensure_leading_slash("no").must_equal "/no"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "make sure there is never a leading slash in path" do
|
33
|
+
Utils.remove_leading_slash("path/to/file/wow").must_equal "path/to/file/wow"
|
34
|
+
Utils.remove_leading_slash("/no/place/wow/").must_equal "no/place/wow/"
|
35
|
+
Utils.remove_leading_slash("/no").must_equal "no"
|
36
|
+
Utils.remove_leading_slash("no").must_equal "no"
|
37
|
+
end
|
38
|
+
|
39
|
+
it "paginate must return nil if cur_page_nr is nill" do
|
40
|
+
Utils.paginate_path(nil, nil, nil).must_be_nil
|
41
|
+
Utils.paginate_path("/index/moore", nil, "/page:num/").must_be_nil
|
42
|
+
end
|
43
|
+
|
44
|
+
it "paginate must return the url to the template if cur_page_nr is equal to 1" do
|
45
|
+
Utils.paginate_path("/index/moore", 1, "/page:num/").must_equal "/index/moore"
|
46
|
+
Utils.paginate_path("/index.html", 1, "/page/").must_equal "/index.html"
|
47
|
+
end
|
48
|
+
|
49
|
+
it "paginate must throw an error if the permalink path doesn't include :num" do
|
50
|
+
err = ->{ Utils.paginate_path("/index.html", 3, "/page/")}.must_raise ArgumentError
|
51
|
+
err.message.must_include ":num"
|
52
|
+
end
|
53
|
+
|
54
|
+
it "paginate must use the permalink value and format it based on the cur_page_nr" do
|
55
|
+
Utils.paginate_path("/index.html", 3, "/page:num/").must_equal "/page3/"
|
56
|
+
Utils.paginate_path("/index.html", 646, "/page/:num/").must_equal "/page/646/"
|
57
|
+
end
|
58
|
+
|
59
|
+
it "paginate must ensure a leading slash in the url it returns" do
|
60
|
+
Utils.paginate_path("/index.html", 3, "page:num/").must_equal "/page3/"
|
61
|
+
Utils.paginate_path("/index.html", 646, "page/:num/").must_equal "/page/646/"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-paginate-v2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sverrir Sigmundarson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rspec
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '3.0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '3.0'
|
69
55
|
description: An enhanced in-place replacement for the previously built-in jekyll-paginate
|
70
56
|
gem offering full backwards compatability as well as a slew of new frequently requested
|
71
57
|
features
|
@@ -79,6 +65,7 @@ files:
|
|
79
65
|
- Gemfile
|
80
66
|
- LICENSE
|
81
67
|
- README.md
|
68
|
+
- Rakefile
|
82
69
|
- jekyll-paginate-v2.gemspec
|
83
70
|
- lib/jekyll-paginate-v2.rb
|
84
71
|
- lib/jekyll-paginate-v2/defaults.rb
|
@@ -86,6 +73,10 @@ files:
|
|
86
73
|
- lib/jekyll-paginate-v2/paginator.rb
|
87
74
|
- lib/jekyll-paginate-v2/utils.rb
|
88
75
|
- lib/jekyll-paginate-v2/version.rb
|
76
|
+
- spec/defaults_spec.rb
|
77
|
+
- spec/paginator_spec.rb
|
78
|
+
- spec/spec_helper.rb
|
79
|
+
- spec/utils_spec.rb
|
89
80
|
homepage: https://github.com/sverrirs/jekyll-paginate-v2
|
90
81
|
licenses:
|
91
82
|
- MIT
|
@@ -110,4 +101,8 @@ rubygems_version: 2.4.8
|
|
110
101
|
signing_key:
|
111
102
|
specification_version: 4
|
112
103
|
summary: Pagination Generator for Jekyll 3
|
113
|
-
test_files:
|
104
|
+
test_files:
|
105
|
+
- spec/defaults_spec.rb
|
106
|
+
- spec/paginator_spec.rb
|
107
|
+
- spec/spec_helper.rb
|
108
|
+
- spec/utils_spec.rb
|