lib/pagy/extras/items.rb in pagy-6.3.0 vs lib/pagy/extras/items.rb in pagy-6.4.0

- old
+ new

@@ -16,12 +16,18 @@ # Set the items variable considering the params and other pagy variables def pagy_set_items_from_params(vars) return if vars[:items] # :items explicitly set return unless vars.key?(:items_extra) ? vars[:items_extra] : DEFAULT[:items_extra] # :items_extra is false - return unless (items = params[vars[:items_param] || DEFAULT[:items_param]]) # no items from request params + return unless (items_count = pagy_get_items_size(vars)) # no items from request params - vars[:items] = [items.to_i, vars.key?(:max_items) ? vars[:max_items] : DEFAULT[:max_items]].compact.min + vars[:items] = [items_count.to_i, vars.key?(:max_items) ? vars[:max_items] : DEFAULT[:max_items]].compact.min + end + + # Get the items count from the params + # Overridable by the jsonapi extra + def pagy_get_items_size(vars) + params[vars[:items_param] || DEFAULT[:items_param]] end end # Additions for the Frontend module module Frontend