Class: Asciidoctor::PDF::Pdfmark
- Includes:
- Sanitizer
- Defined in:
- lib/asciidoctor/pdf/pdfmark.rb
Constant Summary
Constants included from Sanitizer
Sanitizer::CharRefRx, Sanitizer::InverseXMLSpecialChars, Sanitizer::InverseXMLSpecialCharsRx, Sanitizer::SanitizeXMLRx, Sanitizer::UnescapedAmpersandRx, Sanitizer::XMLSpecialChars, Sanitizer::XMLSpecialCharsRx
Instance Method Summary collapse
- #generate ⇒ Object
- #generate_file(pdf_file) ⇒ Object
-
#initialize(doc) ⇒ Pdfmark
constructor
A new instance of Pdfmark.
Methods included from Sanitizer
#encode_quotes, #escape_amp, #escape_xml, #sanitize, #unescape_xml
Constructor Details
#initialize(doc) ⇒ Pdfmark
Returns a new instance of Pdfmark.
8 9 10 |
# File 'lib/asciidoctor/pdf/pdfmark.rb', line 8 def initialize doc @doc = doc end |
Instance Method Details
#generate ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/asciidoctor/pdf/pdfmark.rb', line 12 def generate doc = @doc if doc.attr? 'reproducible' mod_date = creation_date = (::Time.at 0).utc else mod_date = (::Time.parse doc.attr 'docdatetime') rescue (now ||= ::Time.now) creation_date = (::Time.parse doc.attr 'localdatetime') rescue (now || ::Time.now) end if (doc.attribute_locked? 'author') && !(doc.attribute_locked? 'authors') = sanitize doc.attr 'author' elsif doc.attr? 'authors' = sanitize doc.attr 'authors' elsif doc.attr? 'author' # rubocop:disable Lint/DuplicateBranch = sanitize doc.attr 'author' end # see https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/pdfmark_reference.pdf <<~EOS [ /Title #{(sanitize doc.header? ? doc.doctitle : (doc.attr 'untitled-label')).to_pdf_object} /Author #{.to_pdf_object} /Subject #{((doc.attr? 'subject') ? (sanitize doc.attr 'subject') : nil).to_pdf_object} /Keywords #{((doc.attr? 'keywords') ? (sanitize doc.attr 'keywords') : nil).to_pdf_object} /ModDate #{mod_date.to_pdf_object} /CreationDate #{creation_date.to_pdf_object} /Creator (Asciidoctor PDF #{::Asciidoctor::PDF::VERSION}, based on Prawn #{::Prawn::VERSION}) /Producer #{((doc.attr? 'publisher') ? (sanitize doc.attr 'publisher') : nil).to_pdf_object} /DOCINFO pdfmark EOS end |
#generate_file(pdf_file) ⇒ Object
41 42 43 44 45 |
# File 'lib/asciidoctor/pdf/pdfmark.rb', line 41 def generate_file pdf_file # QUESTION: should we use the extension pdfmeta to be more clear? ::File.write (pdfmark_file = %(#{pdf_file}mark)), generate pdfmark_file end |