grasshopper_paginate 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 90cbc226ca955a66e79dbe64f392af33e8425939
4
+ data.tar.gz: 32096185543e3b65cf31f7267f19491927ea2cd5
5
+ SHA512:
6
+ metadata.gz: 486cabeff0d3e7be1a49716fb0002c29c45dd4c35bb671eb8be9a098f689a4a5c165b74da063b5196d44cd238ad94d7d2a3309d38f8a927d427ccfd411f0bbb0
7
+ data.tar.gz: 1a24f8ceb63a1ea9f9e56ab5940fe9589dc4b46d2ff78177963c816cdb80a7d2116104cea91d3dd1386cec3b1fc1a610014eb42fdc190b70283cf5ac5047fe4a
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in grasshopper_paginate.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 JIEXIN HUANG
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # Grasshopper Pagination
2
+
3
+ Integrates Zurb Foundation's [pagination styles](http://foundation.zurb.com/docs/navigation.php) with [will_paginate](https://github.com/mislav/will_paginate).
4
+
5
+ Based on [foundation-will_paginate](https://github.com/markmcconachie/foundation-will_paginate) with several changes:
6
+
7
+ * When gap is clicked, display an input field for exact page number, hit enter will navigate the the particular page
8
+ * Change default inner_window to 1
9
+ * When total count is no more than 1.5 times of per_page count, do not show pagination links, display all records
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'grasshopper_paginate'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install grasshopper_paginate
24
+
25
+ ## Configuration
26
+
27
+ Include assets
28
+
29
+ application.js
30
+ //= require grasshopper_paginate/paginate
31
+
32
+ application.css
33
+ //= require grasshopper_paginate/paginate
34
+
35
+ ## Usage
36
+
37
+ For paginated query, with will_paginate, you woul usually use
38
+ ``` ruby
39
+ @users = User.paginate page: params[:page]
40
+
41
+ ```
42
+
43
+ Now use
44
+ ``` ruby
45
+ @users = User.smart_paginate page: params[:page]
46
+
47
+ ```
48
+
49
+ In your view where you would usually use
50
+
51
+ ```
52
+ <%= will_paginate @posts %>
53
+ ```
54
+
55
+ Now use
56
+
57
+ ```
58
+ <%= grasshopper_paginate @posts %>
59
+ ```
60
+
61
+ ## Contributing
62
+
63
+ 1. Fork it
64
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
65
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
66
+ 4. Push to the branch (`git push origin my-new-feature`)
67
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,15 @@
1
+ $ ->
2
+ $('body').on 'click', '.pagination .goto-gap', () ->
3
+ root = $(this).closest('.grasshopper-pagination')
4
+ root.find('ul').addClass 'hide'
5
+ goto = root.find 'ul.goto'
6
+ goto.removeClass 'hide'
7
+ gotoInput = goto.find 'input.goto-page'
8
+ gotoInput.focus().select()
9
+ url = gotoInput.attr 'url'
10
+ totalPage = parseInt gotoInput.attr('total')
11
+ gotoInput.keyup (event) ->
12
+ if event.which == 13
13
+ newPage = parseInt(gotoInput.val()) || 1
14
+ newPage = totalPage if newPage > totalPage
15
+ window.location.href = url.replace 'page_number', newPage
@@ -0,0 +1,12 @@
1
+ .grasshopper-pagination {
2
+ input.goto-page {
3
+ width: 3rem;
4
+ text-align: right;
5
+ color: #999;
6
+ padding: 0px 5px;
7
+ }
8
+
9
+ a.total-pages {
10
+ padding: 2px 0px 0px 0px;
11
+ }
12
+ }
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'grasshopper_paginate/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "grasshopper_paginate"
8
+ gem.version = Grasshopper::Paginate::VERSION
9
+ gem.authors = ["JIEXIN HUANG"]
10
+ gem.email = ["hjx500@gmail.com"]
11
+ gem.description = %q{change based on foundation-will_paginate gem, use foundation style pagination and also provides a goto page input area when gap is clicked}
12
+ gem.summary = %q{enhanced foundation pagination with will_paginate}
13
+ gem.homepage = ''
14
+ gem.license = 'MIT'
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.add_dependency 'rails', '>= 4.2.0', '< 5.0.0'
22
+ gem.add_dependency 'foundation-rails', '~> 5.5', '>= 5.5.0'
23
+ gem.add_dependency 'jquery-rails', '~> 3.1.0'
24
+ gem.add_dependency 'sass-rails', '~> 5.0.1'
25
+ gem.add_dependency 'will_paginate', '~> 3.0'
26
+ end
@@ -0,0 +1,2 @@
1
+ require 'grasshopper_paginate/array'
2
+ require 'grasshopper_paginate/engine'
@@ -0,0 +1,19 @@
1
+ require 'will_paginate/per_page'
2
+ require 'active_record'
3
+
4
+ module Grasshopper
5
+ module Paginate
6
+ module ActiveRecord
7
+ module Pagination
8
+ def smart_paginate(options={})
9
+ per_page = options[:per_page] || self.per_page
10
+ options[:per_page] = (per_page*1.5).to_i if self.count <= per_page*1.5
11
+ paginate options
12
+ end
13
+ end
14
+ ::ActiveRecord::Base.extend Pagination
15
+ ::ActiveRecord::Relation.include Pagination
16
+ ::ActiveRecord::Associations::CollectionProxy.include Pagination
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ require 'will_paginate/array'
2
+
3
+ class Array
4
+ def smart_paginate(options={})
5
+ per_page = options[:per_page] || WillPaginate.per_page
6
+ options[:per_page] = (per_page*1.5).to_i if self.count <= per_page*1.5
7
+ paginate options
8
+ end
9
+ end
@@ -0,0 +1,21 @@
1
+ # Rails::Engine is a Railtie, extend rails inside
2
+ require 'grasshopper_paginate/renderer'
3
+ require 'grasshopper_paginate/helper'
4
+
5
+ module Grasshopper
6
+ module Paginate
7
+ class Engine < ::Rails::Engine
8
+ initializer 'view helpers' do |app|
9
+ ActiveSupport.on_load(:action_view) do
10
+ include Grasshopper::Paginate::Helper
11
+ end
12
+ end
13
+
14
+ initializer 'active record extention' do |app|
15
+ ActiveSupport.on_load(:active_record) do
16
+ require 'grasshopper_paginate/active_record'
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module Grasshopper
2
+ module Paginate
3
+ module Helper
4
+ def grasshopper_paginate(pages)
5
+ will_paginate pages, default_options
6
+ end
7
+
8
+ private
9
+
10
+ def default_options
11
+ {
12
+ :inner_window => 1,
13
+ :outer_window => 0,
14
+ :renderer => Grasshopper::Paginate::Renderer,
15
+ :previous_label => '&laquo;'.html_safe,
16
+ :next_label => '&raquo;'.html_safe
17
+ }
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,49 @@
1
+ require 'will_paginate/view_helpers/action_view'
2
+
3
+ module Grasshopper
4
+ module Paginate
5
+ class Renderer < ::WillPaginate::ActionView::LinkRenderer
6
+
7
+ protected
8
+
9
+ def gap
10
+ tag :li, link(super, nil), :class => 'goto-gap'
11
+ end
12
+
13
+ def page_number(page)
14
+ tag :li, link(page, page, :rel => rel_value(page)), :class => ('current' if page == current_page)
15
+ end
16
+
17
+ def previous_or_next_page(page, text, classname)
18
+ tag :li, link(text, page || '#'), :class => [classname[0..3], classname, ('unavailable' unless page)].join(' ')
19
+ end
20
+
21
+ def html_container(html)
22
+ content = tag(:ul, html, container_attributes) + goto_input
23
+ tag :div, content, class: 'grasshopper-pagination'
24
+ end
25
+
26
+ private
27
+
28
+ def goto_input
29
+ tag :ul, page_input, class: 'pagination goto hide'
30
+ end
31
+
32
+ def page_input
33
+ input = tag :input, nil, input_data
34
+ input = tag :li, input
35
+ total_count = tag :li, tag(:a, "&nbsp; / &nbsp; #{total_pages}".html_safe, class: 'total-pages'), class: 'unavailable'
36
+ previous_page + input + total_count + next_page
37
+ end
38
+
39
+ def input_data
40
+ {
41
+ class: 'goto-page',
42
+ value: current_page,
43
+ url: url('page_number'),
44
+ total: total_pages
45
+ }
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,5 @@
1
+ module Grasshopper
2
+ module Paginate
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grasshopper_paginate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - JIEXIN HUANG
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 5.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 4.2.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 5.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: foundation-rails
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '5.5'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 5.5.0
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '5.5'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 5.5.0
53
+ - !ruby/object:Gem::Dependency
54
+ name: jquery-rails
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: 3.1.0
60
+ type: :runtime
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: 3.1.0
67
+ - !ruby/object:Gem::Dependency
68
+ name: sass-rails
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: 5.0.1
74
+ type: :runtime
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: 5.0.1
81
+ - !ruby/object:Gem::Dependency
82
+ name: will_paginate
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: '3.0'
88
+ type: :runtime
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "~>"
93
+ - !ruby/object:Gem::Version
94
+ version: '3.0'
95
+ description: change based on foundation-will_paginate gem, use foundation style pagination
96
+ and also provides a goto page input area when gap is clicked
97
+ email:
98
+ - hjx500@gmail.com
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - ".gitignore"
104
+ - Gemfile
105
+ - LICENSE.txt
106
+ - README.md
107
+ - Rakefile
108
+ - app/assets/javascripts/grasshopper_paginate/paginate.js.coffee
109
+ - app/assets/stylesheets/grasshopper_paginate/paginate.css.scss
110
+ - grasshopper_paginate.gemspec
111
+ - lib/grasshopper_paginate.rb
112
+ - lib/grasshopper_paginate/active_record.rb
113
+ - lib/grasshopper_paginate/array.rb
114
+ - lib/grasshopper_paginate/engine.rb
115
+ - lib/grasshopper_paginate/helper.rb
116
+ - lib/grasshopper_paginate/renderer.rb
117
+ - lib/grasshopper_paginate/version.rb
118
+ homepage: ''
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.2.2
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: enhanced foundation pagination with will_paginate
142
+ test_files: []
143
+ has_rdoc: