jekyll-paginate-v2 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -6
- data/lib/jekyll-paginate-v2.rb +2 -1
- data/lib/jekyll-paginate-v2/paginationGenerator.rb +66 -0
- data/lib/jekyll-paginate-v2/{pagination.rb → paginationModel.rb} +19 -38
- data/lib/jekyll-paginate-v2/paginator.rb +2 -2
- data/lib/jekyll-paginate-v2/version.rb +1 -1
- data/spec/paginator_spec.rb +7 -7
- data/spec/spec_helper.rb +3 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80659d18067d2e6e70c308778083386e55baa867
|
4
|
+
data.tar.gz: 24d4018f4b1df421583e0412079e6fd71cb6ab9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a49c16c2a1e5e450e39a169362a4702ec769160338a9ad081ad0e3a84a4c118117e3ea6039debdd16f05d2d3de35b7837558bf967ac06b5a62f5ecbf065a849
|
7
|
+
data.tar.gz: f34d20de449ce50b39f7c6015425f0f9f8b4ee52d7e04b9faaf5961470b90e6c2e4c0e6fc486714b7c11d29e20394c09c6d25e9c6e690cac14a5186938801594
|
data/README.md
CHANGED
@@ -38,6 +38,15 @@ In addition to all the features offered by the older [jekyll-paginate gem](https
|
|
38
38
|
|
39
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)).
|
40
40
|
|
41
|
+
## Issues / to-be-completed
|
42
|
+
* Not fully compatible with the old jekyll-paginate plugin configuration yet.
|
43
|
+
* Incomplete unit-tests
|
44
|
+
* Missing integration tests [#2](https://github.com/jekyll/jekyll-paginate/pull/2)
|
45
|
+
* Missing more detailed examples
|
46
|
+
* Code is still too tightly coupled with `site` [#26](https://github.com/jekyll/jekyll-paginate/issues/26)
|
47
|
+
* Unable to paginate _pages_ (still under consideration)
|
48
|
+
* Unable to auto-generate category/tag/language pagination pages. Still requires programmer to specify the pages him/herself.
|
49
|
+
* _Exclude_ filter not implemented [#6](https://github.com/jekyll/jekyll-paginate/issues/6)
|
41
50
|
|
42
51
|
## Contributing
|
43
52
|
|
@@ -45,11 +54,12 @@ I currently need testers and people willing to give me feedback and code reviews
|
|
45
54
|
|
46
55
|
1. Fork it ( https://github.com/sverrirs/jekyll-paginate-v2/fork )
|
47
56
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
48
|
-
3.
|
49
|
-
4.
|
50
|
-
5.
|
51
|
-
6.
|
52
|
-
7.
|
57
|
+
3. Run the unit tests (`rake`)
|
58
|
+
4. Commit your changes (`git commit -am 'Add some feature'`)
|
59
|
+
5. Build the gem locally (`gem build jekyll-paginate-v2.gemspec`)
|
60
|
+
6. Test and verify the gem locally (`gem install ./jekyll-paginate-v2-x.x.x.gem`)
|
61
|
+
7. Push to the branch (`git push origin my-new-feature`)
|
62
|
+
8. Create new Pull Request
|
53
63
|
|
54
64
|
Note: This project uses [semantic versioning](http://semver.org/).
|
55
65
|
|
@@ -136,6 +146,8 @@ And to display pagination links, simply
|
|
136
146
|
{% endif %}
|
137
147
|
```
|
138
148
|
|
149
|
+
> All posts that have the `hidden: true` in their front matter are ignored by the pagination logic.
|
150
|
+
|
139
151
|
The code is fully backwards compatible and you will have access to all the normal paginator variables defined in the [official jekyll documentation](https://jekyllrb.com/docs/pagination/#liquid-attributes-available).
|
140
152
|
|
141
153
|
Neat!
|
@@ -241,4 +253,12 @@ pagination:
|
|
241
253
|
category: ruby
|
242
254
|
sort_field: 'title'
|
243
255
|
sort_reverse: false
|
244
|
-
```
|
256
|
+
```
|
257
|
+
|
258
|
+
## Common issues
|
259
|
+
|
260
|
+
#### I'm getting a bundler error after upgrading the gem (Bundler::GemNotFound)
|
261
|
+
|
262
|
+
> bundler/spec_set.rb:95:in `block in materialize': Could not find jekyll-paginate-v2-1.0.0 in any of the sources (Bundler::GemNotFound)
|
263
|
+
|
264
|
+
When running `jekyll serve` if you ever get an error similar to the one above the solution is to delete your `Gemfile.lock` file and try again.
|
data/lib/jekyll-paginate-v2.rb
CHANGED
@@ -13,7 +13,8 @@ require "jekyll-paginate-v2/version"
|
|
13
13
|
require "jekyll-paginate-v2/defaults"
|
14
14
|
require "jekyll-paginate-v2/utils"
|
15
15
|
require "jekyll-paginate-v2/paginator"
|
16
|
-
require "jekyll-paginate-v2/
|
16
|
+
require "jekyll-paginate-v2/paginationModel"
|
17
|
+
require "jekyll-paginate-v2/paginationGenerator"
|
17
18
|
|
18
19
|
module Jekyll
|
19
20
|
module PaginateV2
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module PaginateV2
|
3
|
+
|
4
|
+
#
|
5
|
+
# The main entry point into the generator, called by Jekyll
|
6
|
+
# this function extracts all the necessary information from the jekyll end and passes it into the pagination
|
7
|
+
# logic. Additionally it also contains all site specific actions that the pagination logic needs access to
|
8
|
+
# (such as how to create new pages)
|
9
|
+
#
|
10
|
+
class PaginationGenerator < Generator
|
11
|
+
# This generator is safe from arbitrary code execution.
|
12
|
+
safe true
|
13
|
+
|
14
|
+
# This generator should be passive with regard to its execution
|
15
|
+
priority :lowest
|
16
|
+
|
17
|
+
# Generate paginated pages if necessary (Default entry point)
|
18
|
+
# site - The Site.
|
19
|
+
#
|
20
|
+
# Returns nothing.
|
21
|
+
def generate(site)
|
22
|
+
|
23
|
+
# Retrieve and merge the pagination configuration from the site yml file
|
24
|
+
default_config = DEFAULT.merge(site.config['pagination'] || {})
|
25
|
+
|
26
|
+
# If disabled then simply quit
|
27
|
+
if !default_config['enabled']
|
28
|
+
Jekyll.logger.info "Pagination:","disabled in site.config."
|
29
|
+
return
|
30
|
+
end
|
31
|
+
|
32
|
+
Jekyll.logger.debug "Pagination:","Starting"
|
33
|
+
|
34
|
+
################# 1 ###################
|
35
|
+
# Extract the necessary information out of the site object and then instantiate the model
|
36
|
+
|
37
|
+
# Get all posts that will be generated (excluding hidden posts that have hidden:true in the front matter)
|
38
|
+
all_posts = site.site_payload['site']['posts'].reject { |post| post['hidden'] }
|
39
|
+
|
40
|
+
# Get all pages in the site (this will be used to find the pagination templates)
|
41
|
+
all_pages = site.pages
|
42
|
+
|
43
|
+
# Get the default title of the site (used as backup when there is no title available for pagination)
|
44
|
+
site_title = site.config['title']
|
45
|
+
|
46
|
+
################ 2 ####################
|
47
|
+
# Create the proc that constructs the real-life site page
|
48
|
+
page_create_lambda = lambda do | template_dir, template_name |
|
49
|
+
# Create the new page
|
50
|
+
newpage = Page.new( site, site.source, template_dir, template_name)
|
51
|
+
# Add the page to the site so that it is generated correctly
|
52
|
+
site.pages << newpage
|
53
|
+
# Return the site to the calling code
|
54
|
+
return newpage
|
55
|
+
end
|
56
|
+
|
57
|
+
################ 3 ####################
|
58
|
+
# Now create and call the model with the real-life page creation proc and site data
|
59
|
+
model = PaginationModel.new()
|
60
|
+
model.run(default_config, all_pages, site_title, all_posts, &page_create_lambda)
|
61
|
+
|
62
|
+
end
|
63
|
+
end # class PaginationGenerator
|
64
|
+
|
65
|
+
end # module PaginateV2
|
66
|
+
end # module Jekyll
|
@@ -1,41 +1,21 @@
|
|
1
1
|
module Jekyll
|
2
2
|
module PaginateV2
|
3
3
|
|
4
|
-
class
|
5
|
-
|
6
|
-
|
4
|
+
class PaginationModel
|
5
|
+
|
6
|
+
def run(default_config, site_pages, site_title, all_posts, &page_create_proc)
|
7
|
+
#if !block_given?
|
8
|
+
# raise ArgumentError.new("No page creation block given, cannot continue.")
|
9
|
+
#end
|
7
10
|
|
8
|
-
# This generator should be passive with regard to its execution
|
9
|
-
priority :lowest
|
10
|
-
|
11
|
-
# Generate paginated pages if necessary (Default entry point)
|
12
|
-
# site - The Site.
|
13
|
-
#
|
14
|
-
# Returns nothing.
|
15
|
-
def generate(site)
|
16
|
-
|
17
|
-
# Retrieve and merge the folate configuration from the site yml file
|
18
|
-
default_config = DEFAULT.merge(site.config['pagination'] || {})
|
19
|
-
|
20
|
-
# If disabled then simply quit
|
21
|
-
if !default_config['enabled']
|
22
|
-
Jekyll.logger.info "Pagination:","disabled in site.config."
|
23
|
-
return
|
24
|
-
end
|
25
|
-
|
26
|
-
Jekyll.logger.debug "Pagination:","Starting"
|
27
|
-
|
28
11
|
# By default if pagination is enabled we attempt to find all index.html pages in the site
|
29
|
-
templates = self.discover_paginate_templates(
|
12
|
+
templates = self.discover_paginate_templates(site_pages)
|
30
13
|
if( templates.size.to_i <= 0 )
|
31
14
|
Jekyll.logger.warn "Pagination:","is enabled, but I couldn't find " +
|
32
15
|
"any index.html page to use as the pagination template. Skipping pagination."
|
33
16
|
return
|
34
17
|
end
|
35
18
|
|
36
|
-
# Get all posts that will be generated (excluding hidden posts such as drafts)
|
37
|
-
all_posts = site.site_payload['site']['posts'].reject { |post| post['hidden'] }
|
38
|
-
|
39
19
|
# Create the necessary indexes for the posts
|
40
20
|
all_categories = self.index_posts_by(all_posts, 'categories')
|
41
21
|
all_categories['posts'] = all_posts; # Popuplate a category for all posts
|
@@ -56,7 +36,8 @@ module Jekyll
|
|
56
36
|
if( template_config['enabled'] )
|
57
37
|
Jekyll.logger.info "Pagination:","found template: "+template.path
|
58
38
|
# Now construct the pagination data for this template page
|
59
|
-
self.paginate(site, template, template_config, all_posts, all_tags, all_categories, all_locales)
|
39
|
+
#self.paginate(site, template, template_config, all_posts, all_tags, all_categories, all_locales)
|
40
|
+
self.paginate(template, template_config, site_title, all_posts, all_tags, all_categories, all_locales, &page_create_proc)
|
60
41
|
end
|
61
42
|
end
|
62
43
|
end #for
|
@@ -64,13 +45,14 @@ module Jekyll
|
|
64
45
|
end # function generate
|
65
46
|
|
66
47
|
#
|
67
|
-
# Rolls through the
|
48
|
+
# Rolls through all the pages passed in and finds all pages that have pagination enabled on them.
|
49
|
+
# These pages will be used as templates
|
68
50
|
#
|
69
|
-
#
|
51
|
+
# site_pages - All pages in the site
|
70
52
|
#
|
71
|
-
def discover_paginate_templates(
|
53
|
+
def discover_paginate_templates(site_pages)
|
72
54
|
candidates = []
|
73
|
-
|
55
|
+
site_pages.select do |page|
|
74
56
|
# If the page has the enabled config set, supports any type of file name html or md
|
75
57
|
if page.data['pagination'].is_a?(Hash) && page.data['pagination']['enabled']
|
76
58
|
candidates << page
|
@@ -183,8 +165,7 @@ module Jekyll
|
|
183
165
|
# template - The index.html Page that requires pagination.
|
184
166
|
# config - The configuration settings that should be used
|
185
167
|
#
|
186
|
-
def paginate(
|
187
|
-
|
168
|
+
def paginate(template, config, site_title, all_posts, all_tags, all_categories, all_locales, &page_create_proc)
|
188
169
|
# By default paginate on all posts in the site
|
189
170
|
using_posts = all_posts
|
190
171
|
|
@@ -215,21 +196,21 @@ module Jekyll
|
|
215
196
|
# This .pager member is a built in thing in Jekyll and defines the paginator implementation
|
216
197
|
# Simpy override to use mine
|
217
198
|
(1..total_pages).each do |cur_page_nr|
|
218
|
-
pager =
|
199
|
+
pager = Paginator.new( config['per_page'], config['permalink'], using_posts, cur_page_nr, total_pages, template.url )
|
219
200
|
if( cur_page_nr > 1)
|
220
|
-
|
201
|
+
# External Proc call to create the actual page for us (this is passed in when the pagination is run)
|
202
|
+
newpage = page_create_proc.call( template.dir, template.name )
|
221
203
|
newpage.pager = pager
|
222
204
|
newpage.dir = Utils.paginate_path(template.url, cur_page_nr, config['permalink'])
|
223
205
|
if( config.has_key?('title_suffix'))
|
224
206
|
if( !template.data['title'] )
|
225
|
-
tmp_title =
|
207
|
+
tmp_title = site_title
|
226
208
|
else
|
227
209
|
tmp_title = template.data['title']
|
228
210
|
end
|
229
211
|
|
230
212
|
newpage.data['title'] = "#{tmp_title}#{Utils.format_page_number(config['title_suffix'], cur_page_nr)}"
|
231
213
|
end
|
232
|
-
site.pages << newpage
|
233
214
|
else
|
234
215
|
template.pager = pager
|
235
216
|
end
|
@@ -4,7 +4,7 @@ module Jekyll
|
|
4
4
|
#
|
5
5
|
# Handles the preparation of all the posts based on the current page index
|
6
6
|
#
|
7
|
-
class
|
7
|
+
class Paginator
|
8
8
|
attr_reader :page, :per_page, :posts, :total_posts, :total_pages,
|
9
9
|
:previous_page, :previous_page_path, :next_page, :next_page_path
|
10
10
|
|
@@ -52,7 +52,7 @@ module Jekyll
|
|
52
52
|
}
|
53
53
|
end
|
54
54
|
|
55
|
-
end # class
|
55
|
+
end # class Paginator
|
56
56
|
|
57
57
|
end # module PaginateV2
|
58
58
|
end # module Jekyll
|
data/spec/paginator_spec.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require_relative 'spec_helper.rb'
|
2
2
|
|
3
3
|
module Jekyll::PaginateV2
|
4
|
-
describe
|
4
|
+
describe Paginator do
|
5
5
|
|
6
6
|
it "must include the necessary paginator attributes" do
|
7
7
|
|
8
|
-
pager =
|
8
|
+
pager = Paginator.new(10, "/page:num/", [], 1, 10, "/index.md")
|
9
9
|
|
10
10
|
err = ->{ pager.page }.wont_raise NoMethodError
|
11
11
|
err = ->{ pager.per_page }.wont_raise NoMethodError
|
@@ -20,8 +20,8 @@ module Jekyll::PaginateV2
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it "must throw an error if the current page number is greater than the total pages" do
|
23
|
-
err = -> { pager =
|
24
|
-
err = -> { pager =
|
23
|
+
err = -> { pager = Paginator.new(10, "/page:num/", [], 10, 8, "/index.md") }.must_raise RuntimeError
|
24
|
+
err = -> { pager = Paginator.new(10, "/page:num/", [], 8, 10, "/index.md") }.wont_raise RuntimeError
|
25
25
|
end
|
26
26
|
|
27
27
|
it "must trim the list of posts correctly based on the cur_page_nr and per_page" do
|
@@ -31,7 +31,7 @@ module Jekyll::PaginateV2
|
|
31
31
|
# Initialize a pager with
|
32
32
|
# 5 posts per page
|
33
33
|
# at page 2 out of 5 pages
|
34
|
-
pager =
|
34
|
+
pager = Paginator.new(5, "/page:num/", posts, 2, 5, "/index.md")
|
35
35
|
|
36
36
|
pager.page.must_equal 2
|
37
37
|
pager.per_page.must_equal 5
|
@@ -56,7 +56,7 @@ module Jekyll::PaginateV2
|
|
56
56
|
# Initialize a pager with
|
57
57
|
# 5 posts per page
|
58
58
|
# at page 2 out of 5 pages
|
59
|
-
pager =
|
59
|
+
pager = Paginator.new(5, "/page:num/", posts, 1, 5, "/index.md")
|
60
60
|
|
61
61
|
pager.page.must_equal 1
|
62
62
|
pager.per_page.must_equal 5
|
@@ -81,7 +81,7 @@ module Jekyll::PaginateV2
|
|
81
81
|
# Initialize a pager with
|
82
82
|
# 5 posts per page
|
83
83
|
# at page 2 out of 5 pages
|
84
|
-
pager =
|
84
|
+
pager = Paginator.new(5, "/page:num/", posts, 5, 5, "/index.md")
|
85
85
|
|
86
86
|
pager.page.must_equal 5
|
87
87
|
pager.per_page.must_equal 5
|
data/spec/spec_helper.rb
CHANGED
@@ -2,10 +2,12 @@ require 'minitest/spec'
|
|
2
2
|
require 'minitest/autorun'
|
3
3
|
|
4
4
|
require 'jekyll'
|
5
|
+
require_relative '../lib/jekyll-paginate-v2/version'
|
5
6
|
require_relative '../lib/jekyll-paginate-v2/defaults'
|
6
7
|
require_relative '../lib/jekyll-paginate-v2/utils'
|
7
8
|
require_relative '../lib/jekyll-paginate-v2/paginator'
|
8
|
-
require_relative '../lib/jekyll-paginate-v2/
|
9
|
+
require_relative '../lib/jekyll-paginate-v2/paginationModel'
|
10
|
+
require_relative '../lib/jekyll-paginate-v2/paginationGenerator'
|
9
11
|
|
10
12
|
# From: http://stackoverflow.com/a/32335990/779521
|
11
13
|
module MiniTest
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sverrir Sigmundarson
|
@@ -69,7 +69,8 @@ files:
|
|
69
69
|
- jekyll-paginate-v2.gemspec
|
70
70
|
- lib/jekyll-paginate-v2.rb
|
71
71
|
- lib/jekyll-paginate-v2/defaults.rb
|
72
|
-
- lib/jekyll-paginate-v2/
|
72
|
+
- lib/jekyll-paginate-v2/paginationGenerator.rb
|
73
|
+
- lib/jekyll-paginate-v2/paginationModel.rb
|
73
74
|
- lib/jekyll-paginate-v2/paginator.rb
|
74
75
|
- lib/jekyll-paginate-v2/utils.rb
|
75
76
|
- lib/jekyll-paginate-v2/version.rb
|