Skip to content

Commit

Permalink
update Nokogiri to v1.15 & doctype model
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew2net committed Nov 27, 2023
1 parent a0f08fa commit 9f6c032
Show file tree
Hide file tree
Showing 24 changed files with 52,901 additions and 52,383 deletions.
20 changes: 18 additions & 2 deletions grammars/basicdoc.rng
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@
<ref name="keyword"/>
<ref name="xref"/>
<ref name="hyperlink"/>
<ref name="index"/>
<ref name="index-xref"/>
</choice>
</oneOrMore>
</element>
Expand Down Expand Up @@ -623,6 +625,8 @@
<ref name="eref"/>
<ref name="xref"/>
<ref name="hyperlink"/>
<ref name="index"/>
<ref name="index-xref"/>
</choice>
</zeroOrMore>
</element>
Expand All @@ -636,6 +640,8 @@
<ref name="eref"/>
<ref name="xref"/>
<ref name="hyperlink"/>
<ref name="index"/>
<ref name="index-xref"/>
</choice>
</zeroOrMore>
</element>
Expand All @@ -648,14 +654,20 @@
<ref name="eref"/>
<ref name="xref"/>
<ref name="hyperlink"/>
<ref name="index"/>
<ref name="index-xref"/>
</choice>
</zeroOrMore>
</element>
</define>
<define name="keyword">
<element name="keyword">
<zeroOrMore>
<ref name="PureTextElement"/>
<choice>
<ref name="PureTextElement"/>
<ref name="index"/>
<ref name="index-xref"/>
</choice>
</zeroOrMore>
</element>
</define>
Expand All @@ -676,7 +688,11 @@
<define name="strike">
<element name="strike">
<zeroOrMore>
<ref name="PureTextElement"/>
<choice>
<ref name="PureTextElement"/>
<ref name="index"/>
<ref name="index-xref"/>
</choice>
</zeroOrMore>
</element>
</define>
Expand Down
1 change: 1 addition & 0 deletions grammars/biblio.rng
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,7 @@
<value>obsoleted</value>
<value>confirmed</value>
<value>updated</value>
<value>corrected</value>
<value>issued</value>
<value>transmitted</value>
<value>copied</value>
Expand Down
1 change: 1 addition & 0 deletions lib/relaton_ietf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require "relaton_ietf/version"
require "relaton_ietf/config"
require "relaton_ietf/util"
require "relaton_ietf/document_type"
require "relaton_ietf/bibxml_parser"
require "relaton_ietf/ietf_bibliography"
require "relaton_ietf/xml_parser"
Expand Down
16 changes: 16 additions & 0 deletions lib/relaton_ietf/document_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module RelatonIetf
class DocumentType < RelatonBib::DocumentType
DOCTYPES = %w[rfc internet-draft].freeze

def initialize(type:, abbreviation: nil)
check_type type
super
end

def check_type(type)
unless DOCTYPES.include? type
Util.warn "WARNING: Invalid doctype: `#{type}`"
end
end
end
end
56 changes: 30 additions & 26 deletions lib/relaton_ietf/hash_converter.rb
Original file line number Diff line number Diff line change
@@ -1,36 +1,40 @@
module RelatonIetf
class HashConverter < RelatonBib::HashConverter
class << self
def hash_to_bib(hash)
ret = super
return unless ret
module HashConverter
include RelatonBib::HashConverter
extend self
def hash_to_bib(hash)
ret = super
return unless ret

stream_hash_to_bib ret
ret
end
stream_hash_to_bib ret
ret
end

#
# Ovverides superclass's method
#
# @param item [Hash]
# @retirn [RelatonIetf::IetfBibliographicItem]
def bib_item(item)
IetfBibliographicItem.new(**item)
end
#
# Ovverides superclass's method
#
# @param item [Hash]
# @retirn [RelatonIetf::IetfBibliographicItem]
def bib_item(item)
IetfBibliographicItem.new(**item)
end

# @param ret [Hash]
def editorialgroup_hash_to_bib(ret)
return unless ret[:editorialgroup]
# @param ret [Hash]
def editorialgroup_hash_to_bib(ret)
return unless ret[:editorialgroup]

technical_committee = RelatonBib.array(ret[:editorialgroup]).map do |wg|
Committee.new RelatonBib::WorkGroup.new(**wg)
end
ret[:editorialgroup] = RelatonBib::EditorialGroup.new technical_committee
technical_committee = RelatonBib.array(ret[:editorialgroup]).map do |wg|
Committee.new RelatonBib::WorkGroup.new(**wg)
end
ret[:editorialgroup] = RelatonBib::EditorialGroup.new technical_committee
end

def stream_hash_to_bib(ret)
ret[:stream] = ret[:ext][:stream] if ret[:ext]&.key? :stream
end
def stream_hash_to_bib(ret)
ret[:stream] = ret[:ext][:stream] if ret[:ext]&.key? :stream
end

def create_doctype(**args)
DocumentType.new(**args)
end
end
end
10 changes: 2 additions & 8 deletions lib/relaton_ietf/ietf_bibliographic_item.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
module RelatonIetf
class IetfBibliographicItem < RelatonBib::BibliographicItem
DOCTYPES = %w[rfc internet-draft].freeze

# @return [String, nil]
attr_reader :doctype, :stream
attr_reader :stream

# @return [Array<String>]
attr_reader :keyword

# @param doctype [String]
# @param keyword [Array<String>]
# @param stream [String, nil]
def initialize(**args)
if args[:doctype] && !DOCTYPES.include?(args[:doctype])
Util.warn "WARNING: Invalid doctype: `#{args[:doctype]}`"
end
@stream = args.delete(:stream)
super
end
Expand Down Expand Up @@ -47,7 +41,7 @@ def to_xml(**opts) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexi
if opts[:bibdata] && (doctype || editorialgroup || ics&.any? ||
structuredidentifier&.presence? || stream)
ext = builder.ext do |b|
b.doctype doctype if doctype
doctype&.to_xml b
b.subdoctype subdoctype if subdoctype
editorialgroup&.to_xml b
ics.each { |i| i.to_xml b }
Expand Down
2 changes: 1 addition & 1 deletion lib/relaton_ietf/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module RelatonIetf
VERSION = "1.16.2".freeze
VERSION = "1.17.0".freeze
end
2 changes: 1 addition & 1 deletion relaton_ietf.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]
spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")

spec.add_dependency "relaton-bib", "~> 1.16.0"
spec.add_dependency "relaton-bib", "~> 1.17.0"
spec.add_dependency "relaton-index", "~> 0.2.3"
end
2 changes: 1 addition & 1 deletion spec/examples/bcp_47.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<bibdata type="standard" schema-version="v1.2.4">
<bibdata type="standard" schema-version="v1.2.5">
<fetched>2022-11-26</fetched>
<title format="text/plain" language="en" script="Latn">Best Current Practice 47</title>
<uri type="src">https://www.rfc-editor.org/info/bcp47</uri>
Expand Down
2 changes: 1 addition & 1 deletion spec/examples/bib_item.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<bibdata type="standard" schema-version="v1.2.4">
<bibdata type="standard" schema-version="v1.2.5">
<fetched>2023-07-02</fetched>
<title type="main" format="text/plain">Network Configuration Access Control Model</title>
<uri type="src">https://www.rfc-editor.org/info/rfc8341</uri>
Expand Down
2 changes: 1 addition & 1 deletion spec/examples/from-bibxm-ids.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<bibdata type="standard" schema-version="v1.2.4">
<bibdata type="standard" schema-version="v1.2.5">
<title format="text/plain" language="en" script="Latn">Forming Intuitive Email Addresses</title>
<uri type="src">https://datatracker.ietf.org/doc/html/draft--pale-email-00</uri>
<docidentifier type="Internet-Draft" primary="true">draft--pale-email-00</docidentifier>
Expand Down
2 changes: 1 addition & 1 deletion spec/examples/from_yaml.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<bibdata type="standard" schema-version="v1.2.4">
<bibdata type="standard" schema-version="v1.2.5">
<fetched>2022-06-22</fetched>
<title format="text/plain" language="en" script="Latn">Network Configuration Access Control Model</title>
<uri type="src">https://www.rfc-editor.org/info/rfc8341</uri>
Expand Down
2 changes: 1 addition & 1 deletion spec/examples/i_d_bib_item.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<bibdata type="standard" schema-version="v1.2.4">
<bibdata type="standard" schema-version="v1.2.5">
<fetched>2023-03-08</fetched>
<title format="text/plain" language="en" script="Latn">Centralized Conferencing (XCON) Media Models</title>
<uri type="src">https://datatracker.ietf.org/doc/html/draft-burger-xcon-mmodels-00</uri>
Expand Down
2 changes: 1 addition & 1 deletion spec/examples/rfc_xml.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<bibdata type="standard" schema-version="v1.2.4">
<bibdata type="standard" schema-version="v1.2.5">
<title format="text/plain" language="en" script="Latn">ACVP Secure Hash Algorithm (SHA) JSON Specification</title>
<docidentifier type="Internet-Draft" primary="true">draft-ietf-acvp-subsha-1.0</docidentifier>
<docidentifier type="IETF" scope="docName">draft-ietf-acvp-subsha-1.0</docidentifier>
Expand Down
7 changes: 7 additions & 0 deletions spec/relaton_ietf/document_type_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
describe RelatonIetf::DocumentType do
it "warn if doctype is invalid" do
expect do
described_class.new type: "type"
end.to output(/\[relaton-ietf\] WARNING: Invalid doctype: `type`/).to_stderr_from_any_process
end
end
15 changes: 5 additions & 10 deletions spec/relaton_ietf/ietf_bibliographic_item_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
RSpec.describe RelatonIetf::IetfBibliographicItem do
it "warn if doctype is invalid" do
expect do
described_class.new doctype: "type"
end.to output(/\[relaton-ietf\] WARNING: Invalid doctype: `type`/).to_stderr
end

context "render BibXML" do
it "don't render date if IANA" do
docid = RelatonBib::DocumentIdentifier.new(type: "IANA", id: "IANA 123")
Expand Down Expand Up @@ -46,20 +40,21 @@
context "render" do
subject do
docid = RelatonBib::DocumentIdentifier.new(type: "IETF", id: "RFC 123")
described_class.new(doctype: "RFC", stream: "IETF", docid: [docid])
doctype = RelatonIetf::DocumentType.new type: "RFC"
described_class.new(doctype: doctype, stream: "IETF", docid: [docid])
end

it "to_hash" do
expect(subject.to_hash).to eq(
"docid" => [{ "id" => "RFC 123", "type" => "IETF" }], "doctype" => "RFC",
"docid" => [{ "id" => "RFC 123", "type" => "IETF" }], "doctype" => { "type" => "RFC" },
"ext" => { "schema-version" => "v1.0.1", "stream" => "IETF" },
"id" => "RFC123", "schema-version" => "v1.2.4"
"id" => "RFC123", "schema-version" => "v1.2.5"
)
end

it "to_xml" do
expect(subject.to_xml(bibdata: true)).to be_equivalent_to <<~XML
<bibdata schema-version="v1.2.4">
<bibdata schema-version="v1.2.5">
<docidentifier type="IETF">RFC 123</docidentifier>
<ext schema-version="v1.0.1">
<doctype>RFC</doctype>
Expand Down
Loading

0 comments on commit 9f6c032

Please sign in to comment.