diff --git a/docs/api/pagy.md b/docs/api/pagy.md index 8582f9445..71e22a6df 100644 --- a/docs/api/pagy.md +++ b/docs/api/pagy.md @@ -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. diff --git a/lib/pagy.rb b/lib/pagy.rb index 086787f23..5f3c1a3bc 100644 --- a/lib/pagy.rb +++ b/lib/pagy.rb @@ -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 diff --git a/lib/pagy/frontend.rb b/lib/pagy/frontend.rb index 21e674c5d..1d2cfec53 100644 --- a/lib/pagy/frontend.rb +++ b/lib/pagy/frontend.rb @@ -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