middleman-pagination 1.0.0 → 1.0.1
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ec4df12de80b850fef444d0be189c97c8fdd2d7
|
4
|
+
data.tar.gz: ebdf7415e47c6bc08cf8ac98279c9ffaceec21f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f26c742c07023224891ca0c2ca321d3f30ec835a83fa7ecb5d384d4e70fb40d821a2b10eb1ed6aafbdb7aaad3e4358b7c9ce2f8ac176b9daad70fdf0247a79c3
|
7
|
+
data.tar.gz: 627b85c502bd9acf4c906b22ba2b3e26bac09a4c1bc2c27f2fc0cc71596b56a95e8a4bd5633458adbd7a8f9ab981d66cc519b8af8c6e5983a02346309dc519d7
|
data/README.md
CHANGED
@@ -4,13 +4,23 @@
|
|
4
4
|
[](https://codeclimate.com/github/Aupajo/middleman-pagination)
|
5
5
|
[](https://gemnasium.com/Aupajo/middleman-pagination)
|
6
6
|
|
7
|
-
**Warning: this extension is brand-new, and the API liable to change until the prerelease identifier is dropped.**
|
8
|
-
|
9
7
|
General-purpose pagination support for Middleman pages.
|
10
8
|
|
11
9
|
## Installation
|
12
10
|
|
13
|
-
|
11
|
+
Add this line to your Middleman site's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'middleman-pagination'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install middleman-pagination
|
14
24
|
|
15
25
|
## Usage
|
16
26
|
|
@@ -23,7 +33,7 @@ Let's say you have a set of recipes that you want to create pagination for:
|
|
23
33
|
bacon.html
|
24
34
|
cake.html
|
25
35
|
|
26
|
-
|
36
|
+
Inside your `config.rb`:
|
27
37
|
|
28
38
|
```ruby
|
29
39
|
activate :pagination do
|
@@ -64,8 +74,7 @@ Showing <%= pagination.per_page %> per page
|
|
64
74
|
|
65
75
|
**Note:** the `for` and `per_page` properties must be indented for the `pagination` frontmatter.
|
66
76
|
|
67
|
-
|
68
|
-
You can define as many different types of pageable resources as you like:
|
77
|
+
You can define as many different types of pageable resources as you like, with whatever criteria you like:
|
69
78
|
|
70
79
|
```ruby
|
71
80
|
activate :pagination do
|
@@ -86,6 +95,7 @@ end
|
|
86
95
|
* Customisable path
|
87
96
|
* Custom sorting (e.g. by date)
|
88
97
|
* Convenience helper methods (e.g. make `pagination.` optional)
|
98
|
+
* Pagination link generator (e.g. `Pages: 1 2 [3] ... 7 8 9`)
|
89
99
|
|
90
100
|
## Contributing
|
91
101
|
|
@@ -44,8 +44,14 @@ module Middleman
|
|
44
44
|
|
45
45
|
def build_new_index(first_index, pageable_context, page_num)
|
46
46
|
sitemap = context.sitemap
|
47
|
-
pattern = %r{(^|/)#{Regexp.escape(context.index_file)}}
|
48
|
-
|
47
|
+
pattern = %r{(^|/)#{Regexp.escape(context.index_file)}$}
|
48
|
+
|
49
|
+
path = if first_index.path.match(pattern)
|
50
|
+
first_index.path.sub(pattern, "pages/#{page_num}.html")
|
51
|
+
else
|
52
|
+
first_index.path.sub(%r{(^|/)([^/]*)\.([^/]*)$}, "\\1\\2/pages/#{page_num}.\\3")
|
53
|
+
end
|
54
|
+
|
49
55
|
source_file = first_index.source_file
|
50
56
|
|
51
57
|
new_index = ::Middleman::Sitemap::Resource.new(sitemap, path, source_file)
|
@@ -87,4 +87,26 @@ describe "Pagination with directory indexes", :feature do
|
|
87
87
|
find_on_page 'Prev page: /pages/3/'
|
88
88
|
find_on_page 'Next page: none'
|
89
89
|
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "Pagination with indexes not named index", :feature do
|
93
|
+
it "produces pages for a set of resources" do
|
94
|
+
run_site 'recipes' do
|
95
|
+
activate :pagination do
|
96
|
+
pageable :recipes do |resource|
|
97
|
+
resource.path.start_with?('recipes')
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
visit '/all-recipes.html'
|
103
|
+
find_on_page 'First page: /all-recipes.html'
|
104
|
+
find_on_page 'Prev page: none'
|
105
|
+
find_on_page 'Last page: /all-recipes/pages/2.html'
|
106
|
+
find_on_page 'Next page: /all-recipes/pages/2.html'
|
107
|
+
|
108
|
+
visit '/all-recipes/pages/2.html'
|
109
|
+
find_on_page 'Prev page: /all-recipes.html'
|
110
|
+
find_on_page 'Next page: none'
|
111
|
+
end
|
90
112
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
---
|
2
|
+
pagination:
|
3
|
+
for: recipes
|
4
|
+
per_page: 4
|
5
|
+
---
|
6
|
+
|
7
|
+
<% pagination.each do |recipe| %>
|
8
|
+
- <%= recipe.data.title %>
|
9
|
+
<% end %>
|
10
|
+
|
11
|
+
Page <%= pagination.page_num %> of <%= pagination.total_page_num %>
|
12
|
+
|
13
|
+
Showing <%= pagination.per_page %> per page
|
14
|
+
|
15
|
+
First page: <%= pagination.first_page.url %>
|
16
|
+
|
17
|
+
Next page: <%= pagination.next_page.try(:url) || 'none' %>
|
18
|
+
|
19
|
+
Prev page: <%= pagination.prev_page.try(:url) || 'none' %>
|
20
|
+
|
21
|
+
Last page: <%= pagination.last_page.url %>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: middleman-pagination
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pete Nicholls
|
@@ -119,6 +119,7 @@ files:
|
|
119
119
|
- lib/middleman_extension.rb
|
120
120
|
- middleman-pagination.gemspec
|
121
121
|
- spec/features/pagination_feature_spec.rb
|
122
|
+
- spec/fixtures/recipes/source/all-recipes.html.erb
|
122
123
|
- spec/fixtures/recipes/source/index.html.erb
|
123
124
|
- spec/fixtures/recipes/source/layouts/layout.erb
|
124
125
|
- spec/fixtures/recipes/source/recipes/bacon.html.erb
|
@@ -159,6 +160,7 @@ specification_version: 4
|
|
159
160
|
summary: Pagination for Middleman pages.
|
160
161
|
test_files:
|
161
162
|
- spec/features/pagination_feature_spec.rb
|
163
|
+
- spec/fixtures/recipes/source/all-recipes.html.erb
|
162
164
|
- spec/fixtures/recipes/source/index.html.erb
|
163
165
|
- spec/fixtures/recipes/source/layouts/layout.erb
|
164
166
|
- spec/fixtures/recipes/source/recipes/bacon.html.erb
|