metanorma-generic 1.7.0 → 1.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dbd87f79baeb66107643bd3c6e9377853f72f3b19d17615aced5737609ea31e4
4
- data.tar.gz: a1e014a6a7076b4f39c37bcb35d67fecb221ff0494ba38ce88482affb8aef854
3
+ metadata.gz: 2e39cd0bf72f4464ca05b5e8b31964ca9c4394fece3c6bb40cb503fd587ee158
4
+ data.tar.gz: 74b2cb557b05f508b7a6260ba6b0343a8841f660b6adca537ded5584e015a8f1
5
5
  SHA512:
6
- metadata.gz: b26374f517b2c486fd6780a66f05357689990026dab52e88c8f8b9a1aec881653a4f23f915bf5e6944c83ae8fe943046ae42047382c3968a5b1cca11204f5a53
7
- data.tar.gz: 35502f72cf8aa2f3f19848d4fe9326994f8af544531e71da3dabf61215329c164404cfd5d7fab6e72da66f43ae851272ceaf6a1d9fbf6a72fdf15552d6dcd4e6
6
+ metadata.gz: 378e9b3795ffad13435bd584ec35c0d1bdfb25f9be58f9436dc19257066f4d8a0698f8e30456bf8a5be87bcfb232ad0f7978194ce794c9d01998888bf1973116
7
+ data.tar.gz: 3a054e05fcc4dc3875935ffc39858ad77568861a8517d450171376bcb02155a697af73493edc42257e15a632cdc629be8723857417d35f0c72d54eb809bb1786
@@ -1,13 +1,10 @@
1
1
  require "asciidoctor"
2
2
  require "asciidoctor/standoc/converter"
3
3
  require "fileutils"
4
+ require_relative "front"
4
5
 
5
6
  module Asciidoctor
6
7
  module Generic
7
-
8
- # A {Converter} implementation that generates RSD output, and a document
9
- # schema encapsulation of the document for validation
10
- #
11
8
  class Converter < Standoc::Converter
12
9
  XML_ROOT_TAG = "generic-standard".freeze
13
10
  XML_NAMESPACE = "https://www.metanorma.org/ns/generic".freeze
@@ -28,49 +25,6 @@ module Asciidoctor
28
25
  self.class::_file || __FILE__), "..", "..", "..", loc))
29
26
  end
30
27
 
31
- def default_publisher
32
- configuration.organization_name_long
33
- end
34
-
35
- def org_abbrev
36
- if !configuration.organization_name_long.empty? &&
37
- !configuration.organization_name_short.empty? &&
38
- configuration.organization_name_long !=
39
- configuration.organization_name_short
40
- { configuration.organization_name_long =>
41
- configuration.organization_name_short }
42
- else
43
- super
44
- end
45
- end
46
-
47
- def relaton_relations
48
- Array(configuration.relations) || []
49
- end
50
-
51
- def metadata_committee(node, xml)
52
- return unless node.attr("committee")
53
- xml.editorialgroup do |a|
54
- a.committee node.attr("committee"),
55
- **attr_code(type: node.attr("committee-type"))
56
- i = 2
57
- while node.attr("committee_#{i}") do
58
- a.committee node.attr("committee_#{i}"),
59
- **attr_code(type: node.attr("committee-type_#{i}"))
60
- i += 1
61
- end
62
- end
63
- end
64
-
65
- def metadata_status(node, xml)
66
- xml.status do |s|
67
- s.stage ( node.attr("status") || node.attr("docstage") ||
68
- configuration.default_stage || "published" )
69
- x = node.attr("substage") and s.substage x
70
- x = node.attr("iteration") and s.iteration x
71
- end
72
- end
73
-
74
28
  def docidentifier_cleanup(xmldoc)
75
29
  template = configuration.docid_template ||
76
30
  "{{ organization_name_short }} {{ docnumeric }}"
@@ -79,30 +33,15 @@ module Asciidoctor
79
33
  id.empty? and docid.remove or docid.children = id
80
34
  end
81
35
 
82
- def metadata_id(node, xml)
83
- xml.docidentifier **{ type:
84
- configuration.organization_name_short } do |i|
85
- i << "DUMMY"
86
- end
87
- xml.docnumber { |i| i << node.attr("docnumber") }
88
- end
89
-
90
- def metadata_ext(node, ext)
91
- super
92
- Array(configuration.metadata_extensions).each do |e|
93
- a = node.attr(e) and ext.send e, a
94
- end
95
- end
96
-
97
36
  def doctype(node)
98
37
  d = super
99
38
  configuration.doctypes or return d == "article" ? "standard" : d
100
- default = configuration.default_doctype || Array(configuration.doctypes).dig(0) ||
101
- "standard"
39
+ type = configuration.default_doctype ||
40
+ Array(configuration.doctypes).dig(0) || "standard"
102
41
  unless Array(configuration.doctypes).include? d
103
42
  @log.add("Document Attributes", nil,
104
- "#{d} is not a legal document type: reverting to '#{default}'")
105
- d = default
43
+ "#{d} is not a legal document type: reverting to '#{type}'")
44
+ d = type
106
45
  end
107
46
  d
108
47
  end
@@ -113,13 +52,13 @@ module Asciidoctor
113
52
  end
114
53
 
115
54
  def sectiontype_streamline(ret)
116
- if configuration.termsdefs_titles.map(&:downcase).include? (ret)
55
+ if configuration&.termsdefs_titles&.map(&:downcase)&.include? (ret)
117
56
  "terms and definitions"
118
- elsif configuration.symbols_titles.map(&:downcase).include? (ret)
57
+ elsif configuration&.symbols_titles&.map(&:downcase)&.include? (ret)
119
58
  "symbols and abbreviated terms"
120
- elsif configuration.normref_titles.map(&:downcase).include? (ret)
59
+ elsif configuration&.normref_titles&.map(&:downcase)&.include? (ret)
121
60
  "normative references"
122
- elsif configuration.bibliography_titles.map(&:downcase).include? (ret)
61
+ elsif configuration&.bibliography_titles&.map(&:downcase)&.include? (ret)
123
62
  "bibliography"
124
63
  else
125
64
  ret
@@ -135,9 +74,9 @@ module Asciidoctor
135
74
  File.open(@filename + ".xml", "w:UTF-8") { |f| f.write(ret) }
136
75
  presentation_xml_converter(node)&.convert(@filename + ".xml")
137
76
  html_converter(node)&.convert(@filename + ".presentation.xml",
138
- nil, false, "#{@filename}.html")
77
+ nil, false, "#{@filename}.html")
139
78
  doc_converter(node)&.convert(@filename + ".presentation.xml",
140
- nil, false, "#{@filename}.doc")
79
+ nil, false, "#{@filename}.doc")
141
80
  pdf_converter(node)&.convert(@filename + ".presentation.xml",
142
81
  nil, false, "#{@filename}.pdf")
143
82
 
@@ -221,6 +160,18 @@ module Asciidoctor
221
160
  f.is_a? Hash and f[@lang] and return baselocation(f[@lang])
222
161
  super
223
162
  end
163
+
164
+ def cleanup(xmldoc)
165
+ super
166
+ empty_metadata_cleanup(xmldoc)
167
+ xmldoc
168
+ end
169
+
170
+ def empty_metadata_cleanup(xmldoc)
171
+ xmldoc.xpath("//bibdata/ext//*").each do |x|
172
+ x.remove if x.children.empty?
173
+ end
174
+ end
224
175
  end
225
176
  end
226
177
  end
@@ -0,0 +1,103 @@
1
+ module Asciidoctor
2
+ module Generic
3
+ class Converter < Standoc::Converter
4
+ def default_publisher
5
+ configuration.organization_name_long
6
+ end
7
+
8
+ def org_abbrev
9
+ if !configuration.organization_name_long.empty? &&
10
+ !configuration.organization_name_short.empty? &&
11
+ configuration.organization_name_long !=
12
+ configuration.organization_name_short
13
+ { configuration.organization_name_long =>
14
+ configuration.organization_name_short }
15
+ else
16
+ super
17
+ end
18
+ end
19
+
20
+ def relaton_relations
21
+ Array(configuration.relations) || []
22
+ end
23
+
24
+ def metadata_committee(node, xml)
25
+ return unless node.attr("committee")
26
+ xml.editorialgroup do |a|
27
+ a.committee node.attr("committee"),
28
+ **attr_code(type: node.attr("committee-type"))
29
+ i = 2
30
+ while node.attr("committee_#{i}") do
31
+ a.committee node.attr("committee_#{i}"),
32
+ **attr_code(type: node.attr("committee-type_#{i}"))
33
+ i += 1
34
+ end
35
+ end
36
+ end
37
+
38
+ def metadata_status(node, xml)
39
+ xml.status do |s|
40
+ s.stage ( node.attr("status") || node.attr("docstage") ||
41
+ configuration.default_stage || "published" )
42
+ x = node.attr("substage") and s.substage x
43
+ x = node.attr("iteration") and s.iteration x
44
+ end
45
+ end
46
+
47
+ def metadata_id(node, xml)
48
+ xml.docidentifier **{ type:
49
+ configuration.organization_name_short } do |i|
50
+ i << "DUMMY"
51
+ end
52
+ xml.docnumber { |i| i << node.attr("docnumber") }
53
+ end
54
+
55
+ def metadata_ext(node, ext)
56
+ super
57
+ if configuration.metadata_extensions.is_a? Hash
58
+ metadata_ext_hash(node, ext, configuration.metadata_extensions)
59
+ else
60
+ Array(configuration.metadata_extensions).each do |e|
61
+ a = node.attr(e) and ext.send e, a
62
+ end
63
+ end
64
+ end
65
+
66
+ EXT_STRUCT = %w(_output _attribute _list).freeze
67
+
68
+ def metadata_ext_hash(node, ext, hash)
69
+ hash.each do |k, v|
70
+ next if EXT_STRUCT.include?(k) || !v&.is_a?(Hash) && !node.attr(k)
71
+ if v&.is_a?(Hash) && v["_list"]
72
+ csv_split(node.attr(k)).each do |val|
73
+ metadata_ext_hash1(k, val, ext, v, node)
74
+ end
75
+ else
76
+ metadata_ext_hash1(k, node.attr(k), ext, v, node)
77
+ end
78
+ end
79
+ end
80
+
81
+ def metadata_ext_hash1(key, value, ext, hash, node)
82
+ return if hash&.is_a?(Hash) && hash["_attribute"]
83
+ is_hash = hash&.is_a?(Hash) &&
84
+ !hash.keys.reject { |n| EXT_STRUCT.include?(n) }.empty?
85
+ return if !is_hash && (value.nil? || value.empty?)
86
+ name = hash&.is_a?(Hash) ? (hash["_output"] || key) : key
87
+ ext.send name, **attr_code(metadata_ext_attrs(hash, node)) do |e|
88
+ is_hash ? metadata_ext_hash(node, e, hash) : (e << value)
89
+ end
90
+ end
91
+
92
+ def metadata_ext_attrs(hash, node)
93
+ return {} unless hash.is_a?(Hash)
94
+ ret = {}
95
+ hash.each do |k, v|
96
+ next unless v.is_a?(Hash) && v["_attribute"]
97
+ ret[(v["_output"] || k).to_sym] = node.attr(k)
98
+ end
99
+ ret
100
+ end
101
+ end
102
+ end
103
+ end
@@ -42,7 +42,6 @@
42
42
  </define>
43
43
  <define name="xref">
44
44
  <element name="xref">
45
- <!-- attribute target { xsd:IDREF }, -->
46
45
  <attribute name="target">
47
46
  <data type="string">
48
47
  <param name="pattern">\i\c*|\c+#\c+</param>
@@ -1,7 +1,30 @@
1
1
  require "isodoc"
2
+ require "nokogiri"
2
3
  require_relative "init"
3
4
  require_relative "utils"
4
5
 
6
+ class Nokogiri::XML::Node
7
+ TYPENAMES = {1=>'element',2=>'attribute',3=>'text',4=>'cdata',8=>'comment'}
8
+ def to_hash
9
+ ret = {kind:TYPENAMES[node_type],name:name}.tap do |h|
10
+ h.merge! text:text&.strip
11
+ a = attribute_nodes.map(&:to_hash)
12
+ if element? && !a.empty?
13
+ h.merge! attr: a.inject({}) { |m, v| m[v[:name]] = v[:text]; m }
14
+ end
15
+ c = children.map(&:to_hash)
16
+ if element? && !(c&.size == 1 && c[0][:kind] == "text")
17
+ h.merge! kids: c.delete_if { |n| n[:kind] == "text" && n[:text].empty? }
18
+ end
19
+ end
20
+ ret
21
+ end
22
+ end
23
+
24
+ class Nokogiri::XML::Document
25
+ def to_hash; root.to_hash; end
26
+ end
27
+
5
28
  module IsoDoc
6
29
  module Generic
7
30
 
@@ -24,20 +47,6 @@ module IsoDoc
24
47
  k._file = caller_locations.first.absolute_path
25
48
  end
26
49
 
27
- =begin
28
- def baselocation(loc)
29
- return nil if loc.nil?
30
- File.expand_path(File.join(File.dirname(
31
- self.class.respond_to?(:_file) ? (self.class::_file || __FILE__) :
32
- __FILE__),
33
- "..", "..", "..", loc))
34
- end
35
-
36
- def configuration
37
- Metanorma::Generic.configuration
38
- end
39
- =end
40
-
41
50
  def author(isoxml, _out)
42
51
  super
43
52
  tc = isoxml.at(ns("//bibdata/ext/editorialgroup/committee"))
@@ -54,11 +63,29 @@ module IsoDoc
54
63
  !(Array(stages).map { |m| m.downcase }.include? status.downcase)
55
64
  end
56
65
 
57
- def ext(isoxml, out)
58
- Array(configuration.metadata_extensions).each do |e|
59
- b = isoxml&.at(ns("//bibdata/ext/#{e}"))&.text or next
60
- set(e.to_sym, b)
66
+ def xmlhash2hash(h)
67
+ ret = {}
68
+ return ret if h.nil? || h[:kind] != "element"
69
+ h[:attr].nil? or h[:attr].each { |k, v| ret["#{h[:name]}_#{k}"] = v }
70
+ ret[h[:name]] = h[:kids] ? xmlhash2hash_kids(h) : h[:text]
71
+ ret
72
+ end
73
+
74
+ def xmlhash2hash_kids(h)
75
+ c = {}
76
+ h[:kids].each do |n|
77
+ xmlhash2hash(n).each do |k1, v1|
78
+ c[k1] = c[k1].nil? ? v1 :
79
+ c[k1].is_a?(Array) ? c[k1] << v1 :
80
+ [c[k1], v1]
81
+ end
61
82
  end
83
+ c
84
+ end
85
+
86
+ def ext(isoxml, out)
87
+ b = isoxml&.at(ns("//bibdata/ext")) or return
88
+ set(:metadata_extensions, xmlhash2hash(b.to_hash)["ext"])
62
89
  end
63
90
 
64
91
  include Utils
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Generic
3
- VERSION = "1.7.0"
3
+ VERSION = "1.7.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-generic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-09-26 00:00:00.000000000 Z
11
+ date: 2020-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: htmlentities
@@ -236,6 +236,7 @@ files:
236
236
  - lib/asciidoctor/generic/basicdoc.rng
237
237
  - lib/asciidoctor/generic/biblio.rng
238
238
  - lib/asciidoctor/generic/converter.rb
239
+ - lib/asciidoctor/generic/front.rb
239
240
  - lib/asciidoctor/generic/generic.rng
240
241
  - lib/asciidoctor/generic/isodoc.rng
241
242
  - lib/asciidoctor/generic/reqt.rng