Skip to content

Commit

Permalink
add Pagy::VARS[:item_path] empty default
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Jun 2, 2018
1 parent ce8d09a commit 5e9b7d4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/api/pagy.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ These are the non-core variables: as for the core-variables they can be set glob
| `:params` | the arbitrary param hash to add to the url. (see [Customizing the params](../how-to.md#customizing-the-params) | `{}` |
| `:anchor` | the arbitrary anchor string (including the "#") to add to the url. (see [Customizing the page param](../how-to.md#customizing-the-params) | `""` |
| `:link_extra` | the extra attributes string (formatted as a valid HTML attribute/value pairs) added to the page links | `""` |
| `:item_path` | the dictionary path used by the `pagy_info` method to lookup the item/model name | `nil` |
| `:item_path` | the dictionary path used by the `pagy_info` method to lookup the item/model name | `""` |

There is no specific default nor validation for non-core variables, which are just optional strings.

Expand Down
4 changes: 2 additions & 2 deletions lib/pagy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class OutOfRangeError < StandardError; end
# root pathname to get the path of pagy files like templates or dictionaries
def self.root; Pathname.new(__FILE__).dirname end

# default core vars
VARS = { page:1, items:20, outset:0, size:[1,4,4,1], page_param: :page, params: {}, link_extra: ''.freeze, anchor: ''.freeze }
# default vars
VARS = { page:1, items:20, outset:0, size:[1,4,4,1], page_param: :page, params: {}, anchor: ''.freeze, link_extra: ''.freeze, item_path: 'pagy.info.item_name'.freeze }

attr_reader :count, :page, :items, :vars, :pages, :last, :offset, :from, :to, :prev, :next

Expand Down
6 changes: 3 additions & 3 deletions lib/pagy/frontend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ def pagy_nav(pagy)

# return examples: "Displaying items 41-60 of 324 in total" or "Displaying Products 41-60 of 324 in total"
def pagy_info(pagy)
name = pagy_t(pagy.vars[:item_path] || 'pagy.info.item_name'.freeze, count: pagy.count)
key = pagy.pages == 1 ? 'single_page'.freeze : 'multiple_pages'.freeze
pagy_t("pagy.info.#{key}", item_name: name, count: pagy.count, from: pagy.from, to: pagy.to)
name = pagy_t(pagy.vars[:item_path], count: pagy.count)
path = pagy.pages == 1 ? 'pagy.info.single_page'.freeze : 'pagy.info.multiple_pages'.freeze
pagy_t(path, item_name: name, count: pagy.count, from: pagy.from, to: pagy.to)
end


Expand Down

0 comments on commit 5e9b7d4

Please sign in to comment.