Module: Pagy::GovukExtra

Defined in:
lib/pagy/extras/govuk.rb

Overview

Frontend modules are specially optimized for performance. The resulting code may not look very elegant, but produces the best benchmarks

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.add_default_i18n_load_pathObject

Add default English translations to the I18n load_path. Copy the keys if you don’t need this



11
12
13
# File 'lib/pagy/extras/govuk.rb', line 11

def self.add_default_i18n_load_path
  ::I18n.load_path += Dir[File.join(File.dirname(__FILE__), '../../../config/locales', '**', '*.{rb,yml}')]
end

Instance Method Details

#pagy_govuk_nav(pagy, id: nil, classes: '', aria_label: ::I18n.t('pagy.aria_label.nav'), **vars) ⇒ Object

Pagination for GOV.UK adapted from Pagy’s Bootstrap: it returns the html with the series of links to the pages



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/pagy/extras/govuk.rb', line 16

def pagy_govuk_nav(pagy, id: nil, classes: '', aria_label: ::I18n.t('pagy.aria_label.nav'), **vars)
  id = %( id="#{id}") if id
  a  = pagy_anchor(pagy)

  html = "    <nav\#{id} class=\"govuk-pagination\" \#{nav_aria_label(pagy, aria_label:)}>\n      \#{govuk_prev_html(pagy, a)}\n      <ul class=\"govuk-pagination__list \#{classes}\">\n  HTML\n  pagy.series(**vars).each do |item| # series example: [1, :gap, 7, 8, \"9\", 10, 11, :gap, 36]\n    html << case item\n            when Integer\n              %(<li class=\"govuk-pagination__item\">\#{a.call(item,\n                classes: 'govuk-link govuk-pagination__link')}</li>)\n            when String\n              %(<li class=\"govuk-pagination__item govuk-pagination__item--current\"><a role=\"link\" class=\"govuk-link govuk-pagination__link\" aria-current=\"page\" aria-disabled=\"true\">\#{\n                pagy.label_for(item)}</a></li>)\n            when :gap\n              %(<li class=\"govuk-pagination__item \"><a role=\"link\" class=\"govuk-link govuk-pagination__link\" aria-disabled=\"true\">\#{\n                ::I18n.t('pagy.gap')}</a></li>)\n            else raise InternalError,\n              \"expected item types in series to be Integer, String or :gap; got \#{item.inspect}\"\n            end\n  end\n  html << %(</ul>\#{govuk_next_html(pagy, a)}</nav>)\nend\n"