Module: Asciidoctor::Html::Template
- Defined in:
- lib/asciidoctor/html/template.rb
Overview
The template for the book layout
Class Method Summary collapse
- .appendix_title(chapname, numeral, doctitle, num_appendices) ⇒ Object
- .footer(author, year) ⇒ Object
- .head(title, langs) ⇒ Object
- .header(title, short_title, nav: true) ⇒ Object
- .highlightjs(langs) ⇒ Object
-
.html(content, nav_items, opts = {}) ⇒ Object
opts: - title: String - short_title: String - author: String - date: Date - nav: Boolean - chapnum: Int - chaptitle: String - langs: Array.
- .main(content, chapnum, chaptitle, author, year) ⇒ Object
- .nav_item(target, text, content = "", active: false) ⇒ Object
- .nav_text(chapnum, chaptitle) ⇒ Object
- .sidebar(nav_items) ⇒ Object
Class Method Details
.appendix_title(chapname, numeral, doctitle, num_appendices) ⇒ Object
24 25 26 27 |
# File 'lib/asciidoctor/html/template.rb', line 24 def self.appendix_title(chapname, numeral, doctitle, num_appendices) numeral = num_appendices == 1 ? "" : " #{numeral}" %(<span class="title-prefix">#{chapname}#{numeral}</span>#{doctitle}) end |
.footer(author, year) ⇒ Object
72 73 74 |
# File 'lib/asciidoctor/html/template.rb', line 72 def self.(, year) %(<footer class="footer">© #{year} #{}</footer>\n) end |
.head(title, langs) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/asciidoctor/html/template.rb', line 82 def self.head(title, langs) <<~HTML <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>#{title}</title> <link rel="apple-touch-icon" sizes="180x180" href="#{FAVICON_PATH}/apple-touch-icon.png"> <link rel="icon" type="image/png" sizes="32x32" href="#{FAVICON_PATH}/favicon-32x32.png"> <link rel="icon" type="image/png" sizes="16x16" href="#{FAVICON_PATH}/favicon-16x16.png"> <link rel="manifest" href="#{FAVICON_PATH}/site.webmanifest"> <link rel="stylesheet" href="#{CSS_PATH}/styles.css"> <link rel="stylesheet" href="#{Highlightjs::CDN_PATH}/styles/tomorrow-night-blue.min.css"> <script src="#{Highlightjs::CDN_PATH}/highlight.min.js"></script> #{highlightjs langs} <script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script> </head> HTML end |
.header(title, short_title, nav: true) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/asciidoctor/html/template.rb', line 51 def self.header(title, short_title, nav: true) nav_btn = if nav <<~HTML <button type="button" class="btn menu" data-bs-toggle="collapse" data-bs-target="#sidebar" aria-expanded="false" aria-controls="sidebar"> <i class="bi bi-list"></i> </button> HTML else "" end <<~HTML <header class="header"> <a class="home d-none d-sm-block" href="./">#{title}</a> <a class="home d-block d-sm-none" href="./">#{short_title}</a> #{nav_btn} </header> HTML end |
.highlightjs(langs) ⇒ Object
76 77 78 79 80 |
# File 'lib/asciidoctor/html/template.rb', line 76 def self.highlightjs(langs) langs.map do |lang| %(<script src="#{Highlightjs::CDN_PATH}/languages/#{lang}.min.js"></script>) end.join("\n ") end |
.html(content, nav_items, opts = {}) ⇒ Object
opts:
-
title: String
-
short_title: String
-
author: String
-
date: Date
-
nav: Boolean
-
chapnum: Int
-
chaptitle: String
-
langs: Array
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/asciidoctor/html/template.rb', line 110 def self.html(content, nav_items, opts = {}) hash_listener = if opts[:nav] <<~JS addEventListener('hashchange', function() { collapse = bootstrap.Collapse.getInstance('#sidebar'); if(collapse) collapse.hide(); }); JS else "" end <<~HTML <!DOCTYPE html> <html lang="en"> #{head opts[:title], opts[:langs]} <body> #{header opts[:title], opts[:short_title], nav: opts[:nav]} #{(nav_items) if opts[:nav]} #{main content, opts[:chapnum], opts[:chaptitle], opts[:], opts[:date].year} <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.6/dist/js/bootstrap.bundle.min.js" integrity="sha384-j1CDi7MgGQ12Z7Qab0qlWQ/Qqz24Gc6BM0thvEMVjHnfYGF0rmFCozFSxQBxwHKO" crossorigin="anonymous"></script> <script> const touch = matchMedia('(hover: none)').matches; #{Highlightjs::PLUGIN} hljs.highlightAll(); #{hash_listener} #{Popovers::POPOVERS} </script> </body> </html> HTML end |
.main(content, chapnum, chaptitle, author, year) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/asciidoctor/html/template.rb', line 39 def self.main(content, chapnum, chaptitle, , year) <<~HTML <main class="main"> <div class="content-container"> <h2>#{nav_text chapnum, chaptitle}</h2> #{content} #{ , year} </div> </main> HTML end |
.nav_item(target, text, content = "", active: false) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/asciidoctor/html/template.rb', line 11 def self.nav_item(target, text, content = "", active: false) active_class = active ? %( class="active") : "" link = %(<a href="#{target}">#{text}</a>) = content.empty? ? content : "\n#{content}\n" %(<li#{active_class}>#{link}#{}</li>\n) end |
.nav_text(chapnum, chaptitle) ⇒ Object
18 19 20 21 22 |
# File 'lib/asciidoctor/html/template.rb', line 18 def self.nav_text(chapnum, chaptitle) return chaptitle if chapnum.empty? %(<span class="title-mark">#{chapnum}</span>#{chaptitle}) end |
.sidebar(nav_items) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/asciidoctor/html/template.rb', line 29 def self.(nav_items) <<~HTML <div id="sidebar" class="sidebar collapse collapse-horizontal"> <nav id="sidenav"><ul> #{nav_items.join "\n"} </ul></nav> </div> <!-- .sidebar --> HTML end |