middleman-pagination 1.0.4 → 1.0.5
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 +17 -2
- data/lib/middleman/pagination/index_path.rb +2 -2
- data/lib/middleman/pagination/manipulated_resources.rb +5 -3
- data/lib/middleman/pagination/version.rb +1 -1
- data/spec/features/custom_path_feature_spec.rb +23 -0
- data/spec/fixtures/recipes/source/custom.html.erb +22 -0
- data/spec/middleman/pagination/manipulated_resources_spec.rb +1 -1
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a29ba1726972cb939f315b1f5ac1ded71d23cc1f
|
4
|
+
data.tar.gz: 3660c0071d5073fc8df417b639a5a43c844041b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9e6048da2b6ae427d11fa33b968216ffefab71aef562cdc0f8b22694410332c3eddacc4c0ca1974c4c5a2f57fd168f8dbc8ea88e7cc69e5b599f63dcf1a42c4
|
7
|
+
data.tar.gz: 3f1fd46306b3476eb8d6e43e2436f68fc451d6a6133d79b4666645d3008090a37f8d7e45ca793a36c2133bb0396e7252a0f9ee78ba18eaf364e31d51e395c870
|
data/README.md
CHANGED
@@ -72,7 +72,7 @@ Showing <%= pagination.per_page %> per page
|
|
72
72
|
<%= link_to "Last page", pagination.first_page.url %>
|
73
73
|
```
|
74
74
|
|
75
|
-
**Note:** the `for` and `per_page` properties must be indented for the `pagination` frontmatter.
|
75
|
+
**Note:** the `for` and `per_page` properties must be indented for the `pagination` frontmatter (`per_page` is optional).
|
76
76
|
|
77
77
|
You can define as many different types of pageable resources as you like, with whatever criteria you like:
|
78
78
|
|
@@ -90,13 +90,28 @@ activate :pagination do
|
|
90
90
|
end
|
91
91
|
```
|
92
92
|
|
93
|
+
### Custom path
|
94
|
+
|
95
|
+
If your pagination index is called `all-recipes.html`, the subsequent pages will ba named `all-recipes/pages/2.html`, `all-recipes/pages/3.html`, and so on.
|
96
|
+
|
97
|
+
You can customise the path with the `path` pagination frontmatter. For example, in `all-recipes.html`:
|
98
|
+
|
99
|
+
```
|
100
|
+
---
|
101
|
+
pagination:
|
102
|
+
for: recipes
|
103
|
+
path: p/:num
|
104
|
+
---
|
105
|
+
```
|
106
|
+
|
107
|
+
Your pages would be created at `all-recipes/p/1.html`, `all-recipes/p/2.html`, etc.
|
108
|
+
|
93
109
|
## Getting help
|
94
110
|
|
95
111
|
Bug? Feature request? You can [open an issue](https://github.com/Aupajo/middleman-pagination/issues), [contact me on Twitter](http://twitter.com/aupajo), or [start a new topic on the Middleman forums](http://forum.middlemanapp.com). All feedback and suggestions welcome.
|
96
112
|
|
97
113
|
## TODO
|
98
114
|
|
99
|
-
* Customisable path
|
100
115
|
* Custom sorting (e.g. by date)
|
101
116
|
* Convenience helper methods (e.g. make `pagination.` optional)
|
102
117
|
* Pagination link generator (e.g. `Pages: 1 2 [3] ... 7 8 9`)
|
@@ -3,10 +3,10 @@ module Middleman
|
|
3
3
|
class IndexPath
|
4
4
|
attr_accessor :context, :original_path, :page_num, :symbolic_path_replacement
|
5
5
|
|
6
|
-
def initialize(context, original_path, page_num, symbolic_path_replacement =
|
6
|
+
def initialize(context, original_path, page_num, symbolic_path_replacement = nil)
|
7
7
|
@context = context
|
8
8
|
@original_path = original_path
|
9
|
-
@symbolic_path_replacement = symbolic_path_replacement
|
9
|
+
@symbolic_path_replacement = symbolic_path_replacement || 'pages/:num'
|
10
10
|
|
11
11
|
if page_num < 1
|
12
12
|
raise "Expected page_num greater than 0 (page numbers are not zero-indexed"
|
@@ -29,6 +29,8 @@ module Middleman
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def new_resources_for_index(first_index, filter)
|
32
|
+
symbolic_replacement_path = first_index.data.pagination.try(:path)
|
33
|
+
|
32
34
|
pageable_context = PageableContext.new(
|
33
35
|
per_page: first_index.data.pagination.per_page || 20,
|
34
36
|
# OPTIMIZE
|
@@ -39,13 +41,13 @@ module Middleman
|
|
39
41
|
add_pagination_to(first_index, pageable_context: pageable_context, page_num: 1)
|
40
42
|
|
41
43
|
(2..pageable_context.total_page_num).map do |n|
|
42
|
-
build_new_index(first_index, pageable_context, n)
|
44
|
+
build_new_index(first_index, pageable_context, n, symbolic_replacement_path)
|
43
45
|
end
|
44
46
|
end
|
45
47
|
|
46
|
-
def build_new_index(first_index, pageable_context, page_num)
|
48
|
+
def build_new_index(first_index, pageable_context, page_num, symbolic_replacement_path)
|
47
49
|
sitemap = context.sitemap
|
48
|
-
path = IndexPath.new(context, first_index.path, page_num).to_s
|
50
|
+
path = IndexPath.new(context, first_index.path, page_num, symbolic_replacement_path).to_s
|
49
51
|
source_file = first_index.source_file
|
50
52
|
|
51
53
|
new_index = ::Middleman::Sitemap::Resource.new(sitemap, path, source_file)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Pagination with custom path", :feature do
|
4
|
+
it "produces pages for a set of resources with a custom path" do
|
5
|
+
run_site 'recipes' do
|
6
|
+
activate :pagination do
|
7
|
+
pageable :recipes do |resource|
|
8
|
+
resource.path.start_with?('recipes')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
visit '/custom.html'
|
14
|
+
find_on_page 'First page: /custom.html'
|
15
|
+
find_on_page 'Prev page: none'
|
16
|
+
find_on_page 'Last page: /custom/p/2.html'
|
17
|
+
find_on_page 'Next page: /custom/p/2.html'
|
18
|
+
|
19
|
+
visit '/custom/p/2.html'
|
20
|
+
find_on_page 'Prev page: /custom.html'
|
21
|
+
find_on_page 'Next page: none'
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
---
|
2
|
+
pagination:
|
3
|
+
for: recipes
|
4
|
+
per_page: 4
|
5
|
+
path: p/:num
|
6
|
+
---
|
7
|
+
|
8
|
+
<% pagination.each do |recipe| %>
|
9
|
+
- <%= recipe.data.title %>
|
10
|
+
<% end %>
|
11
|
+
|
12
|
+
Page <%= pagination.page_num %> of <%= pagination.total_page_num %>
|
13
|
+
|
14
|
+
Showing <%= pagination.per_page %> per page
|
15
|
+
|
16
|
+
First page: <%= pagination.first_page.url %>
|
17
|
+
|
18
|
+
Next page: <%= pagination.next_page.try(:url) || 'none' %>
|
19
|
+
|
20
|
+
Prev page: <%= pagination.prev_page.try(:url) || 'none' %>
|
21
|
+
|
22
|
+
Last page: <%= pagination.last_page.url %>
|
@@ -28,7 +28,7 @@ module Middleman::Pagination
|
|
28
28
|
}
|
29
29
|
|
30
30
|
let(:pagination_index) {
|
31
|
-
pagination_data = double(for: 'recipes', per_page: 2)
|
31
|
+
pagination_data = double(for: 'recipes', per_page: 2, path: nil)
|
32
32
|
resource = double(:resource, path: 'index.html', is_recipe?: false, ignored?: false).as_null_object
|
33
33
|
resource.stub_chain(:data, pagination: pagination_data)
|
34
34
|
resource
|
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pete Nicholls
|
@@ -119,10 +119,12 @@ files:
|
|
119
119
|
- lib/middleman/pagination/version.rb
|
120
120
|
- lib/middleman_extension.rb
|
121
121
|
- middleman-pagination.gemspec
|
122
|
+
- spec/features/custom_path_feature_spec.rb
|
122
123
|
- spec/features/pagination_feature_spec.rb
|
123
124
|
- spec/fixtures/mine/source/index.html.erb
|
124
125
|
- spec/fixtures/mine/source/minerals/template.html.erb
|
125
126
|
- spec/fixtures/recipes/source/all-recipes.html.erb
|
127
|
+
- spec/fixtures/recipes/source/custom.html.erb
|
126
128
|
- spec/fixtures/recipes/source/index.html.erb
|
127
129
|
- spec/fixtures/recipes/source/layouts/layout.erb
|
128
130
|
- spec/fixtures/recipes/source/recipes/bacon.html.erb
|
@@ -163,10 +165,12 @@ signing_key:
|
|
163
165
|
specification_version: 4
|
164
166
|
summary: Pagination for Middleman pages.
|
165
167
|
test_files:
|
168
|
+
- spec/features/custom_path_feature_spec.rb
|
166
169
|
- spec/features/pagination_feature_spec.rb
|
167
170
|
- spec/fixtures/mine/source/index.html.erb
|
168
171
|
- spec/fixtures/mine/source/minerals/template.html.erb
|
169
172
|
- spec/fixtures/recipes/source/all-recipes.html.erb
|
173
|
+
- spec/fixtures/recipes/source/custom.html.erb
|
170
174
|
- spec/fixtures/recipes/source/index.html.erb
|
171
175
|
- spec/fixtures/recipes/source/layouts/layout.erb
|
172
176
|
- spec/fixtures/recipes/source/recipes/bacon.html.erb
|