Skip to content

Commit

Permalink
Merge pull request #90 from metanorma/feature/horizontal
Browse files Browse the repository at this point in the history
Feature/horizontal
  • Loading branch information
opoudjis authored Nov 30, 2020
2 parents 86163bd + ff52c1e commit 671a24a
Show file tree
Hide file tree
Showing 17 changed files with 223 additions and 11 deletions.
6 changes: 5 additions & 1 deletion lib/asciidoctor/iec/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def doctype_validate(xmldoc)
publicly-available-specification international-workshop-agreement
guide interpretation-sheet).include? doctype or
@log.add("Document Attributes", nil, "#{doctype} is not a recognised document type")
if function = xmldoc&.at("//bibdata/ext/function")&.text
%w(emc quality-assurance safety environment).include? function or
@log.add("Document Attributes", nil, "#{function} is not a recognised document function")
end
end

def validate(doc)
Expand Down Expand Up @@ -58,7 +62,7 @@ def presentation_xml_converter(node)
node.nil? ? IsoDoc::Iec::PresentationXMLConvert.new({}) :
IsoDoc::Iec::PresentationXMLConvert.new(doc_extract_attributes(node))
end

def norm_ref_preface(f)
return super unless @is_iev
f.at("./title").next =
Expand Down
6 changes: 6 additions & 0 deletions lib/asciidoctor/iec/front.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ def metadata_status(node, xml)
node.attr("iteration") && (s.iteration node.attr("iteration"))
end
end

def metadata_doctype(node, xml)
xml.doctype doctype(node)
xml.horizontal (node.attr("horizontal") || "false")
a = node.attr("function") and xml.function a
end
end
end
end
37 changes: 36 additions & 1 deletion lib/asciidoctor/iec/iec.rng
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<grammar ns="https://www.metanorma.org/ns/iec" xmlns="http://relaxng.org/ns/structure/1.0">
<grammar ns="https://www.metanorma.org/ns/iec" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
<!-- default namespace = "https://www.metanorma.com/ns/iec" -->
<include href="isostandard.rng">
<start>
Expand All @@ -15,8 +15,43 @@
<value>guide</value>
</choice>
</define>
<define name="BibDataExtensionType">
<ref name="doctype"/>
<optional>
<ref name="horizontal"/>
</optional>
<optional>
<ref name="function"/>
</optional>
<ref name="editorialgroup"/>
<zeroOrMore>
<ref name="ics"/>
</zeroOrMore>
<ref name="structuredidentifier"/>
<optional>
<ref name="stagename"/>
</optional>
<optional>
<ref name="updates_document_type"/>
</optional>
</define>
</include>
<!-- end overrides -->
<define name="function">
<element name="function">
<choice>
<value>emc</value>
<value>safety</value>
<value>environment</value>
<value>quality-assurance</value>
</choice>
</element>
</define>
<define name="horizontal">
<element name="horizontal">
<data type="boolean"/>
</element>
</define>
<!--
We display the Normative References between scope and terms; but to keep the
grammar simple, we keep the references together
Expand Down
8 changes: 8 additions & 0 deletions lib/asciidoctor/iec/isostandard.rng
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
</define>
<define name="BibDataExtensionType">
<ref name="doctype"/>
<optional>
<ref name="horizontal"/>
</optional>
<ref name="editorialgroup"/>
<zeroOrMore>
<ref name="ics"/>
Expand Down Expand Up @@ -429,6 +432,11 @@
<ref name="bibliography"/>
</element>
</define>
<define name="horizontal">
<element name="horizontal">
<data type="boolean"/>
</element>
</define>
<define name="documentnumber">
<element name="project-number">
<optional>
Expand Down
16 changes: 16 additions & 0 deletions lib/isodoc/iec/i18n-en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,19 @@ term_def_boilerplate: |
<li> <p>ISO Online browsing platform: available at
<link target="http://www.iso.org/obp"/></p> </li>
</ul>
doctype_dict:
international-standard: International Standard
technical-specification: Technical Specification
technical-report: Technical Report
publicly-available-specification: Publicly Available Specification
international-workshop-agreement: International Workshop Agreement
guide: Guide
interpretation-sheet: Interpretation Sheet
function_dict:
emc: Basic EMC Publication
safety: Basic Safety Publication
environment: Basic Environment Publication
quality-assurance: Basic Quality Assurance Publication
horizontal_dict:
"true": Horizontal Standard
"false":
17 changes: 17 additions & 0 deletions lib/isodoc/iec/i18n-fr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,20 @@ term_def_boilerplate: |
<li> <p>ISO Online browsing platform: disponible à l'adresse
<link target="http://www.iso.org/obp"/></p> </li>
</ul>
doctype_dict:
international-standard: Norme international
technical-specification: Spécification technique
technical-report: Rapport technique
publicly-available-specification: Spécification disponible publiquement
international-workshop-agreement: Accord internationale d’atelier
guide: Guide
interpretation-sheet: Feuille d’interprétation
function_dict:
emc: Publication fondamentale en CEM
safety: Publication fondamentale de sécurité
environment: Publication fondamentale sur l’environnement
quality-assurance: Publication fondamentale sur l’assurance de la qualité
horizontal_dict:
"true": Norme horizontale
"false":

4 changes: 3 additions & 1 deletion lib/isodoc/iec/iec.international-standard.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -2591,6 +2591,7 @@
</xsl:attribute-set><xsl:attribute-set name="term-style">

</xsl:attribute-set><xsl:attribute-set name="figure-name-style">




Expand Down Expand Up @@ -4575,7 +4576,8 @@
</fo:inline>
</xsl:if>
</xsl:template><xsl:template match="*[local-name() = 'figure']">
<fo:block-container id="{@id}">
<fo:block-container id="{@id}">

<fo:block>
<xsl:apply-templates/>
</fo:block>
Expand Down
33 changes: 33 additions & 0 deletions lib/isodoc/iec/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,39 @@ def docstatus(isoxml, _out)
set(:revdate, revdate&.text)
end

def doctype(isoxml, _out)
super
b = isoxml&.at(ns("//bibdata/ext/doctype#{NOLANG}"))&.text
b1 = isoxml&.at(ns("//bibdata/ext/doctype[@language = 'en']"))&.text || b
b1 and set(:doctype_en, status_print(b1))
b1 = isoxml&.at(ns("//bibdata/ext/doctype[@language = 'fr']"))&.text || b
b1 and set(:doctype_fr, status_print(b1))
docfunction(isoxml)
dochorizontal(isoxml)
end

def docfunction(isoxml)
b = isoxml&.at(ns("//bibdata/ext/function#{NOLANG}"))&.text || return
b and set(:function, status_print(b))
b1 = isoxml&.at(ns("//bibdata/ext/function#{currlang}"))&.text || b
b1 and set(:function_display, status_print(b1))
b1 = isoxml&.at(ns("//bibdata/ext/function[@language = 'en']"))&.text || b
b1 and set(:function_en, status_print(b1))
b1 = isoxml&.at(ns("//bibdata/ext/function[@language = 'fr']"))&.text || b
b1 and set(:function_fr, status_print(b1))
end

def dochorizontal(isoxml)
b = isoxml&.at(ns("//bibdata/ext/horizontal#{NOLANG}"))&.text || return
b and set(:horizontal, status_print(b))
b1 = isoxml&.at(ns("//bibdata/ext/horizontal#{currlang}"))&.text
b1 and set(:horizontal_display, status_print(b1))
b1 = isoxml&.at(ns("//bibdata/ext/horizontal[@language = 'en']"))&.text
b1 and set(:horizontal_en, status_print(b1))
b1 = isoxml&.at(ns("//bibdata/ext/horizontal[@language = 'fr']"))&.text
b1 and set(:horizontal_fr, status_print(b1))
end

def unpublished(status)
status.to_i > 0 && status.to_i < 60
end
Expand Down
12 changes: 12 additions & 0 deletions lib/isodoc/iec/presentation_xml_convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ def clause1(f)
call(f)
end

def bibdata_i18n(b)
fr = IsoDoc::Iec::I18n.new("fr", "Latn")
en = IsoDoc::Iec::I18n.new("en", "Latn")
[{ lang: "en", i18n: en }, { lang: "fr", i18n: fr }].each do |v|
hash_translate(b, v[:i18n].get["doctype_dict"], "./ext/doctype", v[:lang])
hash_translate(b, v[:i18n].get["stage_dict"], "./status/stage", v[:lang])
hash_translate(b, v[:i18n].get["substage_dict"], "./status/substage", v[:lang])
hash_translate(b, v[:i18n].get["function_dict"], "./ext/function", v[:lang])
hash_translate(b, v[:i18n].get["horizontal_dict"], "./ext/horizontal", v[:lang])
end
end

include Init
end
end
Expand Down
8 changes: 8 additions & 0 deletions spec/asciidoctor-iec/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
</copyright>
<ext>
<doctype>article</doctype>
<horizontal>false</horizontal>
<editorialgroup>
<technical-committee number="1" type="A">TC</technical-committee>
<technical-committee number="11" type="A1">TC1</technical-committee>
Expand Down Expand Up @@ -190,6 +191,8 @@
:copyright-year: 2001
:docstage: A2CD
:doctype: technical-specification
:function: emc
:horizontal: true
INPUT
<?xml version="1.0" encoding="UTF-8"?>
<iec-standard xmlns="https://www.metanorma.org/ns/iec" type="semantic" version="#{Metanorma::Iec::VERSION}">
Expand Down Expand Up @@ -272,6 +275,8 @@
</copyright>
<ext>
<doctype>technical-specification</doctype>
<horizontal>true</horizontal>
<function>emc</function>
<editorialgroup>
<technical-committee/>
<subcommittee/>
Expand Down Expand Up @@ -376,6 +381,7 @@
</copyright>
<ext>
<doctype>article</doctype>
<horizontal>false</horizontal>
<editorialgroup>
<technical-committee/>
<subcommittee/>
Expand Down Expand Up @@ -440,6 +446,7 @@
</copyright>
<ext>
<doctype>article</doctype>
<horizontal>false</horizontal>
<editorialgroup>
<technical-committee/>
<subcommittee/>
Expand Down Expand Up @@ -505,6 +512,7 @@
</copyright>
<ext>
<doctype>article</doctype>
<horizontal>false</horizontal>
<editorialgroup>
<technical-committee/>
<subcommittee/>
Expand Down
2 changes: 1 addition & 1 deletion spec/asciidoctor-iec/blocks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
#{BLANK_HDR}
<sections>
<admonition id="_" type="safety precautions"><name>Safety Precautions</name><p id="_">While werewolves are hardy community members, keep in mind the following dietary concerns:</p>
<ol id="_" type="arabic">
<ol id="_">
<li>
<p id="_">They are allergic to cinnamon.</p>
</li>
Expand Down
3 changes: 3 additions & 0 deletions spec/asciidoctor-iec/iev_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
</copyright>
<ext>
<doctype>article</doctype>
<horizontal>false</horizontal>
<editorialgroup>
<technical-committee/>
<subcommittee/>
Expand Down Expand Up @@ -131,6 +132,7 @@
</copyright>
<ext>
<doctype>article</doctype>
<horizontal>false</horizontal>
<editorialgroup>
<technical-committee/>
<subcommittee/>
Expand Down Expand Up @@ -209,6 +211,7 @@
</copyright>
<ext>
<doctype>article</doctype>
<horizontal>false</horizontal>
<editorialgroup>
<technical-committee/>
<subcommittee/>
Expand Down
12 changes: 6 additions & 6 deletions spec/asciidoctor-iec/lists_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</li>
<li>
<p id="_">List 3</p>
<ol id="_" type="arabic">
<ol id="_">
<li>
<p id="_">List A</p>
</li>
Expand Down Expand Up @@ -107,13 +107,13 @@
<li><p id="_">Second</p><p id="_">entry1</p>
<p id="_">entry2</p></li>
</ul>
<ol id="id1" type="alphabet">
<ol id="id1">
<li>
<p id="_">First</p>
</li>
<li>
<p id="_">Second</p>
<ol id="_" type="alphabet_upper">
<ol id="_">
<li>
<p id="_">Third</p>
</li>
Expand All @@ -129,19 +129,19 @@
<p id="_">Sixth</p>
</li>
</ol>
<ol id="_" type="roman">
<ol id="_">
<li>
<p id="_">A</p>
</li>
<li>
<p id="_">B</p>
<ol id="_" type="roman_upper">
<ol id="_">
<li>
<p id="_">C</p>
</li>
<li>
<p id="_">D</p>
<ol id="_" type="arabic">
<ol id="_">
<li>
<p id="_">E</p>
</li>
Expand Down
15 changes: 15 additions & 0 deletions spec/asciidoctor-iec/validate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,19 @@
INPUT
expect(File.read("test.err")).to include "pizza is not a recognised document type"
end

it "Warns of illegal function" do
FileUtils.rm_f "test.err"
Asciidoctor.convert(<<~"INPUT", backend: :iec, header_footer: true)
= Document title
Author
:docfile: test.adoc
:nodoc:
:no-isobib:
:function: pizza
text
INPUT
expect(File.read("test.err")).to include "pizza is not a recognised document function"
end
end
Loading

0 comments on commit 671a24a

Please sign in to comment.