rails_will_paginate_seo_helper 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 05f7e580c4e19d52e330ad88215a0597eb0d154e
4
- data.tar.gz: 6f4b08e88bde4b23be7943ca8af0a54247f71d1c
3
+ metadata.gz: 20345eab25324a106d4dcd1cdb4c04053ded7e3c
4
+ data.tar.gz: 3f42274fa552f8d73c5db3ba4f9cdf2536c1380c
5
5
  SHA512:
6
- metadata.gz: 83bdefac9696265fd3743f40cb46ea971cc31e5bbd8974b75c43103b06e39a84afbee237b23bf46ffd50760e48d11f86b1e2900f7e2788f914185d6144feeae1
7
- data.tar.gz: 7a04d87e6bdb89d64ac70306fec0999ef70cff2c877fa72488161f007834c633f175beb896fdb9e11f86df53e8e2f50c8e5060618ebb73c11f5997813d7bcad0
6
+ metadata.gz: 57929fc77321c87ecfde3463e2acee633b2b3caa454b77ea41c8fd1d677336cb2740476896227e850ab6ed6da76bda9cba1bdea3ac4a9d8be4483e3cfe345ca8
7
+ data.tar.gz: c41c726f0308f50a51ad21b1fa317a88c5685455daa8f9d7b04827425984d1297b9c65ea37ac4129e568a8c2d4c30fadb1c8ab30633539ce4bdde9b9a4d23a8d
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/view_helpers.rb CHANGED
@@ -3,34 +3,50 @@ module RailsWillPaginateSeoHelper
3
3
  def will_paginate_seo_links(collection)
4
4
  return unless collection.respond_to?(:current_page)
5
5
  @collection = collection
6
- build_tags.html_safe
6
+ build_tags
7
7
  end
8
8
 
9
9
  private
10
10
 
11
-
12
11
  def build_tags
13
12
  if next_link_tag && previous_link_tag
14
- return previous_link_tag << next_link_tag
15
- end
16
- return next_link_tag if next_link_tag
17
- return previous_link_tag if previous_link_tag
18
- end
19
-
20
- def next_link_tag
21
- next_page = @collection.next_page
22
- if next_page
23
- next_page_url = request.original_url.gsub(/page\=\d{1,}/, "page=#{next_page}")
24
- return tag(:link, href: next_page_url, rel: :next)
13
+ return (previous_link_tag << next_link_tag).html_safe
25
14
  end
15
+ return previous_link_tag.html_safe if previous_link_tag
16
+ next_link_tag.html_safe if next_link_tag
26
17
  end
27
18
 
28
19
  def previous_link_tag
29
20
  previous_page = @collection.previous_page
21
+ original_url = request.original_url
22
+
30
23
  if previous_page
31
- prev_page_url = request.original_url.gsub(/page\=\d{1,}/, "page=#{previous_page}")
24
+ if previous_page == 1
25
+ prev_page_url = original_url.gsub(/(&|\?)page\=\d{1,}/, '')
26
+ else
27
+ prev_page_url = original_url.gsub(/page\=\d{1,}/, "page=#{previous_page}")
28
+ end
32
29
  return tag(:link, href: prev_page_url, rel: :prev)
33
30
  end
34
31
  end
32
+
33
+ def next_link_tag
34
+ next_page = @collection.next_page
35
+ original_url = request.original_url
36
+
37
+ match = original_url.match(/(&|\?)page\=\d{1,}/)
38
+
39
+ if match # has :page url-parameter
40
+ next_page_url = original_url.gsub(/page\=\d{1,}/, "page=#{next_page}")
41
+ else # no :page url-parameter page
42
+ sign_match = original_url.match(/\?/)
43
+ if sign_match # url has parameter attached
44
+ next_page_url = original_url.concat("&page=#{next_page}")
45
+ else # url has no parameter attached
46
+ next_page_url = original_url.concat("?page=#{next_page}")
47
+ end
48
+ end
49
+ tag(:link, href: next_page_url, rel: :next) if next_page_url
50
+ end
35
51
  end
36
52
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_will_paginate_seo_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - rene paulokat
metadata.gz.sig CHANGED
Binary file