Module: Asciidoctor::Standoc::Front

Included in:
Converter
Defined in:
lib/asciidoctor/standoc/front.rb

Constant Summary collapse

DATETYPES =
%w{ published accessed created implemented obsoleted
                confirmed updated issued circulated unchanged received
}.freeze

Instance Method Summary collapse

Instance Method Details

#asciidoc_sub(x) ⇒ Object



155
156
157
158
159
160
161
# File 'lib/asciidoctor/standoc/front.rb', line 155

def asciidoc_sub(x)
  return nil if x.nil?
  return "" if x.empty?
  d = Asciidoctor::Document.new(x.lines.entries, {header_footer: false})
  b = d.parse.blocks.first
  b.apply_subs(b.source)
end

#committee_component(compname, node, out) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/asciidoctor/standoc/front.rb', line 29

def committee_component(compname, node, out)
  out.send compname.gsub(/-/, "_"), node.attr(compname),
    **attr_code(number: node.attr("#{compname}-number"),
                type: node.attr("#{compname}-type"))
  i = 2
  while node.attr(compname+"_#{i}") do
    out.send compname.gsub(/-/, "_"), node.attr(compname+"_#{i}"),
      **attr_code(number: node.attr("#{compname}-number_#{i}"),
                  type: node.attr("#{compname}-type_#{i}"))
    i += 1
  end
end

#metadata(node, xml) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/asciidoctor/standoc/front.rb', line 139

def (node, xml)
  title node, xml
  (node, xml)
  (node, xml)
  (node, xml)
  (node, xml)
  (node, xml)
  (node, xml)
  (node, xml)
  (node, xml)
  (node, xml)
  (node, xml)
  (node, xml)
  (node, xml)
end

#metadata_author(node, xml) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/asciidoctor/standoc/front.rb', line 46

def (node, xml)
  publishers = node.attr("publisher") || return
  publishers.split(/,[ ]?/).each do |p|
    xml.contributor do |c|
      c.role **{ type: "author" }
      c.organization { |a| organization(a, p) }
    end
  end
end

#metadata_committee(node, xml) ⇒ Object



84
85
86
87
88
# File 'lib/asciidoctor/standoc/front.rb', line 84

def (node, xml)
  xml.editorialgroup do |a|
    committee_component("technical-committee", node, a)
  end
end


66
67
68
69
70
71
72
73
74
75
76
# File 'lib/asciidoctor/standoc/front.rb', line 66

def (node, xml)
  publishers = node.attr("publisher") || " "
  publishers.split(/,[ ]?/).each do |p|
    xml.copyright do |c|
      c.from (node.attr("copyright-year") || Date.today.year)
      p.match(/[A-Za-z]/).nil? or c.owner do |owner|
        owner.organization { |o| organization(o, p) }
      end
    end
  end
end

#metadata_date(node, xml) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
# File 'lib/asciidoctor/standoc/front.rb', line 119

def (node, xml)
  DATETYPES.each { |t| (node, xml, t) }
  node.attributes.keys.each do |a|
    next unless a == "date" || /^date_\d+$/.match(a)
    type, date = node.attr(a).split(/ /, 2)
    type or next
    xml.date **{ type: type } do |d|
      d.on date
    end
  end
end

#metadata_date1(node, xml, type) ⇒ Object



108
109
110
111
112
113
# File 'lib/asciidoctor/standoc/front.rb', line 108

def (node, xml, type)
  date = node.attr("#{type}-date")
  date and xml.date **{ type: type } do |d|
    d.on date
  end
end

#metadata_ics(node, xml) ⇒ Object



90
91
92
93
94
95
96
97
# File 'lib/asciidoctor/standoc/front.rb', line 90

def (node, xml)
  ics = node.attr("library-ics")
  ics && ics.split(/,\s*/).each do |i|
    xml.ics do |ics|
      ics.code i
    end
  end
end

#metadata_id(node, xml) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/asciidoctor/standoc/front.rb', line 12

def (node, xml)
  part, subpart = node&.attr("partnumber")&.split(/-/)
  id = node.attr("docnumber") || ""
  id += "-#{part}" if part
  id += "-#{subpart}" if subpart
  xml.docidentifier id
  xml.docnumber node.attr("docnumber")
end

#metadata_language(node, xml) ⇒ Object



131
132
133
# File 'lib/asciidoctor/standoc/front.rb', line 131

def (node, xml)
  xml.language (node.attr("language") || "en")
end

#metadata_publisher(node, xml) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/asciidoctor/standoc/front.rb', line 56

def (node, xml)
  publishers = node.attr("publisher") || return
  publishers.split(/,[ ]?/).each do |p|
    xml.contributor do |c|
      c.role **{ type: "publisher" }
      c.organization { |a| organization(a, p) }
    end
  end
end

#metadata_script(node, xml) ⇒ Object



135
136
137
# File 'lib/asciidoctor/standoc/front.rb', line 135

def (node, xml)
  xml.script (node.attr("script") || "Latn")
end

#metadata_source(node, xml) ⇒ Object



99
100
101
102
103
104
105
106
# File 'lib/asciidoctor/standoc/front.rb', line 99

def (node, xml)
  node.attr("uri") && xml.source(node.attr("uri"))
  node.attr("xml-uri") && xml.source(node.attr("xml-uri"), type: "xml")
  node.attr("html-uri") && xml.source(node.attr("html-uri"), type: "html")
  node.attr("pdf-uri") && xml.source(node.attr("pdf-uri"), type: "pdf")
  node.attr("doc-uri") && xml.source(node.attr("doc-uri"), type: "doc")
  node.attr("relaton-uri") && xml.source(node.attr("relaton-uri"), type: "relaton")
end

#metadata_status(node, xml) ⇒ Object



78
79
80
81
82
# File 'lib/asciidoctor/standoc/front.rb', line 78

def (node, xml)
  xml.status(**{ format: "plain" }) do |s|
    s << ( node.attr("status") || "published" )
  end
end

#metadata_version(node, xml) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/asciidoctor/standoc/front.rb', line 21

def (node, xml)
  xml.edition node.attr("edition") if node.attr("edition")
  xml.version do |v|
    v.revision_date node.attr("revdate") if node.attr("revdate")
    v.draft node.attr("draft") if node.attr("draft")
  end
end

#organization(org, orgname) ⇒ Object



42
43
44
# File 'lib/asciidoctor/standoc/front.rb', line 42

def organization(org, orgname)
  org.name orgname
end

#title(node, xml) ⇒ Object



163
164
165
166
# File 'lib/asciidoctor/standoc/front.rb', line 163

def title(node, xml)
  title_english(node, xml)
  title_otherlangs(node, xml)
end

#title_english(node, xml) ⇒ Object



168
169
170
171
172
173
174
175
# File 'lib/asciidoctor/standoc/front.rb', line 168

def title_english(node, xml)
  ["en"].each do |lang|
    at = { language: lang, format: "text/plain" }
    xml.title **attr_code(at) do |t|
      t << asciidoc_sub(node.attr("title") || node.attr("title-en") || node.title)
    end
  end
end

#title_otherlangs(node, xml) ⇒ Object



177
178
179
180
181
182
183
# File 'lib/asciidoctor/standoc/front.rb', line 177

def title_otherlangs(node, xml)
  node.attributes.each do |k, v|
    next unless /^title-(?<titlelang>.+)$/ =~ k
    next if titlelang == "en"
    xml.title v, { language: titlelang, format: "text/plain" }
  end
end