Sha256: 1ee73aae3991d4779213701b52a8174e66f024cd295785e26f4851cde919cc65

Contents?: true

Size: 1.33 KB

Versions: 7

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

module Asciidoctor
  module PDF
    class Pdfmark
      include ::Asciidoctor::PDF::Sanitizer

      def initialize doc
        @doc = doc
      end

      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
        # FIXME: use sanitize: :plain_text once available
        content = <<~EOS
        [ /Title #{(sanitize doc.doctitle use_fallback: true).to_pdf_object}
          /Author #{(doc.attr 'authors').to_pdf_object}
          /Subject #{(doc.attr 'subject').to_pdf_object}
          /Keywords #{(doc.attr 'keywords').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').to_pdf_object}
          /DOCINFO pdfmark
        EOS
        content
      end

      def generate_file pdf_file
        # QUESTION should we use the extension pdfmeta to be more clear?
        ::File.write %(#{pdf_file}mark), generate
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
asciidoctor-pdf-1.5.3 lib/asciidoctor/pdf/pdfmark.rb
asciidoctor-pdf-1.5.2 lib/asciidoctor/pdf/pdfmark.rb
asciidoctor-pdf-1.5.1 lib/asciidoctor/pdf/pdfmark.rb
asciidoctor-pdf-1.5.0 lib/asciidoctor/pdf/pdfmark.rb
asciidoctor-pdf-1.5.0.rc.3 lib/asciidoctor/pdf/pdfmark.rb
asciidoctor-pdf-1.5.0.rc.2 lib/asciidoctor/pdf/pdfmark.rb
asciidoctor-pdf-1.5.0.rc.1 lib/asciidoctor/pdf/pdfmark.rb