sequel-paginate 0.1.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bfb89cfa8e0702001b6471cc62fbc0cf795d4d04
4
+ data.tar.gz: 9884a170eb85e6a628dc320afaf61160b681387c
5
+ SHA512:
6
+ metadata.gz: 29531fbebdaf61431ee94670ea91c06b42af4e146be51c6b5e4951b297a55058070cd23e3431b5c9efffe2cb44a96f70e22ecfefcebff8102df9e0939feaf7a9
7
+ data.tar.gz: 02ff00fc77008f27f393c61ce1488c884ad3d0b8e985d5ce49bdc6f8a7d28a69edc2a146ceba3d0401598720611a1228db7db7b1d33e75084be8d82e37ee817a
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /*.swp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.4
4
+ before_install: gem install bundler -v 1.10.2
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sequel-paginate.gemspec
4
+ gemspec
5
+
6
+ gem 'sequel'
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 sven199109
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,51 @@
1
+ # Sequel::Paginate
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sequel/paginate`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'sequel-paginate', github: 'sven199109/sequel-paginate'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install sequel-paginate
22
+
23
+ ## Usage
24
+
25
+ Use `paginate @models` in your views, also you can use these options below.
26
+
27
+ * middle (default 3)
28
+ * left (default 3)
29
+ * right (default 3)
30
+ * class (default 'paginate') css class name.
31
+ * remote (default false) Use it in ajax.If you want to use it, ensure include `jquery.js` and `jquery-ujs.js` in your layout file.
32
+
33
+ For example, `paginate @models, left: 5, right: 5, remote: true`.
34
+
35
+ Whatever rails or padrino you use, your can use `ModelName.page(page_no)` to query models the page you want.
36
+
37
+ ## Development
38
+
39
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
40
+
41
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
42
+
43
+ ## Contributing
44
+
45
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sequel-paginate. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
46
+
47
+
48
+ ## License
49
+
50
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
51
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sequel/paginate"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,19 @@
1
+ require "sequel/paginate/version"
2
+ require "sequel/paginate/realization"
3
+ require "sequel/paginate/views_helper"
4
+
5
+ module Sequel
6
+ module Paginate
7
+ # Your code goes here...
8
+ end
9
+ end
10
+
11
+ if defined?(Rails)
12
+ require "sequel/paginate/railtie"
13
+ end
14
+
15
+ if defined?(::Padrino)
16
+ require 'padrino-core'
17
+ ::Padrino::Application.send :include, ::Sequel::Paginate::ViewsHelper
18
+ end
19
+
@@ -0,0 +1,13 @@
1
+ module Sequel
2
+ module Paginate
3
+ class Railtie < ::Rails::Railtie
4
+ initializer 'sequel-paginate' do |_app|
5
+ if defined?(::ActiveSupport)
6
+ ::ActiveSupport.on_load(:action_view) do
7
+ ::ActionView::Base.send :include, ::Sequel::Paginate::ViewsHelper
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,34 @@
1
+ require 'sequel/model'
2
+ module Sequel
3
+ module Paginate
4
+ module Realization
5
+ def self.included(base)
6
+ base.extend(self)
7
+ end
8
+
9
+ def self.extended(base)
10
+ class << base
11
+ def paginate_per(count = 20)
12
+ @paginate_per ||= count
13
+ end
14
+ end
15
+ base.class_eval do
16
+ dataset_module do
17
+ define_method(:page) do |*args, &block|
18
+ begin
19
+ page_per = args[1][:page_per]
20
+ rescue
21
+ page_per = nil
22
+ end
23
+ page_no = args[0].to_i
24
+ page_no = page_no > 0 ? page_no : 1
25
+ where.extension(:pagination).paginate(page_no.to_i, page_per || self.model.paginate_per)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ Sequel::Model.include ::Sequel::Paginate::Realization
@@ -0,0 +1,5 @@
1
+ module Sequel
2
+ module Paginate
3
+ VERSION = "0.1.1"
4
+ end
5
+ end
@@ -0,0 +1,67 @@
1
+ module Sequel
2
+ module Paginate
3
+ module ViewsHelper
4
+ def self.included(base)
5
+ base.extend(self)
6
+ end
7
+ def paginate(models, *args, &block)
8
+ args = [{}] if args.nil? || args.empty?
9
+ page_no = (params[:page] || 1).to_i
10
+ left = args[0][:left] || 3
11
+ right = args[0][:right] || 3
12
+ middle = args[0][:middle] || 3
13
+ remote = args[0][:remote] || false
14
+ html_class = args[0][:class] || "pagination"
15
+ class_name = models.first.class
16
+ path = request.path
17
+ page_count = (1..(class_name.count.to_f / class_name.paginate_per).ceil).to_a
18
+ return nil if page_count.length <= 1
19
+ page_to_show = []
20
+ if page_count.count > left + right + middle
21
+ page_count.each do |p|
22
+ if p > left && p < page_count[-right]
23
+ if (p < page_no + middle && p > page_no - middle)
24
+ page_to_show << p
25
+ else
26
+ page_to_show << -1 unless page_to_show.last == -1
27
+ end
28
+ else
29
+ page_to_show << p
30
+ end
31
+ end
32
+ else
33
+ page_to_show = page_count
34
+ end
35
+
36
+ html = "<div class='#{html_class}'><ul>"
37
+ if page_no <= 1
38
+ html += "<li><a>Prev</a></li>"
39
+ else
40
+ html += "<li class='previous'><a href='#{path}?page=#{page_no-1}' #{remote_tag(remote)}>Prev</a></li>"
41
+ end
42
+ page_to_show.each do |page|
43
+ if page == -1
44
+ html += "<li><a>...</a></li>"
45
+ else
46
+ if page == page_no
47
+ html += "<li class='active'><a>#{page}</a></li>"
48
+ else
49
+ html += "<li><a href='#{path}?page=#{page}' #{remote_tag(remote)}>#{page}</a></li>"
50
+ end
51
+ end
52
+ end
53
+ if page_no >= page_count.count
54
+ html += "<li><a>Next</a></li>"
55
+ else
56
+ html += "<li class='next'><a href='#{path}?page=#{page_no+1}' #{remote_tag(remote)}>Next</a></li>"
57
+ end
58
+ html += "</ul></div>"
59
+ html.html_safe
60
+ end
61
+ private
62
+ def remote_tag(remote)
63
+ "data-remote='true'" if remote
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sequel/paginate/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sequel-paginate"
8
+ spec.version = Sequel::Paginate::VERSION
9
+ spec.authors = ["sven199109"]
10
+ spec.email = ["sven199109@gmail.com"]
11
+
12
+ spec.summary = %q{To use it for sequel paginate.}
13
+ spec.description = %q{To use it for sequel paginate.}
14
+ spec.homepage = "https://github.com/sven199109/sequel-paginate.git"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.10"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rspec"
33
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sequel-paginate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - sven199109
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: To use it for sequel paginate.
56
+ email:
57
+ - sven199109@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - lib/sequel/paginate.rb
73
+ - lib/sequel/paginate/railtie.rb
74
+ - lib/sequel/paginate/realization.rb
75
+ - lib/sequel/paginate/version.rb
76
+ - lib/sequel/paginate/views_helper.rb
77
+ - sequel-paginate.gemspec
78
+ homepage: https://github.com/sven199109/sequel-paginate.git
79
+ licenses:
80
+ - MIT
81
+ metadata:
82
+ allowed_push_host: https://rubygems.org
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.4.5.1
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: To use it for sequel paginate.
103
+ test_files: []