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: a29ba1726972cb939f315b1f5ac1ded71d23cc1f
4
- data.tar.gz: 3660c0071d5073fc8df417b639a5a43c844041b3
3
+ metadata.gz: 6585d00919a91cfbdddc63b60109f4472f7eb005
4
+ data.tar.gz: 616eda1fe14317f7cbaf8b4f26304c5be10aab78
5
5
  SHA512:
6
- metadata.gz: a9e6048da2b6ae427d11fa33b968216ffefab71aef562cdc0f8b22694410332c3eddacc4c0ca1974c4c5a2f57fd168f8dbc8ea88e7cc69e5b599f63dcf1a42c4
7
- data.tar.gz: 3f1fd46306b3476eb8d6e43e2436f68fc451d6a6133d79b4666645d3008090a37f8d7e45ca793a36c2133bb0396e7252a0f9ee78ba18eaf364e31d51e395c870
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.data.pagination.try(:for) == name.to_s
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.data.pagination.try(:path)
40
+ symbolic_replacement_path = pagination_data(first_index, :path)
33
41
 
34
42
  pageable_context = PageableContext.new(
35
- per_page: first_index.data.pagination.per_page || 20,
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(:locals => { 'pagination' => in_page_context })
71
+ resource.add_metadata(locals: { 'pagination' => in_page_context })
64
72
  end
65
73
  end
66
74
  end
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  module Pagination
3
- VERSION = "1.0.5"
3
+ VERSION = "1.0.7"
4
4
  end
5
5
  end
@@ -28,16 +28,17 @@ module Middleman::Pagination
28
28
  }
29
29
 
30
30
  let(:pagination_index) {
31
- pagination_data = double(for: 'recipes', per_page: 2, path: nil)
32
- resource = double(:resource, path: 'index.html', is_recipe?: false, ignored?: false).as_null_object
33
- resource.stub_chain(:data, pagination: pagination_data)
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.5
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-17 00:00:00.000000000 Z
11
+ date: 2013-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: middleman-core