Class: Metanorma::AsciidoctorExtensions::GlobIncludeProcessor
- Inherits:
-
Asciidoctor::Extensions::IncludeProcessor
- Object
- Asciidoctor::Extensions::IncludeProcessor
- Metanorma::AsciidoctorExtensions::GlobIncludeProcessor
- 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.
Instance Method Summary collapse
-
#handles?(target) ⇒ Boolean
Whether this processor handles the given include
target. -
#process(_doc, reader, target_glob, attributes) ⇒ Asciidoctor::Reader
The reader, mutated in place.
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.
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.
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 |