Class: Bridgetown::Paginate::PaginationPage

Inherits:
GeneratedPage
  • Object
show all
Defined in:
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

Instance Method Summary collapse

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 '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 '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 '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