will_paginate_seo 3.0.4

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.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +18 -0
  3. data/README.md +61 -0
  4. data/lib/will_paginate.rb +25 -0
  5. data/lib/will_paginate/active_record.rb +261 -0
  6. data/lib/will_paginate/array.rb +33 -0
  7. data/lib/will_paginate/collection.rb +136 -0
  8. data/lib/will_paginate/core_ext.rb +30 -0
  9. data/lib/will_paginate/data_mapper.rb +100 -0
  10. data/lib/will_paginate/deprecation.rb +55 -0
  11. data/lib/will_paginate/i18n.rb +22 -0
  12. data/lib/will_paginate/locale/en.yml +33 -0
  13. data/lib/will_paginate/mongoid.rb +46 -0
  14. data/lib/will_paginate/page_number.rb +57 -0
  15. data/lib/will_paginate/per_page.rb +27 -0
  16. data/lib/will_paginate/railtie.rb +68 -0
  17. data/lib/will_paginate/sequel.rb +39 -0
  18. data/lib/will_paginate/version.rb +9 -0
  19. data/lib/will_paginate/view_helpers.rb +162 -0
  20. data/lib/will_paginate/view_helpers/action_view.rb +152 -0
  21. data/lib/will_paginate/view_helpers/link_renderer.rb +131 -0
  22. data/lib/will_paginate/view_helpers/link_renderer_base.rb +77 -0
  23. data/lib/will_paginate/view_helpers/merb.rb +26 -0
  24. data/lib/will_paginate/view_helpers/sinatra.rb +41 -0
  25. data/spec/collection_spec.rb +139 -0
  26. data/spec/console +12 -0
  27. data/spec/console_fixtures.rb +28 -0
  28. data/spec/database.yml +22 -0
  29. data/spec/fake_rubygems.rb +18 -0
  30. data/spec/finders/active_record_spec.rb +517 -0
  31. data/spec/finders/activerecord_test_connector.rb +119 -0
  32. data/spec/finders/data_mapper_spec.rb +116 -0
  33. data/spec/finders/data_mapper_test_connector.rb +54 -0
  34. data/spec/finders/mongoid_spec.rb +140 -0
  35. data/spec/finders/sequel_spec.rb +67 -0
  36. data/spec/finders/sequel_test_connector.rb +15 -0
  37. data/spec/fixtures/admin.rb +3 -0
  38. data/spec/fixtures/developer.rb +16 -0
  39. data/spec/fixtures/developers_projects.yml +13 -0
  40. data/spec/fixtures/project.rb +13 -0
  41. data/spec/fixtures/projects.yml +6 -0
  42. data/spec/fixtures/replies.yml +29 -0
  43. data/spec/fixtures/reply.rb +8 -0
  44. data/spec/fixtures/schema.rb +38 -0
  45. data/spec/fixtures/topic.rb +8 -0
  46. data/spec/fixtures/topics.yml +30 -0
  47. data/spec/fixtures/user.rb +2 -0
  48. data/spec/fixtures/users.yml +35 -0
  49. data/spec/matchers/deprecation_matcher.rb +27 -0
  50. data/spec/matchers/phrase_matcher.rb +19 -0
  51. data/spec/matchers/query_count_matcher.rb +36 -0
  52. data/spec/page_number_spec.rb +65 -0
  53. data/spec/per_page_spec.rb +41 -0
  54. data/spec/spec_helper.rb +46 -0
  55. data/spec/view_helpers/action_view_spec.rb +441 -0
  56. data/spec/view_helpers/base_spec.rb +142 -0
  57. data/spec/view_helpers/link_renderer_base_spec.rb +87 -0
  58. data/spec/view_helpers/view_example_group.rb +125 -0
  59. metadata +106 -0
@@ -0,0 +1,87 @@
1
+ require 'spec_helper'
2
+ require 'will_paginate/view_helpers/link_renderer_base'
3
+ require 'will_paginate/collection'
4
+
5
+ describe WillPaginate::ViewHelpers::LinkRendererBase do
6
+
7
+ before do
8
+ @renderer = described_class.new
9
+ end
10
+
11
+ it "should raise error when unprepared" do
12
+ lambda {
13
+ @renderer.pagination
14
+ }.should raise_error
15
+ end
16
+
17
+ it "should prepare with collection and options" do
18
+ prepare({})
19
+ @renderer.send(:current_page).should == 1
20
+ end
21
+
22
+ it "should have total_pages accessor" do
23
+ prepare :total_pages => 42
24
+ @renderer.send(:total_pages).should == 42
25
+ end
26
+
27
+ it "should clear old cached values when prepared" do
28
+ prepare(:total_pages => 1)
29
+ @renderer.send(:total_pages).should == 1
30
+ # prepare with different object:
31
+ prepare(:total_pages => 2)
32
+ @renderer.send(:total_pages).should == 2
33
+ end
34
+
35
+ it "should have pagination definition" do
36
+ prepare({ :total_pages => 1 }, :page_links => true)
37
+ @renderer.pagination.should == [:previous_page, 1, :next_page]
38
+ end
39
+
40
+ describe "visible page numbers" do
41
+ it "should calculate windowed visible links" do
42
+ prepare({ :page => 6, :total_pages => 11 }, :inner_window => 1, :outer_window => 1)
43
+ showing_pages 1, 2, :gap, 5, 6, 7, :gap, 10, 11
44
+ end
45
+
46
+ it "should eliminate small gaps" do
47
+ prepare({ :page => 6, :total_pages => 11 }, :inner_window => 2, :outer_window => 1)
48
+ # pages 4 and 8 appear instead of the gap
49
+ showing_pages 1..11
50
+ end
51
+
52
+ it "should support having no windows at all" do
53
+ prepare({ :page => 4, :total_pages => 7 }, :inner_window => 0, :outer_window => 0)
54
+ showing_pages 1, :gap, 4, :gap, 7
55
+ end
56
+
57
+ it "should adjust upper limit if lower is out of bounds" do
58
+ prepare({ :page => 1, :total_pages => 10 }, :inner_window => 2, :outer_window => 1)
59
+ showing_pages 1, 2, 3, 4, 5, :gap, 9, 10
60
+ end
61
+
62
+ it "should adjust lower limit if upper is out of bounds" do
63
+ prepare({ :page => 10, :total_pages => 10 }, :inner_window => 2, :outer_window => 1)
64
+ showing_pages 1, 2, :gap, 6, 7, 8, 9, 10
65
+ end
66
+
67
+ def showing_pages(*pages)
68
+ pages = pages.first.to_a if Array === pages.first or Range === pages.first
69
+ @renderer.send(:windowed_page_numbers).should == pages
70
+ end
71
+ end
72
+
73
+ protected
74
+
75
+ def collection(params = {})
76
+ if params[:total_pages]
77
+ params[:per_page] = 1
78
+ params[:total_entries] = params[:total_pages]
79
+ end
80
+ WillPaginate::Collection.new(params[:page] || 1, params[:per_page] || 30, params[:total_entries])
81
+ end
82
+
83
+ def prepare(collection_options, options = {})
84
+ @renderer.prepare(collection(collection_options), options)
85
+ end
86
+
87
+ end
@@ -0,0 +1,125 @@
1
+ require 'active_support'
2
+ require 'stringio'
3
+ begin
4
+ $stderr = StringIO.new
5
+ require 'minitest/unit'
6
+ rescue LoadError
7
+ # Fails on Ruby 1.8, but it's OK since we only need MiniTest::Assertions
8
+ # on Rails 4 which doesn't support 1.8 anyway.
9
+ ensure
10
+ $stderr = STDERR
11
+ end
12
+ require 'action_dispatch/testing/assertions'
13
+ require 'will_paginate/array'
14
+
15
+ module ViewExampleGroup
16
+
17
+ include ActionDispatch::Assertions::SelectorAssertions
18
+ include MiniTest::Assertions if defined? MiniTest
19
+
20
+ def assert(value, message)
21
+ raise message unless value
22
+ end
23
+
24
+ def paginate(collection = {}, options = {}, &block)
25
+ if collection.instance_of? Hash
26
+ page_options = { :page => 1, :total_entries => 11, :per_page => 4 }.merge(collection)
27
+ collection = [1].paginate(page_options)
28
+ end
29
+
30
+ locals = { :collection => collection, :options => options }
31
+
32
+ @render_output = render(locals)
33
+ @html_document = nil
34
+
35
+ if block_given?
36
+ classname = options[:class] || WillPaginate::ViewHelpers.pagination_options[:class]
37
+ assert_select("div.#{classname}", 1, 'no main DIV', &block)
38
+ end
39
+
40
+ @render_output
41
+ end
42
+
43
+ def html_document
44
+ @html_document ||= HTML::Document.new(@render_output, true, false)
45
+ end
46
+
47
+ def response_from_page_or_rjs
48
+ html_document.root
49
+ end
50
+
51
+ def validate_page_numbers(expected, links, param_name = :page)
52
+ param_pattern = /\W#{Regexp.escape(param_name.to_s)}=([^&]*)/
53
+
54
+ links.map { |el|
55
+ unescape_href(el) =~ param_pattern
56
+ $1 ? $1.to_i : $1
57
+ }.should == expected
58
+ end
59
+
60
+ def assert_links_match(pattern, links = nil, numbers = nil)
61
+ links ||= assert_select 'div.pagination a[href]' do |elements|
62
+ elements
63
+ end
64
+
65
+ pages = [] if numbers
66
+
67
+ links.each do |el|
68
+ href = unescape_href(el)
69
+ href.should =~ pattern
70
+ if numbers
71
+ href =~ pattern
72
+ pages << ($1.nil?? nil : $1.to_i)
73
+ end
74
+ end
75
+
76
+ pages.should == numbers if numbers
77
+ end
78
+
79
+ def assert_no_links_match(pattern)
80
+ assert_select 'div.pagination a[href]' do |elements|
81
+ elements.each do |el|
82
+ unescape_href(el).should_not =~ pattern
83
+ end
84
+ end
85
+ end
86
+
87
+ def unescape_href(el)
88
+ CGI.unescape CGI.unescapeHTML(el['href'])
89
+ end
90
+
91
+ def build_message(message, pattern, *args)
92
+ built_message = pattern.dup
93
+ for value in args
94
+ built_message.sub! '?', value.inspect
95
+ end
96
+ built_message
97
+ end
98
+
99
+ end
100
+
101
+ RSpec.configure do |config|
102
+ config.include ViewExampleGroup, :type => :view, :example_group => {
103
+ :file_path => %r{spec/view_helpers/}
104
+ }
105
+ end
106
+
107
+ module HTML
108
+ Node.class_eval do
109
+ def inner_text
110
+ children.map(&:inner_text).join('')
111
+ end
112
+ end
113
+
114
+ Text.class_eval do
115
+ def inner_text
116
+ self.to_s
117
+ end
118
+ end
119
+
120
+ Tag.class_eval do
121
+ def inner_text
122
+ childless?? '' : super
123
+ end
124
+ end
125
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: will_paginate_seo
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Vladimir Dimitrov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-22 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: only difference with mislav's will_paginate is that *?page=1* parameter
14
+ is removed from first page, like google seo tips say
15
+ email: vkdimitrov@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files:
19
+ - README.md
20
+ - LICENSE
21
+ files:
22
+ - LICENSE
23
+ - README.md
24
+ - lib/will_paginate.rb
25
+ - lib/will_paginate/active_record.rb
26
+ - lib/will_paginate/array.rb
27
+ - lib/will_paginate/collection.rb
28
+ - lib/will_paginate/core_ext.rb
29
+ - lib/will_paginate/data_mapper.rb
30
+ - lib/will_paginate/deprecation.rb
31
+ - lib/will_paginate/i18n.rb
32
+ - lib/will_paginate/locale/en.yml
33
+ - lib/will_paginate/mongoid.rb
34
+ - lib/will_paginate/page_number.rb
35
+ - lib/will_paginate/per_page.rb
36
+ - lib/will_paginate/railtie.rb
37
+ - lib/will_paginate/sequel.rb
38
+ - lib/will_paginate/version.rb
39
+ - lib/will_paginate/view_helpers.rb
40
+ - lib/will_paginate/view_helpers/action_view.rb
41
+ - lib/will_paginate/view_helpers/link_renderer.rb
42
+ - lib/will_paginate/view_helpers/link_renderer_base.rb
43
+ - lib/will_paginate/view_helpers/merb.rb
44
+ - lib/will_paginate/view_helpers/sinatra.rb
45
+ - spec/collection_spec.rb
46
+ - spec/console
47
+ - spec/console_fixtures.rb
48
+ - spec/database.yml
49
+ - spec/fake_rubygems.rb
50
+ - spec/finders/active_record_spec.rb
51
+ - spec/finders/activerecord_test_connector.rb
52
+ - spec/finders/data_mapper_spec.rb
53
+ - spec/finders/data_mapper_test_connector.rb
54
+ - spec/finders/mongoid_spec.rb
55
+ - spec/finders/sequel_spec.rb
56
+ - spec/finders/sequel_test_connector.rb
57
+ - spec/fixtures/admin.rb
58
+ - spec/fixtures/developer.rb
59
+ - spec/fixtures/developers_projects.yml
60
+ - spec/fixtures/project.rb
61
+ - spec/fixtures/projects.yml
62
+ - spec/fixtures/replies.yml
63
+ - spec/fixtures/reply.rb
64
+ - spec/fixtures/schema.rb
65
+ - spec/fixtures/topic.rb
66
+ - spec/fixtures/topics.yml
67
+ - spec/fixtures/user.rb
68
+ - spec/fixtures/users.yml
69
+ - spec/matchers/deprecation_matcher.rb
70
+ - spec/matchers/phrase_matcher.rb
71
+ - spec/matchers/query_count_matcher.rb
72
+ - spec/page_number_spec.rb
73
+ - spec/per_page_spec.rb
74
+ - spec/spec_helper.rb
75
+ - spec/view_helpers/action_view_spec.rb
76
+ - spec/view_helpers/base_spec.rb
77
+ - spec/view_helpers/link_renderer_base_spec.rb
78
+ - spec/view_helpers/view_example_group.rb
79
+ homepage: https://github.com/vkdimitrov/will_paginate
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options:
85
+ - "--main"
86
+ - README.md
87
+ - "--charset=UTF-8"
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 2.2.2
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: Fork of mislav/will_paginate
106
+ test_files: []