Posted by
1marc1 on
Dec 25, 2018; 1:00pm
URL: https://discuss.asciidoctor.org/Exploring-extensions-tp6659.html
Hi Team,
I have started to do some exploring of extensions. I am using asciidoctor-pdf and have given myself the task to add the keyword "green" to the general properties of a PDF file. The idea is that the extension will force the keyword "green" to be at the start of the list of keywords. I have written the following extension, but I am not getting the desired results.
require 'asciidoctor-pdf' unless defined? ::Asciidoctor::Pdf
module CustomKeyword
def build_pdf_info doc
info = {}
super
info[:Keywords] = 'green'
info
end
end
class Asciidoctor::Pdf::Converter
prepend CustomKeyword
end
I haven't yet figured out how to place "green" at the beginning of the list of keywords, so I though to start with simply setting the entire keyword list to "green".
The result of the extension above is that the keyword "green" indeed shows up in the general properties of the resulting .PDF file, however, all other details, like author, subject, producer, etc. are missing.
I guess I don't quite understand yet how the extension interacts with the code from converter.rb and what the effect of the "super" command is. For example, I also experimented with leaving the "info = {}" line out of the extension, figuring that this would exist upon return from the "super" command. The result of this is an error saying:
undefined local variable or method `info'
, which leads me to believe that the `info` variable is not available to my extension.
Is there a place where these things are documented, perhaps in a step by step guide? I have spent quite a bit of time looking for this information, including looking through various existing extensions for examples, but I am still stuck.
Thank you in advance for any pointers.
Marc.