Module: Asciidoctor::Html::Template
- Defined in:
- lib/asciidoctor/html/template.rb
Overview
The template for the book layout
Constant Summary collapse
- MENU_BTN =
"<button type=\"button\" id=\"menu-btn\" class=\"btn menu\"\n aria-expanded=\"false\" aria-controls=\"sidebar\">\n <i class=\"bi bi-list\"></i>\n</button>\n"
Class Method Summary collapse
- .appendix_title(chapname, numeral, doctitle, num_appendices) ⇒ Object
- .footer(authors) ⇒ Object
- .head(title, description, authors, langs) ⇒ Object
- .header(title, short_title) ⇒ Object
- .highlightjs(langs) ⇒ Object
-
.html(content, nav_items, opts = {}) ⇒ Object
opts: - title: String - short_title: String - authors: String - description: String - chapheading: String - chapsubheading: String - langs: Array - at_head_end: String - at_body_end: String.
-
.main(opts) ⇒ Object
opts: - chapheading: String - chapsubheading: String - content: String - authors: String - date: Date.
- .nav_item(target, text, content = "", active: false) ⇒ Object
- .nav_text(chapprefix, chaptitle) ⇒ Object
- .sidebar(nav_items) ⇒ Object
- .sitemap(entries) ⇒ Object
- .sitemap_entry(url) ⇒ Object
Class Method Details
.appendix_title(chapname, numeral, doctitle, num_appendices) ⇒ Object
33 34 35 36 |
# File 'lib/asciidoctor/html/template.rb', line 33 def self.appendix_title(chapname, numeral, doctitle, num_appendices) numeral = num_appendices == 1 ? "" : " #{numeral}" %(<span class="title-prefix">#{chapname}#{numeral}</span>#{doctitle}) end |
.footer(authors) ⇒ Object
95 96 97 98 99 100 101 102 103 104 |
# File 'lib/asciidoctor/html/template.rb', line 95 def self.() " <footer class=\"footer\">\n <div class=\"footer-left\">© <span id=\"cr-year\"></span> \#{authors}</div>\n <div class=\"footer-right\">Built with\n <a href=\"https://github.com/ravirajani/asciidoctor-html\">asciidoctor-html</a>\n </div>\n </footer>\n HTML\nend\n" |
.head(title, description, authors, langs) ⇒ Object
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 |
# File 'lib/asciidoctor/html/template.rb', line 112 def self.head(title, description, , langs) " <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n \#{%(<meta name=\"description\" content=\"\#{description}\">) if description}\n \#{%(<meta name=\"author\" content=\"\#{authors}\">) if authors}\n <title>\#{title}</title>\n <link rel=\"apple-touch-icon\" sizes=\"180x180\" href=\"\#{FAVICON_PATH}/apple-touch-icon.png\">\n <link rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"\#{FAVICON_PATH}/favicon-32x32.png\">\n <link rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"\#{FAVICON_PATH}/favicon-16x16.png\">\n <link rel=\"manifest\" href=\"\#{FAVICON_PATH}/site.webmanifest\" crossorigin=\"anonymous\">\n <link rel=\"stylesheet\" href=\"\#{CSS_PATH}/styles.css\">\n <link rel=\"stylesheet\" href=\"\#{Highlightjs::CDN_PATH}/styles/tomorrow-night-blue.min.css\">\n <script defer src=\"\#{Highlightjs::CDN_PATH}/highlight.min.js\"></script>\n \#{highlightjs langs}\n <script>\n MathJax = {\n tex: {\n inlineMath: {'[+]': [['$', '$']]}\n }\n };\n </script>\n <script defer src=\"https://cdn.jsdelivr.net/npm/mathjax@4/tex-chtml.js\"></script>\n <script defer src=\"https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js\"\n integrity=\"sha384-j1CDi7MgGQ12Z7Qab0qlWQ/Qqz24Gc6BM0thvEMVjHnfYGF0rmFCozFSxQBxwHKO\"\n crossorigin=\"anonymous\"></script>\n HTML\nend\n" |
.header(title, short_title) ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'lib/asciidoctor/html/template.rb', line 86 def self.header(title, short_title) " <header class=\"header\">\n <a class=\"home d-none d-sm-block\" href=\"./\">\#{title}</a>\n <a class=\"home d-block d-sm-none\" href=\"./\">\#{short_title}</a>\n </header>\n HTML\nend\n" |
.highlightjs(langs) ⇒ Object
106 107 108 109 110 |
# File 'lib/asciidoctor/html/template.rb', line 106 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:
-
title: String
-
short_title: String
-
authors: String
-
description: String
-
chapheading: String
-
chapsubheading: String
-
langs: Array
-
at_head_end: String
-
at_body_end: String
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/asciidoctor/html/template.rb', line 151 def self.html(content, nav_items, opts = {}) nav = (nav_items.size > 1) " <!DOCTYPE html>\n <html lang=\"en\">\n <head>\n \#{head opts[:title], opts[:description], opts[:authors], opts[:langs]}\n \#{opts[:at_head_end]}\n </head>\n <body>\n \#{sidebar(nav_items) if nav}\n <div id=\"page\" class=\"page\">\n \#{MENU_BTN if nav}\n \#{header opts[:title], opts[:short_title]}\n \#{main content:, **opts}\n </div> <!-- .page -->\n <script>document.getElementById(\"cr-year\").textContent = (new Date()).getFullYear();</script>\n <script type=\"module\">\n \#{Highlightjs::PLUGIN}\n \#{Popovers::POPOVERS}\n \#{Sidebar::TOGGLE if nav}\n \#{Scroll::SCROLL}\n </script>\n \#{opts[:at_body_end]}\n </body>\n </html>\n HTML\nend\n" |
.main(opts) ⇒ Object
opts:
-
chapheading: String
-
chapsubheading: String
-
content: String
-
authors: String
-
date: Date
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/asciidoctor/html/template.rb', line 55 def self.main(opts) " <main id=\"main\" class=\"main\">\n <div id=\"content-container\" class=\"content-container\">\n \#{%(<h1 class=\"chapheading\">\#{opts[:chapheading]}</h1>) if opts[:chapheading]}\n <h1 class=\"chaptitle\">\#{opts[:chapsubheading]}</h1>\n \#{opts[:content]}\n \#{footer opts[:authors]}\n </div>\n </main>\n HTML\nend\n" |
.nav_item(target, text, content = "", active: false) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/asciidoctor/html/template.rb', line 20 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}#{subnav}</li>\n) end |
.nav_text(chapprefix, chaptitle) ⇒ Object
27 28 29 30 31 |
# File 'lib/asciidoctor/html/template.rb', line 27 def self.nav_text(chapprefix, chaptitle) return chaptitle if chapprefix.empty? %(<div class="nav-mark">#{chapprefix}</div>#{chaptitle}) end |
.sidebar(nav_items) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/asciidoctor/html/template.rb', line 38 def self.(nav_items) " <div id=\"sidebar\" class=\"sidebar\">\n <button id=\"sidebar-dismiss-btn\" class=\"btn dismiss\"><i class=\"bi bi-x-lg\"></i></button>\n <nav><ul>\n \#{nav_items.join \"\\n\"}\n </ul></nav>\n </div> <!-- .sidebar -->\n HTML\nend\n" |
.sitemap(entries) ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/asciidoctor/html/template.rb', line 68 def self.sitemap(entries) " <?xml version=\"1.0\" encoding=\"UTF-8\"?>\n <urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n\n \#{entries.join \"\\n\"}\n </urlset>\n XML\nend\n" |
.sitemap_entry(url) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/asciidoctor/html/template.rb', line 78 def self.sitemap_entry(url) " <url>\n <loc>\#{url}</loc>\n </url>\n XML\nend\n" |