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



142
143
144
# File 'lib/asciidoctor/generic/converter.rb', line 142

def bibdata_validate(doc)
  stage_validate(doc)
end

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



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

def blank_method(*args); end

#boilerplate_isodoc(xmldoc) ⇒ Object



183
184
185
186
187
188
189
# File 'lib/asciidoctor/generic/converter.rb', line 183

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

#configurationObject



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

def configuration
  Metanorma::Generic.configuration
end

#content_validate(doc) ⇒ Object



137
138
139
140
# File 'lib/asciidoctor/generic/converter.rb', line 137

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



175
176
177
# File 'lib/asciidoctor/generic/converter.rb', line 175

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

#docidentifier_cleanup(xmldoc) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/asciidoctor/generic/converter.rb', line 58

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



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/asciidoctor/generic/converter.rb', line 81

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



113
114
115
116
# File 'lib/asciidoctor/generic/converter.rb', line 113

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

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



163
164
165
# File 'lib/asciidoctor/generic/converter.rb', line 163

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

#metadata_committee(node, xml) ⇒ Object



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

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



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

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



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

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



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

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



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

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



167
168
169
# File 'lib/asciidoctor/generic/converter.rb', line 167

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

#read_config_file(path_to_config_file) ⇒ Object



94
95
96
97
# File 'lib/asciidoctor/generic/converter.rb', line 94

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



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

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

#sectiontype_streamline(ret) ⇒ Object



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

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



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

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



130
131
132
133
134
135
# File 'lib/asciidoctor/generic/converter.rb', line 130

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