jekyll-paginate-v2 1.5.2 → 1.6.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.
@@ -6,33 +6,36 @@ module Jekyll
6
6
  # The code does the same things as the default Jekyll/page.rb code but just forces the code to look
7
7
  # into the template instead of the (currently non-existing) pagination page.
8
8
  #
9
+ # This page exists purely in memory and is not read from disk
10
+ #
9
11
  class PaginationPage < Page
10
- def initialize(site, base, dir, template_path)
11
- @site = site
12
- @base = base
13
- @dir = dir
14
- @template = template_path
12
+ def initialize(page_to_copy, ignored)
13
+ @site = page_to_copy.site
14
+ @base = ''
15
+ @url = ''
15
16
  @name = 'index.html'
16
17
 
17
- templ_dir = File.dirname(template_path)
18
- templ_file = File.basename(template_path)
19
-
20
- # Path is only used by the convertible module and accessed below when calling read_yaml
21
- # in our case we have the path point to the original template instead of our faux new pagination page
22
- @path = if site.in_theme_dir(base) == base # we're in a theme
23
- site.in_theme_dir(base, templ_dir, templ_file)
24
- else
25
- site.in_source_dir(base, templ_dir, templ_file)
26
- end
27
-
28
- self.process(@name)
29
- self.read_yaml(templ_dir, templ_file)
18
+ self.process(@name) # Creates the basename and ext member values
30
19
 
31
- data.default_proc = proc do |_, key|
32
- site.frontmatter_defaults.find(File.join(templ_dir, templ_file), type, key)
20
+ # Only need to copy the data part of the page as it already contains the layout information
21
+ #self.data = Marshal.load(Marshal.dump(page_to_copy.data)) # Deep copying, http://stackoverflow.com/a/8206537/779521
22
+ self.data = Jekyll::Utils.deep_merge_hashes( page_to_copy.data, {} )
23
+ if !page_to_copy.data['autopage']
24
+ self.content = page_to_copy.content
33
25
  end
34
26
 
27
+ # Perform some validation that is also performed in Jekyll::Page
28
+ validate_data! page_to_copy.path
29
+ validate_permalink! page_to_copy.path
30
+
31
+ # Trigger a page event
32
+ #Jekyll::Hooks.trigger :pages, :post_init, self
33
+ end
34
+
35
+ def set_url(url_value)
36
+ @url = url_value
35
37
  end
36
38
  end # class PaginationPage
39
+
37
40
  end # module PaginateV2
38
41
  end # module Jekyll
@@ -6,16 +6,11 @@ module Jekyll
6
6
  #
7
7
  class Paginator
8
8
  attr_reader :page, :per_page, :posts, :total_posts, :total_pages,
9
- :previous_page, :previous_page_path, :next_page, :next_page_path
9
+ :previous_page, :previous_page_path, :next_page, :next_page_path, :page_path
10
10
 
11
11
  # Initialize a new Paginator.
12
12
  #
13
- # site - the Jekyll::Site object
14
- # page_nr - The Integer page number.
15
- # all_posts - The Array of all the site's Posts.
16
- # num_pages - The Integer number of pages or nil if you'd like the number
17
- # of pages calculated.
18
- def initialize(config_per_page, config_permalink, posts, cur_page_nr, num_pages, template_url, template_path )
13
+ def initialize(config_per_page, first_index_page_url, paginated_page_url, posts, cur_page_nr, num_pages)
19
14
  @page = cur_page_nr
20
15
  @per_page = config_per_page.to_i
21
16
  @total_pages = num_pages
@@ -29,10 +24,11 @@ module Jekyll
29
24
 
30
25
  @total_posts = posts.size
31
26
  @posts = posts[init..offset]
27
+ @page_path = @page == 1 ? first_index_page_url : Utils.format_page_number(paginated_page_url, cur_page_nr, @total_pages)
32
28
  @previous_page = @page != 1 ? @page - 1 : nil
33
- @previous_page_path = @page != 1 ? Utils.paginate_path(template_url, template_path, @previous_page, config_permalink) : nil
29
+ @previous_page_path = @page != 1 ? @page == 2 ? first_index_page_url : Utils.format_page_number(paginated_page_url, @previous_page, @total_pages) : nil
34
30
  @next_page = @page != @total_pages ? @page + 1 : nil
35
- @next_page_path = @page != @total_pages ? Utils.paginate_path(template_url, template_path, @next_page, config_permalink) : nil
31
+ @next_page_path = @page != @total_pages ? Utils.format_page_number(paginated_page_url, @next_page, @total_pages) : nil
36
32
  end
37
33
 
38
34
  # Convert this Paginator's data to a Hash suitable for use by Liquid.
@@ -45,6 +41,7 @@ module Jekyll
45
41
  'total_posts' => total_posts,
46
42
  'total_pages' => total_pages,
47
43
  'page' => page,
44
+ 'page_path' => page_path,
48
45
  'previous_page' => previous_page,
49
46
  'previous_page_path' => previous_page_path,
50
47
  'next_page' => next_page,
@@ -17,42 +17,20 @@ module Jekyll
17
17
  (all_posts.size.to_f / per_page.to_i).ceil
18
18
  end
19
19
 
20
- # Static: Return the pagination path of the page
20
+ # Static: returns a fully formatted string with the current (:num) page number and maximum (:max) page count replaced if configured
21
21
  #
22
- # site - the Jekyll::Site object
23
- # cur_page_nr - the pagination page number
24
- # config - the current configuration in use
25
- #
26
- # Returns the pagination path as a string
27
- def self.paginate_path(template_url, template_path, cur_page_nr, permalink_format)
28
- return nil if cur_page_nr.nil?
29
- return template_url if cur_page_nr <= 1
30
- if permalink_format.include?(":num")
31
- permalink_format = Utils.format_page_number(permalink_format, cur_page_nr)
32
- else
33
- raise ArgumentError.new("Invalid pagination path: '#{permalink_format}'. It must include ':num'.")
34
- end
35
-
36
- # If the template url is not just root "/" then pre-pend the template_url path to it
37
- template_dir = File.dirname(template_path)
38
- if( template_dir != "" && template_dir != "/" )
39
- template_url_noext = File.join(File.dirname(template_url), File.basename(template_url, '.*'))
40
- permalink_format = File.join(template_url_noext, permalink_format)
22
+ def self.format_page_number(toFormat, cur_page_nr, total_page_count=nil)
23
+ s = toFormat.sub(':num', cur_page_nr.to_s)
24
+ if !total_page_count.nil?
25
+ s = s.sub(':max', total_page_count.to_s)
41
26
  end
42
-
43
- Utils.ensure_leading_slash(permalink_format)
44
- end #function paginate_path
45
-
46
- # Static: returns a fully formatted string with the current page number if configured
47
- #
48
- def self.format_page_number(toFormat, cur_page_nr)
49
- return toFormat.sub(':num', cur_page_nr.to_s)
27
+ return s
50
28
  end #function format_page_number
51
29
 
52
- # Static: returns a fully formatted string with the :title variable replaced
30
+ # Static: returns a fully formatted string with the :title variable and the current (:num) page number and maximum (:max) page count replaced
53
31
  #
54
- def self.format_page_title(toFormat, title)
55
- return toFormat.sub(':title', title.to_s)
32
+ def self.format_page_title(toFormat, title, cur_page_nr=nil, total_page_count=nil)
33
+ return format_page_number(toFormat.sub(':title', title.to_s), cur_page_nr, total_page_count)
56
34
  end #function format_page_title
57
35
 
58
36
  # Static: Return a String version of the input which has a leading slash.
@@ -1,8 +1,8 @@
1
1
  module Jekyll
2
2
  module PaginateV2
3
- VERSION = "1.5.2"
3
+ VERSION = "1.6.0"
4
4
  # When modifying remember to issue a new tag command in git before committing, then push the new tag
5
- # git tag -a v1.5.2 -m "Gem v1.5.2"
5
+ # git tag -a v1.6.0 -m "Gem v1.6.0"
6
6
  # git push origin --tags
7
7
  end # module PaginateV2
8
8
  end # module Jekyll
@@ -5,7 +5,8 @@ module Jekyll::PaginateV2::Generator
5
5
 
6
6
  it "must include the necessary paginator attributes" do
7
7
 
8
- pager = Paginator.new(10, "/page:num/", [], 1, 10, "/index.md", "/index.md")
8
+ # config_per_page, first_index_page_url, paginated_page_url, posts, cur_page_nr, num_pages
9
+ pager = Paginator.new(10, "index.html", "/page:num/", [], 1, 10)
9
10
 
10
11
  # None of these accessors should throw errors, just run through them to test
11
12
  val = pager.page
@@ -21,10 +22,10 @@ module Jekyll::PaginateV2::Generator
21
22
  end
22
23
 
23
24
  it "must throw an error if the current page number is greater than the total pages" do
24
- err = -> { pager = Paginator.new(10, "/page:num/", [], 10, 8, "/index.md", "/index.md") }.must_raise RuntimeError
25
+ err = -> { pager = Paginator.new(10, "index.html", "/page:num/", [], 10, 8) }.must_raise RuntimeError
25
26
 
26
27
  # No error should be raised below
27
- pager = Paginator.new(10, "/page:num/", [], 8, 10, "/index.md", "/index.md")
28
+ pager = Paginator.new(10, "index.html", "/page:num/", [], 8, 10)
28
29
  end
29
30
 
30
31
  it "must trim the list of posts correctly based on the cur_page_nr and per_page" do
@@ -34,7 +35,7 @@ module Jekyll::PaginateV2::Generator
34
35
  # Initialize a pager with
35
36
  # 5 posts per page
36
37
  # at page 2 out of 5 pages
37
- pager = Paginator.new(5, "/page:num/", posts, 2, 5, "/index.md", "/index.md")
38
+ pager = Paginator.new(5, "index.html", "/page:num/", posts, 2, 5)
38
39
 
39
40
  pager.page.must_equal 2
40
41
  pager.per_page.must_equal 5
@@ -47,7 +48,7 @@ module Jekyll::PaginateV2::Generator
47
48
  pager.posts[4].must_equal '10'
48
49
 
49
50
  pager.previous_page.must_equal 1
50
- pager.previous_page_path.must_equal '/index.md'
51
+ pager.previous_page_path.must_equal 'index.html'
51
52
  pager.next_page.must_equal 3
52
53
  pager.next_page_path.must_equal '/page3/'
53
54
  end
@@ -59,7 +60,7 @@ module Jekyll::PaginateV2::Generator
59
60
  # Initialize a pager with
60
61
  # 5 posts per page
61
62
  # at page 2 out of 5 pages
62
- pager = Paginator.new(5, "/page:num/", posts, 1, 5, "/index.md", "/index.md")
63
+ pager = Paginator.new(5, "index.html", "/page:num/", posts, 1, 5)
63
64
 
64
65
  pager.page.must_equal 1
65
66
  pager.per_page.must_equal 5
@@ -84,7 +85,7 @@ module Jekyll::PaginateV2::Generator
84
85
  # Initialize a pager with
85
86
  # 5 posts per page
86
87
  # at page 2 out of 5 pages
87
- pager = Paginator.new(5, "/page:num/", posts, 5, 5, "/index.md", "/index.md")
88
+ pager = Paginator.new(5, "index.html", "/page:num/", posts, 5, 5)
88
89
 
89
90
  pager.page.must_equal 5
90
91
  pager.per_page.must_equal 5
@@ -36,37 +36,6 @@ module Jekyll::PaginateV2::Generator
36
36
  Utils.remove_leading_slash("no").must_equal "no"
37
37
  end
38
38
 
39
- it "paginate must return nil if cur_page_nr is nill" do
40
- Utils.paginate_path(nil, nil, nil, nil).must_be_nil
41
- Utils.paginate_path("/index/moore","/index/moore.md", 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", "/index/moore.md", 1, "/page:num/").must_equal "/index/moore"
46
- Utils.paginate_path("/index.html", "/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", "/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", "/index.html", 3, "/page:num/").must_equal "/page3/"
56
- Utils.paginate_path("/index.html", "/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", "/index.html", 3, "page:num/").must_equal "/page3/"
61
- Utils.paginate_path("/index.html", "/index.html", 646, "page/:num/").must_equal "/page/646/"
62
- end
63
-
64
- it "paginate must pre-pend the template.path url to it if we're not at root" do
65
- Utils.paginate_path("/sub/index.html", "/sub/index.html", 3, "page:num/").must_equal "/sub/index/page3/"
66
- Utils.paginate_path("/sub/index", "/sub/index.html", 3, "page:num/").must_equal "/sub/index/page3/"
67
- Utils.paginate_path("/index/", "/sub/index.html", 3, "page:num/").must_equal "/index/page3/"
68
- end
69
-
70
39
  it "sort must sort strings lowercase" do
71
40
  Utils.sort_values( "AARON", "Aaron").must_equal 0
72
41
  Utils.sort_values( "AARON", "aaron").must_equal 0
@@ -84,6 +53,14 @@ module Jekyll::PaginateV2::Generator
84
53
  Utils.sort_get_post_data(data, "book").must_be_nil
85
54
  end
86
55
 
56
+ it "should always replace max format with the specified number if specified" do
57
+ Utils.format_page_number( ":num-:max", 7, 16).must_equal "7-16"
58
+ Utils.format_page_number( ":num-:max", 13, 20).must_equal "13-20"
59
+ Utils.format_page_number( ":num-:max", -2, -4).must_equal "-2--4"
60
+ Utils.format_page_number( ":num_of_:max", 0, 10).must_equal "0_of_10"
61
+ Utils.format_page_number( ":num/:max", 1000, 2000).must_equal "1000/2000"
62
+ end
63
+
87
64
 
88
65
  end
89
66
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-paginate-v2
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.2
4
+ version: 1.6.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-12-05 00:00:00.000000000 Z
11
+ date: 2017-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.0'
20
- type: :development
20
+ type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.0'
27
27
  - !ruby/object:Gem::Dependency
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '10.4'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '10.4'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: minitest
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -59,9 +59,6 @@ dependencies:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '5.4'
62
- - - ">="
63
- - !ruby/object:Gem::Version
64
- version: 5.4.3
65
62
  type: :development
66
63
  prerelease: false
67
64
  version_requirements: !ruby/object:Gem::Requirement
@@ -69,13 +66,11 @@ dependencies:
69
66
  - - "~>"
70
67
  - !ruby/object:Gem::Version
71
68
  version: '5.4'
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- version: 5.4.3
75
69
  description: An enhanced zero-configuration in-place replacement for the now decomissioned
76
70
  built-in jekyll-paginate gem. This pagination gem offers full backwards compatability
77
71
  as well as a slew of new frequently requested features with minimal additional site
78
- and page configuration.
72
+ and page configuration. Optional features include auto-generation of paginated collection,
73
+ tag and category pages.
79
74
  email:
80
75
  - jekyll@sverrirs.com
81
76
  executables: []
@@ -85,12 +80,18 @@ files:
85
80
  - CODE_OF_CONDUCT.md
86
81
  - Gemfile
87
82
  - LICENSE
83
+ - README-AUTOPAGES.md
84
+ - README-GENERATOR.md
88
85
  - README.md
89
86
  - Rakefile
90
87
  - jekyll-paginate-v2.gemspec
91
88
  - lib/jekyll-paginate-v2.rb
92
- - lib/jekyll-paginate-v2/autopages/autoTagPages.rb
89
+ - lib/jekyll-paginate-v2/autopages/autoPages.rb
93
90
  - lib/jekyll-paginate-v2/autopages/defaults.rb
91
+ - lib/jekyll-paginate-v2/autopages/pages/baseAutoPage.rb
92
+ - lib/jekyll-paginate-v2/autopages/pages/categoryAutoPage.rb
93
+ - lib/jekyll-paginate-v2/autopages/pages/collectionAutoPage.rb
94
+ - lib/jekyll-paginate-v2/autopages/pages/tagAutoPage.rb
94
95
  - lib/jekyll-paginate-v2/autopages/utils.rb
95
96
  - lib/jekyll-paginate-v2/generator/compatibilityUtils.rb
96
97
  - lib/jekyll-paginate-v2/generator/defaults.rb
@@ -118,7 +119,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
118
119
  requirements:
119
120
  - - ">="
120
121
  - !ruby/object:Gem::Version
121
- version: '0'
122
+ version: 2.0.0
122
123
  required_rubygems_version: !ruby/object:Gem::Requirement
123
124
  requirements:
124
125
  - - ">="
@@ -1,66 +0,0 @@
1
- #module Jekyll
2
- # module PaginateV2::AutoPages
3
- #
4
- # #
5
- # # This code is adapted from Stephen Crosby's code https://github.com/stevecrozz
6
- # Jekyll::Hooks.register :site, :post_read do |site|
7
- #
8
- # # Get the configuration for the auto pages
9
- # default_config = DEFAULT.merge(site.config['autopages'] || {})
10
- #
11
- # # If disabled then don't do anything
12
- # if !default_config['enabled'] || !default_config['tags']
13
- # Jekyll.logger.debug "AutoPages:","Disabled/Not configured in site.config."
14
- # return
15
- # end
16
- #
17
- # # TODO: Should I detect here and disable if we're running the legacy paginate code???!
18
- #
19
- # # Roll through all documents in the posts collection and extract the tags
20
- # # construct the paginated tag page for each
21
- # site.posts.docs.map { |p| p.data['tags'] }.reduce(&:|).each do |tag|
22
- # site.pages << PaginatedTagPage.new(site, site.source, '', tag, default_config['tags'])
23
- # end
24
- # end
25
- #
26
- # class PaginatedTagPage < Jekyll::Page
27
- # def initialize(site, base, dir, tag, tags_config)
28
- # @site = site
29
- # @base = base
30
- # @dir = dir
31
- # @name = 'index.html'
32
- # @ext = '.html'
33
- # @url = Utils.format_tag_macro(tags_config['permalink'], tag)
34
- #
35
- # self.read_yaml(File.join(base, '_layouts'), tags_config['layout'])
36
- # self.data['layout'] = File.basename(tags_config['layout'], File.extname(tags_config['layout']))
37
- # self.data['title'] = Utils.format_tag_macro(tags_config['title'], tag)
38
- # self.data['pagination'] = {
39
- # 'enabled' => true,
40
- # 'collection' => 'posts',
41
- # 'sort_field' => 'date',
42
- # 'sort_reverse' => true,
43
- # 'tag' => tag
44
- # }
45
- #
46
- # 'enabled' => false,
47
- # 'collection' => 'posts',
48
- # 'per_page' => 10,
49
- # 'permalink' => '/page:num/', # Supports :num as customizable elements
50
- # 'title_suffix' => ' - page :num', # Supports :num as customizable elements
51
- # 'page_num' => 1,
52
- # 'sort_reverse' => false,
53
- # 'sort_field' => 'date',
54
- # 'limit' => 0, # Limit how many content objects to paginate (default: 0, means all)
55
- #
56
- # self.process(@name)
57
- #
58
- # data.default_proc = proc do |_, key|
59
- # site.frontmatter_defaults.find(File.join(dir, name), type, key)
60
- # end
61
- #
62
- # Jekyll::Hooks.trigger :pages, :post_init, self
63
- # end
64
- # end
65
- # end # module PaginateV2
66
- #end # module Jekyll