Class: Metanorma::AsciidoctorExtensions::GlobIncludeProcessor

Inherits:
Asciidoctor::Extensions::IncludeProcessor
  • Object
show all
Defined in:
lib/metanorma/asciidoctor_extensions/glob_include_processor.rb

Overview

Asciidoctor IncludeProcessor that expands glob patterns in include:: directives. When the target contains a *, the files matching the glob (relative to the including reader’s dir) are included in reverse-sorted order, each separated from the next by a blank line unless the adjoin-option attribute is set.

Examples:

In an Asciidoc document

include::sections/*.adoc[]

Instance Method Summary collapse

Instance Method Details

#handles?(target) ⇒ Boolean

Whether this processor handles the given include target. Triggers on any target containing * — sufficient for the glob patterns the metanorma stack uses.

Parameters:

  • target (String)

    include directive target.

Returns:

  • (Boolean)


39
40
41
# File 'lib/metanorma/asciidoctor_extensions/glob_include_processor.rb', line 39

def handles?(target)
  target.include? "*"
end

#process(_doc, reader, target_glob, attributes) ⇒ Asciidoctor::Reader

Returns the reader, mutated in place.

Parameters:

  • _doc (Asciidoctor::Document)

    containing document (unused).

  • reader (Asciidoctor::Reader)

    the include site’s reader.

  • target_glob (String)

    glob pattern relative to reader.dir.

  • attributes (Hash)

    include directive attributes; recognises “adjoin-option” to suppress the inter-file blank line.

Returns:

  • (Asciidoctor::Reader)

    the reader, mutated in place.



24
25
26
27
28
29
30
31
# File 'lib/metanorma/asciidoctor_extensions/glob_include_processor.rb', line 24

def process(_doc, reader, target_glob, attributes)
  Dir[File.join reader.dir, target_glob].sort.reverse_each do |target|
    content = File.readlines target
    content.unshift "" unless attributes["adjoin-option"]
    reader.push_include content, target, target, 1, attributes
  end
  reader
end