# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/uikit
# frozen_string_literal: true
require 'pagy/extras/shared'
class Pagy
module Frontend
# Pagination for uikit: it returns the html with the series of links to the pages
def pagy_uikit_nav(pagy)
link = pagy_link_proc(pagy)
html = %(
#{pagy_uikit_prev_html(pagy, link)})
pagy.series.each do |item|
html << case item
when Integer then %(
#{link.call item}
)
when String then %(
#{item}
)
when :gap then %(
#{pagy_t('pagy.nav.gap')}
)
end
end
html << pagy_uikit_next_html(pagy, link)
html << %(
)
end
# Javascript pagination for uikit: it returns a nav and a JSON tag used by the Pagy.nav javascript
def pagy_uikit_nav_js(pagy, id=pagy_id)
link = pagy_link_proc(pagy)
tags = { 'before' => pagy_uikit_prev_html(pagy, link),
'link' => %(
#{link.call(PAGE_PLACEHOLDER)}
),
'active' => %(
#{PAGE_PLACEHOLDER}
),
'gap' => %(
#{pagy_t('pagy.nav.gap')}
),
'after' => pagy_uikit_next_html(pagy, link) }
html = %(
)
html << pagy_json_tag(pagy, :nav, id, tags, pagy.sequels)
end
# Javascript combo pagination for uikit: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
def pagy_uikit_combo_nav_js(pagy, id=pagy_id)
link = pagy_link_proc(pagy)
p_page = pagy.page
p_pages = pagy.pages
input = %()
%(
#{
if (p_prev = pagy.prev)
link.call p_prev, pagy_t('pagy.nav.prev'), 'class="uk-button uk-button-default"'
else
%()
end
}