Skip to content

Commit

Permalink
added link_extra keyword arg to pagy_items_selector_js
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Apr 28, 2021
1 parent 627a0dc commit 2382482
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- `pagy*_nav(@pagy, pagy_id: 'my-id', link-extra: '...')`
- `pagy*_nav_js(@pagy, pagy_id: 'my-id', link-extra: '...', steps: {...})`
- `pagy*_combo_nav_js(@pagy, pagy_id: 'my-id', link-extra: '...')`
- `pagy_items_selector_js(pagy, pagy_id: 'my-id', item_name: '...', i18n_key: '...')`
- `pagy_items_selector_js(pagy, pagy_id: 'my-id', item_name: '...', i18n_key: '...', link_extra: '...')`
- `pagy_info(@pagy, pagy_id: 'my-id', item_name: '...', i18n_key: '...')`
- `pagy_prev_link(@pagy, text: '...', link_extra: '...')`
- `pagy_next_link(@pagy, text: '...', link_extra: '...')`
Expand Down
4 changes: 2 additions & 2 deletions docs/api/frontend.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ This method takes the Pagy object and returns the HTML string with the paginatio

The method accepts also a couple of optional keyword arguments:
- `:pagy_id` which adds the `id` HTML attributedto the `nav` tag
- `:link_extra` which add a verbatim `link_extra` string to the `a` tag (e.g. `'data-remote="true"'`)
- `:link_extra` which add a verbatim string to the `a` tag (e.g. `'data-remote="true"'`)

The `nav.*` templates produce the same output, and can be used as an easier (but slower) way to customize it.

Expand All @@ -62,7 +62,7 @@ Will produce something like:

The method accepts also a few optional keyword arguments:
- `:pagy_id` which adds the `id` HTML attributedto the `span` tag wrapping the info
- `:item_name` an already pluralized string that will be used in place of the dedfault `item/items`
- `:item_name` an already pluralized string that will be used in place of the default `item/items`
- `:i18n_key` the key to lookup in a dictionary

Notice the `:i18n_key` can be passed also to the constructor or be a less useful global variable (i.e. `VARS[:i18n_key]`
Expand Down
6 changes: 3 additions & 3 deletions docs/api/javascript.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,11 @@ Use the `pagy*_combo_nav_js` helpers in any view:

## Methods

### pqgy*_nav_js(pagy, ...)
### pagy*_nav_js(pagy, ...)

The method accepts also a few optional keyword arguments:
- `:pagy_id` which adds the `id` HTML attributedto the `nav` tag
- `:link_extra` which add a verbatim `link_extra` string to the `a` tag (e.g. `'data-remote="true"'`)
- `:link_extra` which add a verbatim string to the `a` tag (e.g. `'data-remote="true"'`)
- `:steps` the [:steps](#steps) variable

**CAVEATS**: the `pagy_bootstrap_nav_js` and `pagy_semantic_nav_js` assign a class attribute to their links, so do not add anoter class attribute with the `:link_extra`. That would be illegal HTML and ignored by most browsers.
Expand All @@ -275,7 +275,7 @@ The method accepts also a few optional keyword arguments:

The method accepts also a couple of optional keyword arguments:
- `:pagy_id` which adds the `id` HTML attributedto the `nav` tag
- `:link_extra` which add a verbatim `link_extra` string to the `a` tag (e.g. `'data-remote="true"'`)
- `:link_extra` which add a verbatim string to the `a` tag (e.g. `'data-remote="true"'`)

**CAVEATS**: the `pagy_semantic_combo_nav_js` assigns a class attribute to its links, so do not add another class attribute with the `:link_extra`. That would be illegal HTML and ignored by most browsers.

Expand Down
3 changes: 2 additions & 1 deletion docs/extras/items.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ This helper provides an items selector UI, which allows the user to select any a

The method accepts also a few optional keyword arguments:
- `:pagy_id` which adds the `id` HTML attributedto the `nav` tag
- `:item_name` an already pluralized string that will be used in place of the dedfault `item/items`
- `:item_name` an already pluralized string that will be used in place of the default `item/items`
- `:i18n_key` the key to lookup in a dictionary
- `:link_extra` which add a verbatim string to the `a` tag (e.g. `'data-remote="true"'`)

Notice the `:i18n_key` can be passed also to the constructor or be a less useful global variable (i.e. `VARS[:i18n_key]`

Expand Down
6 changes: 3 additions & 3 deletions lib/pagy/extras/items.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,18 @@ def pagy_url_for(pagy, page, deprecated_url=nil, absolute: nil)
prepend UseItemsExtra

# Return the items selector HTML. For example "Show [20] items per page"
def pagy_items_selector_js(pagy, deprecated_id=nil, pagy_id: nil, item_name: nil, i18n_key: nil)
def pagy_items_selector_js(pagy, deprecated_id=nil, pagy_id: nil, item_name: nil, i18n_key: nil, link_extra: '')
pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
p_id = %( id="#{pagy_id}") if pagy_id
p_vars = pagy.vars
p_items = p_vars[:items]
p_vars[:items] = ITEMS_PLACEHOLDER
link = pagy_marked_link(pagy_link_proc(pagy))
link = pagy_marked_link(pagy_link_proc(pagy, link_extra: link_extra))
p_vars[:items] = p_items # restore the items

html = %(<span#{p_id} class="pagy-items-selector-js">)
input = %(<input type="number" min="1" max="#{p_vars[:max_items]}" value="#{p_items}" style="padding: 0; text-align: center; width: #{p_items.to_s.length+1}rem;">)
html << pagy_t('pagy.items_selector_js', item_name: item_name || pagy_t(i18n_key || p_vars[:i18n_key], count: p_items),
html << pagy_t('pagy.items_selector_js', item_name: item_name || pagy_t(i18n_key || p_vars[:i18n_key], count: p_items),
items_input: input,
count: p_items)
html << %(</span>#{pagy_json_tag pagy, :items_selector, pagy.from, link})
Expand Down

0 comments on commit 2382482

Please sign in to comment.