Class: Asciidoctor::Acme::Converter

Inherits:
Standoc::Converter
  • Object
show all
Defined in:
lib/asciidoctor/acme/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 =
"acme-standard".freeze
XML_NAMESPACE =
"https://www.metanorma.org/ns/acme".freeze

Instance Method Summary collapse

Instance Method Details

#baselocation(loc) ⇒ Object



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

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

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



149
# File 'lib/asciidoctor/acme/converter.rb', line 149

def blank_method(*args); end

#boilerplate_isodoc(xmldoc) ⇒ Object



167
168
169
170
171
172
173
# File 'lib/asciidoctor/acme/converter.rb', line 167

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

#configurationObject



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

def configuration
  Metanorma::Acme.configuration
end

#docidentifier_cleanup(xmldoc) ⇒ Object



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

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
# File 'lib/asciidoctor/acme/converter.rb', line 97

def doctype(node)
  d = node.attr("doctype")
  unless %w{policy-and-procedures best-practices supporting-document
    report legal directives proposal standard}.include? d
    @log.add("Document Attributes", nil,
             "#{d} is not a legal document type: reverting to 'standard'")
    d = "standard"
  end
  d
end

#document(node) ⇒ Object



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

def document(node)
  read_config_file(node.attr("customize")) if node.attr("customize")
  init(node)
  ret1 = makexml(node)
  ret = ret1.to_xml(indent: 2)
  unless node.attr("nodoc") || !node.attr("docfile")
    filename = node.attr("docfile").gsub(/\.adoc/, ".xml").
      gsub(%r{^.*/}, "")
    File.open(filename, "w") { |f| f.write(ret) }
    html_converter(node).convert filename unless node.attr("nodoc")
    word_converter(node).convert filename unless node.attr("nodoc")
    pdf_converter(node).convert filename unless node.attr("nodoc")
  end
  @log.write(@filename + ".err") unless @novalid
  @files_to_delete.each { |f| FileUtils.rm f }
  ret
end

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



151
152
153
# File 'lib/asciidoctor/acme/converter.rb', line 151

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

#html_path_acme(file) ⇒ Object



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

def html_path_acme(file)
  File.join(File.dirname(__FILE__), File.join("html", file))
end

#makexml(node) ⇒ Object



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

def makexml(node)
  root_tag = configuration.xml_root_tag || XML_ROOT_TAG
  result = ["<?xml version='1.0' encoding='UTF-8'?>\n<#{root_tag}>"]
  @draft = node.attributes.has_key?("draft")
  result << noko { |ixml| front node, ixml }
  result << noko { |ixml| middle node, ixml }
  result << "</#{root_tag}>"
  result = textcleanup(result)
  ret1 = cleanup(Nokogiri::XML(result))
  validate(ret1) unless @novalid
  ret1.root.add_namespace(nil, configuration.document_namespace ||
                          XML_NAMESPACE)
  ret1
end

#metadata_author(node, xml) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/asciidoctor/acme/converter.rb', line 22

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

#metadata_committee(node, xml) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/asciidoctor/acme/converter.rb', line 41

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


70
71
72
73
74
75
76
77
78
79
80
# File 'lib/asciidoctor/acme/converter.rb', line 70

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_short
      end
    end
  end
end

#metadata_id(node, xml) ⇒ Object



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

def (node, xml)
  xml.docidentifier do |i|
    i << "DUMMY"
  end
  xml.docnumber { |i| i << node.attr("docnumber") }
end

#metadata_publisher(node, xml) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/asciidoctor/acme/converter.rb', line 32

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

#read_config_file(path_to_config_file) ⇒ Object



108
109
110
111
# File 'lib/asciidoctor/acme/converter.rb', line 108

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

#sections_cleanup(x) ⇒ Object



142
143
144
145
146
147
# File 'lib/asciidoctor/acme/converter.rb', line 142

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

#validate(doc) ⇒ Object



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

def validate(doc)
  content_validate(doc)
  schema_validate(formattedstr_strip(doc.dup),
                  baselocation(configuration.validate_rng_file) ||
                  File.join(File.dirname(__FILE__), "acme.rng"))
end

#word_converter(node) ⇒ Object



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

def word_converter(node)
  IsoDoc::Acme::WordConvert.new(doc_extract_attributes(node))
end