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
- #sections_cleanup(xml) ⇒ Object
Instance Method Details
#bibdata_hash(xmldoc) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# 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! 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
34 35 36 37 38 39 40 |
# File 'lib/metanorma/generic/cleanup.rb', line 34 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
47 48 49 |
# File 'lib/metanorma/generic/cleanup.rb', line 47 def configuration @conv.configuration end |
#published?(status, _xmldoc) ⇒ Boolean
42 43 44 45 |
# File 'lib/metanorma/generic/cleanup.rb', line 42 def published?(status, _xmldoc) stages = configuration&.published_stages || ["published"] (Array(stages).map(&:downcase).include? status.downcase) 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 |