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
# File 'lib/asciidoctor/html/pagination.rb', line 10

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

#pagination(key = -1)) ⇒ Object



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

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



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

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