Class: Asciidoctor::Iec::Converter

Inherits:
ISO::Converter
  • Object
show all
Defined in:
lib/asciidoctor/iec/front.rb,
lib/asciidoctor/iec/converter.rb

Constant Summary collapse

STAGE_CODES =
{
  "PNW" => "1000", "ANW" => "2000", "CAN" => "2098", "ACD" => "2099", "CD" => "3020",
  "BWG" => "3092", "A2CD" => "3099", "2CD" => "3520", "3CD" => "3520", "4CD" => "3520",
  "5CD" => "3520", "6CD" => "3520", "7CD" => "3520", "8CD" => "3520", "9CD" => "3520",
  "CDM" => "3591", "A3CD" => "3592", "A4CD" => "3592", "A5CD" => "3592", "A6CD" => "3592",
  "A7CD" => "3592", "A8CD" => "3592", "A9CD" => "3592", "ACDV" => "3599", "CCDV" => "4020",
  "CDVM" => "4091", "NCDV" => "4092", "NADIS" => "4093", "ADIS" => "4099", "ADTR" => "4099",
  "ADTS" => "4099", "RDISH" => "5000", "RFDIS" => "5000", "CDISH" => "5020", "CDPAS" => "5020",
  "CDTR" => "5020", "CDTS" => "5020", "CFDIS" => "5020", "DTRM" => "5092", "DTSM" => "5092",
  "NDTR" => "5092", "NDTS" => "5092", "NFDIS" => "5092", "APUB" => "5099", "BPUB" => "6000",
  "PPUB" => "6060", "RR" => "9092", "AMW" => "9220", "WPUB" => "9599", "DELPUB" => "9960",
  "PWI" => "0000", "NWIP" => "1000", "WD" => "2000", "CDV" => "4000", "FDIS" => "5000",
}.freeze
DOC_STAGE =
{
  "00": "PWI",
  "10": "NWIP",
  "20": "WD",
  "30": "CD",
  "40": "CDV",
  "50": "FDIS",
  "60": "PPUB",
  "90": "RR",
  "92": "AMW",
  "95": "WPUB",
  "99": "DELPUB",
}.freeze
STAGE_ABBRS =
{
  "00" => {"00" => "PWI"},
  "10" => {"00" => "PNW"},
  "20" => {"00" => "ANW", "98" => "CAN", "99" => "ACD"},
  "30" => {"00" => "CD", "20" => "CD", "92" => "BWG", "97" => "MERGED", "98" => "DREJ", "99" => "A2CD"},
  "35" => {"00" => "CD", "20" => "CD", "91" => "CDM", "92" => "ACD", "99" => "ACDV"},
  "40" => {"00" => "CCDV", "20" => "CCDV", "91" => "CDVM", "92" => "NCDV", "93" => "NADIS", 
           "95" => "ADISSB", "99" => "ADIS"},
  "50" => {"00" => "RFDIS", "20" => "CFDIS", "92" => "NFDIS", "95" => "APUBSB", "99" => "APUB"},
  "60" => {"00" => "BPUB", "60" => "PPUB"},
  "90" => {"00" => "RR", "92" => "RR"},
  "92" => {"00" => "AMW", "20" => "AMW"},
  "95" => {"00" => "WPUB", "99" => "WPUB"},
  "99" => {"00" => "DELPUB", "60" => "DELPUB"},
}.freeze
STAGE_NAMES =
{
  "00": "Preliminary work item",
  "10": "New work item proposal",
  "20": "Working draft",
  "30": "Committee draft",
  "35": "Committee draft",
  "40": "Committed draft for vote",
  "50": "Final draft international standard",
  "60": "International standard",
  "90": "Review",
  "92": "Review",
  "95": "Withdrawal",
  "99": "Deleted",
}.freeze
XML_ROOT_TAG =
"iec-standard".freeze
XML_NAMESPACE =
"https://www.metanorma.org/ns/iec".freeze

Instance Method Summary collapse

Instance Method Details

#boilerplate_file(x_orig) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/asciidoctor/iec/converter.rb', line 18

def boilerplate_file(x_orig)
  lang = case x_orig&.at("//bibdata/language")&.text
         when "fr" then "fr"
         else
           "en"
         end
  File.join(@libdir, "iec_intro_#{lang}.xml")
end

#doc_converter(node) ⇒ Object



50
51
52
53
# File 'lib/asciidoctor/iec/converter.rb', line 50

def doc_converter(node)
  node.nil? ? IsoDoc::Iec::WordConvert.new({}) :
    IsoDoc::Iec::WordConvert.new(doc_extract_attributes(node))
end

#doctype_validate(xmldoc) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/asciidoctor/iec/converter.rb', line 27

def doctype_validate(xmldoc)
  doctype = xmldoc&.at("//bibdata/ext/doctype")&.text
  %w(international-standard technical-specification technical-report 
  publicly-available-specification international-workshop-agreement 
  guide interpretation-sheet).include? doctype or
  @log.add("Document Attributes", nil, "#{doctype} is not a recognised document type")
  if function = xmldoc&.at("//bibdata/ext/function")&.text
    %w(emc quality-assurance safety environment).include? function or 
      @log.add("Document Attributes", nil, "#{function} is not a recognised document function")
  end
end

#get_stage(node) ⇒ Object



146
147
148
149
150
151
# File 'lib/asciidoctor/iec/front.rb', line 146

def get_stage(node)
  stage = node.attr("status") || node.attr("docstage") || "60"
  m = /([0-9])CD$/.match(stage) and node.set_attr("iteration", m[1])
  STAGE_CODES[stage] and stage = STAGE_CODES[stage][0..1]
  stage
end

#get_substage(node) ⇒ Object



153
154
155
156
157
158
# File 'lib/asciidoctor/iec/front.rb', line 153

def get_substage(node)
  st = node.attr("status") || node.attr("docstage")
  stage = get_stage(node)
  node.attr("docsubstage") ||
    ( stage == "60" ? "60" : STAGE_CODES[st] ? STAGE_CODES[st][2..3] : "00" )
end

#html_converter(node) ⇒ Object



45
46
47
48
# File 'lib/asciidoctor/iec/converter.rb', line 45

def html_converter(node)
  node.nil? ? IsoDoc::Iec::HtmlConvert.new({}) :
    IsoDoc::Iec::HtmlConvert.new(html_extract_attributes(node))
end

#id_edition_suffix(dn, node) ⇒ Object



47
48
49
50
51
# File 'lib/asciidoctor/iec/front.rb', line 47

def id_edition_suffix(dn, node)
  ed = node.attr("edition") || 1
  dn += " ED #{ed}"
  dn
end

#id_stage_abbr(stage, substage, node) ⇒ Object



160
161
162
163
164
165
# File 'lib/asciidoctor/iec/front.rb', line 160

def id_stage_abbr(stage, substage, node)
  return "" if stage == "60"
  abbr = DOC_STAGE[stage.to_sym] || ""
  abbr = node.attr("iteration") + abbr if node.attr("iteration")
  abbr
end

#image_name_validate(xmldoc) ⇒ Object



101
102
# File 'lib/asciidoctor/iec/converter.rb', line 101

def image_name_validate(xmldoc)
end

#init(node) ⇒ Object



13
14
15
16
# File 'lib/asciidoctor/iec/converter.rb', line 13

def init(node)
  super
  @is_iev = node.attr("docnumber") == "60050"
end

#iso_id(node, xml) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/asciidoctor/iec/front.rb', line 38

def iso_id(node, xml)
  return unless node.attr("docnumber")
  part, subpart = node&.attr("partnumber")&.split(/-/)
  dn = add_id_parts(node.attr("docnumber"), part, subpart)
  dn = id_stage_prefix(dn, node, false)
  dn = id_edition_suffix(dn, node)
  xml.docidentifier dn, **attr_code(type: "ISO")
end

#metadata_author(node, xml) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/asciidoctor/iec/front.rb', line 4

def (node, xml)
  publishers = node.attr("publisher") || "IEC"
  csv_split(publishers)&.each do |p|
    xml.contributor do |c|
      c.role **{ type: "author" }
      c.organization { |a| organization(a, p, node, !node.attr("publisher")) }
    end
  end
end


24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/asciidoctor/iec/front.rb', line 24

def (node, xml)
  publishers = node.attr("copyright-holder") || node.attr("publisher") || "IEC"
  csv_split(publishers)&.each do |p|
    xml.copyright do |c|
      c.from (node.attr("copyright-year") || Date.today.year)
      c.owner do |owner|
        owner.organization do |o|
          organization(o, p, node, !node.attr("copyright-holder") || node.attr("publisher"))
        end
      end
    end
  end
end

#metadata_doctype(node, xml) ⇒ Object



179
180
181
182
183
# File 'lib/asciidoctor/iec/front.rb', line 179

def (node, xml)
  xml.doctype doctype(node)
  xml.horizontal (node.attr("horizontal") || "false")
  a = node.attr("function") and xml.function a
end

#metadata_ext(node, xml) ⇒ Object



189
190
191
192
193
194
195
196
# File 'lib/asciidoctor/iec/front.rb', line 189

def (node, xml)
  super
  a = node.attr("accessibility-color-inside") and xml.accessibility_color_inside a
  a = node.attr("price-code") and xml.price_code a
  a = node.attr("cen-processing") and xml.cen_processing a
  a = node.attr("secretary") and xml.secretary a
  a = node.attr("interest-to-committees") and xml.interest_to_committees a
end

#metadata_publisher(node, xml) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/asciidoctor/iec/front.rb', line 14

def (node, xml)
  publishers = node.attr("publisher") || "IEC"
  csv_split(publishers)&.each do |p|
    xml.contributor do |c|
      c.role **{ type: "publisher" }
      c.organization { |a| organization(a, p, node, !node.attr("publisher")) }
    end
  end
end

#metadata_status(node, xml) ⇒ Object



167
168
169
170
171
172
173
174
175
176
177
# File 'lib/asciidoctor/iec/front.rb', line 167

def (node, xml)
  stage = get_stage(node)
  substage = get_substage(node)
  xml.status do |s|
    s.stage stage, **attr_code(abbreviation: stage_abbr(stage, substage))
    s.substage substage,
      **attr_code(abbreviation: status_abbrev1(stage, substage, node.attr("iteration"), 
                                               doctype(node),node.attr("draft")))
    node.attr("iteration") && (s.iteration node.attr("iteration"))
  end
end

#norm_ref_preface(f) ⇒ Object



66
67
68
69
70
# File 'lib/asciidoctor/iec/converter.rb', line 66

def norm_ref_preface(f)
  return super unless @is_iev
  f.at("./title").next =
    "<p>#{@i18n.norm_empty_pref}</p>"
end

#note(n) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
# File 'lib/asciidoctor/iec/converter.rb', line 84

def note(n)
  if n.title == "Note from TC/SC Officers"
    noko do |xml|
      xml.tc_sc_officers_note do |c|
        wrap_in_para(n, c)
      end
    end.join("\n")
  else
    super
  end
end

#note_cleanup(xmldoc) ⇒ Object



96
97
98
99
# File 'lib/asciidoctor/iec/converter.rb', line 96

def note_cleanup(xmldoc)
  super
  n = xmldoc.at("//tc-sc-officers-note") and xmldoc.at("//bibdata/ext").add_child(n.remove)
end

#pdf_converter(node) ⇒ Object



55
56
57
58
59
# File 'lib/asciidoctor/iec/converter.rb', line 55

def pdf_converter(node)
  return if node.attr("no-pdf")
  node.nil? ? IsoDoc::Iec::PdfConvert.new({}) :
    IsoDoc::Iec::PdfConvert.new(doc_extract_attributes(node))
end

#presentation_xml_converter(node) ⇒ Object



61
62
63
64
# File 'lib/asciidoctor/iec/converter.rb', line 61

def presentation_xml_converter(node)
  node.nil? ? IsoDoc::Iec::PresentationXMLConvert.new({}) :
    IsoDoc::Iec::PresentationXMLConvert.new(doc_extract_attributes(node))
end

#relaton_relationsObject



185
186
187
# File 'lib/asciidoctor/iec/front.rb', line 185

def relaton_relations
  super + %w(obsoletes)
end

#sections_names_cleanup(x) ⇒ Object



79
80
81
82
# File 'lib/asciidoctor/iec/converter.rb', line 79

def sections_names_cleanup(x)
  super
  @is_iev and replace_title(x, "//introduction", @i18n&.introduction_iev)
end

#stage_abbr(stage, substage) ⇒ Object



137
138
139
140
# File 'lib/asciidoctor/iec/front.rb', line 137

def stage_abbr(stage, substage)
  return "PPUB" if stage == "60"
  DOC_STAGE[stage.to_sym] || "??"
end

#stage_name(stage, substage, _doctype, _iteration) ⇒ Object



142
143
144
# File 'lib/asciidoctor/iec/front.rb', line 142

def stage_name(stage, substage, _doctype, _iteration)
  STAGE_NAMES[stage.to_sym]
end

#status_abbrev1(stage, substage, iter, doctype, draft) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/asciidoctor/iec/front.rb', line 112

def status_abbrev1(stage, substage, iter, doctype, draft)
  return "" unless stage
  abbr = STAGE_ABBRS.dig(stage, substage) || "??"
  if stage == "35" && substage == "92"
    iter = (iter.to_i + 1) % "02"
  end
  case doctype
  when "technical-report"
    stage = "ADTR" if stage == "40" && substage == "99"
    stage = "CDTR" if stage == "50" && substage == "20"
    stage = "DTRM" if stage == "50" && substage == "92"
  when "technical-specification"
    stage = "ADTS" if stage == "40" && substage == "99"
    stage = "CDTS" if stage == "50" && substage == "20"
    stage = "DTSM" if stage == "50" && substage == "92"
  when "interpretation-sheet"
    stage = "RDISH" if stage == "50" && substage == "00"
    stage = "CDISH" if stage == "50" && substage == "20"
  when "publicly-available-specification"
    stage = "CDPAS" if stage == "50" && substage == "20"
  end
  abbr = abbr.sub(/CD$/, "#{iter}CD") if iter
  abbr
end

#sts_converter(node) ⇒ Object



76
77
# File 'lib/asciidoctor/iec/converter.rb', line 76

def sts_converter(node)
end

#term_defs_boilerplate(div, source, term, preface, isodoc) ⇒ Object



72
73
74
# File 'lib/asciidoctor/iec/converter.rb', line 72

def term_defs_boilerplate(div, source, term, preface, isodoc)
  return super unless @is_iev
end

#validate(doc) ⇒ Object



39
40
41
42
43
# File 'lib/asciidoctor/iec/converter.rb', line 39

def validate(doc)
  content_validate(doc)
  schema_validate(formattedstr_strip(doc.dup),
                  File.join(File.dirname(__FILE__), "iec.rng"))
end