Module: Asciidoctor::Html::Pagination

Included in:
Book
Defined in:
lib/asciidoctor/html/pagination.rb

Overview

Mixin to add pagination support to Book class

Defined Under Namespace

Classes: PagItem

Instance Method Summary collapse

Instance Method Details

#display_paginator(prv, nxt) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/asciidoctor/html/pagination.rb', line 10

def display_paginator(prv, nxt)
  return "" unless prv || nxt

  <<~HTML
    <div class="paginator-wrapper">
    <div class="d-inline-block">
    <div class="paginator">
      #{%(<a href="#{prv.url}">&laquo; #{prv.title}</a>) if prv}
      #{%(<span class="blank">&nbsp;</span>) unless prv && nxt}
      #{%(<a href="#{nxt.url}">#{nxt.title} &raquo;</a>) if nxt}
    </div>
    </div>
    </div>
  HTML
end

#pagination(key = -1)) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/asciidoctor/html/pagination.rb', line 43

def pagination(key = -1)
  keys = @refs.keys
  idx = keys.find_index key
  return "" unless idx

  prv_nxt keys, idx
end

#prv_nxt(keys, idx) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/asciidoctor/html/pagination.rb', line 26

def prv_nxt(keys, idx)
  pagitems = []
  [idx - 1, idx + 1].each do |i|
    if i.between?(0, keys.size - 1)
      key = keys[i]
      ref = @refs[key]
      pagitems << PagItem.new(
        url: "#{key}.html",
        title: ref["chapref"]
      )
    else
      pagitems << nil
    end
  end
  display_paginator(*pagitems)
end