Class: Metanorma::Generic::Cleanup
- Inherits:
-
Standoc::Cleanup
- Object
- Standoc::Cleanup
- Metanorma::Generic::Cleanup
- Extended by:
- Forwardable
- Defined in:
- lib/metanorma/generic/cleanup.rb
Instance Method Summary collapse
- #bibdata_hash(xmldoc) ⇒ Object
- #boilerplate_file(xmldoc) ⇒ Object
- #boilerplate_isodoc(xmldoc) ⇒ Object
- #configuration ⇒ Object
- #published?(status, _xmldoc) ⇒ Boolean
-
#refresh_isodoc_bibdata(xmldoc, conv) ⇒ Object
Override standoc’s hook: in addition to re-running isodoc_bibdata_parse, refresh conv.meta with the bibdata_hash now that docidentifiers have been substituted, so downstream consumers (boilerplate Liquid expansion, coverpage interpolation, etc.) see the resolved values.
- #sections_cleanup(xml) ⇒ Object
Instance Method Details
#bibdata_hash(xmldoc) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/metanorma/generic/cleanup.rb', line 23 def bibdata_hash(xmldoc) b = xmldoc.at("//bibdata") || xmldoc.at("//xmlns:bibdata") or return nil stripped = Nokogiri::XML(b.to_xml) stripped.remove_namespaces! # Drop @boilerplate="true" docidentifiers before handing the # bibdata to Relaton::Cli.parse_xml: their content is an # unresolved Liquid template, and recent relaton-iho / # relaton-cc / etc. eagerly call pubid in their docidentifier # content= setter, which crashes on raw Liquid syntax. The # template variables for substitution come from other bibdata # fields (seriesabbr, docnumeric, …), not from the # docidentifier itself, so dropping it here does not affect # what we feed back into isodoc.meta. Substitution still runs # on the original xmldoc via standoc's # docidentifier_boilerplate_isodoc; afterwards # refresh_isodoc_bibdata re-calls bibdata_hash to seed # isodoc.meta with the resolved docidentifier. # See https://github.com/metanorma/metanorma/issues/558. stripped.xpath("//docidentifier[@boilerplate = 'true']").each(&:remove) bib = BibdataConfig.from_xml( "<metanorma>#{stripped.root.to_xml}</metanorma>", ).bibdata or return nil YAML.safe_load(bib.to_yaml, permitted_classes: [Date, Symbol], symbolize_names: true) end |
#boilerplate_file(xmldoc) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/metanorma/generic/cleanup.rb', line 59 def boilerplate_file(xmldoc) f = configuration.boilerplate f.nil? and return super f.is_a? String and return @conv.baselocation(f) f.is_a? Hash and f[@lang] and return @conv.baselocation(f[@lang]) super end |
#boilerplate_isodoc(xmldoc) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/metanorma/generic/cleanup.rb', line 13 def boilerplate_isodoc(xmldoc) conv = super or return nil Metanorma::Generic::Configuration::CONFIG_ATTRS.each do |a| conv..set(a, configuration.send(a)) end conv..set(:bibdata, bibdata_hash(xmldoc)) @isodoc = conv @isodoc end |
#configuration ⇒ Object
72 73 74 |
# File 'lib/metanorma/generic/cleanup.rb', line 72 def configuration @conv.configuration end |
#published?(status, _xmldoc) ⇒ Boolean
67 68 69 70 |
# File 'lib/metanorma/generic/cleanup.rb', line 67 def published?(status, _xmldoc) stages = configuration&.published_stages || ["published"] (Array(stages).map(&:downcase).include? status.downcase) end |
#refresh_isodoc_bibdata(xmldoc, conv) ⇒ Object
Override standoc’s hook: in addition to re-running isodoc_bibdata_parse, refresh conv.meta with the bibdata_hash now that docidentifiers have been substituted, so downstream consumers (boilerplate Liquid expansion, coverpage interpolation, etc.) see the resolved values.
54 55 56 57 |
# File 'lib/metanorma/generic/cleanup.rb', line 54 def refresh_isodoc_bibdata(xmldoc, conv) super conv..set(:bibdata, bibdata_hash(xmldoc)) end |
#sections_cleanup(xml) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/metanorma/generic/cleanup.rb', line 6 def sections_cleanup(xml) super xml.xpath("//*[@inline-header]").each do |h| h.delete("inline-header") end end |