Class: RailsAdminContent::Paginate
- Inherits:
-
Object
- Object
- RailsAdminContent::Paginate
- Defined in:
- lib/rails_admin_content/paginate.rb
Instance Method Summary collapse
-
#initialize(scope, options = {}) ⇒ Paginate
constructor
A new instance of Paginate.
- #to_s ⇒ Object
Constructor Details
#initialize(scope, options = {}) ⇒ Paginate
Returns a new instance of Paginate.
4 5 6 |
# File 'lib/rails_admin_content/paginate.rb', line 4 def initialize(scope, = {}) @scope, @options = scope, end |
Instance Method Details
#to_s ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rails_admin_content/paginate.rb', line 8 def to_s return "" unless @scope current_page, total_pages = @options[:spage].to_i, RailsAdminContent::Client.total_nums / @options[:stint] + 1 # return "共#{RailsAdminContent::Client.total_nums}条数据" if total_pages <= 1 param_name = @options["param_name"] || "page" url = @options["url"] || "" helpers.content_tag :div, :class => "pagination" do helpers.content_tag :ul do result = '' result += helpers.content_tag(:li, class: 'previous'){helpers.link_to("‹ 上一页","#{url}?#{param_name}=#{current_page-1}")} if current_page.to_i > 1 if total_pages > 8 1.upto(3) { |i| result << page_link(i, current_page) } if current_page > 1 and current_page < total_pages result << helpers.content_tag(:li, helpers.link_to("...",'#'), class: 'disabled') if current_page > 5 min = current_page > 4 ? current_page-1 : 4 max = current_page < total_pages-4 ? current_page+2 : total_pages-2 (min..max-1).each { |i| result << page_link(i, current_page) } if max >= min+1 result << helpers.content_tag(:li, helpers.link_to("...", "#"), class: 'disabled') if current_page < total_pages-4 else result << helpers.content_tag(:li, helpers.link_to("...",'#'), class: 'disabled') end (total_pages-2..total_pages).each{ |i| result << page_link(i, current_page) } else (1..total_pages).each{ |i| result << page_link(i, current_page) } end result += helpers.content_tag(:li, class: "next"){helpers.link_to("下一页 ›", "#{url}?#{param_name}=#{current_page+1}")} if current_page < total_pages result += helpers.content_tag(:li, class: 'disabled total_pages'){helpers.link_to "共#{RailsAdminContent::Client.total_nums}条数据", "#"} result.html_safe end end end |