octopress-paginate 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: acab0386b92350ad9e120e5b4412dd80a53b4d36
4
+ data.tar.gz: a26a9217a701686b3fc3d4d9927a92c91e84774f
5
+ SHA512:
6
+ metadata.gz: f835d5f0918a183738991b0b74be51f6e3ab57121557a8a70f3d4d0f0e30d9b8579d795da357460966f2c8e860a080a6e68c71ef75bb6b25dd5d589074297e43
7
+ data.tar.gz: fc3ace64ead955a8eba2b362d84cea5e36f24dd4d0afc1166a8bb2764b2cd9954cfc9f69d472ceac22687706d9eadad65c8b1b6f7614687f4e48fbb09e370508
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ### 1.0.0 (2015-02-10)
4
+
5
+ - Initial release
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Brandon Mathis
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,128 @@
1
+ # Octopress Paginate
2
+
3
+ Simple and flexible pagination for Jekyll sites featuring:
4
+
5
+ - Simple configuration
6
+ - Paginate posts and collections
7
+ - Page limits (Because who's reading page 35?)
8
+ - Filter by categories or tags
9
+ - Multi-language support (with [octopress-multilingual](https://github.com/octopress/multilingual))
10
+
11
+ ## Installation
12
+
13
+ If you're using bundler add this gem to your site's Gemfile in the `:jekyll_plugins` group:
14
+
15
+ group :jekyll_plugins do
16
+ gem 'octopress-paginate'
17
+ end
18
+
19
+ Then install the gem with Bundler
20
+
21
+ $ bundle
22
+
23
+ To install manually without bundler:
24
+
25
+ $ gem install octopress-paginate
26
+
27
+ Then add the gem to your Jekyll configuration.
28
+
29
+ gems:
30
+ - octopress-paginate
31
+
32
+ ## Usage
33
+
34
+ ### To paginate posts
35
+
36
+ Create a page to be used as the pagination template.
37
+
38
+ ```
39
+ ---
40
+ title: Post Index
41
+ paginate: true
42
+ ---
43
+
44
+ {% for post in paginator.posts %}
45
+ / do stuff /
46
+ {% endfor %}
47
+ ```
48
+
49
+ ### To paginate collections
50
+
51
+ This is basically the same as paginating posts, except you have to configure the paginate collection and set up the paginator to
52
+ use the collection name.
53
+
54
+ ```
55
+ ---
56
+ title: Penguin Index
57
+ paginate:
58
+ collection: penguins
59
+ ---
60
+
61
+ {% for penguin in paginator.penguins %}
62
+ / do stuff /
63
+ {% endfor %}
64
+ ```
65
+
66
+ ### Template variables
67
+
68
+ Just like Jekyll's paginator, your pagination pages will have access to the following liquid variables.
69
+
70
+
71
+ ```yaml
72
+ {{ paginator.total_pages }} # Number of paginated pages
73
+ {{ paginator.total_posts }} # Total number of posts being paginated
74
+ {{ paginator.per_page }} # Posts per page
75
+ {{ paginator.limit }} # Maximum number of paginated pages
76
+ {{ paginator.page }} # Current page number
77
+ {{ paginator.previous_page }} # Previous page number (nil if first page)
78
+ {{ paginator.previous_page_path }} # Url for previous page (nil if first page)
79
+ {{ paginator.next_page }} # Next page number (nil if last page)
80
+ {{ paginator.next_page_path }} # Next page URL (nil if last page)
81
+
82
+ # If you're pagination through a collection named `penguins`
83
+ {{ pagination.total_penguins }} # Total number of peguins being paginated
84
+ ```
85
+
86
+ ## Configuration
87
+
88
+ In a page's YAML front-matter, setting `paginate: true` turns that page into a template for pagination. To configure pagination,
89
+ set the options for the `paginate` key. Here are the defaults.
90
+
91
+ ```yaml
92
+ paginate:
93
+ collection: posts
94
+ per_page: 10 # maximum number of posts per page
95
+ limit: 5 # Maximum number of pages to paginate (0 for unlimited)
96
+ permalink: /page:num/ # pagination path (relative to template page)
97
+ title_suffix: " - page :num" # Append to template's page title
98
+ category: '' # Paginate posts in this category
99
+ categories: [] # Paginate posts in any of these categories
100
+ tag: '' # Paginate posts tagged with this tag
101
+ tags: [] # Paginate posts tagged with any of these tags
102
+ ```
103
+
104
+ ### Pagination permalinks
105
+
106
+ Assume your pagination template page was at `/index.html`. The second pagination page would be
107
+ published to `/page2/index.html` by default. If your template page was at `/posts/index.html` or if was configured
108
+ with `permalink: /posts/` the second pagination page would be published to `/posts/page2/index.html`.
109
+
110
+
111
+ Here are some examples:
112
+
113
+ ```
114
+ paginate:
115
+ permalink /page-:num/ # => /page-2/index.html
116
+ permalink /page/:num/ # => /page/2/index.html
117
+ permalink /:num/ # => /2/index.html
118
+ ```
119
+
120
+ You get the idea.
121
+
122
+ ## Contributing
123
+
124
+ 1. Fork it ( https://github.com/octopress/paginate/fork )
125
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
126
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
127
+ 4. Push to the branch (`git push origin my-new-feature`)
128
+ 5. Create a new Pull Request
@@ -0,0 +1,133 @@
1
+ require "octopress-hooks"
2
+ require "octopress-paginate/version"
3
+ require "octopress-paginate/hooks"
4
+ require "octopress-paginate/page"
5
+
6
+ module Octopress
7
+ module Paginate
8
+ extend self
9
+
10
+ DEFAULT = {
11
+ 'collection' => 'posts',
12
+ 'per_page' => 10,
13
+ 'limit' => 5,
14
+ 'permalink' => '/page:num/',
15
+ 'title_suffix' => ' - page :num',
16
+ 'page_num' => 1
17
+ }
18
+
19
+ LOOP = /(paginate.+\s+in)\s+(site\.(.+?))(.+)%}/
20
+
21
+ def paginate(page)
22
+ if page.data['paginate'].is_a? Hash
23
+ page.data['paginate'] = DEFAULT.merge(page.data['paginate'])
24
+ else
25
+ page.data['paginate'] = DEFAULT
26
+ end
27
+
28
+ if tag = page.data['paginate']['tag']
29
+ page.data['paginate']['tags'] = Array(tag)
30
+ end
31
+
32
+ if category = page.data['paginate']['category']
33
+ page.data['paginate']['categories'] = Array(category)
34
+ end
35
+
36
+ add_pages(page)
37
+ end
38
+
39
+ def add_pages(page)
40
+ config = page.data['paginate']
41
+ pages = (collection(page).size.to_f / config['per_page']).ceil - 1
42
+
43
+ if config['limit'] > 0
44
+ pages = [pages, config['limit'] - 1].min
45
+ end
46
+
47
+ page.data['paginate']['pages'] = pages + 1
48
+
49
+ new_pages = []
50
+
51
+ pages.times do |i|
52
+ new_pages << PaginationPage.new(page.site, page.site.source, i+2, page)
53
+ end
54
+
55
+ all_pages = [page].concat(new_pages)
56
+
57
+ all_pages.each_with_index do |p, index|
58
+
59
+ if index > 0
60
+ prev_page = all_pages[index - 1]
61
+ p.data['paginate']['previous_page'] = index
62
+ p.data['paginate']['previous_page_path'] = prev_page.url
63
+ end
64
+
65
+ if next_page = all_pages[index + 1]
66
+ p.data['paginate']['next_page'] = index + 2
67
+ p.data['paginate']['next_page_path'] = next_page.url
68
+ end
69
+ end
70
+
71
+ page.site.pages.concat new_pages
72
+ end
73
+
74
+ def collection(page)
75
+ collection = if page['paginate']['collection'] == 'posts'
76
+ if defined?(Octopress::Multilingual) && page.lang
77
+ page.site.posts_by_language[page.lang]
78
+ else
79
+ page.site.posts.reverse
80
+ end
81
+ else
82
+ page.site.collections[page['paginate']['collection']].docs
83
+ end
84
+
85
+ if categories = page.data['paginate']['categories']
86
+ collection = collection.reject{|p| (p.categories & categories).empty?}
87
+ end
88
+
89
+ if tags = page.data['paginate']['tags']
90
+ collection = collection.reject{|p| (p.tags & tags).empty?}
91
+ end
92
+
93
+ collection
94
+ end
95
+
96
+ def page_payload(payload, page)
97
+ config = page.data['paginate']
98
+ collection = collection(page)
99
+ { 'paginator' => {
100
+ "#{config['collection']}" => items(payload, collection),
101
+ "page" => config['page_num'],
102
+ "per_page" => config['per_page'],
103
+ "limit" => config['limit'],
104
+ "total_#{config['collection']}" => collection.size,
105
+ "total_pages" => config['pages'],
106
+ 'previous_page' => config['previous_page'],
107
+ 'previous_page_path' => config['previous_page_path'],
108
+ 'next_page' => config['next_page'],
109
+ 'next_page_path' => config['next_page_path']
110
+ }}
111
+ end
112
+
113
+ def items(payload, collection)
114
+ config = payload['page']['paginate']
115
+
116
+ n = (config['page_num'] - 1) * config['per_page']
117
+ max = n + (config['per_page'] - 1)
118
+
119
+ collection[n..max]
120
+ end
121
+ end
122
+ end
123
+
124
+ if defined? Octopress::Docs
125
+ Octopress::Docs.add({
126
+ name: "Octopress Paginate",
127
+ gem: "octopress-paginate",
128
+ version: Octopress::Paginate::VERSION,
129
+ description: "Simple and flexible pagination for Jekyll posts and collections",
130
+ path: File.expand_path(File.join(File.dirname(__FILE__), "../")),
131
+ source_url: "https://github.com/octopress/paginate"
132
+ })
133
+ end
@@ -0,0 +1,19 @@
1
+ module Octopress
2
+ module Paginate
3
+ class SiteHook < Hooks::Site
4
+ def post_read(site)
5
+ site.pages.select {|p| p.data['paginate'] }.each do |page|
6
+ Octopress::Paginate.paginate(page)
7
+ end
8
+ end
9
+ end
10
+
11
+ class PageHook < Hooks::Page
12
+ def merge_payload(payload, page)
13
+ if page.data['paginate']
14
+ Octopress::Paginate.page_payload(payload, page)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ module Octopress
2
+ module Paginate
3
+ class PaginationPage < Jekyll::Page
4
+ def initialize(site, base, index, template)
5
+ @site = site
6
+ @base = base
7
+ @dir = File.join(template.dir, template.data['paginate']['permalink'].clone.sub(':num', index.to_s))
8
+ @name = 'index.html'
9
+ process(name)
10
+ read_yaml(File.join(base, File.dirname(template.path)), File.basename(template.path))
11
+
12
+ self.data.delete('permalink')
13
+ self.data.merge!({ 'paginate' => template.data['paginate'].clone })
14
+ self.data['paginate']['page_num'] = index
15
+
16
+ self.data['title'] ||= self.data['paginate']['collection'].capitlaize
17
+ self.data['title'] << data['paginate']['title_suffix'].sub(/:num/, data['paginate']['page_num'].to_s)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ module Octopress
2
+ module Paginate
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: octopress-paginate
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Brandon Mathis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: octopress-hooks
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: clash
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: octopress-multilingual
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: octopress
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-byebug
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description:
112
+ email:
113
+ - brandon@imathis.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - CHANGELOG.md
119
+ - LICENSE.txt
120
+ - README.md
121
+ - lib/octopress-paginate.rb
122
+ - lib/octopress-paginate/hooks.rb
123
+ - lib/octopress-paginate/page.rb
124
+ - lib/octopress-paginate/version.rb
125
+ homepage: https://github.com/octopress/paginate
126
+ licenses:
127
+ - MIT
128
+ metadata: {}
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 2.2.2
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: A nice and simple paginator for Jekyll sites.
149
+ test_files: []