class Asciidoctor::IndirExt::IndirIncludeProcessor
Asciidoctor
extension that adds a variable “indir”, pointing at the directory of included asciidoc files.
Public Class Methods
new(*args, &block)
click to toggle source
Calls superclass method
# File lib/asciidoctor/indir_ext/extension.rb, line 8 def initialize(*args, &block) # temporary storage helper that won't be frozen by Asciidoctor @tmp = { } super end
Public Instance Methods
process(document, reader, target, attributes)
click to toggle source
Calls superclass method
# File lib/asciidoctor/indir_ext/extension.rb, line 14 def process(document, reader, target, attributes) @tmp[:document] = document @tmp[:reader] = reader super end
read_lines(filename, selector)
click to toggle source
Calls superclass method
# File lib/asciidoctor/indir_ext/extension.rb, line 20 def read_lines(filename, selector) # read content using functionality from super content = super(filename, selector) # Ignore non-asciidoc files if not ['.asciidoc', '.adoc', '.ad', '.asc', '.txt'].include? File.extname(filename) then return content end # split content into a list of lines if it has been provided as string if content.is_a? String then content = content.lines end # Set variables at the beginning of the included content included_docfile = filename included_docdir = ::File.dirname filename content.unshift '' content.unshift %(:indir: #{included_docdir}) # Reset the variables at the end of the included content parent_docfile = @tmp[:reader].include_stack&.dig(-1, 1) || (@tmp[:document].attr 'docfile') parent_docdir = ::File.dirname parent_docfile content << '' content << %(:indir: #{parent_docdir}) return content end