Class: Xantora::Document
- Inherits:
-
Object
- Object
- Xantora::Document
- Defined in:
- lib/xantora/document.rb
Overview
Document represents a Antora document and holds the functionality for PDF conversion based on asciidoctor-pdf
Constant Summary collapse
- GEM_DIR =
File.("../..", __dir__)
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #asciidoc_attributes(optional_attributes = {}) ⇒ Object
- #asciidoctor_options(options) ⇒ Object
- #attachments_path ⇒ Object
- #component_dir ⇒ Object
- #convert_to_pdf(options = {}) ⇒ Object
- #images_dir ⇒ Object
-
#initialize(path, options = {}) ⇒ Document
constructor
A new instance of Document.
- #module_dir ⇒ Object
- #page_component_title ⇒ Object
- #pdf_name ⇒ Object
- #pdf_path(options) ⇒ Object
Constructor Details
#initialize(path, options = {}) ⇒ Document
Returns a new instance of Document.
13 14 15 16 17 |
# File 'lib/xantora/document.rb', line 13 def initialize(path, = {}) @path = path @to_dir = [:to_dir] @to_file = [:to_file] end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/xantora/document.rb', line 9 def path @path end |
Instance Method Details
#asciidoc_attributes(optional_attributes = {}) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 |
# 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) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/xantora/document.rb', line 74 def () a_opts = {} a_opts[:to_file] = pdf_path() a_opts[:backend] = "pdf" a_opts[:safe] = :unsafe a_opts[:attributes] = asciidoc_attributes([:attributes]) a_opts end |
#attachments_path ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/xantora/document.rb', line 56 def if Dir.exist? File.join(module_dir, "attachments") File.join(module_dir, "attachments") else File.join(module_dir, "assets/attachments") end end |
#component_dir ⇒ Object
19 20 21 |
# File 'lib/xantora/document.rb', line 19 def component_dir File. "../../../", File.dirname(@path) end |
#convert_to_pdf(options = {}) ⇒ Object
96 97 98 |
# File 'lib/xantora/document.rb', line 96 def convert_to_pdf( = {}) Asciidoctor.convert_file @path, () end |
#images_dir ⇒ Object
64 65 66 67 68 69 70 71 72 |
# 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 ⇒ Object
23 24 25 |
# File 'lib/xantora/document.rb', line 23 def module_dir File. "..", File.dirname(@path) end |
#page_component_title ⇒ Object
27 28 29 30 31 32 33 |
# 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 ⇒ Object
35 36 37 38 39 40 41 42 |
# 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) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/xantora/document.rb', line 44 def pdf_path() if [:to_attachments] File.join(, pdf_name) elsif ![:output] pdf_name elsif [:output].end_with? ".pdf" [:output] else File.join [:output], pdf_name end end |