middleman-pagination 1.0.5 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6585d00919a91cfbdddc63b60109f4472f7eb005
|
4
|
+
data.tar.gz: 616eda1fe14317f7cbaf8b4f26304c5be10aab78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2700db7a4c0f1d3b264dbdd0ba59f5444962dfbb2fa363ec7e562576113231ad17e9fa261a8e506d4030e4fab59413a22c95f517f1a46330f5b1c8d5caf5a4e0
|
7
|
+
data.tar.gz: 79ac07a2e77556d20586a315e9b36fc8af03fd7f4a65c3c188c254a80550ccc173370448f95e464fa2a7b6e2d0d92797c99e4f1ffc38e9b05e35349a765e6a5b
|
data/README.md
CHANGED
@@ -113,6 +113,7 @@ Bug? Feature request? You can [open an issue](https://github.com/Aupajo/middlema
|
|
113
113
|
## TODO
|
114
114
|
|
115
115
|
* Custom sorting (e.g. by date)
|
116
|
+
* Add tests for metadata support
|
116
117
|
* Convenience helper methods (e.g. make `pagination.` optional)
|
117
118
|
* Pagination link generator (e.g. `Pages: 1 2 [3] ... 7 8 9`)
|
118
119
|
* Adopt Middleman's Queryable interface
|
@@ -14,6 +14,14 @@ module Middleman
|
|
14
14
|
|
15
15
|
private
|
16
16
|
|
17
|
+
def pagination_data(resource, key)
|
18
|
+
keys = [:pagination, key]
|
19
|
+
|
20
|
+
[resource.data, resource.metadata[:options]].inject(nil) do |result, data_source|
|
21
|
+
result or keys.inject(data_source) { |source, key| source.try(:[], key) }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
17
25
|
def new_resources
|
18
26
|
context.configuration.map do |name, filter|
|
19
27
|
new_resources_for_pageable(name, filter)
|
@@ -22,17 +30,17 @@ module Middleman
|
|
22
30
|
|
23
31
|
def new_resources_for_pageable(name, filter)
|
24
32
|
original_resources.map do |resource|
|
25
|
-
if !resource.ignored? && resource
|
33
|
+
if !resource.ignored? && pagination_data(resource, :for) == name.to_s
|
26
34
|
new_resources_for_index(resource, filter)
|
27
35
|
end
|
28
36
|
end.compact
|
29
37
|
end
|
30
|
-
|
38
|
+
|
31
39
|
def new_resources_for_index(first_index, filter)
|
32
|
-
symbolic_replacement_path = first_index
|
40
|
+
symbolic_replacement_path = pagination_data(first_index, :path)
|
33
41
|
|
34
42
|
pageable_context = PageableContext.new(
|
35
|
-
per_page: first_index
|
43
|
+
per_page: pagination_data(first_index, :per_page) || 20,
|
36
44
|
# OPTIMIZE
|
37
45
|
resources: original_resources.reject(&:ignored?).select(&filter).sort_by(&:path),
|
38
46
|
index_resources: [first_index]
|
@@ -60,7 +68,7 @@ module Middleman
|
|
60
68
|
|
61
69
|
def add_pagination_to(resource, attributes = {})
|
62
70
|
in_page_context = InPageContext.new(attributes)
|
63
|
-
resource.add_metadata(:
|
71
|
+
resource.add_metadata(locals: { 'pagination' => in_page_context })
|
64
72
|
end
|
65
73
|
end
|
66
74
|
end
|
@@ -28,16 +28,17 @@ module Middleman::Pagination
|
|
28
28
|
}
|
29
29
|
|
30
30
|
let(:pagination_index) {
|
31
|
-
pagination_data =
|
32
|
-
|
33
|
-
resource
|
31
|
+
pagination_data = { for: 'recipes', per_page: 2, path: nil }
|
32
|
+
resource_data = { pagination: pagination_data }
|
33
|
+
resource = double(:resource, path: 'index.html', is_recipe?: false, ignored?: false, metadata: {}).as_null_object
|
34
|
+
resource.stub(data: resource_data)
|
34
35
|
resource
|
35
36
|
}
|
36
37
|
|
37
38
|
let(:resource_list) {
|
38
39
|
[pagination_index] +
|
39
40
|
7.times.map do |n|
|
40
|
-
double(:resource, path: "recipe-#{n}.html", is_recipe?: true, ignored?: false).as_null_object
|
41
|
+
double(:resource, path: "recipe-#{n}.html", is_recipe?: true, ignored?: false, metadata: {}, data: {}).as_null_object
|
41
42
|
end
|
42
43
|
}
|
43
44
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pete Nicholls
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: middleman-core
|