Class: Asciidoctor::Html::Book
- Inherits:
-
Object
- Object
- Asciidoctor::Html::Book
- 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 }.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) ⇒ Object
params: - chapters: array of filenames - appendices: array of filenames - outdir: directory to write the converted html files to.
Constructor Details
#initialize(opts = {}) ⇒ Book
opts:
-
title
-
short_title
-
author
-
date
-
se_id
-
chapname
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/asciidoctor/html/book.rb', line 51 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] @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.
18 19 20 |
# File 'lib/asciidoctor/html/book.rb', line 18 def @author end |
#chapname ⇒ Object (readonly)
Returns the value of attribute chapname.
18 19 20 |
# File 'lib/asciidoctor/html/book.rb', line 18 def chapname @chapname end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
18 19 20 |
# File 'lib/asciidoctor/html/book.rb', line 18 def date @date end |
#refs ⇒ Object (readonly)
Returns the value of attribute refs.
18 19 20 |
# File 'lib/asciidoctor/html/book.rb', line 18 def refs @refs end |
#templates ⇒ Object (readonly)
Returns the value of attribute templates.
18 19 20 |
# File 'lib/asciidoctor/html/book.rb', line 18 def templates @templates end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
18 19 20 |
# File 'lib/asciidoctor/html/book.rb', line 18 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)
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/asciidoctor/html/book.rb', line 67 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) ⇒ Object
params:
-
chapters: array of filenames
-
appendices: array of filenames
-
outdir: directory to write the converted html files to
84 85 86 87 88 89 |
# File 'lib/asciidoctor/html/book.rb', line 84 def write(chapters, appendices, outdir) read(chapters, appendices).each do |name, html| File.write("#{outdir}/#{name}.html", html) end File.write("#{outdir}/#{SEARCH_PAGE}", search_page(@se_id)) if @se_id end |