Class: GovukComponent::PaginationComponent
- Includes:
- Pagy::UrlHelpers
- Defined in:
- app/components/govuk_component/pagination_component.rb
Defined Under Namespace
Classes: AdjacentPage, Item, NextPage, PreviousPage
Instance Attribute Summary collapse
-
#block_mode ⇒ Object
(also: #block_mode?)
readonly
Returns the value of attribute block_mode.
-
#landmark_label ⇒ Object
readonly
Returns the value of attribute landmark_label.
-
#next_content ⇒ Object
readonly
Returns the value of attribute next_content.
-
#next_text ⇒ Object
readonly
Returns the value of attribute next_text.
-
#page_items ⇒ Object
readonly
Returns the value of attribute page_items.
-
#pagy ⇒ Object
readonly
Returns the value of attribute pagy.
-
#previous_content ⇒ Object
readonly
Returns the value of attribute previous_content.
-
#previous_text ⇒ Object
readonly
Returns the value of attribute previous_text.
Attributes inherited from Base
Instance Method Summary collapse
- #before_render ⇒ Object
- #call ⇒ Object
-
#initialize(pagy: nil, next_text: nil, previous_text: nil, block_mode: false, landmark_label: config.default_pagination_landmark_label, classes: [], html_attributes: {}) ⇒ PaginationComponent
constructor
A new instance of PaginationComponent.
- #render? ⇒ Boolean
Methods inherited from Base
Constructor Details
#initialize(pagy: nil, next_text: nil, previous_text: nil, block_mode: false, landmark_label: config.default_pagination_landmark_label, classes: [], html_attributes: {}) ⇒ PaginationComponent
Returns a new instance of PaginationComponent.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/components/govuk_component/pagination_component.rb', line 39 def initialize(pagy: nil, next_text: nil, previous_text: nil, block_mode: false, landmark_label: config.default_pagination_landmark_label, classes: [], html_attributes: {}) @pagy = pagy @next_text = next_text @previous_text = previous_text @block_mode = block_mode @landmark_label = landmark_label super(classes:, html_attributes:) end |
Instance Attribute Details
#block_mode ⇒ Object (readonly) Also known as: block_mode?
Returns the value of attribute block_mode.
4 5 6 |
# File 'app/components/govuk_component/pagination_component.rb', line 4 def block_mode @block_mode end |
#landmark_label ⇒ Object (readonly)
Returns the value of attribute landmark_label.
4 5 6 |
# File 'app/components/govuk_component/pagination_component.rb', line 4 def landmark_label @landmark_label end |
#next_content ⇒ Object (readonly)
Returns the value of attribute next_content.
4 5 6 |
# File 'app/components/govuk_component/pagination_component.rb', line 4 def next_content @next_content end |
#next_text ⇒ Object (readonly)
Returns the value of attribute next_text.
4 5 6 |
# File 'app/components/govuk_component/pagination_component.rb', line 4 def next_text @next_text end |
#page_items ⇒ Object (readonly)
Returns the value of attribute page_items.
4 5 6 |
# File 'app/components/govuk_component/pagination_component.rb', line 4 def page_items @page_items end |
#pagy ⇒ Object (readonly)
Returns the value of attribute pagy.
4 5 6 |
# File 'app/components/govuk_component/pagination_component.rb', line 4 def pagy @pagy end |
#previous_content ⇒ Object (readonly)
Returns the value of attribute previous_content.
4 5 6 |
# File 'app/components/govuk_component/pagination_component.rb', line 4 def previous_content @previous_content end |
#previous_text ⇒ Object (readonly)
Returns the value of attribute previous_text.
4 5 6 |
# File 'app/components/govuk_component/pagination_component.rb', line 4 def previous_text @previous_text end |
Instance Method Details
#before_render ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/components/govuk_component/pagination_component.rb', line 55 def before_render @page_items = if pagy.present? build_items elsif items.any? items else [] end @previous_content = previous_page || build_previous @next_content = next_page || build_next end |
#call ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/components/govuk_component/pagination_component.rb', line 68 def call attributes = html_attributes.tap { |ha| (ha[:class] << "#{brand}-pagination--block") if items.empty? } tag.nav(**attributes) do safe_join([ previous_content, tag.ul(class: "#{brand}-pagination__list") { safe_join(page_items) }, next_content ]) end end |
#render? ⇒ Boolean
80 81 82 83 |
# File 'app/components/govuk_component/pagination_component.rb', line 80 def render? # probably isn't any point rendering if there's only one page (pagy.present? && pagy.series.size > 1) || @previous_content.present? || @next_content.present? end |