Using own custom Foundation 6 paginator
This commit is contained in:
parent
7e7d2e6c0b
commit
28e4f8e705
6 changed files with 67 additions and 13 deletions
3
Gemfile
3
Gemfile
|
|
@ -85,7 +85,8 @@ gem 'will_paginate'
|
|||
|
||||
# Style the paginator properly to use Zurb Foundation's style
|
||||
# https://github.com/acrogenesis/will_paginate-foundation
|
||||
gem 'will_paginate-foundation'
|
||||
# (Does not support Foundation 6 yet.)
|
||||
#gem 'will_paginate-foundation'
|
||||
|
||||
# Lightbox image viewer for full-sized images
|
||||
gem 'fancybox2-rails', '~> 0.2.8'
|
||||
|
|
|
|||
|
|
@ -269,8 +269,6 @@ GEM
|
|||
railties (>= 4.0)
|
||||
sprockets-rails (>= 2.0, < 4.0)
|
||||
will_paginate (3.1.0)
|
||||
will_paginate-foundation (5.3.4)
|
||||
will_paginate (>= 3.0.3)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
|
@ -305,7 +303,6 @@ DEPENDENCIES
|
|||
uglifier (>= 1.3.0)
|
||||
web-console (~> 2.0)
|
||||
will_paginate
|
||||
will_paginate-foundation
|
||||
|
||||
BUNDLED WITH
|
||||
1.11.2
|
||||
|
|
|
|||
|
|
@ -2,14 +2,13 @@
|
|||
a.black href=package_path(name: pkg.name)
|
||||
div.grid-thumbnail
|
||||
- if pkg.screenshots.any?
|
||||
// TODO: smarter search for the beste screenshot instead of taking the first one
|
||||
// TODO: smarter selection of the most useful screenshot instead of taking the first one
|
||||
- screenshot = pkg.screenshots.first
|
||||
= image_tag(screenshot.image.url(:thumb, timestamp: false), alt: screenshot.caption)
|
||||
= image_tag(screenshot.image.url(:thumb, timestamp: false), alt: screenshot.caption, class: 'thumbnail')
|
||||
- else
|
||||
img.screenshot src="/images/dummy/no-screenshots-upload-one.svg"
|
||||
img.screenshot.thumbnail src="/images/dummy/no-screenshots-upload-one.svg"
|
||||
div
|
||||
// TODO: use description instead of package name (as soon as it is available)
|
||||
.pkgname
|
||||
=pkg.name
|
||||
= pkg.name
|
||||
.pkgdescription
|
||||
= pkg.description
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
- if @packages.length>0
|
||||
// Use different pagination navigators depending on the screen width
|
||||
div.show-for-large-up
|
||||
=will_paginate @packages, renderer: FoundationPagination::Rails, :inner_window => 3
|
||||
div.show-for-large
|
||||
=will_paginate @packages, :renderer => FoundationPaginationRenderer, :inner_window => 3
|
||||
div.show-for-medium-only
|
||||
=will_paginate @packages, renderer: FoundationPagination::Rails, :inner_window => 1
|
||||
=will_paginate @packages, :renderer => FoundationPaginationRenderer, :inner_window => 1
|
||||
div.show-for-small-only
|
||||
=will_paginate @packages, renderer: FoundationPagination::Rails, :page_links => false
|
||||
=will_paginate @packages, :renderer => FoundationPaginationRenderer, :page_links => false
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ module Debshots
|
|||
# Application configuration should go into files in config/initializers
|
||||
# -- all .rb files in that directory are automatically loaded.
|
||||
|
||||
config.autoload_paths << Rails.root.join('lib')
|
||||
|
||||
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
||||
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
||||
# config.time_zone = 'Central Time (US & Canada)'
|
||||
|
|
|
|||
55
lib/foundation_pagination_renderer.rb
Normal file
55
lib/foundation_pagination_renderer.rb
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
include WillPaginate
|
||||
|
||||
class FoundationPaginationRenderer < WillPaginate::ActionView::LinkRenderer
|
||||
def to_html
|
||||
list_items = pagination.map do |item|
|
||||
case item
|
||||
when Fixnum
|
||||
page_number(item)
|
||||
else
|
||||
send(item)
|
||||
end
|
||||
end.join(@options[:link_separator])
|
||||
|
||||
tag("ul", list_items, class: 'pagination', role: 'navigation', 'aria-label' => 'Pagination')
|
||||
end
|
||||
|
||||
def container_attributes
|
||||
super.except(*[:link_options])
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def page_number(page)
|
||||
link_options = @options[:link_options] || {}
|
||||
|
||||
if page == current_page
|
||||
tag :li, page, :class => ('current')
|
||||
else
|
||||
tag :li, link(page, page, link_options.merge(:rel => rel_value(page)))
|
||||
end
|
||||
end
|
||||
|
||||
def previous_or_next_page(page, text, classname)
|
||||
link_options = @options[:link_options] || {}
|
||||
if page
|
||||
tag :li, link(text, page, link_options), :class => classname
|
||||
else
|
||||
tag :li, '', :class => "%s disabled" % classname
|
||||
end
|
||||
end
|
||||
|
||||
def gap
|
||||
tag :li, '', class: 'ellipsis', 'aria-hidden' => 'true'
|
||||
end
|
||||
|
||||
def previous_page
|
||||
num = @collection.current_page > 1 && @collection.current_page - 1
|
||||
previous_or_next_page(num, '', "pagination-previous")
|
||||
end
|
||||
|
||||
def next_page
|
||||
num = @collection.current_page < @collection.total_pages && @collection.current_page + 1
|
||||
previous_or_next_page(num, '', "pagination-next")
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue