Class: Asciidoctor::Generic::Converter

Inherits:
Standoc::Converter
  • Object
show all
Defined in:
lib/asciidoctor/generic/converter.rb

Overview

A Converter implementation that generates RSD output, and a document schema encapsulation of the document for validation

Constant Summary collapse

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

Instance Method Summary collapse

Instance Method Details

#baselocation(loc) ⇒ Object



25
26
27
28
# File 'lib/asciidoctor/generic/converter.rb', line 25

def baselocation(loc)
  return nil if loc.nil?
  File.expand_path(File.join(File.dirname(self.class::_file || __FILE__), "..", "..", "..", loc))
end

#bibdata_validate(doc) ⇒ Object



165
166
167
# File 'lib/asciidoctor/generic/converter.rb', line 165

def bibdata_validate(doc)
  stage_validate(doc)
end

#blank_method(*args) ⇒ Object Also known as: style, title_validate



184
# File 'lib/asciidoctor/generic/converter.rb', line 184

def blank_method(*args); end

#boilerplate_isodoc(xmldoc) ⇒ Object



206
207
208
209
210
211
212
# File 'lib/asciidoctor/generic/converter.rb', line 206

def boilerplate_isodoc(xmldoc)
  conv = super
  Metanorma::Generic::Configuration::CONFIG_ATTRS.each do |a|
    conv.labels[a] = configuration.send a
  end
  conv
end

#configurationObject



202
203
204
# File 'lib/asciidoctor/generic/converter.rb', line 202

def configuration
  Metanorma::Generic.configuration
end

#content_validate(doc) ⇒ Object



160
161
162
163
# File 'lib/asciidoctor/generic/converter.rb', line 160

def content_validate(doc)
  super
  bibdata_validate(doc.root)
end

#doc_converter(node) ⇒ Object



198
199
200
# File 'lib/asciidoctor/generic/converter.rb', line 198

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

#docidentifier_cleanup(xmldoc) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/asciidoctor/generic/converter.rb', line 72

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

#doctype(node) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/asciidoctor/generic/converter.rb', line 107

def doctype(node)
  d = node.attr("doctype")
  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 '#{default}'")
    d = default
  end
  d
end

#document(node) ⇒ Object



139
140
141
142
# File 'lib/asciidoctor/generic/converter.rb', line 139

def document(node)
  read_config_file(node.attr("customize")) if node.attr("customize")
  super
end

#html_converter(node) ⇒ Object Also known as: pdf_converter



186
187
188
# File 'lib/asciidoctor/generic/converter.rb', line 186

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

#metadata_author(node, xml) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/asciidoctor/generic/converter.rb', line 30

def (node, xml)
  xml.contributor do |c|
    c.role **{ type: "author" }
    c.organization do |a|
      a.name configuration.organization_name_long
    end
  end
  personal_author(node, xml)
end

#metadata_committee(node, xml) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/asciidoctor/generic/converter.rb', line 49

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


88
89
90
91
92
93
94
95
96
97
98
# File 'lib/asciidoctor/generic/converter.rb', line 88

def (node, xml)
  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_long
      end
    end
  end
end

#metadata_ext(node, ext) ⇒ Object



100
101
102
103
104
105
# File 'lib/asciidoctor/generic/converter.rb', line 100

def (node, ext)
  super
  Array(configuration.).each do |e|
    a = node.attr(e) and ext.send e, a
  end
end

#metadata_id(node, xml) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/asciidoctor/generic/converter.rb', line 80

def (node, xml)
  xml.docidentifier **{ type:
                        configuration.organization_name_short } do |i|
    i << "DUMMY"
  end
  xml.docnumber { |i| i << node.attr("docnumber") }
end

#metadata_publisher(node, xml) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/asciidoctor/generic/converter.rb', line 40

def (node, xml)
  xml.contributor do |c|
    c.role **{ type: "publisher" }
    c.organization do |a|
      a.name configuration.organization_name_long
    end
  end
end

#metadata_status(node, xml) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/asciidoctor/generic/converter.rb', line 63

def (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

#outputs(node, ret) ⇒ Object



144
145
146
147
148
149
150
151
# File 'lib/asciidoctor/generic/converter.rb', line 144

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

#presentation_xml_converter(node) ⇒ Object



190
191
192
# File 'lib/asciidoctor/generic/converter.rb', line 190

def presentation_xml_converter(node)
  IsoDoc::Generic::PresentationXMLConvert.new(html_extract_attributes(node))
end

#read_config_file(path_to_config_file) ⇒ Object



120
121
122
123
# File 'lib/asciidoctor/generic/converter.rb', line 120

def read_config_file(path_to_config_file)
  Metanorma::Generic.configuration.
    set_default_values_from_yaml_file(path_to_config_file)
end

#sections_cleanup(x) ⇒ Object



177
178
179
180
181
182
# File 'lib/asciidoctor/generic/converter.rb', line 177

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

#sectiontype_streamline(ret) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/asciidoctor/generic/converter.rb', line 125

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

#stage_validate(xmldoc) ⇒ Object



169
170
171
172
173
174
175
# File 'lib/asciidoctor/generic/converter.rb', line 169

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

#validate(doc) ⇒ Object



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

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

#xml_namespaceObject



21
22
23
# File 'lib/asciidoctor/generic/converter.rb', line 21

def xml_namespace
  configuration.document_namespace || XML_NAMESPACE
end

#xml_root_tagObject



17
18
19
# File 'lib/asciidoctor/generic/converter.rb', line 17

def xml_root_tag
  configuration.xml_root_tag || XML_ROOT_TAG
end