class Xantora::Document
Document
represents a Antora document and holds the functionality for PDF conversion based on asciidoctor-pdf
Constants
- GEM_DIR
Attributes
path[R]
Public Class Methods
new(path, options = {})
click to toggle source
# File lib/xantora/document.rb, line 13 def initialize(path, options = {}) @path = path @to_dir = options[:to_dir] @to_file = options[:to_file] end
Public Instance Methods
asciidoc_attributes(optional_attributes = {})
click to toggle source
# File lib/xantora/document.rb, line 83 def asciidoc_attributes(optional_attributes = {}) attributes = { "toc" => "auto", "toclevels" => "1", "pdf-theme" => "puzzle", "pdf-themesdir" => File.join(GEM_DIR, "asciidoctor-pdf/themes"), "pdf-fontsdir" => "#{File.join(GEM_DIR, "asciidoctor-pdf/fonts")};GEM_FONTS_DIR", "imagesdir" => images_dir } attributes.merge!({ "page-component-title" => page_component_title }) attributes.merge(optional_attributes) end
asciidoctor_options(options)
click to toggle source
# File lib/xantora/document.rb, line 74 def asciidoctor_options(options) a_opts = {} a_opts[:to_file] = pdf_path(options) a_opts[:backend] = "pdf" a_opts[:safe] = :unsafe a_opts[:attributes] = asciidoc_attributes(options[:attributes]) a_opts end
attachments_path()
click to toggle source
# File lib/xantora/document.rb, line 56 def attachments_path if Dir.exist? File.join(module_dir, "attachments") File.join(module_dir, "attachments") else File.join(module_dir, "assets/attachments") end end
component_dir()
click to toggle source
# File lib/xantora/document.rb, line 19 def component_dir File.expand_path "../../../", File.dirname(@path) end
convert_to_pdf(options = {})
click to toggle source
# File lib/xantora/document.rb, line 96 def convert_to_pdf(options = {}) Asciidoctor.convert_file @path, asciidoctor_options(options) end
images_dir()
click to toggle source
# File lib/xantora/document.rb, line 64 def images_dir if Dir.exist? File.join(module_dir, "images") "../images" elsif Dir.exist? File.join(module_dir, "assets/images") "../assets/images" else "" end end
module_dir()
click to toggle source
# File lib/xantora/document.rb, line 23 def module_dir File.expand_path "..", File.dirname(@path) end
page_component_title()
click to toggle source
# File lib/xantora/document.rb, line 27 def page_component_title YAML.load_file( File.join(component_dir, "antora.yml") )["title"] rescue StandardError "" end
pdf_name()
click to toggle source
# File lib/xantora/document.rb, line 35 def pdf_name name = File.basename(@path, ".adoc") if name == "index" doc = Asciidoctor.load_file @path, safe: :safe name = doc.doctitle ? doc.doctitle.gsub(/[^0-9A-Za-z.\-]/, "_") : "index" end "#{name}.pdf" end
pdf_path(options)
click to toggle source
# File lib/xantora/document.rb, line 44 def pdf_path(options) if options[:to_attachments] File.join(attachments_path, pdf_name) elsif !options[:output] pdf_name elsif options[:output].end_with? ".pdf" options[:output] else File.join options[:output], pdf_name end end