Class: Bridgetown::Paginate::PaginationPage

Inherits:
GeneratedPage show all
Defined in:
bridgetown-paginate/lib/bridgetown-paginate/pagination_page.rb

Overview

This page handles the creation of the fake pagination pages based on the original page configuration. The code does the same things as the default Bridgetown page.rb code but just forces the code to look into the template instead of the (currently non-existing) pagination page. This page exists purely in memory and is not read from disk

Constant Summary

Constants inherited from GeneratedPage

GeneratedPage::HTML_EXTENSIONS

Instance Attribute Summary

Attributes inherited from GeneratedPage

#basename, #content, #data, #dir, #ext, #name, #output, #paginator, #site

Instance Method Summary collapse

Methods inherited from GeneratedPage

#[], #converter_output_ext, #converters, #html?, #index?, #inspect, #layout, #output_ext, #output_exts, #path, #permalink, #permalink_ext, #place_into_layouts, #process, #relative_path, #slots, #template, #to_liquid, #to_s, #transform!, #trigger_hooks, #type, #url, #url_placeholders, #write, #write?

Methods included from Transformable

#transform_content, #transform_with_layout

Methods included from Bridgetown::Publishable

#publishable?, #published?

Methods included from Localizable

#all_locales, #localeless_path, #matches_resource?

Methods included from LiquidRenderable

#liquid_engine_configured?, #render_with_liquid?, #yaml_file?

Methods included from LayoutPlaceable

#no_layout?, #place_in_layout?

Constructor Details

#initialize(page_to_copy, cur_page_nr, total_pages, index_pageandext, template_ext) ⇒ PaginationPage

rubocop:disable Lint/MissingSuper



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'bridgetown-paginate/lib/bridgetown-paginate/pagination_page.rb', line 14

def initialize(page_to_copy, cur_page_nr, total_pages, index_pageandext, template_ext) # rubocop:disable Lint/MissingSuper
  @site = page_to_copy.site
  @base = ""
  @url = ""
  @name = index_pageandext.nil? ? "index#{template_ext}" : index_pageandext
  @path = page_to_copy.path
  @basename = File.basename(@path, ".*")
  @ext = File.extname(@name)

  # Only need to copy the data part of the page as it already contains the
  # layout information
  self.data = Bridgetown::Utils.deep_merge_hashes page_to_copy.data, {}
  self.content = page_to_copy.content

  # Store the current page and total page numbers in the pagination_info construct
  data["pagination_info"] = { "curr_page" => cur_page_nr, "total_pages" => total_pages }

  Bridgetown::Hooks.trigger :generated_pages, :post_init, self
end

Instance Method Details

#destination(dest) ⇒ Object

rubocop:enable Naming/AccessorMethodName



42
43
44
45
46
47
48
49
# File 'bridgetown-paginate/lib/bridgetown-paginate/pagination_page.rb', line 42

def destination(dest)
  path = site.in_dest_dir(
    dest, URL.unescape_path(url).delete_prefix(site.base_path(strip_slash_only: true))
  )
  path = File.join(path, "index") if url.end_with?("/")
  path << output_ext unless path.end_with? output_ext
  path
end

#set_url(url_value) ⇒ Object

rubocop:disable Naming/AccessorMethodName



35
36
37
38
39
# File 'bridgetown-paginate/lib/bridgetown-paginate/pagination_page.rb', line 35

def set_url(url_value)
  @path = url_value.delete_prefix "/"
  @dir = @path.ends_with?("/") ? @path : File.dirname(@path)
  @url = url_value
end