Class: Asciidoctor::Html::Book

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Book

opts:

  • title

  • author

  • date

  • chapname



49
50
51
52
53
54
55
56
57
58
# File 'lib/asciidoctor/html/book.rb', line 49

def initialize(opts = {})
  opts = DEFAULT_OPTS.merge opts
  @title = ERB::Escape.html_escape opts[: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

#authorObject (readonly)

Returns the value of attribute author.



18
19
20
# File 'lib/asciidoctor/html/book.rb', line 18

def author
  @author
end

#chapnameObject (readonly)

Returns the value of attribute chapname.



18
19
20
# File 'lib/asciidoctor/html/book.rb', line 18

def chapname
  @chapname
end

#dateObject (readonly)

Returns the value of attribute date.



18
19
20
# File 'lib/asciidoctor/html/book.rb', line 18

def date
  @date
end

#refsObject (readonly)

Returns the value of attribute refs.



18
19
20
# File 'lib/asciidoctor/html/book.rb', line 18

def refs
  @refs
end

#templatesObject (readonly)

Returns the value of attribute templates.



18
19
20
# File 'lib/asciidoctor/html/book.rb', line 18

def templates
  @templates
end

#titleObject (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)



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/asciidoctor/html/book.rb', line 64

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



81
82
83
84
85
86
# File 'lib/asciidoctor/html/book.rb', line 81

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