middleman-pagination 1.0.3 → 1.0.4

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: 0fe88f717f7ddc57f1ee1a68851a0cfbe3ad4d8f
4
- data.tar.gz: cc3230860874e8e19771ae200087a3b9d3e73147
3
+ metadata.gz: 1a5de30344c93337f35a33f43bb16272af19d0d9
4
+ data.tar.gz: 47e3482871978d4dd24219b4648f5091e801e976
5
5
  SHA512:
6
- metadata.gz: 05f8d50c012c3d7f34e0941a6db2bcdad55bc154ab5d0c00b28fd378fe569b5776f44807eac6507c5fb510ee098a05c4bc71a7a30acbeb6acd89ec494139cd81
7
- data.tar.gz: c8100e62f88d8ad5893d1f7808e38b1b424ceda6ec777928e8521263e4a885cbd95b1d1cf6a4c7969245203d280f7f80bd868e9adedba7419d2ccec10e8c83e0
6
+ metadata.gz: adfb6c1815df41983f8e08242ff26469046554f2136a7dac6c87b563803216d50c27b9fecc56e456d46d7524cc33bcf74e5177755866e9cfab9ded25ba810eba
7
+ data.tar.gz: 715d36ca42f3f1a11520db51520e1d808af8aedcf476bb821810faeb920a7801a1971c3baf15e31d9652d328baf4003b672c67da7e898aaeae26378f54978c71
@@ -0,0 +1,68 @@
1
+ module Middleman
2
+ module Pagination
3
+ class IndexPath
4
+ attr_accessor :context, :original_path, :page_num, :symbolic_path_replacement
5
+
6
+ def initialize(context, original_path, page_num, symbolic_path_replacement = 'pages/:num')
7
+ @context = context
8
+ @original_path = original_path
9
+ @symbolic_path_replacement = symbolic_path_replacement
10
+
11
+ if page_num < 1
12
+ raise "Expected page_num greater than 0 (page numbers are not zero-indexed"
13
+ end
14
+
15
+ @page_num = page_num
16
+ end
17
+
18
+ def to_s
19
+ if first_index?
20
+ original_path
21
+ else
22
+ replaced_path
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def first_index?
29
+ page_num == 1
30
+ end
31
+
32
+ def replaced_path
33
+ if original_path.match(index_file_pattern)
34
+ original_path.sub(index_file_pattern, "\\1#{replaced_symbolic_path}\\2")
35
+ else
36
+ original_path.sub(non_index_path_pattern, "\\1\\2/#{replaced_symbolic_path}.\\3")
37
+ end
38
+ end
39
+
40
+ def index_file_pattern
41
+ index_file_ext = File.extname(context.index_file)
42
+ index_file_path = context.index_file.delete(index_file_ext)
43
+
44
+ %r{
45
+ (/)? # An optional slash
46
+ #{Regexp.escape(index_file_path)} # Followed by the index path (usually "index")
47
+ (#{Regexp.escape(index_file_ext)}) # Followed by the index extension (usually ".html")
48
+ $ # Followed by the end of the string
49
+ }x
50
+ end
51
+
52
+ def non_index_path_pattern
53
+ %r{
54
+ (^|/) # Match the start of the string or a slash
55
+ ([^/]*) # Followed by any character not a slash
56
+ \. # Followed by a dot
57
+ ([^/]*) # Followed by any character not a slash
58
+ $ # Followed by the end of the string
59
+ }x
60
+ end
61
+
62
+ def replaced_symbolic_path
63
+ symbolic_path_replacement.sub(':num', page_num.to_s)
64
+ end
65
+
66
+ end
67
+ end
68
+ end
@@ -45,7 +45,7 @@ module Middleman
45
45
 
46
46
  def build_new_index(first_index, pageable_context, page_num)
47
47
  sitemap = context.sitemap
48
- path = secondary_index_path(first_index.path, page_num)
48
+ path = IndexPath.new(context, first_index.path, page_num).to_s
49
49
  source_file = first_index.source_file
50
50
 
51
51
  new_index = ::Middleman::Sitemap::Resource.new(sitemap, path, source_file)
@@ -56,18 +56,6 @@ module Middleman
56
56
  new_index
57
57
  end
58
58
 
59
- def secondary_index_path(original_path, page_num)
60
- symbolic_path_replacement = "pages/:num"
61
- pattern = %r{^?(/)?#{Regexp.escape(context.index_file)}$}
62
- replacement = symbolic_path_replacement.sub(':num', page_num.to_s)
63
-
64
- if original_path.match(pattern)
65
- original_path.sub(pattern, "\\1#{replacement}.html")
66
- else
67
- original_path.sub(%r{(^|/)([^/]*)\.([^/]*)$}, "\\1\\2/#{replacement}.\\3")
68
- end
69
- end
70
-
71
59
  def add_pagination_to(resource, attributes = {})
72
60
  in_page_context = InPageContext.new(attributes)
73
61
  resource.add_metadata(:locals => { 'pagination' => in_page_context })
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  module Pagination
3
- VERSION = "1.0.3"
3
+ VERSION = "1.0.4"
4
4
  end
5
5
  end
@@ -5,6 +5,7 @@ require "middleman/pagination/configuration"
5
5
  require "middleman/pagination/extension_context"
6
6
  require "middleman/pagination/manipulated_resources"
7
7
  require "middleman/pagination/pageable_context"
8
+ require "middleman/pagination/index_path"
8
9
  require "middleman/pagination/in_page_context"
9
10
  require "middleman/pagination/extension"
10
11
 
@@ -47,14 +47,6 @@ describe "Simple pagination", :feature do
47
47
  find_on_page 'Prev page: /pages/3.html'
48
48
  find_on_page 'Next page: none'
49
49
  end
50
-
51
- def visit(path)
52
- expect(get(path)).to be_ok
53
- end
54
-
55
- def find_on_page(string)
56
- expect(last_response.body).to include(string)
57
- end
58
50
  end
59
51
 
60
52
  describe "Pagination with directory indexes", :feature do
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ module Middleman::Pagination
4
+ describe IndexPath do
5
+
6
+ describe "#to_s" do
7
+ let(:ext_context) { double(index_file: 'index.html') }
8
+
9
+ context "when the page num is 0" do
10
+ it "raises an error" do
11
+ expect {
12
+ IndexPath.new(ext_context, 'original.html', 0)
13
+ }.to raise_error
14
+ end
15
+ end
16
+
17
+ context "when the page num is 1" do
18
+ it "returns the original path" do
19
+ path = IndexPath.new(ext_context, 'original.html', 1)
20
+ expect(path.to_s).to eql('original.html')
21
+ end
22
+ end
23
+
24
+ context "when the page num is greater than 1" do
25
+ it "returns a path including the page number" do
26
+ path = IndexPath.new(ext_context, 'original.html', 2)
27
+ expect(path.to_s).to eql('original/pages/2.html')
28
+ end
29
+
30
+ it "supports a custom path format" do
31
+ path = IndexPath.new(ext_context, 'original.html', 2, 'index/at/:num/list')
32
+ expect(path.to_s).to eql('original/index/at/2/list.html')
33
+ end
34
+
35
+ it "preserves the original file extension" do
36
+ path = IndexPath.new(ext_context, 'original.htm', 2)
37
+ expect(path.to_s).to eql('original/pages/2.htm')
38
+ end
39
+
40
+ it "takes index files into account" do
41
+ ext_context.stub(index_file: 'index.html')
42
+ path = IndexPath.new(ext_context, 'original/index.html', 2)
43
+ expect(path.to_s).to eql('original/pages/2.html')
44
+ end
45
+
46
+ it "preserves the index file extension" do
47
+ ext_context.stub(index_file: 'index.htm')
48
+ path = IndexPath.new(ext_context, 'original/index.htm', 2)
49
+ expect(path.to_s).to eql('original/pages/2.htm')
50
+ end
51
+ end
52
+
53
+ end
54
+
55
+ end
56
+ end
@@ -9,7 +9,7 @@ module MiddlemanServerHelpers
9
9
  end
10
10
 
11
11
  def visit(path)
12
- expect(get(path)).to be_ok
12
+ expect(get(path).status).to eql(200)
13
13
  end
14
14
 
15
15
  def find_on_page(string)
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.3
4
+ version: 1.0.4
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-04 00:00:00.000000000 Z
11
+ date: 2013-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: middleman-core
@@ -113,6 +113,7 @@ files:
113
113
  - lib/middleman/pagination/extension.rb
114
114
  - lib/middleman/pagination/extension_context.rb
115
115
  - lib/middleman/pagination/in_page_context.rb
116
+ - lib/middleman/pagination/index_path.rb
116
117
  - lib/middleman/pagination/manipulated_resources.rb
117
118
  - lib/middleman/pagination/pageable_context.rb
118
119
  - lib/middleman/pagination/version.rb
@@ -133,6 +134,7 @@ files:
133
134
  - spec/fixtures/recipes/source/recipes/yeti.html.erb
134
135
  - spec/middleman/pagination/configuration_spec.rb
135
136
  - spec/middleman/pagination/extension_context_spec.rb
137
+ - spec/middleman/pagination/index_path_spec.rb
136
138
  - spec/middleman/pagination/manipulated_resources_spec.rb
137
139
  - spec/spec_helper.rb
138
140
  - spec/support/middleman_server_helpers.rb
@@ -156,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
158
  version: '0'
157
159
  requirements: []
158
160
  rubyforge_project:
159
- rubygems_version: 2.0.3
161
+ rubygems_version: 2.0.7
160
162
  signing_key:
161
163
  specification_version: 4
162
164
  summary: Pagination for Middleman pages.
@@ -176,6 +178,7 @@ test_files:
176
178
  - spec/fixtures/recipes/source/recipes/yeti.html.erb
177
179
  - spec/middleman/pagination/configuration_spec.rb
178
180
  - spec/middleman/pagination/extension_context_spec.rb
181
+ - spec/middleman/pagination/index_path_spec.rb
179
182
  - spec/middleman/pagination/manipulated_resources_spec.rb
180
183
  - spec/spec_helper.rb
181
184
  - spec/support/middleman_server_helpers.rb