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 collapse

Attributes inherited from GeneratedPage

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

Instance Method Summary collapse

Methods inherited from GeneratedPage

#[], #add_permalink_suffix, #converter_output_ext, #converters, #html?, #index?, #inspect, #layout, #mark_for_fast_refresh!, #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, #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 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



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
42
# File 'bridgetown-paginate/lib/bridgetown-paginate/pagination_page.rb', line 16

def initialize(page_to_copy, cur_page_nr, total_pages, index_pageandext, template_ext) # rubocop:disable Lint/MissingSuper
  self.original_resource = if page_to_copy.is_a?(Bridgetown::Resource::Base)
                             page_to_copy
                           elsif page_to_copy.original_resource
                             page_to_copy.original_resource
                           end
  @page_to_copy = page_to_copy
  @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)
  @cur_page_r = cur_page_nr
  @total_pages = total_pages

  # 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 Attribute Details

#page_to_copyObject (readonly)

Returns the value of attribute page_to_copy.



14
15
16
# File 'bridgetown-paginate/lib/bridgetown-paginate/pagination_page.rb', line 14

def page_to_copy
  @page_to_copy
end

Instance Method Details

#destination(dest) ⇒ Object

rubocop:enable Naming/AccessorMethodName



66
67
68
69
70
71
72
73
74
75
# File 'bridgetown-paginate/lib/bridgetown-paginate/pagination_page.rb', line 66

def destination(dest)
  path = site.in_dest_dir(
    dest, Bridgetown::Utils
      .unencode_uri(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

#fast_refresh!Object



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

def fast_refresh!
  page_to_copy.fast_refresh! if page_to_copy.respond_to?(:fast_refresh!)

  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 }
end

#set_url(url_value) ⇒ Object

rubocop:disable Naming/AccessorMethodName



59
60
61
62
63
# File 'bridgetown-paginate/lib/bridgetown-paginate/pagination_page.rb', line 59

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

#unmark_for_fast_refresh!Object



53
54
55
56
# File 'bridgetown-paginate/lib/bridgetown-paginate/pagination_page.rb', line 53

def unmark_for_fast_refresh!
  super
  page_to_copy.unmark_for_fast_refresh! if page_to_copy.is_a?(Bridgetown::GeneratedPage)
end