diff --git a/lib/pagy/extras/bootstrap.rb b/lib/pagy/extras/bootstrap.rb index 56a6145fb..e6060a8f9 100644 --- a/lib/pagy/extras/bootstrap.rb +++ b/lib/pagy/extras/bootstrap.rb @@ -6,18 +6,18 @@ module Frontend # Pagination for bootstrap: it returns the html with the series of links to the pages def pagy_nav_bootstrap(pagy) - tags = ''; link = pagy_link_proc(pagy, 'class="page-link"'.freeze) + tags, link, p_prev, p_next = '', pagy_link_proc(pagy, 'class="page-link"'.freeze), pagy.prev, pagy.next - tags << (pagy.prev ? %() - : %()) + tags << (p_prev ? %() + : %()) pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36] tags << if item.is_a?(Integer); %(
  • #{link.call item}
  • ) # page link elsif item.is_a?(String) ; %(
  • #{link.call item}
  • ) # active page elsif item == :gap ; %(
  • #{pagy_t('pagy.nav.gap'.freeze)}
  • ) # page gap end end - tags << (pagy.next ? %() - : %()) + tags << (p_next ? %() + : %()) %() end diff --git a/lib/pagy/extras/compact.rb b/lib/pagy/extras/compact.rb index 9a4b0493e..193bcdcfc 100644 --- a/lib/pagy/extras/compact.rb +++ b/lib/pagy/extras/compact.rb @@ -7,43 +7,43 @@ module Frontend # Generic compact pagination: it returns the html with the series of links to the pages # we use a numeric input tag to set the page and the PagyCompact javascript to navigate def pagy_nav_compact(pagy, id=caller(1,1)[0].hash) - tags = ''; link = pagy_link_proc(pagy) + tags, link, p_prev, p_next, p_page, p_pages = '', pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages tags << %() + tags << %() end # Compact pagination for bootstrap: it returns the html with the series of links to the pages # we use a numeric input tag to set the page and the PagyCompact javascript to navigate def pagy_nav_bootstrap_compact(pagy, id=caller(1,1)[0].hash) - tags = ''; link = pagy_link_proc(pagy) + tags, link, p_prev, p_next, p_page, p_pages = '', pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages tags << %() + tags << %() end end diff --git a/lib/pagy/extras/responsive.rb b/lib/pagy/extras/responsive.rb index 9c2abea25..2878035df 100644 --- a/lib/pagy/extras/responsive.rb +++ b/lib/pagy/extras/responsive.rb @@ -33,18 +33,18 @@ module Frontend # Generic responsive pagination: it returns the html with the series of links to the pages # we build the tags as a json object string and render them with the PagyResponsive javascript def pagy_nav_responsive(pagy, id=caller(1,1)[0].hash) - tags = '{'; link = pagy_link_proc(pagy); responsive = pagy.responsive + tags, link, p_prev, p_next, responsive = '{', pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.responsive - tags << (pagy.prev ? %('prev':'#{link.call pagy.prev, pagy_t('pagy.nav.prev'.freeze), 'aria-label="previous"'.freeze} ',) - : %('prev':'#{pagy_t('pagy.nav.prev'.freeze)} ',)) + tags << (p_prev ? %('prev':'#{link.call p_prev, pagy_t('pagy.nav.prev'.freeze), 'aria-label="previous"'.freeze} ',) + : %('prev':'#{pagy_t('pagy.nav.prev'.freeze)} ',)) responsive[:items].each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36] tags << if item.is_a?(Integer); %('#{item}':'#{link.call item} ',) # page link elsif item.is_a?(String) ; %('#{item}':'#{item} ',) # current page elsif item == :gap ; %('#{item}':'#{pagy_t('pagy.nav.gap'.freeze)} ',) # page gap end end - tags << (pagy.next ? %('next':'#{link.call pagy.next, pagy_t('pagy.nav.next'.freeze), 'aria-label="next"'.freeze}'}) - : %('next':'#{pagy_t('pagy.nav.next'.freeze)}'})) + tags << (p_next ? %('next':'#{link.call p_next, pagy_t('pagy.nav.next'.freeze), 'aria-label="next"'.freeze}'}) + : %('next':'#{pagy_t('pagy.nav.next'.freeze)}'})) script = %() %(#{script}) end @@ -53,18 +53,18 @@ def pagy_nav_responsive(pagy, id=caller(1,1)[0].hash) # Responsive pagination for bootstrap: it returns the html with the series of links to the pages # we build the tags as a json object string and render them with the PagyResponsive javascript def pagy_nav_bootstrap_responsive(pagy, id=caller(1,1)[0].hash) - tags = '{'; link = pagy_link_proc(pagy, 'class="page-link"'.freeze); responsive = pagy.responsive + tags, link, p_prev, p_next, responsive = '{', pagy_link_proc(pagy, 'class="page-link"'.freeze), pagy.prev, pagy.next, pagy.responsive - tags << (pagy.prev ? %('prev':'',) - : %('prev':'',)) + tags << (p_prev ? %('prev':'',) + : %('prev':'',)) responsive[:items].each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36] tags << if item.is_a?(Integer); %('#{item}':'
  • #{link.call item}
  • ',) # page link elsif item.is_a?(String) ; %('#{item}':'
  • #{link.call item}
  • ',) # active page elsif item == :gap ; %('#{item}':'
  • #{pagy_t('pagy.nav.gap'.freeze)}
  • ',) # page gap end end - tags << (pagy.next ? %('next':''}) - : %('next':''})) + tags << (p_next ? %('next':''}) + : %('next':''})) script = %() %(#{script}) end diff --git a/lib/pagy/frontend.rb b/lib/pagy/frontend.rb index 6dda88246..e6c957457 100644 --- a/lib/pagy/frontend.rb +++ b/lib/pagy/frontend.rb @@ -10,18 +10,18 @@ module Frontend # Generic pagination: it returns the html with the series of links to the pages def pagy_nav(pagy) - tags = ''; link = pagy_link_proc(pagy) + tags, link, p_prev, p_next = '', pagy_link_proc(pagy), pagy.prev, pagy.next - tags << (pagy.prev ? %(#{link.call pagy.prev, pagy_t('pagy.nav.prev'.freeze), 'aria-label="previous"'.freeze} ) - : %(#{pagy_t('pagy.nav.prev'.freeze)} )) + tags << (p_prev ? %(#{link.call p_prev, pagy_t('pagy.nav.prev'.freeze), 'aria-label="previous"'.freeze} ) + : %(#{pagy_t('pagy.nav.prev'.freeze)} )) pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36] tags << if item.is_a?(Integer); %(#{link.call item} ) # page link elsif item.is_a?(String) ; %(#{item} ) # current page elsif item == :gap ; %(#{pagy_t('pagy.nav.gap'.freeze)} ) # page gap end end - tags << (pagy.next ? %(#{link.call pagy.next, pagy_t('pagy.nav.next'.freeze), 'aria-label="next"'.freeze}) - : %(#{pagy_t('pagy.nav.next'.freeze)})) + tags << (p_next ? %(#{link.call p_next, pagy_t('pagy.nav.next'.freeze), 'aria-label="next"'.freeze}) + : %(#{pagy_t('pagy.nav.next'.freeze)})) %() end @@ -36,8 +36,8 @@ def pagy_info(pagy) # this works with all Rack-based frameworks (Sinatra, Padrino, Rails, ...) def pagy_url_for(page, pagy) - params = request.GET.merge(pagy.vars[:page_param] => page, **pagy.vars[:params]) - "#{request.path}?#{Rack::Utils.build_nested_query(pagy_get_params(params))}#{pagy.vars[:anchor]}" + p_vars = pagy.vars; params = request.GET.merge(p_vars[:page_param] => page, **p_vars[:params]) + "#{request.path}?#{Rack::Utils.build_nested_query(pagy_get_params(params))}#{p_vars[:anchor]}" end