Skip to content

Commit

Permalink
Appendix support: #5
Browse files Browse the repository at this point in the history
  • Loading branch information
opoudjis committed Sep 25, 2020
1 parent ad91b5f commit 92ec02d
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 20 deletions.
4 changes: 4 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ metadata about the document. These include:
`:title-fr:`:: The title of the document in French (mandatory)
`:title-cover-en:`:: The title of the front cover of the document in English (where different from the title proper)
`:title-cover-fr:`:: The title of the front cover of the document in French (where different from the title proper)
`:title-appendix-en:`:: The title of the appendix in English, if this document is an appendix published separately; `title-en` becomes the title of the main document, as presented within the standalone appendix.
`:title-appendix-fr:`:: The title of the appendix in English, if this document is an appendix published separately; `title-en` becomes the title of the main document, as presented within the standalone appendix.

`:appendix-id:`:: The number of the appendix, if this document is an appendix published separately

`:copyright-year:`:: The year which will be claimed as when the copyright for
the document was issued
Expand Down
15 changes: 4 additions & 11 deletions lib/asciidoctor/bipm/basicdoc.rng
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,7 @@
<data type="ID"/>
</attribute>
<oneOrMore>
<choice>
<ref name="formula"/>
<ref name="ul"/>
<ref name="ol"/>
<ref name="dl"/>
<ref name="quote"/>
<ref name="sourcecode"/>
<ref name="paragraph"/>
<ref name="table"/>
<ref name="figure"/>
</choice>
<ref name="paragraph"/>
</oneOrMore>
</element>
</define>
Expand Down Expand Up @@ -1028,6 +1018,9 @@
<value>alphabet_upper</value>
</choice>
</attribute>
<optional>
<attribute name="start"/>
</optional>
<oneOrMore>
<ref name="li"/>
</oneOrMore>
Expand Down
18 changes: 18 additions & 0 deletions lib/asciidoctor/bipm/bipm.rng
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<optional>
<ref name="comment-period-to"/>
</optional>
<ref name="structuredidentifier"/>
</define>
</include>
<define name="comment-period-from">
Expand All @@ -57,6 +58,23 @@
<ref name="ISO8601Date"/>
</element>
</define>
<define name="structuredidentifier">
<element name="structuredidentifier">
<element name="docnumber">
<text/>
</element>
<optional>
<element name="part">
<text/>
</element>
</optional>
<optional>
<element name="appendix">
<text/>
</element>
</optional>
</element>
</define>
<define name="committee">
<element name="committee">
<choice>
Expand Down
16 changes: 15 additions & 1 deletion lib/asciidoctor/bipm/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def title(node, xml)
node.attr("title-#{lang}"))
end
typed_title(node, xml, lang, "cover")
typed_title(node, xml, lang, "appendix")
end
end

Expand All @@ -50,6 +51,20 @@ def typed_title(node, xml, lang, type)
end
end

def metadata_ext(node, xml)
super
structured_id(node, xml)
end

def structured_id(node, xml)
return unless node.attr("docnumber")
xml.structuredidentifier do |i|
i.docnumber node.attr("docnumber")
a = node.attr("partnumber") and i.part a
a = node.attr("appendix-id") and i.appendix a
end
end

def sectiontype_streamline(ret)
case ret
when "introduction" then "clause"
Expand All @@ -58,7 +73,6 @@ def sectiontype_streamline(ret)
end
end


def html_converter(node)
IsoDoc::BIPM::HtmlConvert.new(html_extract_attributes(node))
end
Expand Down
14 changes: 12 additions & 2 deletions lib/isodoc/bipm/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ def title(isoxml, _out)
lang1 = @lang == "fr" ? "fr" : "en"
lang2 = @lang == "fr" ? "en" : "fr"
set(:doctitle, @c.encode(isoxml&.at(
ns("//bibdata/title[@language='#{lang1}']"))&.text || ""))
ns("//bibdata/title[@type='main'][@language='#{lang1}']"))&.text || ""))
set(:docsubtitle, @c.encode(isoxml&.at(
ns("//bibdata/title[@language='#{lang2}']"))&.text || ""))
ns("//bibdata/title[@type='main'][@language='#{lang2}']"))&.text || ""))
set(:appendixtitle, @c.encode(isoxml&.at(
ns("//bibdata/title[@type='appendix'][@language='#{lang1}']"))&.text || ""))
set(:appendixsubtitle, @c.encode(isoxml&.at(
ns("//bibdata/title[@type='appendix'][@language='#{lang2}']"))&.text || ""))
end

def status_print(status)
Expand All @@ -23,6 +27,12 @@ def status_print(status)
(%w(en de).include?(s) && i > 0) ? s : s.capitalize
end.join(' ')
end

def docid(isoxml, _out)
super
dn = isoxml.at(ns("//bibdata/ext/structuredidentifier/appendix"))
dn and set(:appendixid, @i18n.l10n("#{@labels["annex"]} #{dn&.text}"))
end
end
end
end
14 changes: 14 additions & 0 deletions spec/asciidoctor/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@
:title-fr: Chef Title
:title-cover-en: Main Title (SI)
:title-cover-fr: Chef Title (SI)
:title-appendix-en: Main Title (SI)
:title-appendix-fr: Chef Title (SI)
:appendix-id: ABC
:security: Client Confidential
:comment-period-from: X
:comment-period-to: Y
Expand All @@ -80,8 +83,10 @@
<bibdata type="standard">
<title language='en' format='text/plain' type='main'>Main Title</title>
<title language='en' format='text/plain' type='cover'>Main Title (SI)</title>
<title language='en' format='text/plain' type='appendix'>Main Title (SI)</title>
<title language='fr' format='text/plain' type='main'>Chef Title</title>
<title language='fr' format='text/plain' type='cover'>Chef Title (SI)</title>
<title language='fr' format='text/plain' type='appendix'>Chef Title (SI)</title>
<docidentifier type="BIPM">#{Metanorma::BIPM.configuration.organization_name_short} 1000</docidentifier>
<docnumber>1000</docnumber>
<date type='implemented'>
Expand Down Expand Up @@ -144,6 +149,10 @@
</editorialgroup>
<comment-period-from>X</comment-period-from>
<comment-period-to>Y</comment-period-to>
<structuredidentifier>
<docnumber>1000</docnumber>
<appendix>ABC</appendix>
</structuredidentifier>
</ext>
</bibdata>
#{boilerplate("en").gsub(/2020/, "2001")}
Expand Down Expand Up @@ -185,6 +194,7 @@
:title-cover-en: Main Title (SI)
:title-cover-fr: Chef Title (SI)
:security: Client Confidential
:appendix-id: ABC
:comment-period-from: X
:comment-period-to: Y
:supersedes: A
Expand Down Expand Up @@ -263,6 +273,10 @@
</editorialgroup>
<comment-period-from>X</comment-period-from>
<comment-period-to>Y</comment-period-to>
<structuredidentifier>
<docnumber>1000</docnumber>
<appendix>ABC</appendix>
</structuredidentifier>
</ext>
</bibdata>
#{boilerplate("fr").gsub(/2020/, "2001")}
Expand Down
55 changes: 49 additions & 6 deletions spec/isodoc/html_convert_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
input = <<~"INPUT"
<bipm-standard xmlns="https://open.ribose.com/standards/bipm">
<bibdata type="standard">
<title language="en" format="plain">Main Title</title>
<title language="fr" format="plain">Chef Title</title>
<title type="main" language="en" format="plain">Main Title</title>
<title type="main" language="fr" format="plain">Chef Title</title>
<title type="cover" language="en" format="plain">Main Title Cover</title>
<title type="cover" language="fr" format="plain">Chef Title Cover</title>
<title type="appendix" language="en" format="plain">Main Title Appendix</title>
<title type="appendix" language="fr" format="plain">Chef Title Appendix</title>
<docidentifier>1000</docidentifier>
<contributor>
<role type="author"/>
Expand Down Expand Up @@ -40,10 +44,16 @@
</organization>
</owner>
</copyright>
<ext>
<editorialgroup>
<committee type="A">TC</committee>
</editorialgroup>
<security>Client Confidential</security>
<structuredidentifier>
<docnumber>1000</docnumber>
<appendix>ABC</appendix>
</structuredidentifier>
</ext>
</bibdata>
<local_bibdata type="standard">
<title language="en" format="plain">Main Title</title>
Expand Down Expand Up @@ -77,10 +87,16 @@
</organization>
</owner>
</copyright>
<ext>
<editorialgroup>
<committee type="A">TC</committee>
</editorialgroup>
<security>Client Confidential</security>
<structuredidentifier>
<docnumber>1000</docnumber>
<appendix>ABC</appendix>
</structuredidentifier>
</ext>
</local_bibdata>
<sections/>
</bipm-standard>
Expand All @@ -89,6 +105,9 @@
output = <<~"OUTPUT"
{:accesseddate=>"XXX",
:agency=>"#{Metanorma::BIPM.configuration.organization_name_long}",
:appendixid=>"Appendix ABC",
:appendixsubtitle=>"Chef Title Appendix",
:appendixtitle=>"Main Title Appendix",
:authors=>[],
:authors_affiliations=>{},
:circulateddate=>"XXX",
Expand Down Expand Up @@ -116,6 +135,7 @@
:stage=>"Mise en Pratique",
:stage_display=>"En Vigeur",
:stageabbr=>nil,
:tc=>"TC",
:transmitteddate=>"XXX",
:unchangeddate=>"XXX",
:unpublished=>true,
Expand All @@ -133,8 +153,12 @@
input = <<~"INPUT"
<bipm-standard xmlns="https://open.ribose.com/standards/bipm">
<bibdata type="standard">
<title language="en" format="plain">Main Title</title>
<title language="fr" format="plain">Chef Title</title>
<title type="main" language="en" format="plain">Main Title</title>
<title type="main" language="fr" format="plain">Chef Title</title>
<title type="cover" language="en" format="plain">Main Title Cover</title>
<title type="cover" language="fr" format="plain">Chef Title Cover</title>
<title type="appendix" language="en" format="plain">Main Title Appendix</title>
<title type="appendix" language="fr" format="plain">Chef Title Appendix</title>
<docidentifier>1000</docidentifier>
<contributor>
<role type="author"/>
Expand Down Expand Up @@ -168,7 +192,12 @@
<committee type="A">TC</committee>
</editorialgroup>
<security>Client Confidential</security>
<ext><doctype>cipm-mra</doctype></ext>
<ext><doctype>cipm-mra</doctype>
<structuredidentifier>
<docnumber>1000</docnumber>
<appendix>ABC</appendix>
</structuredidentifier>
</ext>
</bibdata>
<local_bibdata type="standard">
<title language="en" format="plain">Main Title</title>
Expand Down Expand Up @@ -206,7 +235,12 @@
<committee type="A">TC</committee>
</editorialgroup>
<security>Client Confidential</security>
<ext><doctype>procès-verbal</doctype></ext>
<ext><doctype>procès-verbal</doctype>
<structuredidentifier>
<docnumber>1000</docnumber>
<appendix>ABC</appendix>
</structuredidentifier>
</ext>
</local_bibdata>
<sections/>
</bipm-standard>
Expand All @@ -215,6 +249,9 @@
output = <<~"OUTPUT"
{:accesseddate=>"XXX",
:agency=>"#{Metanorma::BIPM.configuration.organization_name_long}",
:appendixid=>"Annexe ABC",
:appendixsubtitle=>"Main Title Appendix",
:appendixtitle=>"Chef Title Appendix",
:authors=>[],
:authors_affiliations=>{},
:circulateddate=>"XXX",
Expand Down Expand Up @@ -273,6 +310,8 @@
output = <<~"OUTPUT"
{:accesseddate=>"XXX",
:agency=>"",
:appendixsubtitle=>"",
:appendixtitle=>"",
:authors=>[],
:authors_affiliations=>{},
:circulateddate=>"XXX",
Expand Down Expand Up @@ -329,6 +368,8 @@
output = <<~"OUTPUT"
{:accesseddate=>"XXX",
:agency=>"",
:appendixsubtitle=>"",
:appendixtitle=>"",
:authors=>[],
:authors_affiliations=>{},
:circulateddate=>"XXX",
Expand Down Expand Up @@ -385,6 +426,8 @@
output = <<~"OUTPUT"
{:accesseddate=>"XXX",
:agency=>"",
:appendixsubtitle=>"",
:appendixtitle=>"",
:authors=>[],
:authors_affiliations=>{},
:circulateddate=>"XXX",
Expand Down

0 comments on commit 92ec02d

Please sign in to comment.