Module: Metanorma::Core::Isodoc
- Defined in:
- lib/metanorma/core/isodoc.rb
Overview
Construction and initialisation of an isodoc converter instance for a given Metanorma flavor. Two entry points:
-
Isodoc.resolve_converter — pick the right converter class for the flavor + output stage (presentation XML or HTML), instantiate it, and return a fresh, uninitialised converter.
-
Isodoc.init — wire i18n, metadata, and xref state onto an existing converter, returning it ready for use.
Callers usually need both: init(resolve_converter(flavor), …). The collection layer’s Util::isodoc_create is the canonical wrapper around that pair.
Defined Under Namespace
Classes: EmptyNode
Class Method Summary collapse
-
.create(flavor, lang:, script:, locale: nil, i18nyaml: nil, xml: nil, localdir: nil, presxml: true) ⇒ Object
Convenience wrapper combining Isodoc.resolve_converter and Isodoc.init: resolve the converter for
flavorand immediately initialise it with the supplied i18n / metadata kwargs. -
.init(converter, lang:, script:, locale: nil, i18nyaml: nil, xml: nil, localdir: nil) ⇒ Object
Initialise the i18n / metadata / xref state on an existing converter.
-
.resolve_converter(flavor, presxml: true) ⇒ Object
Resolve the right IsoDoc converter for a given Metanorma flavor and output stage, and return a fresh, uninitialised instance of it.
Class Method Details
.create(flavor, lang:, script:, locale: nil, i18nyaml: nil, xml: nil, localdir: nil, presxml: true) ⇒ Object
Convenience wrapper combining resolve_converter and init: resolve the converter for flavor and immediately initialise it with the supplied i18n / metadata kwargs. Most callers want this one-stop helper rather than the two-step form.
123 124 125 126 127 128 |
# File 'lib/metanorma/core/isodoc.rb', line 123 def self.create(flavor, lang:, script:, locale: nil, i18nyaml: nil, xml: nil, localdir: nil, presxml: true) conv = resolve_converter(flavor, presxml: presxml) init(conv, lang: lang, script: script, locale: locale, i18nyaml: i18nyaml, xml: xml, localdir: localdir) end |
.init(converter, lang:, script:, locale: nil, i18nyaml: nil, xml: nil, localdir: nil) ⇒ Object
Initialise the i18n / metadata / xref state on an existing converter. Mutates the converter in place and returns it.
The converter must already implement the standard Metanorma converter contract: #init_i18n, #i18n_init, #metadata_init, #meta, #xref_init, #xrefs, and (optionally) #info.
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/metanorma/core/isodoc.rb', line 60 def self.init(converter, lang:, script:, locale: nil, i18nyaml: nil, xml: nil, localdir: nil) converter.init_i18n(i18nyaml: i18nyaml, language: lang, script: script, locale: locale) i18n = converter.i18n_init(lang, script, locale, i18nyaml) converter.(lang, script, locale, i18n) converter..localdir = localdir if localdir converter.xref_init(lang, script, nil, i18n, {}) converter.xrefs.klass. = converter. converter.xrefs.klass.localdir = localdir if localdir converter.info(xml, nil) if xml converter end |
.resolve_converter(flavor, presxml: true) ⇒ Object
Resolve the right IsoDoc converter for a given Metanorma flavor and output stage, and return a fresh, uninitialised instance of it. The flavor’s gem (e.g. metanorma-iso) is autoloaded via FlavorLoader.load_flavor if it is not already registered.
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/metanorma/core/isodoc.rb', line 89 def self.resolve_converter(flavor, presxml: true) resolved = Metanorma::Core::FlavorLoader.load_flavor(flavor) conv_class = ::Asciidoctor::Converter.for(resolved.to_s) || ::Asciidoctor::Converter.for(resolved) conv_class or raise "No Asciidoctor converter registered for #{resolved}" conv_instance = conv_class.new(resolved.to_s, {}) method_name = presxml ? :presentation_xml_converter : :html_converter conv_instance.respond_to?(method_name) or raise "Flavor #{resolved} does not support " \ "#{presxml ? 'presentation XML' : 'HTML'} conversion" conv_instance.send(method_name, EmptyNode.new) end |