kaminari-sinatra 0.1.0 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4fec598fd8d63563a8d139f51b64d024171bf243
4
- data.tar.gz: ceffc543cafab67c63245e42f69a85052f0fef18
3
+ metadata.gz: c4738ac5cda28114105594798e24bdbb1a2f9364
4
+ data.tar.gz: 033d48a1a250aa4c3d10debddfc368559aae99c7
5
5
  SHA512:
6
- metadata.gz: 8e5bac3c9adea62733242d1583b580000a917bf4ca234d3713c8c05c0c6898bc7c8343efe543e77a32bf8d4079f5da0ae354a8eeca70392d95ea92a202c6753c
7
- data.tar.gz: 8e736d8e881b76304b78cf5add500006aca08d7b956f8c84d34e3ab45fef853c75f9c4892fdd7bd61405b48309a657f03ff2961b91c421a812bb8b27970a0b4e
6
+ metadata.gz: 22be9d021ac330d3f57c8784967191b7b6569ee0f27a6063f5eef6e8c5d318ffa25ce852777fb1269bc4113918bf09697169cb6204a71f4adeaeb6db201daeb4
7
+ data.tar.gz: 1114d56624cd11896e721384c60233f7a3d3b7a3f311a12c506632fc1a171f506da7e12b5e297a48691a5ad64732e6ec44f91c6bfbd70be4951e66964f123252
@@ -1,12 +1,10 @@
1
1
  language: ruby
2
2
 
3
- before_install: gem install bundler -v 1.11.2
3
+ before_install: gem update bundler
4
4
 
5
5
  rvm:
6
- - 2.0.0
7
- - 2.1.10
8
- - 2.2.4
9
- - 2.3.1
6
+ - 2.2.6
7
+ - 2.3.3
10
8
  - ruby-head
11
9
  - jruby
12
10
  - jruby-head
@@ -17,7 +15,7 @@ gemfile:
17
15
 
18
16
  sudo: false
19
17
 
20
- script: 'bundle exec rake spec'
18
+ script: 'bundle exec rake test'
21
19
 
22
20
  cache: bundler
23
21
 
data/Gemfile CHANGED
@@ -1,6 +1,12 @@
1
+ # frozen_string_literal: true
1
2
  source 'https://rubygems.org'
2
3
 
3
4
  # Specify your gem's dependencies in kaminari-sinatra.gemspec
4
5
  gemspec
5
6
 
6
- gem 'kaminari'
7
+ #FIXME bundle GH master for now
8
+ gem 'kaminari-core', github: 'amatsuda/kaminari'
9
+ gem 'kaminari-activerecord', github: 'amatsuda/kaminari'
10
+
11
+ #FIXME need to bundle AV for now, because the helper still depends on ActionView
12
+ gem 'actionview', require: 'action_view'
data/Rakefile CHANGED
@@ -1,9 +1,12 @@
1
+ # frozen_string_literal: true
1
2
  require "bundler/gem_tasks"
2
- require 'rspec/core'
3
- require 'rspec/core/rake_task'
3
+ require 'rake/testtask'
4
4
 
5
- RSpec::Core::RakeTask.new(:spec) do |spec|
6
- spec.pattern = [FileList['spec/**/*_spec.rb'], "#{File.join(Gem.loaded_specs['kaminari'].gem_dir, 'spec')}/**/*_spec.rb"]
5
+ Rake::TestTask.new do |t|
6
+ t.libs << 'test'
7
+ t.pattern = "{test,#{File.join(Gem.loaded_specs['kaminari-core'].gem_dir, 'test')}}/**/*_test.rb"
8
+ t.warning = true
9
+ t.verbose = true
7
10
  end
8
11
 
9
- task :default => :spec
12
+ task default: :test
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require "bundler/setup"
4
5
  require "kaminari/sinatra"
@@ -1,11 +1,13 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- #FIXME bundle GH branch for now
4
- gem 'kaminari', github: 'amatsuda/kaminari', branch: 'extract_adapters'
3
+ #FIXME bundle GH master for now
4
+ gem 'kaminari-core', github: 'amatsuda/kaminari'
5
+ gem 'kaminari-activerecord', github: 'amatsuda/kaminari'
5
6
 
6
- gem 'activerecord', '>= 4.0.0', :require => 'active_record'
7
+ gem 'activerecord', '>= 5.0.0', :require => 'active_record'
8
+ #FIXME need to bundle AV for now, because the helper still depends on ActionView
9
+ gem 'actionview', '>= 5.0.0', :require => 'action_view'
7
10
  gem 'sinatra', '~> 1.4.0'
8
- gem 'rspec', '~> 2.14.1'
9
11
  gem 'padrino-helpers', '~> 0.12.0'
10
12
  gem 'rack-test', '>= 0'
11
13
  gem 'sinatra-contrib', '~> 1.4.0'
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'kaminari/sinatra/version'
@@ -10,7 +11,7 @@ Gem::Specification.new do |spec|
10
11
  spec.email = ["ronnie@dio.jp"]
11
12
 
12
13
  spec.summary = 'Kaminari Sinatra adapter'
13
- spec.description = 'Kaminari Sinatra adapter'
14
+ spec.description = 'kaminari-sinatra privides pagination helpers for your Sinatra templates'
14
15
  spec.homepage = 'https://github.com/kaminari/kaminari-sinatra'
15
16
  spec.license = "MIT"
16
17
 
@@ -21,15 +22,15 @@ Gem::Specification.new do |spec|
21
22
 
22
23
  spec.add_development_dependency "bundler", "~> 1.11"
23
24
  spec.add_development_dependency "rake", "~> 10.0"
24
- spec.add_development_dependency 'rspec', '< 2.9'
25
+ spec.add_development_dependency 'test-unit-activesupport'
26
+ spec.add_development_dependency 'test-unit-rr'
25
27
  spec.add_development_dependency 'capybara'
26
- spec.add_development_dependency 'rr'
27
28
  spec.add_development_dependency 'sinatra-contrib'
28
29
  spec.add_development_dependency 'activerecord'
29
30
  spec.add_development_dependency 'sqlite3'
30
31
  spec.add_development_dependency 'byebug'
31
32
  spec.add_development_dependency 'database_cleaner'
32
- spec.add_dependency 'kaminari'
33
+ spec.add_dependency 'kaminari-core', Kaminari::Sinatra::VERSION
33
34
  spec.add_dependency 'sinatra'
34
35
  spec.add_dependency 'actionview'
35
36
  spec.add_dependency 'padrino-helpers'
@@ -1,10 +1,11 @@
1
+ # frozen_string_literal: true
1
2
  require 'active_support/core_ext/object'
2
3
  require 'active_support/core_ext/string'
3
- require 'action_dispatch/http/mime_type'
4
-
5
- begin
6
-
7
4
  require 'padrino-helpers'
5
+ require 'kaminari/helpers/helper_methods'
6
+ require 'action_view'
7
+ require 'action_view/base'
8
+
8
9
  module Kaminari::Helpers
9
10
  module SinatraHelpers
10
11
  class << self
@@ -21,156 +22,84 @@ module Kaminari::Helpers
21
22
  alias included registered
22
23
  end
23
24
 
24
- class ActionViewTemplateProxy
25
- include Padrino::Helpers::OutputHelpers
26
- include Padrino::Helpers::TagHelpers
27
- include Padrino::Helpers::AssetTagHelpers
28
- include Padrino::Helpers::FormatHelpers
29
- include Padrino::Helpers::TranslationHelpers
30
-
31
- def initialize(opts={})
32
- @current_path = opts[:current_path]
33
- @param_name = (opts[:param_name] || :page).to_sym
34
- @current_params = opts[:current_params]
25
+ # kaminari-sinatra uses Action View for rendering the Paginator
26
+ # because the default template uses Rails 3-ish `<%=` + block syntax that can't be rendered
27
+ # with pure ERB.
28
+ class ActionViewTemplateProxy < ActionView::Base
29
+ def initialize(current_path: nil, param_name: nil, current_params: nil)
30
+ super()
31
+
32
+ @current_path = current_path
33
+ @param_name = param_name || Kaminari.config.page_method_name
34
+ @current_params = current_params || {}
35
35
  @current_params.delete(@param_name)
36
- end
37
36
 
38
- def render(*args)
39
- base = ActionView::Base.new.tap do |a|
40
- a.view_paths << SinatraHelpers.view_paths
41
- a.view_paths << File.join(Gem.loaded_specs['kaminari'].gem_dir, 'app/views')
42
- end
43
- base.render(*args)
37
+ view_paths << SinatraHelpers.view_paths
38
+ view_paths << File.join(Gem.loaded_specs['kaminari-core'].gem_dir, 'app/views')
44
39
  end
45
40
 
46
41
  def url_for(params)
42
+ return params if String === params
43
+
47
44
  extra_params = {}
48
- if (page = params[@param_name]) && (Kaminari.config.params_on_first_page || page != 1)
45
+ if (page = params[@param_name]) && (Kaminari.config.params_on_first_page || (page.to_i != 1))
49
46
  extra_params[@param_name] = page
50
47
  end
51
48
  query = @current_params.merge(extra_params)
52
49
  @current_path + (query.empty? ? '' : "?#{query.to_query}")
53
50
  end
54
51
 
55
- def link_to_unless(condition, name, options = {}, html_options = {}, &block)
56
- options = url_for(options) if options.is_a? Hash
57
- if condition
58
- if block_given?
59
- block.arity <= 1 ? capture(name, &block) : capture(name, options, html_options, &block)
60
- else
61
- name
62
- end
63
- else
64
- link_to(name, options, html_options)
65
- end
66
- end
67
-
68
52
  def params
69
53
  @current_params
70
54
  end
71
55
  end
72
56
 
73
- module HelperMethods
74
- # A helper that renders the pagination links - for Sinatra.
75
- #
76
- # <%= paginate @articles %>
77
- #
78
- # ==== Options
79
- # * <tt>:window</tt> - The "inner window" size (4 by default).
80
- # * <tt>:outer_window</tt> - The "outer window" size (0 by default).
81
- # * <tt>:left</tt> - The "left outer window" size (0 by default).
82
- # * <tt>:right</tt> - The "right outer window" size (0 by default).
83
- # * <tt>:params</tt> - url_for parameters for the links (:id, :locale, etc.)
84
- # * <tt>:param_name</tt> - parameter name for page number in the links (:page by default)
85
- # * <tt>:remote</tt> - Ajax? (false by default)
86
- # * <tt>:ANY_OTHER_VALUES</tt> - Any other hash key & values would be directly passed into each tag as :locals value.
87
- def paginate(scope, options = {}, &block)
57
+ # Some helper methods that are used in Kaminari::Helpers::HelperMethods.
58
+ # Plus, monkey-patch for `paginate` to pass in an ActionViewTemplateProxy instance.
59
+ module SinatraHelperMethods
60
+ def url_for(params)
88
61
  current_path = env['PATH_INFO'] rescue nil
89
- current_params = Rack::Utils.parse_query(env['QUERY_STRING']).symbolize_keys rescue {}
90
- paginator = Kaminari::Helpers::Paginator.new(
91
- ActionViewTemplateProxy.new(:current_params => current_params, :current_path => current_path, :param_name => options[:param_name] || Kaminari.config.param_name),
92
- options.reverse_merge(:current_page => scope.current_page, :total_pages => scope.total_pages, :per_page => scope.limit_value, :param_name => Kaminari.config.param_name, :remote => false)
93
- )
94
- paginator.to_s
95
- end
62
+ current_params = Rack::Utils.parse_query(env['QUERY_STRING']) rescue {}
96
63
 
97
- # A simple "Twitter like" pagination link that creates a link to the previous page.
98
- # Works on Sinatra.
99
- #
100
- # ==== Examples
101
- # Basic usage:
102
- #
103
- # <%= link_to_previous_page @items, 'Previous Page' %>
104
- #
105
- # Ajax:
106
- #
107
- # <%= link_to_previous_page @items, 'Previous Page', :remote => true %>
108
- #
109
- # By default, it renders nothing if there are no more results on the previous page.
110
- # You can customize this output by passing a parameter <tt>:placeholder</tt>.
111
- #
112
- # <%= link_to_previous_page @users, 'Previous Page', :placeholder => %{<span>At the Beginning</span>} %>
113
- #
114
- def link_to_previous_page(scope, name, options = {})
115
- params = options.delete(:params) || (Rack::Utils.parse_query(env['QUERY_STRING']).symbolize_keys rescue {})
116
- param_name = options.delete(:param_name) || Kaminari.config.param_name
117
- placeholder = options.delete(:placeholder)
118
-
119
- if scope.first_page?
120
- placeholder.to_s.html_safe
121
- else
122
- query = params.merge(param_name => scope.prev_page)
123
- link_to name, env['PATH_INFO'] + (query.empty? ? '' : "?#{query.to_query}"), options.reverse_merge(:rel => 'previous')
124
- end
64
+ extra_params = params.dup
65
+ extra_params.delete :only_path
66
+
67
+ query = current_params.merge(extra_params)
68
+ res = current_path + (query.empty? ? '' : "?#{query.to_query}")
69
+ res
125
70
  end
126
71
 
127
- # A simple "Twitter like" pagination link that creates a link to the next page.
128
- # Works on Sinatra.
129
- #
130
- # ==== Examples
131
- # Basic usage:
132
- #
133
- # <%= link_to_next_page @items, 'Next Page' %>
134
- #
135
- # Ajax:
136
- #
137
- # <%= link_to_next_page @items, 'Next Page', :remote => true %>
138
- #
139
- # By default, it renders nothing if there are no more results on the next page.
140
- # You can customize this output by passing a parameter <tt>:placeholder</tt>.
141
- #
142
- # <%= link_to_next_page @items, 'Next Page', :placeholder => %{<span>No More Pages</span>} %>
143
- #
144
- def link_to_next_page(scope, name, options = {})
145
- params = options.delete(:params) || (Rack::Utils.parse_query(env['QUERY_STRING']).symbolize_keys rescue {})
146
- param_name = options.delete(:param_name) || Kaminari.config.param_name
147
- placeholder = options.delete(:placeholder)
148
-
149
- if scope.last_page? || scope.out_of_range?
150
- placeholder.to_s.html_safe
72
+ def link_to_if(condition, name, options = {}, html_options = {}, &block)
73
+ options = url_for(options) if options.is_a? Hash
74
+ if condition
75
+ link_to(name, options, html_options)
76
+ elsif block_given?
77
+ capture_html(&block).html_safe
151
78
  else
152
- query = params.merge(param_name => scope.next_page)
153
- link_to name, env['PATH_INFO'] + (query.empty? ? '' : "?#{query.to_query}"), options.reverse_merge(:rel => 'next')
79
+ name
154
80
  end
155
81
  end
156
- end
157
- end
158
- end
159
82
 
160
- if defined? I18n
161
- I18n.load_path += Dir.glob(File.join(Gem.loaded_specs['kaminari'].gem_dir, 'config/locales/*.yml'))
162
- end
83
+ def link_to_unless(condition, name, options = {}, html_options = {}, &block)
84
+ link_to_if !condition, name, options, html_options, &block
85
+ end
163
86
 
164
- rescue LoadError
87
+ # Overriding `paginate` to pass in an Action View renderer.
88
+ # If you're sure your custom template is compatible with Padrino renderer, you might not need it.
89
+ # In that case, please add `template: self` option when calling this method.
90
+ def paginate(scope, options = {})
91
+ current_path = env['PATH_INFO'] rescue nil
92
+ current_params = Rack::Utils.parse_query(env['QUERY_STRING']).symbolize_keys rescue {}
165
93
 
166
- $stderr.puts "[!]You should install `padrino-helpers' gem if you want to use kaminari's pagination helpers with Sinatra."
167
- $stderr.puts "[!]Kaminari::Helpers::SinatraHelper does nothing now..."
94
+ template = ActionViewTemplateProxy.new current_params: current_params, current_path: current_path, param_name: options[:param_name] || Kaminari.config.param_name
168
95
 
169
- module Kaminari::Helpers
170
- module SinatraHelper
171
- def self.registered(*)
96
+ super scope, {template: template}.merge(options)
97
+ end
172
98
  end
99
+ Kaminari::Helpers::HelperMethods.prepend SinatraHelperMethods
173
100
  end
174
101
  end
175
102
 
103
+ if defined? I18n
104
+ I18n.load_path += Dir.glob(File.join(Gem.loaded_specs['kaminari-core'].gem_dir, 'config/locales/*.yml'))
176
105
  end
@@ -1,5 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'sinatra/base'
2
- require 'kaminari'
3
+ require 'kaminari/core'
3
4
  require 'kaminari/helpers/sinatra_helpers'
4
-
5
- Kaminari::Hooks.init
@@ -1,5 +1,6 @@
1
+ # frozen_string_literal: true
1
2
  module Kaminari
2
3
  module Sinatra
3
- VERSION = "0.1.0"
4
+ VERSION = '1.0.0.rc1'
4
5
  end
5
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kaminari-sinatra
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akira Matsuda
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-01 00:00:00.000000000 Z
11
+ date: 2016-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -39,21 +39,21 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec
42
+ name: test-unit-activesupport
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "<"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '2.9'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "<"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '2.9'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: capybara
56
+ name: test-unit-rr
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rr
70
+ name: capybara
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -151,19 +151,19 @@ dependencies:
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  - !ruby/object:Gem::Dependency
154
- name: kaminari
154
+ name: kaminari-core
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - ">="
157
+ - - '='
158
158
  - !ruby/object:Gem::Version
159
- version: '0'
159
+ version: 1.0.0.rc1
160
160
  type: :runtime
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - ">="
164
+ - - '='
165
165
  - !ruby/object:Gem::Version
166
- version: '0'
166
+ version: 1.0.0.rc1
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: sinatra
169
169
  requirement: !ruby/object:Gem::Requirement
@@ -206,7 +206,7 @@ dependencies:
206
206
  - - ">="
207
207
  - !ruby/object:Gem::Version
208
208
  version: '0'
209
- description: Kaminari Sinatra adapter
209
+ description: kaminari-sinatra privides pagination helpers for your Sinatra templates
210
210
  email:
211
211
  - ronnie@dio.jp
212
212
  executables: []
@@ -241,12 +241,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
241
241
  version: '0'
242
242
  required_rubygems_version: !ruby/object:Gem::Requirement
243
243
  requirements:
244
- - - ">="
244
+ - - ">"
245
245
  - !ruby/object:Gem::Version
246
- version: '0'
246
+ version: 1.3.1
247
247
  requirements: []
248
248
  rubyforge_project:
249
- rubygems_version: 2.6.4
249
+ rubygems_version: 2.6.8
250
250
  signing_key:
251
251
  specification_version: 4
252
252
  summary: Kaminari Sinatra adapter