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

Documentation: anchor_string option in pagy_bootstrap_nav (example from documentation) doesn't appear to be working #711

Closed
7 tasks done
alexandergitter opened this issue Jun 9, 2024 · 1 comment

Comments

@alexandergitter
Copy link

👀 Before submitting...

  • I upgraded to pagy version 8.4.4
  • I searched through the Documentation
  • I searched through the Issues
  • I searched through the Q&A

🧐 REQUIREMENTS

  • I am providing a VALID code file that confirms the bug
  • I am NOT posting any of the USELESS THINGS listed above
  • I am aware that this issue will be automatically closed if the code file is missing or INVALID

💬 Description

Repro app versions:

  • Ruby: 3.2.4
  • Rack: 3.0.11
  • Sinatra: 4.0.0
  • Pagy: 8.4.4

The documentation has an example snippet on how to add custom attributes to the link tags here: https://ddnexus.github.io/pagy/docs/how-to/#customize-the-link-attributes

I'm referring to this last snippet in the example code:

# or from a view: e.g.:
< %== pagy_bootstrap_nav(@pagy, anchor_string: 'data-action="hello#world"') % >

I tried this with the pagy repro app, but it looks like the data-action attribute does not get added to the pagination links. Here's the slightly adjusted code of repro.ru (added the helper line from the docs, include of the Bootstrap css and pagy/extras/bootstrap):

# frozen_string_literal: true

# Starting point app to try pagy or reproduce issues

# DEV USAGE
#    pagy clone repro
#    pagy ./repro.ru

# URL
#    http://0.0.0.0:8000

# HELP
#    pagy -h

# DOC
#    https://ddnexus.github.io/pagy/playground/#1-repro-app

VERSION = '8.4.4'

require 'bundler/inline'
require 'bundler'
Bundler.configure
gemfile(ENV['PAGY_INSTALL_BUNDLE'] == 'true') do
  source 'https://rubygems.org'
  gem 'oj'
  gem 'puma'
  gem 'sinatra'
  gem 'sinatra-contrib'
end

# Edit this section adding/removing the extras and Pagy::DEFAULT as needed
# pagy initializer
require 'pagy/extras/pagy'
require 'pagy/extras/items'
require 'pagy/extras/overflow'
require 'pagy/extras/bootstrap'
Pagy::DEFAULT[:overflow] = :empty_page
Pagy::DEFAULT[:size]     = [1, 4, 4, 1]
Pagy::DEFAULT.freeze

require 'sinatra/base'
# Sinatra application
class PagyRepro < Sinatra::Base
  configure do
    enable :inline_templates
  end
  include Pagy::Backend

  get('/javascripts/:file') do
    format = params[:file].split('.').last
    if format == 'js'
      content_type 'application/javascript'
    elsif format == 'map'
      content_type 'application/json'
    end
    send_file Pagy.root.join('javascripts', params[:file])
  end

  # Edit this action as needed
  get '/' do
    collection = MockCollection.new
    @pagy, @records = pagy(collection)
    erb :main # template available in the __END__ section as @@ main
  end
  # Edit this section adding your own helpers as needed
  helpers do
    include Pagy::Frontend
  end
end

# Simple array-based collection that acts as a standard DB collection.
# Use it as a simple way to get a collection that acts as a AR scope, but without any DB
# or create an ActiveRecord class or anything else that you need instead
class MockCollection < Array
  def initialize(arr = Array(1..1000))
    super
    @collection = clone
  end

  def offset(value)
    @collection = self[value..]
    self
  end

  def limit(value)
    @collection[0, value]
  end

  def count(*)
    size
  end
end

run PagyRepro

__END__

@@ layout
<!DOCTYPE html>
<html lang="en">
<html>
<head>
   <title>Pagy Repro App</title>
  <script src="javascripts/pagy.min.js"></script>
  <script>
    window.addEventListener("load", Pagy.init);
  </script>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
  <style type="text/css">
    @media screen { html, body {
      font-size: 1rem;
      line-height: 1.2s;
      padding: 0;
      margin: 0;
    } }
    body {
      background: white !important;
      margin: 0 !important;
      font-family: sans-serif !important;
    }
    .content {
      padding: 1rem 1.5rem 2rem !important;
    }

    /* Quick demo for overriding the element style attribute of certain pagy helpers
    .pagy input[style] {
      width: 5rem !important;
    }
    */

    /*
      If you want to customize the style,
      please replace the line below with the actual file content
    */
    <%= Pagy.root.join('stylesheets', 'pagy.css').read %>
  </style>
</head>
<body>
  <%= yield %>
</body>
</html>

@@ main
<div class="content">
  <h1>Pagy Repro App</h1>
  <p> Self-contained, standalone Sinatra app usable to easily reproduce any pagy issue.</p>
  <p>Please, report the following versions in any new issue.</p>
  <h2>Versions</h2>
  <ul>
    <li>Ruby: <%= RUBY_VERSION %></li>
    <li>Rack: <%= Rack::RELEASE %></li>
    <li>Sinatra: <%= Sinatra::VERSION %></li>
    <li>Pagy: <%= Pagy::VERSION %></li>
  </ul>

  <h4>pagy_nav</h4>
  <%= pagy_bootstrap_nav(@pagy, anchor_string: 'data-action="hello#world"') %>
</div>
@ddnexus
Copy link
Owner

ddnexus commented Jun 9, 2024

@alexandergitter Thanks for your report.

The bug is actually a documentation inconsistency/bug . The :anchor_string is not a helper argument, but an instance variable, as documented in this section of the breaking changes.

The doc should have been updated from the :link_extra changing name and semantic, but - at least in that case - it has been only renamed. I will check for other related inconsistencies and fix the doc.

Thank you

@ddnexus ddnexus added documentation and removed bug labels Jun 9, 2024
@ddnexus ddnexus changed the title Bug: anchor_string option in pagy_bootstrap_nav (example from documentation) doesn't appear to be working Documentation: anchor_string option in pagy_bootstrap_nav (example from documentation) doesn't appear to be working Jun 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants