Skip to content

Instantly share code, notes, and snippets.

@abelsromero
Created January 21, 2018 09:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abelsromero/4fab85713751aa609fdbbf8337ff97bc to your computer and use it in GitHub Desktop.
Save abelsromero/4fab85713751aa609fdbbf8337ff97bc to your computer and use it in GitHub Desktop.
Asciidoctor extension to include files from several directories defines in a an attribute
class GlobIncludeProcessor < Asciidoctor::Extensions::IncludeProcessor
def process doc, reader, target_glob, attributes
# paths contains absolute paths
paths = doc.attributes['paths'].nil? ? false : doc.attributes['paths'].split(',')
# puts paths
# puts '-------------'
if paths
paths.each do |p|
path = File.join p, target_glob
# puts "Processing: #{path}"
Dir[path, target_glob].sort.reverse_each do |target|
# puts "Files found: #{target}"
content = IO.readlines target
content.unshift '' unless attributes['adjoin-option']
reader.push_include content, target, target, 1, attributes
end
end
# look for files from the Asciidoc file location
elsif
Dir[File.join reader.dir, target_glob].sort.reverse_each do |target|
content = IO.readlines target
content.unshift '' unless attributes['adjoin-option']
reader.push_include content, target, target, 1, attributes
end
end
reader
end
def handles? target
target.include? '*'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment