Skip to content

Commit

Permalink
add year to BIPM output citations: #164
Browse files Browse the repository at this point in the history
  • Loading branch information
opoudjis committed May 13, 2022
1 parent 820a78b commit 5d97b81
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 77 deletions.
1 change: 1 addition & 0 deletions lib/isodoc/bipm/presentation_xml_convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ def expand_citeas(text)
Resolution: "Résolution",
Decision: "Décision",
Recommendation: "Recommandation",
Declaration: "Déclaration",
}.freeze

include Init
Expand Down
32 changes: 32 additions & 0 deletions lib/metanorma/bipm/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,38 @@ def inline_anchor_xref_attrs(node)
ret
end

def reference_names(xmldoc)
xmldoc.xpath("//bibitem[not(ancestor::bibitem)]").each do |ref|
docid = ref.at("./docidentifier[@type = 'metanorma']") ||
ref.at("./docidentifier[not(@type = 'DOI')]") or next
date = ref.at("./date[@type = 'published']")
reference = format_ref(reference_names1(docid, date, docid["type"]),
docid["type"])
@anchors[ref["id"]] = { xref: reference }
end
end

def reference_names1(docid, date, type)
ret = docid.children.to_xml
if type == "BIPM" && date &&
/(CIPM|CGPM) (Decision|Resolution)/.match?(docid)
ret += " (#{date_range(date)})"
end
ret
end

def date_range(date)
from = date.at(("./from"))
to = date.at(("./to"))
on = date.at(("./on"))
return date.text unless from || on || to
return on.text.sub(/-.*$/, "") if on

ret = "#{from.text.sub(/-.*$/, '')}–"
ret += to.text.sub(/-.*$/, "") if to
ret
end

def format_ref(ref, type)
ref = ref.sub(/^BIPM /, "") if type == "BIPM"
super
Expand Down
73 changes: 2 additions & 71 deletions spec/asciidoctor/base_spec.rb
Original file line number Diff line number Diff line change
@@ -1,75 +1,6 @@
require "spec_helper"

OPTIONS = [backend: :bipm, header_footer: true].freeze

RSpec.describe Metanorma::BIPM do
it "processes a blank document" do
input = <<~"INPUT"
#{ASCIIDOC_BLANK_HDR}
INPUT

output = xmlpp(<<~"OUTPUT")
#{BLANK_HDR}
<sections/>
</bipm-standard>
OUTPUT

expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
.to be_equivalent_to output
end

it "converts a blank document" do
FileUtils.rm_rf("test.html")
FileUtils.rm_rf("test.pdf")
input = <<~"INPUT"
= Document title
Author
:docfile: test.adoc
:novalid:
INPUT

output = xmlpp(<<~"OUTPUT")
#{BLANK_HDR}
<sections/>
</bipm-standard>
OUTPUT

expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
.to be_equivalent_to output
expect(File.exist?("test.html")).to be true
expect(File.exist?("test.pdf")).to be true
end

it "converts a blank JCGM document" do
FileUtils.rm_rf("test.html")
FileUtils.rm_rf("test.pdf")
input = <<~"INPUT"
= Document title
Author
:docfile: test.adoc
:novalid:
:committee-acronym: JCGM
:committee-en: Joint Committee for Guides in Metrology#{' '}
INPUT

output = xmlpp(<<~"OUTPUT")
#{BLANK_HDR.sub(%r{<boilerplate>.*</boilerplate>}m, boilerplate('jcgm'))
.sub(/<docidentifier type="BIPM">BIPM/, %(<docidentifier type="BIPM">JCGM))
.sub(%r{</ext>}, "<editorialgroup>
<committee acronym='JCGM'>
<variant language='en' script='Latn'>Joint Committee for Guides in Metrology</variant>
</committee>
</editorialgroup></ext>") }
<sections/>
</bipm-standard>
OUTPUT

expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
.to be_equivalent_to output
expect(File.exist?("test.html")).to be true
expect(File.exist?("test.pdf")).to be true
end

it "processes default metadata" do
input = <<~"INPUT"
= Document title
Expand Down Expand Up @@ -1312,8 +1243,8 @@
<clause id='_' obligation='normative'>
<title>Clause</title>
<p id='_'>
<eref type='inline' bibitemid='a1' citeas='CGPM Resolution 1'/>
<eref type='inline' bibitemid='a2' citeas='CIPM Decision 105'/>
<eref type='inline' bibitemid='a1' citeas='CGPM Resolution 1 (1889)'/>
<eref type='inline' bibitemid='a2' citeas='CIPM Decision 105 (2016)'/>
</p>
</clause>
</sections>
Expand Down
70 changes: 70 additions & 0 deletions spec/asciidoctor/blank_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
require "spec_helper"

RSpec.describe Metanorma::BIPM do
it "processes a blank document" do
input = <<~"INPUT"
#{ASCIIDOC_BLANK_HDR}
INPUT

output = xmlpp(<<~"OUTPUT")
#{BLANK_HDR}
<sections/>
</bipm-standard>
OUTPUT

expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
.to be_equivalent_to output
end

it "converts a blank document" do
FileUtils.rm_rf("test.html")
FileUtils.rm_rf("test.pdf")
input = <<~"INPUT"
= Document title
Author
:docfile: test.adoc
:novalid:
INPUT

output = xmlpp(<<~"OUTPUT")
#{BLANK_HDR}
<sections/>
</bipm-standard>
OUTPUT

expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
.to be_equivalent_to output
expect(File.exist?("test.html")).to be true
expect(File.exist?("test.pdf")).to be true
end

it "converts a blank JCGM document" do
FileUtils.rm_rf("test.html")
FileUtils.rm_rf("test.pdf")
input = <<~"INPUT"
= Document title
Author
:docfile: test.adoc
:novalid:
:committee-acronym: JCGM
:committee-en: Joint Committee for Guides in Metrology#{' '}
INPUT

output = xmlpp(<<~"OUTPUT")
#{BLANK_HDR.sub(%r{<boilerplate>.*</boilerplate>}m, boilerplate('jcgm'))
.sub(/<docidentifier type="BIPM">BIPM/, %(<docidentifier type="BIPM">JCGM))
.sub(%r{</ext>}, "<editorialgroup>
<committee acronym='JCGM'>
<variant language='en' script='Latn'>Joint Committee for Guides in Metrology</variant>
</committee>
</editorialgroup></ext>") }
<sections/>
</bipm-standard>
OUTPUT

expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
.to be_equivalent_to output
expect(File.exist?("test.html")).to be true
expect(File.exist?("test.pdf")).to be true
end
end
12 changes: 6 additions & 6 deletions spec/isodoc/ref_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,8 @@
<preface>
<foreword>
<p>
<eref type='inline' bibitemid='a1' citeas='CGPM Resolution 1'/>
<eref type='inline' bibitemid='a2' citeas='CIPM Decision 105'/>
<eref type='inline' bibitemid='a1' citeas='CGPM Resolution 1 (1889)'/>
<eref type='inline' bibitemid='a2' citeas='CIPM Decision 105 (2016)'/>
</p>
</foreword>
</preface>
Expand Down Expand Up @@ -644,16 +644,16 @@
presxml_en = <<~PRESXML
<foreword displayorder='1'>
<p>
<eref type='inline' bibitemid='a1' citeas='CGPM Resolution 1'>CGPM Resolution 1</eref>
<eref type='inline' bibitemid='a2' citeas='CIPM Decision 105'>CIPM Decision 105</eref>
<eref type='inline' bibitemid='a1' citeas='CGPM Resolution 1 (1889)'>CGPM Resolution 1 (1889)</eref>
<eref type='inline' bibitemid='a2' citeas='CIPM Decision 105 (2016)'>CIPM Decision 105 (2016)</eref>
</p>
</foreword>
PRESXML
presxml_fr = <<~PRESXML
<foreword displayorder='1'>
<p>
<eref type='inline' bibitemid='a1' citeas='CGPM Resolution 1'>CGPM &#x2013; R&#xE9;solution 1</eref>
<eref type='inline' bibitemid='a2' citeas='CIPM Decision 105'>CIPM &#x2013; D&#xE9;cision 105</eref>
<eref type='inline' bibitemid='a1' citeas='CGPM Resolution 1 (1889)'>CGPM &#x2013; R&#xE9;solution 1 (1889)</eref>
<eref type='inline' bibitemid='a2' citeas='CIPM Decision 105 (2016)'>CIPM &#x2013; D&#xE9;cision 105 (2016)</eref>
</p>
</foreword>
PRESXML
Expand Down
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
end
end

OPTIONS = [backend: :bipm, header_footer: true].freeze

def metadata(hash)
Hash[hash.sort].delete_if do |_, v|
v.nil? || (v.respond_to?(:empty?) && v.empty?)
Expand Down

0 comments on commit 5d97b81

Please sign in to comment.