Module: Asciidoctor::Html::Template
- Defined in:
- lib/asciidoctor/html/template.rb
Overview
The template for the book layout
Constant Summary collapse
- MENU_BTN =
<<~HTML <button type="button" id="menu-btn" class="btn menu" aria-expanded="false" aria-controls="sidebar"> <i class="bi bi-list"></i> </button> HTML
Class Method Summary collapse
- .appendix_title(chapname, numeral, doctitle, num_appendices) ⇒ Object
- .chapheading(text) ⇒ Object
- .footer(authors) ⇒ Object
- .head(title, description, authors, langs) ⇒ Object
- .header(title, short_title, has_subnav) ⇒ Object
- .highlightjs(langs) ⇒ Object
-
.html(content, nav_items, opts = {}) ⇒ Object
opts: - has_subnav: Boolean - title: String - short_title: String - authors: String - description: String - chapheading: String - chapsubheading: String - langs: Array - at_head_end: String - at_body_end: String - multipage: Boolean|Null.
-
.main(opts) ⇒ Object
opts: - chapheading: String - chapsubheading: String - content: String - has_subnav: Boolean - authors: String - date: Date - multipage: Boolean|Null.
- .nav_item(target, text, content = "", active: false) ⇒ Object
- .nav_text(chapprefix, chaptitle) ⇒ Object
- .sidebar(nav_items) ⇒ Object
- .sitemap(entries) ⇒ Object
- .sitemap_entry(url) ⇒ Object
- .toggle_button(multipage) ⇒ Object
Class Method Details
.appendix_title(chapname, numeral, doctitle, num_appendices) ⇒ Object
34 35 36 37 |
# File 'lib/asciidoctor/html/template.rb', line 34 def self.appendix_title(chapname, numeral, doctitle, num_appendices) numeral = num_appendices == 1 ? "" : " #{numeral}" %(<span class="title-prefix">#{chapname}#{numeral}</span>#{doctitle}) end |
.chapheading(text) ⇒ Object
59 60 61 |
# File 'lib/asciidoctor/html/template.rb', line 59 def self.chapheading(text) %(<h1 class="chapheading">#{text}</h1>) if text end |
.footer(authors) ⇒ Object
114 115 116 117 118 119 120 121 122 123 |
# File 'lib/asciidoctor/html/template.rb', line 114 def self.() <<~HTML <footer class="footer"> <div class="footer-left">© <span id="cr-year"></span> #{}</div> <div class="footer-right">Built with <a href="https://github.com/ravirajani/asciidoctor-html">asciidoctor-html</a> </div> </footer> HTML end |
.head(title, description, authors, langs) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/asciidoctor/html/template.rb', line 131 def self.head(title, description, , langs) <<~HTML <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> #{%(<meta name="description" content="#{description}">) if description} #{%(<meta name="author" content="#{}">) if } <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" crossorigin="anonymous"> <link rel="stylesheet" href="#{CSS_PATH}/styles.css"> <link rel="stylesheet" href="#{Highlightjs::CDN_PATH}/styles/tomorrow-night-blue.min.css"> <script defer src="#{Highlightjs::CDN_PATH}/highlight.min.js"></script> #{highlightjs langs} <script> MathJax = { tex: { inlineMath: {'[+]': [['$', '$']]} }, output: { displayOverflow: 'linebreak' } }; ADHT = {}; // Custom namespace. </script> <script defer src="https://cdn.jsdelivr.net/npm/mathjax@4/tex-chtml.js"></script> <script defer src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.6/dist/js/bootstrap.bundle.min.js" integrity="sha384-j1CDi7MgGQ12Z7Qab0qlWQ/Qqz24Gc6BM0thvEMVjHnfYGF0rmFCozFSxQBxwHKO" crossorigin="anonymous"></script> HTML end |
.header(title, short_title, has_subnav) ⇒ Object
105 106 107 108 109 110 111 112 |
# File 'lib/asciidoctor/html/template.rb', line 105 def self.header(title, short_title, ) <<~HTML <header class="header#{" with-margin" unless }"> <a class="home d-none d-sm-block" href="./">#{title}</a> <a class="home d-block d-sm-none" href="./">#{short_title}</a> </header> HTML end |
.highlightjs(langs) ⇒ Object
125 126 127 128 129 |
# File 'lib/asciidoctor/html/template.rb', line 125 def self.highlightjs(langs) langs.map do |lang| %(<script defer src="#{Highlightjs::CDN_PATH}/languages/#{lang}.min.js"></script>) end.join("\n ") end |
.html(content, nav_items, opts = {}) ⇒ Object
opts:
-
has_subnav: Boolean
-
title: String
-
short_title: String
-
authors: String
-
description: String
-
chapheading: String
-
chapsubheading: String
-
langs: Array
-
at_head_end: String
-
at_body_end: String
-
multipage: Boolean|Null
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/asciidoctor/html/template.rb', line 176 def self.html(content, nav_items, opts = {}) nav = (nav_items.size > 1) <<~HTML <!DOCTYPE html> <html lang="en"> <head> #{head opts[:title], opts[:description], opts[:], opts[:langs]} #{opts[:at_head_end]} </head> <body> #{(nav_items) if nav} <div id="page" class="page#{" multi" if opts[:multipage]}"> #{MENU_BTN if nav} #{header opts[:title], opts[:short_title], opts[:]} #{main content:, **opts} </div> <!-- .page --> <script>document.getElementById("cr-year").textContent = (new Date()).getFullYear();</script> <script type="module"> #{Highlightjs::PLUGIN} #{Popovers::POPOVERS} #{Sidebar::TOGGLE if nav} #{Scroll::SCROLL} #{Flip::FLIP} </script> #{opts[:at_body_end]} </body> </html> HTML end |
.main(opts) ⇒ Object
opts:
-
chapheading: String
-
chapsubheading: String
-
content: String
-
has_subnav: Boolean
-
authors: String
-
date: Date
-
multipage: Boolean|Null
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/asciidoctor/html/template.rb', line 71 def self.main(opts) <<~HTML <main id="main" class="main"> <div id="content-container" class="content-container"> <div class="chaphead"> #{ opts[:multipage] if opts[:]} #{chapheading opts[:chapheading]} <h1 class="chaptitle">#{opts[:chapsubheading]}</h1> </div> #{opts[:content]} #{ opts[:]} </div> </main> HTML end |
.nav_item(target, text, content = "", active: false) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/asciidoctor/html/template.rb', line 21 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(chapprefix, chaptitle) ⇒ Object
28 29 30 31 32 |
# File 'lib/asciidoctor/html/template.rb', line 28 def self.nav_text(chapprefix, chaptitle) return chaptitle if chapprefix.empty? %(<div class="nav-mark">#{chapprefix}</div>#{chaptitle}) end |
.sidebar(nav_items) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/asciidoctor/html/template.rb', line 39 def self.(nav_items) <<~HTML <div id="sidebar" class="sidebar"> <button id="sidebar-dismiss-btn" class="btn dismiss"><i class="bi bi-x-lg"></i></button> <nav><ul> #{nav_items.join "\n"} </ul></nav> </div> <!-- .sidebar --> HTML end |
.sitemap(entries) ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'lib/asciidoctor/html/template.rb', line 87 def self.sitemap(entries) <<~XML <?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> #{entries.join "\n"} </urlset> XML end |
.sitemap_entry(url) ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/asciidoctor/html/template.rb', line 97 def self.sitemap_entry(url) <<~XML <url> <loc>#{url}</loc> </url> XML end |
.toggle_button(multipage) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/asciidoctor/html/template.rb', line 50 def self.(multipage) toggle_text = multipage ? "single page" : "multiple pages" <<~HTML <div class="layout-toggle"> <label for="btn-layout">View as</label> <button id="btn-layout" type="button" class="btn btn-link">#{toggle_text}</button> </div> HTML end |