jbuilder_pagination 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: b5e96a670102c2f927e59e21c26d90f9b4d2d070
4
+ data.tar.gz: ee270b6e1ebcd7ac567aa3c5a43e4f18083b5893
5
+ SHA512:
6
+ metadata.gz: 77db3f4d5c32df65b5c68ee9a387b3038c16571c8827d9ce8741517531d96b1302f127c391e24e452b0072660bbc39a41d800af60594e5e7ac707a4692ff48ab
7
+ data.tar.gz: d4474e11826257048f4261475af2bd28a370012c162c130848f5fd43fba3bc032b83072b181f70791881ae66cb0ba61f1460b911f449e71299c1c962ce38d806
data/.gitignore ADDED
@@ -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
+ *.sw?
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ jbuilder_pagination
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ install: bin/setup
5
+ script:
6
+ - bundle exec rspec spec
@@ -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, 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,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jbuilder_pagination.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Bruno Bacarini
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.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # Jbuilder::Pagination [![Build Status](https://travis-ci.org/bacarini/jbuilder_pagination.svg?branch=master)](https://travis-ci.org/bacarini/jbuilder_pagination)
2
+
3
+ [Jbuilder](https://github.com/rails/jbuilder) extension that makes easier to use pagination according to the [JSON API](http://jsonapi.org/format/#fetching-pagination) conventions.
4
+
5
+ ## Requirement
6
+
7
+ It is based on [will_paginate](https://github.com/mislav/will_paginate).
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'jbuilder_pagination', require: 'jbuilder/pagination'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install jbuilder_pagination
24
+
25
+ ## Usage
26
+
27
+ ```ruby
28
+ json.links do
29
+ json.pages! @servers, url: "https://api.example.com/v1/servers"
30
+ end
31
+
32
+ # =>
33
+ # "links": {
34
+ # "pages": {
35
+ # "first": "https://api.example.com/v1/servers/v1/servers?page=1&per_page=1",
36
+ # "prev": "https://api.example.com/v1/servers/v1/servers?page=1&per_page=1",
37
+ # "last": "https://api.example.com/v1/servers/v1/servers?page=3&per_page=1",
38
+ # "next": "https://api.example.com/v1/servers/v1/servers?page=3&per_page=1"
39
+ # }
40
+ # },
41
+ ```
42
+
43
+ In case there is no pagination at all, `links` will be omitted.
44
+
45
+ ## Development
46
+
47
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
48
+
49
+ ## Contributing
50
+
51
+ 1. Fork it
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "jbuilder/pagination"
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
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install --jobs=3 --retry=3
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jbuilder/pagination/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jbuilder_pagination"
8
+ spec.version = Jbuilder::Pagination::VERSION
9
+ spec.authors = ["Bruno Bacarini"]
10
+ spec.email = ["bacarini.bruno@gmail.com"]
11
+
12
+ spec.summary = "Jbuilder extension to allows pagination according to JSON API format"
13
+ spec.description = "Jbuilder extension to allows pagination according to JSON API format. See http://jsonapi.org for details on the format"
14
+ spec.homepage = "https://github.com/bacarini/jbuilder_pagination"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency 'jbuilder', '~> 2.2', '>= 2.2.0'
23
+ spec.add_development_dependency 'rspec', '~> 3.2', '>= 3.2.0'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'pry', '~> 0'
26
+ end
@@ -0,0 +1,3 @@
1
+ require "jbuilder"
2
+ require "jbuilder/pagination/pages"
3
+
@@ -0,0 +1,29 @@
1
+ class Jbuilder
2
+ def pages!(collection, options={})
3
+ return unless collection
4
+
5
+ pages do
6
+ pages_from(collection).map do |k, v|
7
+ _set_value k, "#{options[:url]}?page=#{v}&per_page=#{collection.per_page}"
8
+ end
9
+ end
10
+ end
11
+
12
+ private
13
+
14
+ def pages_from(collection)
15
+ return {} if collection.total_pages == 1
16
+
17
+ {}.tap do |pages|
18
+ unless collection.current_page == 1
19
+ pages[:first] = 1
20
+ pages[:prev] = collection.current_page - 1
21
+ end
22
+
23
+ unless collection.current_page == collection.total_pages
24
+ pages[:last] = collection.total_pages
25
+ pages[:next] = collection.current_page + 1
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ module Jbuilder
2
+ class Pagination
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jbuilder_pagination
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Bruno Bacarini
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-04-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jbuilder
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '2.2'
20
+ - - '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 2.2.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '2.2'
30
+ - - '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 2.2.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: rspec
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ~>
38
+ - !ruby/object:Gem::Version
39
+ version: '3.2'
40
+ - - '>='
41
+ - !ruby/object:Gem::Version
42
+ version: 3.2.0
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ~>
48
+ - !ruby/object:Gem::Version
49
+ version: '3.2'
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: 3.2.0
53
+ - !ruby/object:Gem::Dependency
54
+ name: rake
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ version: '10.0'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ~>
65
+ - !ruby/object:Gem::Version
66
+ version: '10.0'
67
+ - !ruby/object:Gem::Dependency
68
+ name: pry
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ~>
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ~>
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ description: Jbuilder extension to allows pagination according to JSON API format.
82
+ See http://jsonapi.org for details on the format
83
+ email:
84
+ - bacarini.bruno@gmail.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - .gitignore
90
+ - .rspec
91
+ - .ruby-gemset
92
+ - .ruby-version
93
+ - .travis.yml
94
+ - CODE_OF_CONDUCT.md
95
+ - Gemfile
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - jbuilder_pagination.gemspec
102
+ - lib/jbuilder/pagination.rb
103
+ - lib/jbuilder/pagination/pages.rb
104
+ - lib/jbuilder/pagination/version.rb
105
+ homepage: https://github.com/bacarini/jbuilder_pagination
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.4.6
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Jbuilder extension to allows pagination according to JSON API format
129
+ test_files: []