Module: Pagy::NumericHelpers
- Includes:
- NumericHelperLoader
- Included in:
- Calendar::Unit, Keyset::Keynav, Offset
- Defined in:
- lib/pagy.rb,
lib/pagy/toolbox/helpers/info_tag.rb,
lib/pagy/toolbox/helpers/series_nav.rb,
lib/pagy/toolbox/helpers/anchor_tags.rb,
lib/pagy/toolbox/helpers/input_nav_js.rb,
lib/pagy/toolbox/helpers/limit_tag_js.rb,
lib/pagy/toolbox/helpers/series_nav_js.rb,
lib/pagy/toolbox/helpers/bulma/series_nav.rb,
lib/pagy/toolbox/helpers/bulma/input_nav_js.rb,
lib/pagy/toolbox/helpers/bulma/series_nav_js.rb,
lib/pagy/toolbox/helpers/bootstrap/series_nav.rb,
lib/pagy/toolbox/helpers/bootstrap/input_nav_js.rb,
lib/pagy/toolbox/helpers/bootstrap/series_nav_js.rb,
lib/pagy/toolbox/helpers/bulma/previous_next_html.rb,
lib/pagy/toolbox/helpers/bootstrap/previous_next_html.rb
Overview
Hook module for numeric UI helpers
Instance Method Summary collapse
-
#info_tag(id: nil, item_name: nil) ⇒ Object
Instances with count return “Displaying items 41-60 of 324 in total” or “Displaying Products 41-60 of 324 in total” Instances with no count return only page info: “Page 3 of 100”.
-
#input_nav_js(style = nil) ⇒ Object
JavaScript input pagination: it returns a nav with a data-pagy attribute used by the pagy.js file.
-
#limit_tag_js(id: nil, item_name: nil, client_max_limit: @options[:client_max_limit]) ⇒ Object
Return the limit selector HTML.
-
#previous_tag ⇒ Object
Return the enabled/disabled previous page anchor tag.
-
#series_nav(style = nil) ⇒ Object
Return the HTML with the series of links to the pages.
-
#series_nav_js(style = nil) ⇒ Object
Return a nav with a data-pagy attribute used by the pagy.js file.
Instance Method Details
#info_tag(id: nil, item_name: nil) ⇒ Object
Instances with count return “Displaying items 41-60 of 324 in total” or “Displaying Products 41-60 of 324 in total” Instances with no count return only page info: “Page 3 of 100”
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/pagy/toolbox/helpers/info_tag.rb', line 7 def info_tag(id: nil, item_name: nil) i18n_key = if @count.nil? 'pagy.info_tag.no_count' elsif @count.zero? 'pagy.info_tag.no_items' elsif @in == @count 'pagy.info_tag.single_page' else 'pagy.info_tag.multiple_pages' end info_data = if @count.nil? { page: @page, pages: @last } else { item_name: item_name || I18n.translate('pagy.item_name', count: @count), count: @count, from: @from, to: @to } end %(<span#{%( id="#{id}") if id} class="pagy info">#{I18n.translate(i18n_key, **info_data)}</span>) end |
#input_nav_js(style = nil) ⇒ Object
JavaScript input pagination: it returns a nav with a data-pagy attribute used by the pagy.js file
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/pagy/toolbox/helpers/input_nav_js.rb', line 8 def input_nav_js(style = nil, **) return send(:"#{style}_input_nav_js", **) if style && style.to_s != 'pagy' a_lambda = a_lambda(**) input = %(<input name="page" type="number" min="1" max="#{@last}" value="#{@page}" aria-current="page" ) + %(style="text-align: center; width: #{@page.to_s.length + 1}rem; padding: 0;">#{A_TAG}) html = %(#{previous_tag(a_lambda)}<label>#{ I18n.translate('pagy.input_nav_js', page_input: input, pages: @last)}</label>#{ next_tag(a_lambda)}) wrap_input_nav_js(html, 'pagy input-nav-js', **) end |
#limit_tag_js(id: nil, item_name: nil, client_max_limit: @options[:client_max_limit]) ⇒ Object
Return the limit selector HTML. For example “Show [20] items per page”
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/pagy/toolbox/helpers/limit_tag_js.rb', line 8 def limit_tag_js(id: nil, item_name: nil, client_max_limit: [:client_max_limit], **) raise OptionError.new(self, :client_max_limit, 'to be truthy', client_max_limit) unless client_max_limit limit_input = %(<input name="limit" type="number" min="1" max="#{client_max_limit}" value="#{ @limit}" style="padding: 0; text-align: center; width: #{@limit.to_s.length + 1}rem;">#{A_TAG}) url_token = compose_page_url(PAGE_TOKEN, limit: LIMIT_TOKEN) %(<span#{%( id="#{id}") if id} class="pagy limit-tag-js" #{ data_pagy_attribute(:ltj, @from, url_token, PAGE_TOKEN, LIMIT_TOKEN) }><label>#{ I18n.translate('pagy.limit_tag_js', item_name: item_name || I18n.translate('pagy.item_name', count: @limit), limit_input:, count: @limit) }</label></span>) end |
#previous_tag ⇒ Object
Return the enabled/disabled previous page anchor tag
8 |
# File 'lib/pagy/toolbox/helpers/anchor_tags.rb', line 8 def previous_tag(...) = anchor_tag_for(:previous, ...) |
#series_nav(style = nil) ⇒ Object
Return the HTML with the series of links to the pages
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/pagy/toolbox/helpers/series_nav.rb', line 8 def series_nav(style = nil, **) return send(:"#{style}_series_nav", **) if style && style.to_s != 'pagy' a_lambda = a_lambda(**) html = previous_tag(a_lambda) series(**).each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36] html << case item when Integer a_lambda.(item) when String %(<a role="link" aria-disabled="true" aria-current="page">#{page_label(item)}</a>) when :gap %(<a role="separator" aria-disabled="true">#{I18n.translate('pagy.gap')}</a>) else raise InternalError, "expected item types in series to be Integer, String or :gap; got #{item.inspect}" end end html << next_tag(a_lambda) wrap_series_nav(html, 'pagy series-nav', **) end |
#series_nav_js(style = nil) ⇒ Object
Return a nav with a data-pagy attribute used by the pagy.js file
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/pagy/toolbox/helpers/series_nav_js.rb', line 8 def series_nav_js(style = nil, **) return send(:"#{style}_series_nav_js", **) if style && style.to_s != 'pagy' a_lambda = a_lambda(**) tokens = { before: previous_tag(a_lambda), anchor: a_lambda.(PAGE_TOKEN, LABEL_TOKEN), current: %(<a role="link" aria-current="page" aria-disabled="true">#{LABEL_TOKEN}</a>), gap: %(<a role="separator" aria-disabled="true">#{I18n.translate('pagy.gap')}</a>), after: next_tag(a_lambda) } wrap_series_nav_js(tokens, 'pagy series-nav-js', **) end |