Class: Metanorma::Processor
- Inherits:
-
Object
- Object
- Metanorma::Processor
- Defined in:
- lib/metanorma/processor/processor.rb
Overview
Abstract base class for Metanorma flavor processors. Each flavor gem (metanorma-iso, metanorma-itu, etc.) defines a subclass and registers it with Registry; the registry then dispatches input documents to the appropriate processor based on the document’s declared flavor / class.
Subclasses MUST set @short, @input_format, and (if Asciidoctor is the input parser) @asciidoctor_backend in their initialize, and MAY override #output_formats, #use_presentation_xml, #options_preprocess, and #output to customise their output pipeline.
Instance Attribute Summary collapse
-
#asciidoctor_backend ⇒ Symbol?
readonly
Asciidoctor backend symbol used when the processor’s input is Asciidoc (e.g.
:iso,:standoc);nilfor non-Asciidoc inputs. -
#input_format ⇒ Symbol
readonly
Input parser identifier (typically
:asciidoc). -
#short ⇒ Symbol
readonly
Short name registered with the Registry (e.g.
:iso,:itu).
Instance Method Summary collapse
-
#extract_metanorma_options(file) ⇒ Hash
Read metanorma-specific options from the input file’s header via Input::Asciidoc#extract_metanorma_options.
-
#extract_options(file) ⇒ Hash
Read processor-relevant options from the input file’s header via Input::Asciidoc#extract_options, merging in this processor’s
output_formatsfor downstream stages. -
#initialize ⇒ Processor
constructor
A new instance of Processor.
-
#input_to_isodoc(file, filename, options = {}) ⇒ String
Convert an input file to Metanorma semantic XML by routing it through the Input::Asciidoc processor with this processor’s Asciidoctor backend.
-
#options_preprocess(options) ⇒ Hash
Mutate
optionsin place to ensure:output_formatsis set. -
#output(isodoc_node, _inname, outname, _format, _options = {}) ⇒ Integer
Default output-writer: dump the rendered output string to a UTF-8 file.
-
#output_formats ⇒ Hash{Symbol => String}
Mapping of output-format name to file extension.
-
#use_presentation_xml(ext) ⇒ Boolean
Whether the given output extension is downstream of the presentation XML stage (and therefore needs presentation XML generated first).
Constructor Details
#initialize ⇒ Processor
Returns a new instance of Processor.
30 31 32 |
# File 'lib/metanorma/processor/processor.rb', line 30 def initialize raise "This is an abstract class!" end |
Instance Attribute Details
#asciidoctor_backend ⇒ Symbol? (readonly)
Returns Asciidoctor backend symbol used when the processor’s input is Asciidoc (e.g. :iso, :standoc); nil for non-Asciidoc inputs.
27 28 29 |
# File 'lib/metanorma/processor/processor.rb', line 27 def asciidoctor_backend @asciidoctor_backend end |
#input_format ⇒ Symbol (readonly)
Returns input parser identifier (typically :asciidoc).
22 23 24 |
# File 'lib/metanorma/processor/processor.rb', line 22 def input_format @input_format end |
#short ⇒ Symbol (readonly)
Returns short name registered with the Registry (e.g. :iso, :itu).
19 20 21 |
# File 'lib/metanorma/processor/processor.rb', line 19 def short @short end |
Instance Method Details
#extract_metanorma_options(file) ⇒ Hash
Read metanorma-specific options from the input file’s header via Input::Asciidoc#extract_metanorma_options.
121 122 123 |
# File 'lib/metanorma/processor/processor.rb', line 121 def (file) Metanorma::Input::Asciidoc.new.(file) end |
#extract_options(file) ⇒ Hash
Read processor-relevant options from the input file’s header via Input::Asciidoc#extract_options, merging in this processor’s output_formats for downstream stages.
110 111 112 113 |
# File 'lib/metanorma/processor/processor.rb', line 110 def (file) Metanorma::Input::Asciidoc.new.(file) .merge(output_formats: output_formats) end |
#input_to_isodoc(file, filename, options = {}) ⇒ String
Convert an input file to Metanorma semantic XML by routing it through the Input::Asciidoc processor with this processor’s Asciidoctor backend. Override for non-Asciidoc inputs.
57 58 59 60 |
# File 'lib/metanorma/processor/processor.rb', line 57 def input_to_isodoc(file, filename, = {}) Metanorma::Input::Asciidoc.new.process(file, filename, @asciidoctor_backend, ) end |
#options_preprocess(options) ⇒ Hash
Mutate options in place to ensure :output_formats is set. Override to add other flavor-specific defaults.
86 87 88 |
# File 'lib/metanorma/processor/processor.rb', line 86 def () [:output_formats] ||= output_formats end |
#output(isodoc_node, _inname, outname, _format, _options = {}) ⇒ Integer
Default output-writer: dump the rendered output string to a UTF-8 file. Override for binary formats (Word, PDF) that need different post-processing.
100 101 102 |
# File 'lib/metanorma/processor/processor.rb', line 100 def output(isodoc_node, _inname, outname, _format, = {}) File.open(outname, "w:UTF-8") { |f| f.write(isodoc_node) } end |
#output_formats ⇒ Hash{Symbol => String}
Mapping of output-format name to file extension. Subclasses typically extend this with HTML / Word / PDF entries.
38 39 40 41 42 43 44 |
# File 'lib/metanorma/processor/processor.rb', line 38 def output_formats { xml: "xml", presentation: "presentation.xml", rxl: "rxl", } end |
#use_presentation_xml(ext) ⇒ Boolean
Whether the given output extension is downstream of the presentation XML stage (and therefore needs presentation XML generated first). Defaults to true for HTML/Word/PDF. Other formats such as RFC and STS are generated directly from semantic XML
73 74 75 76 77 78 79 |
# File 'lib/metanorma/processor/processor.rb', line 73 def use_presentation_xml(ext) case ext when :html, :doc, :pdf then true else false end end |