views: factor out paginator component.
* Refactor the paginator into a ViewComponent.
* Fix inconsistent spacing between paginator items.
* Fix a bug where the sequential paginator generated the wrong next /
previous page links in the <link rel="{next|prev}"> tags in the <head>.
* Always include the final page as a hidden html element, so that it can
be unhidden with custom CSS.
* Make it easier to change the pagination window.
This commit is contained in:
@@ -50,4 +50,19 @@ module ComponentsHelper
|
||||
tags = TagListComponent.tags_from_names(tag_names)
|
||||
render TagListComponent.new(tags: tags, **options).with_variant(:search)
|
||||
end
|
||||
|
||||
# The <link rel="next"> / <link rel="prev"> links in the <meta> element of the <head>.
|
||||
def render_meta_links(records)
|
||||
render PaginatorComponent.new(records: records, params: params).with_variant(:meta_links)
|
||||
end
|
||||
|
||||
def numbered_paginator(records)
|
||||
paginator = PaginatorComponent.new(records: records, params: params)
|
||||
|
||||
if paginator.use_sequential_paginator?
|
||||
render paginator.with_variant(:sequential)
|
||||
else
|
||||
render paginator.with_variant(:numbered)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user