-
-
Notifications
You must be signed in to change notification settings - Fork 5
Description
Hi, thank you for this nice and clean extension!
Can we make it easier for subclasses to modify the content to be included? I can offer a pull request for it. Which solution would you prefer?
Background:
I wrote the asciidoctor-indir_ext extension based on this extension. My extension adds lines at the beginning and end of included content, based information from the document
and reader
objects.
Problems and Proposed Solutions:
-
Problem A: Overriding
read_lines
seems to be the obvious way to go. But I cannot access thedocument
andreader
objects from within this method. (And I cannot simply set member variables because the include extension gets frozen by asciidoctor; the current implementation of my extension has an ugly workaround for this).- Proposed solution A:
Pass the arguments that were received by theprocess
method to the submethods, for example in a single hash objectprocess_args
to avoid cluttering the method signatures:def process(document, reader, target, attributes) process_args = { 'document': document, 'reader': reader, 'target': target, 'attributes': attributes } # ... lines = read_lines(path, selector, process_args)
- Proposed solution A:
-
Problem B: Overriding
process
instead ofread_lines
would allow my extension to access thedocument
andreader
objects, but would need a lot of code duplication. To ease overriding, it would be better if the method was split into smaller methods and/or if it included a methodpreprocess_lines
that could be overridden by subclasses.- Proposed solution B: Add and call an additional method
As shown above, the
def preprocess_lines (lines, process_args) return lines
preprocess_lines
method can simply be implemented as identity function in asciidoctor-indir_ext, allowing subclasses to override the method.
- Proposed solution B: Add and call an additional method
Personally, I think solution A would be the most simple and elegant.