lib/asciidoctor/nist/validate.rb in metanorma-nist-0.0.9 vs lib/asciidoctor/nist/validate.rb in metanorma-nist-0.1.0

- old
+ new

@@ -1,25 +1,71 @@ module Asciidoctor module NIST class Converter < Standoc::Converter - def title_validate(root) + def title_validate(root) nil end - def validate(doc) + def content_validate(doc) + super + bibdata_validate(doc.root) + end + + def bibdata_validate(doc) + doctype_validate(doc) + stage_validate(doc) + substage_validate(doc) + iteration_validate(doc) + series_validate(doc) + end + + def doctype_validate(xmldoc) + doctype = xmldoc&.at("//bibdata/ext/doctype")&.text + %w(standard).include? doctype or + warn "Document Attributes: #{doctype} is not a recognised document type" + end + + def stage_validate(xmldoc) + stage = xmldoc&.at("//bibdata/status/stage")&.text + %w(draft-internal draft-wip draft-prelim draft-public draft-approval + final final-review).include? stage or + warn "Document Attributes: #{stage} is not a recognised stage" + end + + def substage_validate(xmldoc) + substage = xmldoc&.at("//bibdata/status/substage")&.text or return + %w(active retired withdrawn).include? substage or + warn "Document Attributes: #{substage} is not a recognised substage" + end + + def iteration_validate(xmldoc) + iteration = xmldoc&.at("//bibdata/status/iteration")&.text or return + %w(final).include? iteration.downcase or /^\d+$/.match(iteration) or + warn "Document Attributes: #{iteration} is not a recognised iteration" + end + + def series_validate(xmldoc) + series = xmldoc&.at("//bibdata/series/title")&.text or return + found = false + SERIES.each { |_, v| found = true if v == series } + found or + warn "Document Attributes: #{series} is not a recognised series" + end + + def validate(doc) content_validate(doc) schema_validate(formattedstr_strip(doc.dup), File.join(File.dirname(__FILE__), "nist.rng")) end - def introduction_validate(doc) + def introduction_validate(doc) intro = doc.at("//sections/clause/title") intro&.text == "Introduction" or warn "First section of document body should be Introduction, "\ "not #{intro&.text}" end - REF_SECTIONS_TO_VALIDATE = "//references[not(parent::clause)]/title | "\ + REF_SECTIONS_TO_VALIDATE = "//references[not(parent::clause)]/title | "\ "//clause[descendant::references][not(parent::clause)]/title".freeze def section_validate(doc) super introduction_validate(doc)