Class: Asciidoctor::Html::Book
- Inherits:
-
Object
- Object
- Asciidoctor::Html::Book
- Includes:
- Pagination, Search
- Defined in:
- lib/asciidoctor/html/book.rb
Overview
A book is a collection of documents with cross referencing supported via the cref macro.
Defined Under Namespace
Classes: TData
Constant Summary collapse
- DOCATTRS =
{ "sectids" => false, "stem" => "latexmath", "hide-uri-scheme" => true, "source-highlighter" => "highlight.js", "imagesdir" => IMG_PATH, "dollar" => "$", "parskip" => %(<span class="parskip"></span><br>) }.freeze
- DEFAULT_OPTS =
{ title: "Untitled Book", chapname: "Chapter" }.freeze
Constants included from Search
Search::SEARCH_RESULT_OVERFLOW
Instance Attribute Summary collapse
-
#chapname ⇒ Object
readonly
Returns the value of attribute chapname.
-
#refs ⇒ Object
readonly
Returns the value of attribute refs.
-
#templates ⇒ Object
readonly
Returns the value of attribute templates.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Book
constructor
opts: - title - short_title - authors - chapname.
-
#read(chapters = [], appendices = []) ⇒ Object
params: - chapters: array of filenames - appendices: array of filenames returns: Hash(file_basename_without_ext => html).
-
#write(chapters, appendices, outdir, sitemap: false) ⇒ Object
params: - chapters: array of filenames - appendices: array of filenames - outdir: directory to write the converted html files to.
Methods included from Search
#build_index, #lunr_script, #search_json, #search_page
Methods included from Pagination
#display_paginator, #pagination, #prv_nxt
Constructor Details
#initialize(opts = {}) ⇒ Book
opts:
-
title
-
short_title
-
authors
-
chapname
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/asciidoctor/html/book.rb', line 59 def initialize(opts = {}) opts = DEFAULT_OPTS.merge opts @title = ERB::Escape.html_escape opts[:title] @short_title = ERB::Escape.html_escape opts[:short_title] = opts[:authors] @base_url = opts[:base_url] @chapname = opts[:chapname] @search_index = {} # Hash(docname => Array[SearchData]) @refs = {} # Hash(docname => Hash(id => reftext)) @templates = {} # Hash(docname => TData) end |
Instance Attribute Details
#chapname ⇒ Object (readonly)
Returns the value of attribute chapname.
22 23 24 |
# File 'lib/asciidoctor/html/book.rb', line 22 def chapname @chapname end |
#refs ⇒ Object (readonly)
Returns the value of attribute refs.
22 23 24 |
# File 'lib/asciidoctor/html/book.rb', line 22 def refs @refs end |
#templates ⇒ Object (readonly)
Returns the value of attribute templates.
22 23 24 |
# File 'lib/asciidoctor/html/book.rb', line 22 def templates @templates end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
22 23 24 |
# File 'lib/asciidoctor/html/book.rb', line 22 def title @title end |
Instance Method Details
#read(chapters = [], appendices = []) ⇒ Object
params:
-
chapters: array of filenames
-
appendices: array of filenames
returns: Hash(file_basename_without_ext => html)
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/asciidoctor/html/book.rb', line 75 def read(chapters = [], appendices = []) docs = {} # Hash(docname => document) chapters.each_with_index do |filename, idx| doc = chapter filename, idx register! docs, filename, doc end appendices.each_with_index do |filename, idx| doc = appendix filename, idx, appendices.size register! docs, filename, doc end html docs end |
#write(chapters, appendices, outdir, sitemap: false) ⇒ Object
params:
-
chapters: array of filenames
-
appendices: array of filenames
-
outdir: directory to write the converted html files to
92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/asciidoctor/html/book.rb', line 92 def write(chapters, appendices, outdir, sitemap: false) needs_sitemap = sitemap && @base_url entries = [] # for sitemap read(chapters, appendices).each do |name, html| filename = "#{name}.html" File.write("#{outdir}/#{filename}", html) build_index(name, html) unless omit_search? entries << Template.sitemap_entry("#{@base_url}#{filename}") if needs_sitemap end File.write "#{outdir}/#{SEARCH_PAGE}", search_page unless omit_search? File.write("#{outdir}/sitemap.xml", Template.sitemap(entries)) if needs_sitemap end |