metanorma-ietf 2.2.10 → 2.3.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,6 +3,9 @@ module IsoDoc::Ietf
3
3
  # TODO displayreference will be implemented as combination of autofetch and user-provided citations
4
4
 
5
5
  def bibliography(isoxml, out)
6
+ isoxml.xpath(ns("//references/bibitem/docidentifier")).each do |i|
7
+ i.children = docid_prefix(i["type"], i.text)
8
+ end
6
9
  isoxml.xpath(ns("//bibliography/references | "\
7
10
  "//bibliography/clause[.//references] | "\
8
11
  "//annex/clause[.//references] | "\
@@ -31,22 +34,21 @@ module IsoDoc::Ietf
31
34
  i = 0
32
35
  f.xpath(ns("./bibitem | ./note")).each do |b|
33
36
  next if implicit_reference(b)
37
+
34
38
  i += 1 if b.name == "bibitem"
35
39
  if b.name == "note" then note_parse(b, div)
36
- elsif(is_ietf(b)) then ietf_bibitem_entry(div, b, i)
40
+ elsif is_ietf(b) then ietf_bibitem_entry(div, b, i)
37
41
  else
38
42
  nonstd_bibitem(div, b, i, biblio)
39
43
  end
40
44
  end
41
45
  end
42
46
 
43
- def nonstd_bibitem(list, b, ordinal, bibliography)
47
+ def nonstd_bibitem(list, b, _ordinal, _bibliography)
44
48
  uris = b.xpath(ns("./uri"))
45
49
  target = nil
46
50
  uris&.each do |u|
47
- if u["type"] == "src" then
48
- target = u.text
49
- end
51
+ target = u.text if u["type"] == "src"
50
52
  end
51
53
  list.reference **attr_code(target: target,
52
54
  anchor: b["id"]) do |r|
@@ -66,7 +68,8 @@ module IsoDoc::Ietf
66
68
  r.refcontent id[1]
67
69
  docidentifiers&.each do |u|
68
70
  if %w(DOI IETF).include? u["type"]
69
- r.seriesInfo nil, **attr_code(value: u.text, name: u["type"])
71
+ r.seriesInfo nil, **attr_code(value: u.text.sub(/^DOI /, ""),
72
+ name: u["type"])
70
73
  end
71
74
  end
72
75
  end
@@ -86,7 +89,7 @@ module IsoDoc::Ietf
86
89
  "'publisher']"))
87
90
  auths.each do |a|
88
91
  role = a.at(ns("./role[@type = 'editor']")) ? "editor" : nil
89
- p = a&.at(ns("./person/name")) and
92
+ p = a&.at(ns("./person/name")) and
90
93
  relaton_person_to_author(p, role, f) or
91
94
  relaton_org_to_author(a&.at(ns("./organization")), role, f)
92
95
  end
@@ -99,17 +102,17 @@ module IsoDoc::Ietf
99
102
  p&.xpath(ns("./forename"))&.map { |i| i.text[0] }&.join(" ")
100
103
  initials = nil if initials.empty?
101
104
  f.author nil,
102
- **attr_code(fullname: fullname, asciiFullname: fullname&.transliterate,
103
- role: role, surname: surname, initials: initials,
104
- asciiSurname: fullname ? surname&.transliterate : nil,
105
- asciiInitials: fullname ? initials&.transliterate : nil)
105
+ **attr_code(fullname: fullname, asciiFullname: fullname&.transliterate,
106
+ role: role, surname: surname, initials: initials,
107
+ asciiSurname: fullname ? surname&.transliterate : nil,
108
+ asciiInitials: fullname ? initials&.transliterate : nil)
106
109
  end
107
110
 
108
- def relaton_org_to_author(o, role, f)
111
+ def relaton_org_to_author(o, _role, f)
109
112
  name = o&.at(ns("./name"))&.text
110
113
  abbrev = o&.at(ns("./abbreviation"))&.text
111
- f.author do |a|
112
- f.organization name, **attr_code(ascii: name&.transliterate,
114
+ f.author do |_a|
115
+ f.organization name, **attr_code(ascii: name&.transliterate,
113
116
  abbrev: abbrev)
114
117
  end
115
118
  end
@@ -119,6 +122,7 @@ module IsoDoc::Ietf
119
122
  b.at(ns("./date[@type = 'issued']")) ||
120
123
  b.at(ns("./date[@type = 'circulated']"))
121
124
  return unless date
125
+
122
126
  attr = date_attr(date&.at(ns("./on | ./from"))&.text) || return
123
127
  f.date **attr_code(attr)
124
128
  end
@@ -145,13 +149,14 @@ module IsoDoc::Ietf
145
149
  end
146
150
  end
147
151
 
148
- def ietf_bibitem_entry(div, b, i)
152
+ def ietf_bibitem_entry(div, b, _i)
149
153
  url = b&.at(ns("./uri[@type = 'xml']"))&.text
150
154
  div << "<xi:include href='#{url}'/>"
151
155
  end
152
156
 
153
157
  def is_ietf(b)
154
158
  return false if !@xinclude
159
+
155
160
  url = b.at(ns("./uri[@type = 'xml']")) or return false
156
161
  /xml2rfc\.tools\.ietf\.org/.match(url)
157
162
  end
@@ -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,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.2.10".freeze
3
+ VERSION = "2.3.4".freeze
4
4
  end
5
5
  end
@@ -1,6 +1,6 @@
1
1
  # coding: utf-8
2
2
 
3
- lib = File.expand_path("../lib", __FILE__)
3
+ lib = File.expand_path("lib", __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require "metanorma/ietf/version"
6
6
 
@@ -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 "metanorma-standoc", "~> 1.8.0"
39
- spec.add_dependency "isodoc", "~> 1.5.0"
38
+ spec.add_dependency "isodoc", "~> 1.6.0"
40
39
  spec.add_dependency "mathml2asciimath"
41
- spec.add_dependency "nokogiri", "~> 1.10.4"
40
+ spec.add_dependency "metanorma-standoc", "~> 1.9.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,71 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-ietf
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.10
4
+ version: 2.3.4
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-03-29 00:00:00.000000000 Z
11
+ date: 2021-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: metanorma-standoc
14
+ name: isodoc
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.8.0
19
+ version: 1.6.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.8.0
26
+ version: 1.6.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: isodoc
28
+ name: mathml2asciimath
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 1.5.0
33
+ version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 1.5.0
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: mathml2asciimath
42
+ name: metanorma-standoc
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 1.9.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: '0'
54
+ version: 1.9.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
  - - ">="