metanorma-ietf 2.3.0 → 2.3.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,7 +15,7 @@ require_relative "./init"
15
15
 
16
16
  module IsoDoc::Ietf
17
17
  class RfcConvert < ::IsoDoc::Convert
18
- def convert1(docxml, filename, dir)
18
+ def convert1(docxml, _filename, _dir)
19
19
  @xrefs.parse docxml
20
20
  info docxml, nil
21
21
  xml = noko do |xml|
@@ -51,6 +51,7 @@ module IsoDoc::Ietf
51
51
  def error_parse(node, out)
52
52
  case node.name
53
53
  when "bcp14" then bcp14_parse(node, out)
54
+ when "concept" then concept_parse(node, out)
54
55
  else
55
56
  text = node.to_xml.gsub(/</, "&lt;").gsub(/>/, "&gt;")
56
57
  out.t { |p| p << text }
@@ -59,6 +60,7 @@ module IsoDoc::Ietf
59
60
 
60
61
  def omit_docid_prefix(prefix)
61
62
  return true if prefix == "IETF"
63
+
62
64
  super
63
65
  end
64
66
 
@@ -67,9 +69,9 @@ module IsoDoc::Ietf
67
69
  end
68
70
 
69
71
  def postprocess(result, filename, _dir)
70
- result = from_xhtml(cleanup(to_xhtml(textcleanup(result)))).
71
- sub(/<!DOCTYPE[^>]+>\n/, "").
72
- sub(/(<rfc[^<]+? )lang="[^"]+"/, "\\1")
72
+ result = from_xhtml(cleanup(to_xhtml(textcleanup(result))))
73
+ .sub(/<!DOCTYPE[^>]+>\n/, "")
74
+ .sub(/(<rfc[^<]+? )lang="[^"]+"/, "\\1")
73
75
  File.open(filename, "w:UTF-8") { |f| f.write(result) }
74
76
  schema_validate(filename)
75
77
  @files_to_delete.each { |f| FileUtils.rm_rf f }
@@ -2,7 +2,7 @@ module IsoDoc::Ietf
2
2
  class RfcConvert < ::IsoDoc::Convert
3
3
  def common_rfc_pis(node)
4
4
  rfc_pis = {
5
- artworkdelimiter: node&.at(ns("//pi/artworkdelimiter"))&.text,
5
+ artworkdelimiter: node&.at(ns("//pi/artworkdelimiter"))&.text,
6
6
  artworklines: node&.at(ns("//pi/artworklines"))&.text,
7
7
  authorship: node&.at(ns("//pi/authorship"))&.text,
8
8
  autobreaks: node&.at(ns("//pi/autobreaks"))&.text,
@@ -53,30 +53,32 @@ module IsoDoc::Ietf
53
53
 
54
54
  def rfc_attributes(docxml)
55
55
  t = Time.now.getutc
56
- obs = xpath_comma(docxml.xpath(ns(
57
- "//bibdata/relation[@type = 'obsoletes']/bibitem/docidentifier")))
58
- upd = xpath_comma(docxml.xpath(ns(
59
- "//bibdata/relation[@type = 'updates']/bibitem/docidentifier")))
56
+ obs = xpath_comma(docxml
57
+ .xpath(ns("//bibdata/relation[@type = 'obsoletes']/bibitem/docidentifier")))
58
+ upd = xpath_comma(docxml
59
+ .xpath(ns("//bibdata/relation[@type = 'updates']/bibitem/docidentifier")))
60
60
  {
61
- docName: @meta.get[:doctype] == "Internet Draft" ? @meta.get[:docnumber] : nil,
62
- number: @meta.get[:doctype].casecmp?("rfc") ? @meta.get[:docnumber] : nil,
63
- category: series2category(
64
- docxml&.at(ns("//bibdata/series[@type = 'intended']/title"))&.text),
65
- ipr: docxml&.at(ns("//bibdata/ext/ipr"))&.text,
66
- consensus: docxml&.at(ns("//bibdata/ext/consensus"))&.text,
67
- obsoletes: obs,
68
- updates: upd,
69
- indexInclude: docxml&.at(ns("//bibdata/ext/indexInclude"))&.text,
70
- iprExtract: docxml&.at(ns("//bibdata/ext/iprExtract"))&.text,
71
- sortRefs: docxml&.at(ns("//bibdata/ext/sortRefs"))&.text,
72
- symRefs: docxml&.at(ns("//bibdata/ext/symRefs"))&.text,
73
- tocInclude: docxml&.at(ns("//bibdata/ext/tocInclude"))&.text,
74
- tocDepth: docxml&.at(ns("//bibdata/ext/tocDepth"))&.text,
61
+ docName: @meta.get[:doctype] == "Internet Draft" ? @meta.get[:docnumber] : nil,
62
+ number: @meta.get[:doctype].casecmp?("rfc") ? @meta.get[:docnumber] : nil,
63
+ category: series2category(
64
+ docxml&.at(ns("//bibdata/series[@type = 'intended']/title"))&.text,
65
+ ),
66
+ ipr: docxml&.at(ns("//bibdata/ext/ipr"))&.text,
67
+ consensus: docxml&.at(ns("//bibdata/ext/consensus"))&.text,
68
+ obsoletes: obs,
69
+ updates: upd,
70
+ indexInclude: docxml&.at(ns("//bibdata/ext/indexInclude"))&.text,
71
+ iprExtract: docxml&.at(ns("//bibdata/ext/iprExtract"))&.text,
72
+ sortRefs: docxml&.at(ns("//bibdata/ext/sortRefs"))&.text,
73
+ symRefs: docxml&.at(ns("//bibdata/ext/symRefs"))&.text,
74
+ tocInclude: docxml&.at(ns("//bibdata/ext/tocInclude"))&.text,
75
+ tocDepth: docxml&.at(ns("//bibdata/ext/tocDepth"))&.text,
75
76
  submissionType: docxml&.at(ns(
76
- "//bibdata/series[@type = 'stream']/title"))&.text || "IETF",
77
- 'xml:lang': docxml&.at(ns("//bibdata/language"))&.text,
78
- version: "3",
79
- 'xmlns:xi': "http://www.w3.org/2001/XInclude",
77
+ "//bibdata/series[@type = 'stream']/title",
78
+ ))&.text || "IETF",
79
+ 'xml:lang': docxml&.at(ns("//bibdata/language"))&.text,
80
+ version: "3",
81
+ 'xmlns:xi': "http://www.w3.org/2001/XInclude",
80
82
  }
81
83
  end
82
84
 
@@ -86,7 +88,7 @@ module IsoDoc::Ietf
86
88
  when "informational", "info" then "info"
87
89
  when "experimental", "exp" then "exp"
88
90
  when "bcp" then "bcp"
89
- when "fyi", "info" then "info"
91
+ when "fyi" then "info"
90
92
  when "full-standard" then "std"
91
93
  when "historic" then "historic"
92
94
  else
@@ -96,17 +98,19 @@ module IsoDoc::Ietf
96
98
 
97
99
  def xpath_comma(xpath)
98
100
  return nil if xpath.empty?
99
- xpath.map { |x| x.text }.join(", ")
101
+
102
+ xpath.map(&:text).join(", ")
100
103
  end
101
104
 
102
105
  def make_link(out, isoxml)
103
- links = isoxml.xpath(ns(
104
- "//bibdata/relation[@type = 'includedIn' or @type = 'describedBy' or "\
105
- "@type = 'derivedFrom' or @type = 'instance']")) || return
106
- links.each do |l|
107
- out.link **{ href: l&.at(ns("./bibitem/docidentifier"))&.text,
108
- rel: rel2iana(l["type"]) }
109
- end
106
+ links = isoxml
107
+ .xpath(ns("//bibdata/relation[@type = 'includedIn' or "\
108
+ "@type = 'describedBy' or @type = 'derivedFrom' or "\
109
+ "@type = 'instance']")) || return
110
+ links.each do |l|
111
+ out.link **{ href: l&.at(ns("./bibitem/docidentifier"))&.text,
112
+ rel: rel2iana(l["type"]) }
113
+ end
110
114
  end
111
115
 
112
116
  def rel2iana(type)
@@ -115,7 +119,7 @@ module IsoDoc::Ietf
115
119
  when "describedBy" then "describedby"
116
120
  when "derivedFrom" then "convertedfrom"
117
121
  when "instance" then "alternate"
118
- else
122
+ else
119
123
  "alternate"
120
124
  end
121
125
  end
@@ -133,17 +137,21 @@ module IsoDoc::Ietf
133
137
  end
134
138
  end
135
139
 
136
- def clause_parse_title(node, div, c1, out, _heading_attrs = {})
137
- return unless c1
140
+ def clause_parse_title(_node, div, clause, _out, _heading_attrs = {})
141
+ return unless clause
142
+
138
143
  div.name do |n|
139
- c1&.children&.each { |c2| parse(c2, n) }
144
+ clause&.children&.each { |c2| parse(c2, n) }
140
145
  end
141
146
  end
142
147
 
143
148
  def clause_parse(node, out)
144
149
  return if node.at(ns(".//references"))
145
- out.section **attr_code( anchor: node["id"], numbered: node["numbered"],
146
- removeInRFC: node["removeInRFC"], toc: node["toc"]) do |div|
150
+
151
+ out.section **attr_code(
152
+ anchor: node["id"], numbered: node["numbered"],
153
+ removeInRFC: node["removeInRFC"], toc: node["toc"]
154
+ ) do |div|
147
155
  clause_parse_title(node, div, node.at(ns("./title")), out)
148
156
  node.children.reject { |c1| c1.name == "title" }.each do |c1|
149
157
  parse(c1, div)
@@ -152,11 +160,12 @@ module IsoDoc::Ietf
152
160
  end
153
161
 
154
162
  def clause(isoxml, out)
155
- isoxml.xpath("//xmlns:preface/child::*[not(name() = 'abstract' or name() = 'foreword')] "\
163
+ isoxml.xpath("//xmlns:preface/child::*"\
164
+ "[not(name() = 'abstract' or name() = 'foreword')] "\
156
165
  "| //xmlns:sections/child::*").each do |c|
157
- #cdup = c.dup
158
- #cdup.xpath(ns(".//references")).each { |r| r.remove }
159
- #cdup.at("./*[local-name() != 'title'][normalize-space(text()) != '']") or next
166
+ # cdup = c.dup
167
+ # cdup.xpath(ns(".//references")).each { |r| r.remove }
168
+ # cdup.at("./*[local-name() != 'title'][normalize-space(text()) != '']") or next
160
169
  clause_parse(c, out)
161
170
  end
162
171
  end
@@ -1,6 +1,5 @@
1
1
  module IsoDoc::Ietf
2
2
  class RfcConvert < ::IsoDoc::Convert
3
-
4
3
  def definition_parse(node, out)
5
4
  node.children.each { |n| parse(n, out) }
6
5
  end
@@ -46,7 +45,19 @@ module IsoDoc::Ietf
46
45
  clause_parse(node, out)
47
46
  end
48
47
 
49
- def termdocsource_parse(_node, _out)
48
+ def termdocsource_parse(_node, _out); end
49
+
50
+ def concept_parse(node, out)
51
+ if d = node.at(ns("./renderterm"))
52
+ out.em do |em|
53
+ d.children.each { |n| parse(n, em) }
54
+ end
55
+ out << " "
56
+ end
57
+ out << "[term defined in "
58
+ r = node.at(ns("./xref | ./eref | ./termref"))
59
+ parse(r, out)
60
+ out << "]"
50
61
  end
51
62
  end
52
63
  end
@@ -1,11 +1,14 @@
1
1
  require "metanorma/processor"
2
2
  require "tempfile"
3
3
 
4
+ require "isodoc/ietf/rfc_convert"
5
+
4
6
  module Metanorma
5
7
  module Ietf
6
- class Processor < Metanorma::Processor
8
+ RfcConvert = ::IsoDoc::Ietf::RfcConvert
7
9
 
8
- def initialize
10
+ class Processor < Metanorma::Processor
11
+ def initialize # rubocop:disable Lint/MissingSuper
9
12
  @short = :ietf
10
13
  @input_format = :asciidoc
11
14
  @asciidoctor_backend = :ietf
@@ -18,7 +21,7 @@ module Metanorma
18
21
  rfc: "rfc.xml",
19
22
  html: "html",
20
23
  txt: "txt",
21
- pdf: "pdf"
24
+ pdf: "pdf",
22
25
  }
23
26
  end
24
27
 
@@ -26,15 +29,15 @@ module Metanorma
26
29
  "Metanorma::Ietf #{::Metanorma::Ietf::VERSION}"
27
30
  end
28
31
 
29
- def extract_options(isodocxml)
32
+ def extract_options(_isodocxml)
30
33
  {}
31
34
  end
32
35
 
33
36
  # From mislav: https://stackoverflow.com/questions/2108727
34
37
  # /which-in-ruby-checking-if-program-exists-in-path-from-ruby
35
38
  def which(cmd)
36
- exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
37
- ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
39
+ exts = ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""]
40
+ ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
38
41
  exts.each do |ext|
39
42
  exe = File.join(path, "#{cmd}#{ext}")
40
43
  return exe if File.executable?(exe) && !File.directory?(exe)
@@ -43,49 +46,43 @@ module Metanorma
43
46
  nil
44
47
  end
45
48
 
46
- def use_presentation_xml(ext)
49
+ def use_presentation_xml(_ext)
47
50
  false
48
51
  end
49
52
 
50
- def xml2rfc_present?
51
- !which("xml2rfc").nil?
53
+ def check_xml2rfc_present?(format)
54
+ if which("xml2rfc").nil?
55
+ raise "[metanorma-ietf] Fatal: unable to generate #{format}," \
56
+ " the command `xml2rfc` is not found in path."
57
+ end
52
58
  end
53
59
 
54
- def output(isodoc_node, inname, outname, format, options={})
60
+ def output(isodoc_node, inname, outname, format, options = {})
55
61
  case format
56
62
  when :rfc
57
63
  outname ||= inname.sub(/\.xml$/, ".rfc.xml")
58
- IsoDoc::Ietf::RfcConvert.new(options).convert(inname, isodoc_node, nil, outname)
64
+ RfcConvert.new(options).convert(inname, isodoc_node, nil, outname)
59
65
  @done_rfc = true
60
-
61
66
  when :txt, :pdf, :html
62
- unless xml2rfc_present?
63
- warn "[metanorma-ietf] Error: unable to generate #{format}, the command `xml2rfc` is not found in path."
64
- return
65
- end
67
+ xml2rfc(isodoc_node, inname, outname, format, options)
68
+ else
69
+ super
70
+ end
71
+ end
66
72
 
67
- rfcname = inname.sub(/\.xml$/, ".rfc.xml")
68
- unless @done_rfc && File.exist?(rfcname)
69
- output(isodoc_node, inname, rfcname, :rfc, options)
70
- end
73
+ def xml2rfc(isodoc_node, inname, outname, format, options)
74
+ check_xml2rfc_present?(format)
71
75
 
72
- outext = case format
73
- when :txt then ".txt"
74
- when :pdf then ".pdf"
75
- when :html then ".html"
76
- end
76
+ rfcname = inname.sub(/\.xml$/, ".rfc.xml")
77
+ unless @done_rfc && File.exist?(rfcname)
78
+ output(isodoc_node, inname, rfcname, :rfc, options)
79
+ end
77
80
 
78
- outflag = case format
79
- when :txt then "--text"
80
- when :pdf then "--pdf"
81
- when :html then "--html"
82
- end
81
+ outext = { txt: ".txt", pdf: ".pdf", html: ".html" }[format]
82
+ outflag = { txt: "--text", pdf: "--pdf", html: "--html" }[format]
83
83
 
84
- outname ||= inname.sub(/\.xml$/, outext)
85
- system("xml2rfc #{outflag} #{rfcname} -o #{outname}")
86
- else
87
- super
88
- end
84
+ outname ||= inname.sub(/\.xml$/, outext)
85
+ system("xml2rfc #{outflag} #{rfcname} -o #{outname}")
89
86
  end
90
87
  end
91
88
  end
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Ietf
3
- VERSION = "2.3.0".freeze
3
+ VERSION = "2.3.5".freeze
4
4
  end
5
5
  end
@@ -33,12 +33,13 @@ Gem::Specification.new do |spec|
33
33
  spec.bindir = "exe"
34
34
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
35
  spec.require_paths = ["lib"]
36
- spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
36
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
37
37
 
38
- spec.add_dependency "isodoc", "~> 1.6.0"
38
+ spec.add_dependency "isodoc", "~> 1.7.0"
39
39
  spec.add_dependency "mathml2asciimath"
40
- spec.add_dependency "metanorma-standoc", "~> 1.9.0"
41
- spec.add_dependency "nokogiri", "~> 1.10.4"
40
+ spec.add_dependency "metanorma-standoc", "~> 1.10.0"
41
+ spec.add_dependency "nokogiri", "~> 1.11.6"
42
+ spec.add_dependency "open-uri"
42
43
 
43
44
  spec.add_development_dependency "byebug"
44
45
  spec.add_development_dependency "equivalent-xml", "~> 0.6"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-ietf
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-12 00:00:00.000000000 Z
11
+ date: 2021-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: isodoc
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.6.0
19
+ version: 1.7.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.6.0
26
+ version: 1.7.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mathml2asciimath
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,28 +44,42 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 1.9.0
47
+ version: 1.10.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 1.9.0
54
+ version: 1.10.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: nokogiri
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 1.10.4
61
+ version: 1.11.6
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 1.10.4
68
+ version: 1.11.6
69
+ - !ruby/object:Gem::Dependency
70
+ name: open-uri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: byebug
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -306,7 +320,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
306
320
  requirements:
307
321
  - - ">="
308
322
  - !ruby/object:Gem::Version
309
- version: 2.4.0
323
+ version: 2.5.0
310
324
  required_rubygems_version: !ruby/object:Gem::Requirement
311
325
  requirements:
312
326
  - - ">="