Class: Asciidoctor::Html::Book
- Inherits:
-
Object
- Object
- Asciidoctor::Html::Book
- Includes:
- Pagination
- 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", author: "Anonymous Author", chapname: "Chapter" }.freeze
Instance Attribute Summary collapse
-
#author ⇒ Object
readonly
Returns the value of attribute author.
-
#chapname ⇒ Object
readonly
Returns the value of attribute chapname.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#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 - author - date - se_id - 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 Pagination
#display_paginator, #pagination, #prv_nxt
Constructor Details
#initialize(opts = {}) ⇒ Book
opts:
-
title
-
short_title
-
author
-
date
-
se_id
-
chapname
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/asciidoctor/html/book.rb', line 61 def initialize(opts = {}) opts = DEFAULT_OPTS.merge opts @title = ERB::Escape.html_escape opts[:title] @short_title = ERB::Escape.html_escape opts[:short_title] @author = ERB::Escape.html_escape opts[:author] @date = opts.include?(:date) ? Date.parse(opts[:date]) : Date.today @se_id = opts[:se_id] @base_url = opts[:base_url] @chapname = opts[:chapname] @refs = {} # Hash(docname => Hash(id => reftext)) @templates = {} # Hash(docname => TData) end |
Instance Attribute Details
#author ⇒ Object (readonly)
Returns the value of attribute author.
20 21 22 |
# File 'lib/asciidoctor/html/book.rb', line 20 def @author end |
#chapname ⇒ Object (readonly)
Returns the value of attribute chapname.
20 21 22 |
# File 'lib/asciidoctor/html/book.rb', line 20 def chapname @chapname end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
20 21 22 |
# File 'lib/asciidoctor/html/book.rb', line 20 def date @date end |
#refs ⇒ Object (readonly)
Returns the value of attribute refs.
20 21 22 |
# File 'lib/asciidoctor/html/book.rb', line 20 def refs @refs end |
#templates ⇒ Object (readonly)
Returns the value of attribute templates.
20 21 22 |
# File 'lib/asciidoctor/html/book.rb', line 20 def templates @templates end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
20 21 22 |
# File 'lib/asciidoctor/html/book.rb', line 20 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)
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/asciidoctor/html/book.rb', line 78 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
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/asciidoctor/html/book.rb', line 95 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) entries << Template.sitemap_entry("#{@base_url}#{filename}") if needs_sitemap end File.write("#{outdir}/#{SEARCH_PAGE}", search_page(@se_id)) if @se_id File.write("#{outdir}/sitemap.xml", Template.sitemap(entries)) if needs_sitemap end |