Created
January 21, 2018 09:46
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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