middleman-pagination 1.0.1 → 1.0.2

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: 2ec4df12de80b850fef444d0be189c97c8fdd2d7
4
- data.tar.gz: ebdf7415e47c6bc08cf8ac98279c9ffaceec21f6
3
+ metadata.gz: 102b81437ae7290ba740170291acecfba9734692
4
+ data.tar.gz: 626ed8051a0aedc31ceb84321ef811916b1efc81
5
5
  SHA512:
6
- metadata.gz: f26c742c07023224891ca0c2ca321d3f30ec835a83fa7ecb5d384d4e70fb40d821a2b10eb1ed6aafbdb7aaad3e4358b7c9ce2f8ac176b9daad70fdf0247a79c3
7
- data.tar.gz: 627b85c502bd9acf4c906b22ba2b3e26bac09a4c1bc2c27f2fc0cc71596b56a95e8a4bd5633458adbd7a8f9ab981d66cc519b8af8c6e5983a02346309dc519d7
6
+ metadata.gz: 5db875234970ea265ed0a35a3d1211b6baa3139ddf595a44d814f74ec8eaf8ada18e4d8ad095eb2f71c564d57a5be6263d294fced1d445e2754be989f0b9843d
7
+ data.tar.gz: 9b9f8734c8d42819a3ff595585bd0c73f22754d110af05438d705008ff7c54c5c8cfe836b5af1df1f620601c4dc3c28239cf04873e26fc356f2dfd1400df130a
data/README.md CHANGED
@@ -4,8 +4,8 @@
4
4
  [![Code Climate](https://codeclimate.com/github/Aupajo/middleman-pagination.png)](https://codeclimate.com/github/Aupajo/middleman-pagination)
5
5
  [![Dependency Status](https://gemnasium.com/Aupajo/middleman-pagination.png)](https://gemnasium.com/Aupajo/middleman-pagination)
6
6
 
7
- General-purpose pagination support for Middleman pages.
8
-
7
+ General-purpose pagination support for Middleman pages. Proxy pages for both pageable resources and pagination indexes are supported.
8
+
9
9
  ## Installation
10
10
 
11
11
  Add this line to your Middleman site's Gemfile:
@@ -84,7 +84,7 @@ activate :pagination do
84
84
  end
85
85
 
86
86
  pageable :news do |page|
87
- # Match any page that has "news" in its frontmatter
87
+ # Match any page that has a "news" property in its frontmatter
88
88
  page.data.news.present?
89
89
  end
90
90
  end
@@ -22,16 +22,18 @@ module Middleman
22
22
 
23
23
  def new_resources_for_pageable(name, filter)
24
24
  original_resources.map do |resource|
25
- if resource.data.pagination.try(:for) == name.to_s
25
+ if !resource.ignored? && resource.data.pagination.try(:for) == name.to_s
26
26
  new_resources_for_index(resource, filter)
27
27
  end
28
28
  end.compact
29
29
  end
30
30
 
31
31
  def new_resources_for_index(first_index, filter)
32
+ puts "Creating new resources for index: #{first_index.path}"
32
33
  pageable_context = PageableContext.new(
33
34
  per_page: first_index.data.pagination.per_page || 20,
34
- resources: original_resources.select(&filter).sort_by(&:path),
35
+ # OPTIMIZE
36
+ resources: original_resources.reject(&:ignored?).select(&filter).sort_by(&:path),
35
37
  index_resources: [first_index]
36
38
  )
37
39
 
@@ -44,14 +46,7 @@ module Middleman
44
46
 
45
47
  def build_new_index(first_index, pageable_context, page_num)
46
48
  sitemap = context.sitemap
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
+ path = secondary_index_path(first_index.path, page_num)
55
50
  source_file = first_index.source_file
56
51
 
57
52
  new_index = ::Middleman::Sitemap::Resource.new(sitemap, path, source_file)
@@ -62,6 +57,18 @@ module Middleman
62
57
  new_index
63
58
  end
64
59
 
60
+ def secondary_index_path(original_path, page_num)
61
+ symbolic_path_replacement = "pages/:num"
62
+ pattern = %r{^?(/)?#{Regexp.escape(context.index_file)}$}
63
+ replacement = symbolic_path_replacement.sub(':num', page_num.to_s)
64
+
65
+ if original_path.match(pattern)
66
+ original_path.sub(pattern, "\\1#{replacement}.html")
67
+ else
68
+ original_path.sub(%r{(^|/)([^/]*)\.([^/]*)$}, "\\1\\2/#{replacement}.\\3")
69
+ end
70
+ end
71
+
65
72
  def add_pagination_to(resource, attributes = {})
66
73
  in_page_context = InPageContext.new(attributes)
67
74
  resource.add_metadata(:locals => { 'pagination' => in_page_context })
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  module Pagination
3
- VERSION = "1.0.1"
3
+ VERSION = "1.0.2"
4
4
  end
5
5
  end
@@ -109,4 +109,115 @@ describe "Pagination with indexes not named index", :feature do
109
109
  find_on_page 'Prev page: /all-recipes.html'
110
110
  find_on_page 'Next page: none'
111
111
  end
112
+ end
113
+
114
+ describe "Pagination with proxied resources and ignored proxy resource template", :feature do
115
+ it "produces pages for a set of resources" do
116
+ run_site 'mine' do
117
+ %w{ Feldspar Olivine Quartz }.each do |mineral|
118
+ proxy "/minerals/#{mineral.downcase}.html", '/minerals/template.html', locals: { mineral: mineral }, ignore: true
119
+ end
120
+
121
+ activate :pagination do
122
+ pageable :minerals do |resource|
123
+ resource.path.start_with?('mineral')
124
+ end
125
+ end
126
+ end
127
+
128
+ visit '/'
129
+ find_on_page 'Feldspar'
130
+ find_on_page 'Olivine'
131
+ find_on_page 'First page: /'
132
+ find_on_page 'Prev page: none'
133
+ find_on_page 'Last page: /pages/2.html'
134
+ find_on_page 'Next page: /pages/2.html'
135
+
136
+ visit '/pages/2.html'
137
+ find_on_page 'Quartz'
138
+ find_on_page 'Prev page: /'
139
+ find_on_page 'Next page: none'
140
+ expect(last_response.body).not_to include('minerals/template')
141
+ end
142
+ end
143
+
144
+ describe "Pagination with proxied resources and ignored proxy index", :feature do
145
+ it "produces pages for a set of resources" do
146
+ run_site 'mine' do
147
+ %w{ Feldspar Olivine Quartz }.each do |mineral|
148
+ proxy "/minerals/#{mineral.downcase}.html", '/minerals/template.html', locals: { mineral: mineral }, ignore: true
149
+ end
150
+
151
+ proxy '/alternative/index.html', '/index.html', ignore: true
152
+
153
+ activate :pagination do
154
+ pageable :minerals do |resource|
155
+ resource.path.start_with?('mineral')
156
+ end
157
+ end
158
+ end
159
+
160
+ get '/'
161
+ expect(last_response.status).to eql(404)
162
+
163
+ get '/pages/2.html'
164
+ expect(last_response.status).to eql(404)
165
+
166
+ visit '/alternative/'
167
+ find_on_page 'Feldspar'
168
+ find_on_page 'Olivine'
169
+ find_on_page 'First page: /alternative/'
170
+ find_on_page 'Prev page: none'
171
+ find_on_page 'Last page: /alternative/pages/2.html'
172
+ find_on_page 'Next page: /alternative/pages/2.html'
173
+
174
+ visit '/alternative/pages/2.html'
175
+ find_on_page 'Quartz'
176
+ find_on_page 'Prev page: /alternative/'
177
+ find_on_page 'Next page: none'
178
+ end
179
+ end
180
+
181
+ describe "Pagination with proxied resources and two indexes (one proxied)", :feature do
182
+ it "produces pages for a set of resources" do
183
+ run_site 'mine' do
184
+ %w{ Feldspar Olivine Quartz }.each do |mineral|
185
+ proxy "/minerals/#{mineral.downcase}.html", '/minerals/template.html', locals: { mineral: mineral }, ignore: true
186
+ end
187
+
188
+ proxy '/alternative/index.html', '/index.html'
189
+
190
+ activate :pagination do
191
+ pageable :minerals do |resource|
192
+ resource.path.start_with?('mineral')
193
+ end
194
+ end
195
+ end
196
+
197
+ visit '/'
198
+ find_on_page 'Feldspar'
199
+ find_on_page 'Olivine'
200
+ find_on_page 'First page: /'
201
+ find_on_page 'Prev page: none'
202
+ find_on_page 'Last page: /pages/2.html'
203
+ find_on_page 'Next page: /pages/2.html'
204
+
205
+ visit '/pages/2.html'
206
+ find_on_page 'Quartz'
207
+ find_on_page 'Prev page: /'
208
+ find_on_page 'Next page: none'
209
+
210
+ visit '/alternative/'
211
+ find_on_page 'Feldspar'
212
+ find_on_page 'Olivine'
213
+ find_on_page 'First page: /alternative/'
214
+ find_on_page 'Prev page: none'
215
+ find_on_page 'Last page: /alternative/pages/2.html'
216
+ find_on_page 'Next page: /alternative/pages/2.html'
217
+
218
+ visit '/alternative/pages/2.html'
219
+ find_on_page 'Quartz'
220
+ find_on_page 'Prev page: /alternative/'
221
+ find_on_page 'Next page: none'
222
+ end
112
223
  end
@@ -0,0 +1,21 @@
1
+ ---
2
+ pagination:
3
+ for: minerals
4
+ per_page: 2
5
+ ---
6
+
7
+ <% pagination.each do |page| %>
8
+ - <%= page.metadata[:locals][:mineral] %> (<%= page.url %>)
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 %>
@@ -0,0 +1 @@
1
+ Mineral: <%= mineral %>
@@ -29,7 +29,7 @@ module Middleman::Pagination
29
29
 
30
30
  let(:pagination_index) {
31
31
  pagination_data = double(for: 'recipes', per_page: 2)
32
- resource = double(:resource, path: 'index.html', is_recipe?: false).as_null_object
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
35
35
  }
@@ -37,7 +37,7 @@ module Middleman::Pagination
37
37
  let(:resource_list) {
38
38
  [pagination_index] +
39
39
  7.times.map do |n|
40
- double(:resource, path: "recipe-#{n}.html", is_recipe?: true).as_null_object
40
+ double(:resource, path: "recipe-#{n}.html", is_recipe?: true, ignored?: false).as_null_object
41
41
  end
42
42
  }
43
43
 
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.1
4
+ version: 1.0.2
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-10-28 00:00:00.000000000 Z
11
+ date: 2013-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: middleman-core
@@ -119,6 +119,8 @@ files:
119
119
  - lib/middleman_extension.rb
120
120
  - middleman-pagination.gemspec
121
121
  - spec/features/pagination_feature_spec.rb
122
+ - spec/fixtures/mine/source/index.html.erb
123
+ - spec/fixtures/mine/source/minerals/template.html.erb
122
124
  - spec/fixtures/recipes/source/all-recipes.html.erb
123
125
  - spec/fixtures/recipes/source/index.html.erb
124
126
  - spec/fixtures/recipes/source/layouts/layout.erb
@@ -160,6 +162,8 @@ specification_version: 4
160
162
  summary: Pagination for Middleman pages.
161
163
  test_files:
162
164
  - spec/features/pagination_feature_spec.rb
165
+ - spec/fixtures/mine/source/index.html.erb
166
+ - spec/fixtures/mine/source/minerals/template.html.erb
163
167
  - spec/fixtures/recipes/source/all-recipes.html.erb
164
168
  - spec/fixtures/recipes/source/index.html.erb
165
169
  - spec/fixtures/recipes/source/layouts/layout.erb