lib/asciidoctor/generic/converter.rb in metanorma-generic-1.4.7 vs lib/asciidoctor/generic/converter.rb in metanorma-generic-1.4.8

- old
+ new

@@ -29,21 +29,21 @@ def metadata_author(node, xml) xml.contributor do |c| c.role **{ type: "author" } c.organization do |a| - a.name configuration.organization_name_short + a.name configuration.organization_name_long end end personal_author(node, xml) end def metadata_publisher(node, xml) xml.contributor do |c| c.role **{ type: "publisher" } c.organization do |a| - a.name configuration.organization_name_short + a.name configuration.organization_name_long end end end def metadata_committee(node, xml) @@ -58,20 +58,30 @@ i += 1 end end end + def metadata_status(node, xml) + xml.status do |s| + s.stage ( node.attr("status") || node.attr("docstage") || + configuration.default_stage || "published" ) + x = node.attr("substage") and s.substage x + x = node.attr("iteration") and s.iteration x + end + end + def docidentifier_cleanup(xmldoc) template = configuration.docid_template || "{{ organization_name_short }} {{ docnumeric }}" docid = xmldoc.at("//bibdata/docidentifier") id = boilerplate_isodoc(xmldoc).populate_template(template, nil) id.empty? and docid.remove or docid.children = id end def metadata_id(node, xml) - xml.docidentifier do |i| + xml.docidentifier **{ type: + configuration.organization_name_short } do |i| i << "DUMMY" end xml.docnumber { |i| i << node.attr("docnumber") } end @@ -79,11 +89,11 @@ from = node.attr("copyright-year") || Date.today.year xml.copyright do |c| c.from from c.owner do |owner| owner.organization do |o| - o.name configuration.organization_name_short + o.name configuration.organization_name_long end end end end @@ -92,44 +102,42 @@ Array(configuration.metadata_extensions).each do |e| a = node.attr(e) and ext.send e, a end end -=begin - def makexml(node) - #root_tag = configuration.xml_root_tag || XML_ROOT_TAG - root_tag = XML_ROOT_TAG - result = ["<?xml version='1.0' encoding='UTF-8'?>\n<#{root_tag}>"] - @draft = node.attributes.has_key?("draft") - result << noko { |ixml| front node, ixml } - result << noko { |ixml| middle node, ixml } - result << "</#{root_tag}>" - result = textcleanup(result) - ret1 = cleanup(Nokogiri::XML(result)) - validate(ret1) unless @novalid - ret1.root.add_namespace(nil, configuration.document_namespace || - XML_NAMESPACE) - ret1 - end -=end - def doctype(node) d = node.attr("doctype") - unless %w{policy-and-procedures best-practices supporting-document - report legal directives proposal standard}.include? d + configuration.doctypes or return d == "article" ? "standard" : d + default = configuration.default_doctype || Array(configuration.doctypes).dig(0) || + "standard" + unless Array(configuration.doctypes).include? d @log.add("Document Attributes", nil, - "#{d} is not a legal document type: reverting to 'standard'") - d = "standard" + "#{d} is not a legal document type: reverting to '#{default}'") + d = default end d end def read_config_file(path_to_config_file) Metanorma::Generic.configuration. set_default_values_from_yaml_file(path_to_config_file) end + def sectiontype_streamline(ret) + if configuration.termsdefs_titles.map(&:downcase).include? (ret) + "terms and definitions" + elsif configuration.symbols_titles.map(&:downcase).include? (ret) + "symbols and abbreviated terms" + elsif configuration.normref_titles.map(&:downcase).include? (ret) + "normative references" + elsif configuration.bibliography_titles.map(&:downcase).include? (ret) + "bibliography" + else + ret + end + end + def document(node) read_config_file(node.attr("customize")) if node.attr("customize") init(node) ret1 = makexml(node) ret = ret1.to_xml(indent: 2) @@ -149,9 +157,26 @@ def validate(doc) content_validate(doc) schema_validate(formattedstr_strip(doc.dup), baselocation(configuration.validate_rng_file) || File.join(File.dirname(__FILE__), "generic.rng")) + end + + def content_validate(doc) + super + bibdata_validate(doc.root) + end + + def bibdata_validate(doc) + stage_validate(doc) + end + + def stage_validate(xmldoc) + stages = configuration&.stage_abbreviations&.keys || return + stages.empty? and return + stage = xmldoc&.at("//bibdata/status/stage")&.text + stages.include? stage or + @log.add("Document Attributes", nil, "#{stage} is not a recognised status") end def sections_cleanup(x) super x.xpath("//*[@inline-header]").each do |h|