class Asciidoctor::PDF::ImplicitHeaderProcessor

An include processor that skips the implicit author line below the document title within include documents.

Public Instance Methods

handles?(target) click to toggle source
# File lib/asciidoctor-pdf/implicit_header_processor.rb, line 48
def handles? target
  # FIXME should not require this hack to skip processing bio
  !(target.end_with? 'bio.adoc') && ((target.end_with? '.adoc') || (target.end_with? '.asciidoc'))
end
process(doc, reader, target, attributes) click to toggle source
# File lib/asciidoctor-pdf/implicit_header_processor.rb, line 8
def process doc, reader, target, attributes
  return reader unless File.exist? target
  ::File.open target, 'r' do |fd|
    # FIXME handle case where doc id is specified above title
    if (first_line = fd.readline) && (first_line.start_with? '= ')
      # HACK reset counters for each article for Editions
      if doc.attr? 'env', 'editions'
        doc.counters.each do |counter_key, counter_val|
          doc.attributes.delete counter_key
        end
        doc.counters.clear
      end
      if (second_line = fd.readline)
        if AuthorInfoLineRx =~ second_line
          # FIXME temporary hack to set author and e-mail attributes; this should handle all attributes in header!
          author = [$1, $2, $3].compact * ' '
          email = $4
          reader.push_include fd.readlines, target, target, 3, attributes unless fd.eof?
          reader.push_include first_line, target, target, 1, attributes
          lines = [%(:author: #{author})]
          lines << %(:email: #{email}) if email
          reader.push_include lines, target, target, 2, attributes
        else
          lines = [second_line]
          lines += fd.readlines unless fd.eof?
          reader.push_include lines, target, target, 2, attributes
          reader.push_include first_line, target, target, 1, attributes
        end
      else
        reader.push_include first_line, target, target, 1, attributes
      end
    else
      lines = [first_line]
      lines += fd.readlines unless fd.eof?
      reader.push_include lines, target, target, 1, attributes
    end
  end
  reader
end
update_config(config) click to toggle source

FIXME this method shouldn't be required

# File lib/asciidoctor-pdf/implicit_header_processor.rb, line 54
def update_config config
  (@config ||= {}).update config
end