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 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/asciidoctor/html/pagination.rb', line 10 def display_paginator(prv, nxt) blank = %(<span class="blank"> </span>) visible_class = " visible" if prv || nxt html = [<<~HTML <div class="paginator-wrapper"> <div class="paginator#{visible_class}"> HTML ] html << if prv <<~HTML <a href="#{prv.url}"> <div><i class="bi bi-chevron-compact-left"></i></div> <div>#{"#{prv.title}<br>" if prv.title}#{prv.text}</div> </a> HTML else blank end html << if nxt <<~HTML <a href="#{nxt.url}"> <div>#{"#{nxt.title}<br>" if nxt.title}#{nxt.text}</div> <div><i class="bi bi-chevron-compact-right"></i></div> </a> HTML else blank end html << %(</div></div>) html.join("\n") end |
#pagination(key = -1)) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/asciidoctor/html/pagination.rb', line 60 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
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/asciidoctor/html/pagination.rb', line 42 def prv_nxt(keys, idx) pagitems = [] [idx - 1, idx + 1].each do |i| if i.between?(0, keys.size - 1) key = keys[i] tdata = @templates[key] pagitems << PagItem.new( url: "#{key}.html", title: tdata[:chapheading], text: tdata[:chapsubheading] ) else pagitems << nil end end display_paginator(*pagitems) end |