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
29
# 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



158
159
160
161
# File 'lib/asciidoctor/generic/converter.rb', line 158

def bibdata_validate(doc)
  stage_validate(doc)
  committee_validate(doc)
end

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



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

def blank_method(*args); end

#boilerplate_file(xmldoc) ⇒ Object



217
218
219
220
221
222
223
# File 'lib/asciidoctor/generic/converter.rb', line 217

def boilerplate_file(xmldoc)
  f = configuration.boilerplate
  f.nil? and return super
  f.is_a? String and return baselocation(f)
  f.is_a? Hash and f[@lang] and return baselocation(f[@lang])
  super
end

#boilerplate_isodoc(xmldoc) ⇒ Object



209
210
211
212
213
214
215
# File 'lib/asciidoctor/generic/converter.rb', line 209

def boilerplate_isodoc(xmldoc)
  conv = super
  Metanorma::Generic::Configuration::CONFIG_ATTRS.each do |a|
    conv.i18n.set(a, configuration.send(a))
  end
  conv
end

#committee_validate(xmldoc) ⇒ Object



171
172
173
174
175
176
177
178
# File 'lib/asciidoctor/generic/converter.rb', line 171

def committee_validate(xmldoc)
  committees = Array(configuration&.committees) || return
  committees.empty? and return
  xmldoc.xpath("//bibdata/ext/editorialgroup/committee").each do |c|
    committees.include? c.text or
      @log.add("Document Attributes", nil, "#{c.text} is not a recognised committee")
  end
end

#configurationObject



205
206
207
# File 'lib/asciidoctor/generic/converter.rb', line 205

def configuration
  Metanorma::Generic.configuration
end

#content_validate(doc) ⇒ Object



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

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

#default_publisherObject



31
32
33
# File 'lib/asciidoctor/generic/converter.rb', line 31

def default_publisher
  configuration.organization_name_long
end

#doc_converter(node) ⇒ Object



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

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

#docidentifier_cleanup(xmldoc) ⇒ Object



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

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



97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/asciidoctor/generic/converter.rb', line 97

def doctype(node)
  d = super
  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



129
130
131
132
# File 'lib/asciidoctor/generic/converter.rb', line 129

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

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



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

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

#metadata_committee(node, xml) ⇒ Object



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

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

#metadata_ext(node, ext) ⇒ Object



90
91
92
93
94
95
# File 'lib/asciidoctor/generic/converter.rb', line 90

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



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

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

#metadata_status(node, xml) ⇒ Object



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

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

#org_abbrevObject



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/asciidoctor/generic/converter.rb', line 35

def org_abbrev
  if !configuration.organization_name_long.empty? &&
      !configuration.organization_name_short.empty? &&
      configuration.organization_name_long !=
      configuration.organization_name_short
    { configuration.organization_name_long =>
      configuration.organization_name_short }
  else
    super
  end
end

#outputs(node, ret) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
# File 'lib/asciidoctor/generic/converter.rb', line 134

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



193
194
195
# File 'lib/asciidoctor/generic/converter.rb', line 193

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

#read_config_file(path_to_config_file) ⇒ Object



110
111
112
113
# File 'lib/asciidoctor/generic/converter.rb', line 110

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

#relaton_relationsObject



47
48
49
# File 'lib/asciidoctor/generic/converter.rb', line 47

def relaton_relations
  Array(configuration.relations) || []
end

#sections_cleanup(x) ⇒ Object



180
181
182
183
184
185
# File 'lib/asciidoctor/generic/converter.rb', line 180

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

#sectiontype_streamline(ret) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/asciidoctor/generic/converter.rb', line 115

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



163
164
165
166
167
168
169
# File 'lib/asciidoctor/generic/converter.rb', line 163

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



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

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