Skip to content

Commit

Permalink
doc id refactoring; metanorma/metanorma-iso#237
Browse files Browse the repository at this point in the history
  • Loading branch information
opoudjis committed Nov 10, 2018
1 parent 67ccf39 commit ccc354d
Show file tree
Hide file tree
Showing 9 changed files with 851 additions and 713 deletions.
8 changes: 8 additions & 0 deletions lib/asciidoctor/csand/biblio.rng
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,9 @@
<zeroOrMore>
<ref name="docidentifier"/>
</zeroOrMore>
<optional>
<ref name="docnumber"/>
</optional>
<zeroOrMore>
<ref name="bdate"/>
</zeroOrMore>
Expand Down Expand Up @@ -675,6 +678,11 @@
<text/>
</element>
</define>
<define name="docnumber">
<element name="docnumber">
<text/>
</element>
</define>
<define name="bclassification">
<element name="classification">
<optional>
Expand Down
11 changes: 10 additions & 1 deletion lib/asciidoctor/csand/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,16 @@ def metadata_status(node, xml)
end

def metadata_id(node, xml)
xml.docidentifier { |i| i << node.attr("docnumber") }
docstatus = node.attr("status")
dn = node.attr("docnumber")
if docstatus
abbr = IsoDoc::Csand::Metadata.new("en", "Latn", {}).
status_abbr(docstatus)
dn = "#{dn}(#{abbr})" unless abbr.empty?
end
node.attr("copyright-year") and dn += ":#{node.attr("copyright-year")}"
xml.docidentifier dn, **{type: "csand"}
xml.docnumber { |i| i << node.attr("docnumber") }
end

def metadata_copyright(node, xml)
Expand Down
3 changes: 3 additions & 0 deletions lib/asciidoctor/csand/isodoc.rng
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,9 @@
<zeroOrMore>
<ref name="docidentifier"/>
</zeroOrMore>
<optional>
<ref name="docnumber"/>
</optional>
<zeroOrMore>
<ref name="bdate"/>
</zeroOrMore>
Expand Down
6 changes: 6 additions & 0 deletions lib/asciidoctor/csand/isostandard.rng
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@
<zeroOrMore>
<ref name="docidentifier"/>
</zeroOrMore>
<optional>
<ref name="docnumber"/>
</optional>
<zeroOrMore>
<ref name="bdate"/>
</zeroOrMore>
Expand Down Expand Up @@ -163,6 +166,9 @@
<zeroOrMore>
<ref name="docidentifier"/>
</zeroOrMore>
<optional>
<ref name="docnumber"/>
</optional>
<zeroOrMore>
<ref name="bdate"/>
</zeroOrMore>
Expand Down
2 changes: 0 additions & 2 deletions lib/isodoc/csand/html/html_csand_titlepage.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

<div class="doc-number">
<span class="docnumber">{{ docnumber }}</span>
<span class="docnumber-separator">:</span>
<span class="docyear">{{ docyear }}</span>
</div>

<div class="title-first">{{ doctitle }}</div>
Expand Down
11 changes: 2 additions & 9 deletions lib/isodoc/csand/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,8 @@ def author(isoxml, _out)


def docid(isoxml, _out)
docnumber = isoxml.at(ns("//bibdata/docidentifier"))
docstatus = isoxml.at(ns("//bibdata/status"))
dn = docnumber&.text
if docstatus
set(:status, status_print(docstatus.text))
abbr = status_abbr(docstatus.text)
dn = "#{dn}(#{abbr})" unless abbr.empty?
end
set(:docnumber, dn)
docnumber = isoxml.at(ns("//bibdata/docidentifier[@type = 'csand']"))
set(:docnumber, docnumber&.text)
end

def status_print(status)
Expand Down
180 changes: 178 additions & 2 deletions spec/asciidoctor/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<csand-standard xmlns="https://open.ribose.com/standards/csand">
<bibdata type="standard">
<title language="en" format="plain">Main Title</title>
<docidentifier>1000</docidentifier>
<title language="en" format="text/plain">Main Title</title>
<docidentifier type="csand">1000(wd):2001</docidentifier>
<docnumber>1000</docnumber>
<contributor>
<role type="author"/>
<organization>
Expand Down Expand Up @@ -111,6 +112,181 @@
OUTPUT
end

it "processes committee-draft" do
expect(Asciidoctor.convert(<<~"INPUT", backend: :csand, header_footer: true)).to be_equivalent_to <<~"OUTPUT"
= Document title
Author
:docfile: test.adoc
:nodoc:
:novalid:
:docnumber: 1000
:doctype: standard
:edition: 2
:revdate: 2000-01-01
:draft: 3.4
:status: committee-draft
:iteration: 3
:language: en
:title: Main Title
INPUT
<csand-standard xmlns="https://open.ribose.com/standards/csand">
<bibdata type="standard">
<title language="en" format="text/plain">Main Title</title>
<docidentifier type="csand">1000(cd)</docidentifier>
<docnumber>1000</docnumber>
<contributor>
<role type="author"/>
<organization>
<name>Ribose</name>
</organization>
</contributor>
<contributor>
<role type="publisher"/>
<organization>
<name>Ribose</name>
</organization>
</contributor>
<language>en</language>
<script>Latn</script>
<status format="plain">committee-draft</status>
<copyright>
<from>#{Date.today.year}</from>
<owner>
<organization>
<name>Ribose</name>
</organization>
</owner>
</copyright>
<editorialgroup>
<committee/>
</editorialgroup>
</bibdata><version>
<edition>2</edition>
<revision-date>2000-01-01</revision-date>
<draft>3.4</draft>
</version>
<sections/>
</csand-standard>
OUTPUT
end

it "processes draft-standard" do
expect(Asciidoctor.convert(<<~"INPUT", backend: :csand, header_footer: true)).to be_equivalent_to <<~"OUTPUT"
= Document title
Author
:docfile: test.adoc
:nodoc:
:novalid:
:docnumber: 1000
:doctype: standard
:edition: 2
:revdate: 2000-01-01
:draft: 3.4
:status: draft-standard
:iteration: 3
:language: en
:title: Main Title
INPUT
<csand-standard xmlns="https://open.ribose.com/standards/csand">
<bibdata type="standard">
<title language="en" format="text/plain">Main Title</title>
<docidentifier type="csand">1000(d)</docidentifier>
<docnumber>1000</docnumber>
<contributor>
<role type="author"/>
<organization>
<name>Ribose</name>
</organization>
</contributor>
<contributor>
<role type="publisher"/>
<organization>
<name>Ribose</name>
</organization>
</contributor>
<language>en</language>
<script>Latn</script>
<status format="plain">draft-standard</status>
<copyright>
<from>#{Date.today.year}</from>
<owner>
<organization>
<name>Ribose</name>
</organization>
</owner>
</copyright>
<editorialgroup>
<committee/>
</editorialgroup>
</bibdata><version>
<edition>2</edition>
<revision-date>2000-01-01</revision-date>
<draft>3.4</draft>
</version>
<sections/>
</csand-standard>
OUTPUT
end

it "ignores unrecognised status" do
expect(Asciidoctor.convert(<<~"INPUT", backend: :csand, header_footer: true)).to be_equivalent_to <<~'OUTPUT'
= Document title
Author
:docfile: test.adoc
:nodoc:
:novalid:
:docnumber: 1000
:doctype: standard
:edition: 2
:revdate: 2000-01-01
:draft: 3.4
:copyright-year: 2001
:status: standard
:iteration: 3
:language: en
:title: Main Title
INPUT
<csand-standard xmlns="https://open.ribose.com/standards/csand">
<bibdata type="standard">
<title language="en" format="text/plain">Main Title</title>
<docidentifier type="csand">1000:2001</docidentifier>
<docnumber>1000</docnumber>
<contributor>
<role type="author"/>
<organization>
<name>Ribose</name>
</organization>
</contributor>
<contributor>
<role type="publisher"/>
<organization>
<name>Ribose</name>
</organization>
</contributor>
<language>en</language>
<script>Latn</script>
<status format="plain">standard</status>
<copyright>
<from>2001</from>
<owner>
<organization>
<name>Ribose</name>
</organization>
</owner>
</copyright>
<editorialgroup>
<committee/>
</editorialgroup>
</bibdata><version>
<edition>2</edition>
<revision-date>2000-01-01</revision-date>
<draft>3.4</draft>
</version>
<sections/>
</csand-standard>
OUTPUT
end

it "processes figures" do
expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :csand, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
#{ASCIIDOC_BLANK_HDR}
Expand Down
Loading

0 comments on commit ccc354d

Please sign in to comment.