class Asciidoctor::PDF::Pdfmark

Public Class Methods

new(doc) click to toggle source
# File lib/asciidoctor/pdf/pdfmark.rb, line 7
def initialize doc
  @doc = doc
end

Public Instance Methods

generate() click to toggle source
# File lib/asciidoctor/pdf/pdfmark.rb, line 11
  def generate
    doc = @doc
    if doc.attr? 'reproducible'
      mod_date = creation_date = ::Time.at 0
    else
      mod_date = ::Time.parse doc.attr 'docdatetime' rescue (now ||= ::Time.now)
      creation_date = ::Time.parse doc.attr 'localdatetime' rescue (now ||= ::Time.now)
    end
    # FIXME use sanitize: :plain_text once available
    content = <<~EOS
    [ /Title #{sanitize(doc.doctitle use_fallback: true).to_pdf}
      /Author #{(doc.attr 'authors').to_pdf}
      /Subject #{(doc.attr 'subject').to_pdf}
      /Keywords #{(doc.attr 'keywords').to_pdf}
      /ModDate #{mod_date.to_pdf}
      /CreationDate #{creation_date.to_pdf}
      /Creator (Asciidoctor PDF #{::Asciidoctor::PDF::VERSION}, based on Prawn #{::Prawn::VERSION})
      /Producer #{(doc.attr 'publisher').to_pdf}
      /DOCINFO pdfmark
    EOS
    content
  end
generate_file(pdf_file) click to toggle source
# File lib/asciidoctor/pdf/pdfmark.rb, line 34
def generate_file pdf_file
  # QUESTION should we use the extension pdfmeta to be more clear?
  ::File.write %(#{pdf_file}mark), generate
end