mirror of
https://github.com/kaminari/kaminari.git
synced 2022-11-09 13:44:37 -05:00
83 lines
1.6 KiB
Ruby
83 lines
1.6 KiB
Ruby
module Kaminari
|
|
def self.frameworks
|
|
frameworks = []
|
|
case
|
|
when rails? then frameworks << 'rails'
|
|
when sinatra? then frameworks << 'sinatra/base'
|
|
when grape? then frameworks << 'grape'
|
|
end
|
|
frameworks
|
|
end
|
|
|
|
def self.load_framework!
|
|
show_warning if frameworks.empty?
|
|
frameworks.each do |framework|
|
|
begin
|
|
require framework
|
|
rescue NameError => e
|
|
raise "Failed to load framework #{framework.inspect}. Have you added it to Gemfile?"
|
|
end
|
|
end
|
|
end
|
|
|
|
def self.show_warning
|
|
$stderr.puts <<-EOC
|
|
warning: no framework detected.
|
|
would you check out if your Gemfile appropriately configured?
|
|
---- e.g. ----
|
|
when Rails:
|
|
gem 'rails'
|
|
gem 'kaminari'
|
|
|
|
when Sinatra/Padrino:
|
|
gem 'kaminari', :require => 'kaminari/sinatra'
|
|
|
|
when Grape:
|
|
gem 'kaminari', :require => 'kaminari/grape'
|
|
|
|
EOC
|
|
end
|
|
|
|
def self.load_kaminari!
|
|
require 'kaminari/config'
|
|
require 'kaminari/helpers/action_view_extension'
|
|
require 'kaminari/helpers/paginator'
|
|
require 'kaminari/models/page_scope_methods'
|
|
require 'kaminari/models/configuration_methods'
|
|
end
|
|
|
|
def self.hook!
|
|
load_framework!
|
|
load_kaminari!
|
|
require 'kaminari/hooks'
|
|
if rails?
|
|
require 'kaminari/railtie'
|
|
require 'kaminari/engine'
|
|
elsif sinatra?
|
|
require 'kaminari/sinatra'
|
|
elsif grape?
|
|
require 'kaminari/grape'
|
|
else
|
|
Kaminari::Hooks.init!
|
|
end
|
|
end
|
|
|
|
def self.load!
|
|
hook!
|
|
end
|
|
|
|
private
|
|
def self.rails?
|
|
defined?(::Rails)
|
|
end
|
|
|
|
def self.sinatra?
|
|
defined?(::Sinatra)
|
|
end
|
|
|
|
def self.grape?
|
|
defined?(::Grape)
|
|
end
|
|
end
|
|
|
|
Kaminari.load!
|