Class: Metanorma::Csa::Converter

Inherits:
Generic::Converter
  • Object
show all
Defined in:
lib/metanorma/csa/converter.rb

Constant Summary collapse

XML_ROOT_TAG =
"csa-standard"
XML_NAMESPACE =
"https://www.metanorma.org/ns/csa"

Instance Method Summary collapse

Instance Method Details

#bibdata_validate(doc) ⇒ Object



68
69
70
71
# File 'lib/metanorma/csa/converter.rb', line 68

def bibdata_validate(doc)
  super
  role_validate(doc)
end

#configurationObject



20
21
22
# File 'lib/metanorma/csa/converter.rb', line 20

def configuration
  Metanorma::Csa.configuration
end

#doc_converter(node) ⇒ Object



97
98
99
# File 'lib/metanorma/csa/converter.rb', line 97

def doc_converter(node)
  IsoDoc::Csa::WordConvert.new(doc_extract_attributes(node))
end

#html_converter(node) ⇒ Object



87
88
89
# File 'lib/metanorma/csa/converter.rb', line 87

def html_converter(node)
  IsoDoc::Csa::HtmlConvert.new(html_extract_attributes(node))
end

#metadata_committee(node, xml) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/metanorma/csa/converter.rb', line 31

def (node, xml)
  return unless node.attr("technical-committee")

  xml.editorialgroup do |a|
    a.committee node.attr("technical-committee"),
                **attr_code(type: node.attr("technical-committee-type"))
    i = 2
    while node.attr("technical-committee_#{i}")
      a.committee node.attr("technical-committee_#{i}"),
                  **attr_code(type: node.attr("technical-committee-type_#{i}"))
      i += 1
    end
  end
end

#outputs(node, ret) ⇒ Object



50
51
52
53
54
55
56
57
58
59
# File 'lib/metanorma/csa/converter.rb', line 50

def outputs(node, ret)
  File.open("#{@filename}.xml", "w:UTF-8") { |f| f.write(ret) }
  presentation_xml_converter(node).convert("#{@filename}.xml")
  html_converter(node).convert("#{@filename}.presentation.xml",
                               nil, false, "#{@filename}.html")
  doc_converter(node).convert("#{@filename}.presentation.xml",
                              nil, false, "#{@filename}.doc")
  pdf_converter(node)&.convert("#{@filename}.presentation.xml",
                               nil, false, "#{@filename}.pdf")
end

#pdf_converter(node) ⇒ Object



91
92
93
94
95
# File 'lib/metanorma/csa/converter.rb', line 91

def pdf_converter(node)
  return if node.attr("no-pdf")

  IsoDoc::Csa::PdfConvert.new(pdf_extract_attributes(node))
end

#personal_role(node, contrib, suffix) ⇒ Object



24
25
26
27
28
29
# File 'lib/metanorma/csa/converter.rb', line 24

def personal_role(node, contrib, suffix)
  role = node.attr("role#{suffix}")&.downcase || "full author"
  contrib.role **{ type: role == "editor" ? "editor" : "author" } do |r|
    r.description role.strip.gsub(/\s/, "-")
  end
end

#presentation_xml_converter(node) ⇒ Object



101
102
103
104
105
# File 'lib/metanorma/csa/converter.rb', line 101

def presentation_xml_converter(node)
  IsoDoc::Csa::PresentationXMLConvert
    .new(doc_extract_attributes(node)
    .merge(output_formats: ::Metanorma::Csa::Processor.new.output_formats))
end

#role_validate(doc) ⇒ Object



73
74
75
76
77
78
79
80
81
# File 'lib/metanorma/csa/converter.rb', line 73

def role_validate(doc)
  doc&.xpath("//bibdata/contributor/role[description]")&.each do |r|
    r["type"] == "author" or next
    role = r.at("./description").text
    %w{full-author contributor staff reviewer}.include?(role) or
      @log.add("Document Attributes", nil,
               "#{role} is not a recognised role")
  end
end

#sections_cleanup(xml) ⇒ Object



61
62
63
64
65
66
# File 'lib/metanorma/csa/converter.rb', line 61

def sections_cleanup(xml)
  super
  xml.xpath("//*[@inline-header]").each do |h|
    h.delete("inline-header")
  end
end

#style(_node, _text) ⇒ Object



83
84
85
# File 'lib/metanorma/csa/converter.rb', line 83

def style(_node, _text)
  nil
end

#title_validate(_root) ⇒ Object



46
47
48
# File 'lib/metanorma/csa/converter.rb', line 46

def title_validate(_root)
  nil
end