Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagy version is old (6.5.0) #1450

Open
swombat opened this issue May 10, 2024 · 0 comments
Open

Pagy version is old (6.5.0) #1450

swombat opened this issue May 10, 2024 · 0 comments

Comments

@swombat
Copy link

swombat commented May 10, 2024

Nothing is technically "broken" because of this, but for example, to add support for multiple pagy's on one html page (e.g. for several lists of things on different tabs), I ended up having to do a dirty and override the pagy_link_proc method in my application_helper:

  # Return a performance optimized proc to generate the HTML links
  # Benchmarked on a 20 link nav: it is ~22x faster and uses ~18x less memory than rails' link_to
  def pagy_link_proc(pagy, link_extra: '')
    p_prev      = pagy.prev
    p_next      = pagy.next
    open_tab    = pagy.vars[:open_tab].present? ? %(&open_tab=#{pagy.vars[:open_tab]}) : ''
    left, right = %(<a href="#{pagy_url_for(pagy, PAGE_PLACEHOLDER, html_escaped: true)}#{open_tab}" #{
                      pagy.vars[:link_extra]} #{link_extra}).split(PAGE_PLACEHOLDER, 2)
    lambda do |page, text = pagy.label_for(page), extra_attrs = ''|
      %(#{left}#{page}#{right}#{ case page
                                  when p_prev then ' rel="prev"'
                                  when p_next then ' rel="next"'
                                  else             ''
                                  end } #{extra_attrs}>#{text}</a>)
    end
  end

This wouldn't have been necessary with the latest version (8.5.0) which supports the :html_anchor parameter to pass some additional arguments for this specific use.

However, just updating the gem doesn't work - the styling gets lost. So this is not quite as trivial as it seems on the surface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant