metanorma-bsi 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/.hound.yml +3 -0
- data/.rubocop.yml +14 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/LICENSE +25 -0
- data/README.adoc +199 -0
- data/Rakefile +8 -0
- data/bin/rspec +18 -0
- data/lib/asciidoctor/bsi/basicdoc.rng +1131 -0
- data/lib/asciidoctor/bsi/biblio.rng +1235 -0
- data/lib/asciidoctor/bsi/bsi.rng +120 -0
- data/lib/asciidoctor/bsi/bsi_intro_en.xml +105 -0
- data/lib/asciidoctor/bsi/cleanup.rb +78 -0
- data/lib/asciidoctor/bsi/cleanup_ref.rb +183 -0
- data/lib/asciidoctor/bsi/converter.rb +83 -0
- data/lib/asciidoctor/bsi/front.rb +67 -0
- data/lib/asciidoctor/bsi/isodoc.rng +1870 -0
- data/lib/asciidoctor/bsi/isostandard.rng +477 -0
- data/lib/asciidoctor/bsi/reqt.rng +194 -0
- data/lib/asciidoctor/bsi/validate.rb +224 -0
- data/lib/asciidoctor/bsi/validate_list.rb +72 -0
- data/lib/asciidoctor/bsi/validate_requirement.rb +163 -0
- data/lib/isodoc/bsi/base_convert.rb +91 -0
- data/lib/isodoc/bsi/bsi.international-standard.xsl +6540 -0
- data/lib/isodoc/bsi/html/html_bsi_intro.html +8 -0
- data/lib/isodoc/bsi/html/html_bsi_titlepage.html +50 -0
- data/lib/isodoc/bsi/html/htmlstyle.css +968 -0
- data/lib/isodoc/bsi/html/htmlstyle.scss +699 -0
- data/lib/isodoc/bsi/html_convert.rb +56 -0
- data/lib/isodoc/bsi/i18n-en.yaml +56 -0
- data/lib/isodoc/bsi/i18n.rb +15 -0
- data/lib/isodoc/bsi/init.rb +24 -0
- data/lib/isodoc/bsi/metadata.rb +33 -0
- data/lib/isodoc/bsi/pdf_convert.rb +17 -0
- data/lib/isodoc/bsi/presentation_xml_convert.rb +72 -0
- data/lib/isodoc/bsi/sts_convert.rb +30 -0
- data/lib/isodoc/bsi/xref.rb +134 -0
- data/lib/metanorma-bsi.rb +15 -0
- data/lib/metanorma/bsi.rb +6 -0
- data/lib/metanorma/bsi/processor.rb +51 -0
- data/lib/metanorma/bsi/version.rb +6 -0
- data/metanorma-bsi.gemspec +47 -0
- data/spec/asciidoctor/base_spec.rb +778 -0
- data/spec/asciidoctor/blocks_spec.rb +553 -0
- data/spec/asciidoctor/cleanup_spec.rb +547 -0
- data/spec/asciidoctor/inline_spec.rb +176 -0
- data/spec/asciidoctor/lists_spec.rb +194 -0
- data/spec/asciidoctor/refs_spec.rb +318 -0
- data/spec/asciidoctor/section_spec.rb +382 -0
- data/spec/asciidoctor/validate_spec.rb +858 -0
- data/spec/assets/header.html +7 -0
- data/spec/assets/html.css +2 -0
- data/spec/assets/iso.xml +71 -0
- data/spec/assets/rice_image1.png +0 -0
- data/spec/assets/word.css +2 -0
- data/spec/assets/wordintro.html +4 -0
- data/spec/assets/xref_error.adoc +7 -0
- data/spec/isodoc/blocks_spec.rb +259 -0
- data/spec/isodoc/i18n_spec.rb +442 -0
- data/spec/isodoc/inline_spec.rb +287 -0
- data/spec/isodoc/iso_spec.rb +116 -0
- data/spec/isodoc/metadata_spec.rb +262 -0
- data/spec/isodoc/postproc_spec.rb +137 -0
- data/spec/isodoc/ref_spec.rb +376 -0
- data/spec/isodoc/section_spec.rb +467 -0
- data/spec/isodoc/terms_spec.rb +246 -0
- data/spec/isodoc/xref_spec.rb +1730 -0
- data/spec/metanorma/processor_spec.rb +76 -0
- data/spec/spec_helper.rb +291 -0
- data/spec/vcr_cassettes/iso-639.yml +182 -0
- data/spec/vcr_cassettes/isobib_get_639_1967.yml +136 -0
- data/spec/vcr_cassettes/multistandard.yml +352 -0
- metadata +343 -0
@@ -0,0 +1,120 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<grammar ns="https://www.metanorma.org/ns/bsi" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
|
3
|
+
<!-- default namespace = "https://www.metanorma.com/ns/bsi" -->
|
4
|
+
<include href="isostandard.rng">
|
5
|
+
<start>
|
6
|
+
<ref name="bsi-standard"/>
|
7
|
+
</start>
|
8
|
+
<define name="DocumentType">
|
9
|
+
<choice>
|
10
|
+
<value>specification</value>
|
11
|
+
<value>management-systems-standard</value>
|
12
|
+
<value>code-of-practice</value>
|
13
|
+
<value>guide</value>
|
14
|
+
<value>method-of-test</value>
|
15
|
+
<value>method-of-specifying</value>
|
16
|
+
<value>vocabulary</value>
|
17
|
+
<value>classification</value>
|
18
|
+
</choice>
|
19
|
+
</define>
|
20
|
+
<define name="BibDataExtensionType">
|
21
|
+
<ref name="doctype"/>
|
22
|
+
<ref name="editorialgroup"/>
|
23
|
+
<zeroOrMore>
|
24
|
+
<ref name="ics"/>
|
25
|
+
</zeroOrMore>
|
26
|
+
<ref name="structuredidentifier"/>
|
27
|
+
<optional>
|
28
|
+
<ref name="stagename"/>
|
29
|
+
</optional>
|
30
|
+
<optional>
|
31
|
+
<ref name="price-code"/>
|
32
|
+
</optional>
|
33
|
+
<optional>
|
34
|
+
<ref name="cen-processing"/>
|
35
|
+
</optional>
|
36
|
+
</define>
|
37
|
+
<define name="admonition">
|
38
|
+
<element name="admonition">
|
39
|
+
<attribute name="type">
|
40
|
+
<ref name="AdmonitionType"/>
|
41
|
+
</attribute>
|
42
|
+
<optional>
|
43
|
+
<attribute name="class"/>
|
44
|
+
</optional>
|
45
|
+
<attribute name="id">
|
46
|
+
<data type="ID"/>
|
47
|
+
</attribute>
|
48
|
+
<optional>
|
49
|
+
<attribute name="target">
|
50
|
+
<data type="IDREF"/>
|
51
|
+
</attribute>
|
52
|
+
</optional>
|
53
|
+
<optional>
|
54
|
+
<attribute name="uri">
|
55
|
+
<data type="anyURI"/>
|
56
|
+
</attribute>
|
57
|
+
</optional>
|
58
|
+
<optional>
|
59
|
+
<ref name="tname"/>
|
60
|
+
</optional>
|
61
|
+
<zeroOrMore>
|
62
|
+
<ref name="paragraph-with-footnote"/>
|
63
|
+
</zeroOrMore>
|
64
|
+
<zeroOrMore>
|
65
|
+
<ref name="note"/>
|
66
|
+
</zeroOrMore>
|
67
|
+
</element>
|
68
|
+
</define>
|
69
|
+
</include>
|
70
|
+
<!-- end overrides -->
|
71
|
+
<define name="AdmonitionType" combine="choice">
|
72
|
+
<value>commentary</value>
|
73
|
+
</define>
|
74
|
+
<define name="price-code">
|
75
|
+
<element name="price-code">
|
76
|
+
<text/>
|
77
|
+
</element>
|
78
|
+
</define>
|
79
|
+
<define name="cen-processing">
|
80
|
+
<element name="cen-processing">
|
81
|
+
<data type="boolean"/>
|
82
|
+
</element>
|
83
|
+
</define>
|
84
|
+
<!--
|
85
|
+
We display the Normative References between scope and terms; but to keep the
|
86
|
+
grammar simple, we keep the references together
|
87
|
+
-->
|
88
|
+
<define name="bsi-standard">
|
89
|
+
<element name="bsi-standard">
|
90
|
+
<attribute name="version"/>
|
91
|
+
<attribute name="type">
|
92
|
+
<choice>
|
93
|
+
<value>semantic</value>
|
94
|
+
<value>presentation</value>
|
95
|
+
</choice>
|
96
|
+
</attribute>
|
97
|
+
<ref name="bibdata"/>
|
98
|
+
<zeroOrMore>
|
99
|
+
<ref name="termdocsource"/>
|
100
|
+
</zeroOrMore>
|
101
|
+
<optional>
|
102
|
+
<ref name="misccontainer"/>
|
103
|
+
</optional>
|
104
|
+
<optional>
|
105
|
+
<ref name="boilerplate"/>
|
106
|
+
</optional>
|
107
|
+
<ref name="preface"/>
|
108
|
+
<oneOrMore>
|
109
|
+
<ref name="sections"/>
|
110
|
+
</oneOrMore>
|
111
|
+
<zeroOrMore>
|
112
|
+
<ref name="annex"/>
|
113
|
+
</zeroOrMore>
|
114
|
+
<ref name="bibliography"/>
|
115
|
+
<zeroOrMore>
|
116
|
+
<ref name="indexsect"/>
|
117
|
+
</zeroOrMore>
|
118
|
+
</element>
|
119
|
+
</define>
|
120
|
+
</grammar>
|
@@ -0,0 +1,105 @@
|
|
1
|
+
<boilerplate>
|
2
|
+
<copyright-statement>
|
3
|
+
<clause>
|
4
|
+
{% if unpublished %}
|
5
|
+
<p><strong>Copyright © {{ docyear }} International Electrotechnical Commission, IEC.</strong>
|
6
|
+
All rights reserved. It is permitted to download this electronic file, to make a copy and to
|
7
|
+
print out the content for the sole purpose of preparing National Committee positions. You
|
8
|
+
may not copy or "mirror" the file or printed version of the document, or any part of it,
|
9
|
+
for any other purpose without permission in writing from IEC.
|
10
|
+
{% else %}
|
11
|
+
<p id="boilerplate-year">
|
12
|
+
© {{ agency }} {{ docyear }}, Published in Switzerland
|
13
|
+
</p>
|
14
|
+
<p id="boilerplate-message">
|
15
|
+
All rights
|
16
|
+
reserved. Unless otherwise specified, no part of this publication may be
|
17
|
+
reproduced or utilized otherwise in any form or by any means, electronic or
|
18
|
+
mechanical, including photocopying, or posting on the internet or an intranet,
|
19
|
+
without prior written permission. Permission can be requested from either IEC
|
20
|
+
at the address below or IEC's member body in the country of the requester.
|
21
|
+
</p>
|
22
|
+
<p id="boilerplate-name">IEC Central Office</p>
|
23
|
+
<p id="boilerplate-address" align="left">
|
24
|
+
3, rue de Varembé<br/>
|
25
|
+
CH-1211 Geneva 20, Switzerland<br/>
|
26
|
+
Tel.  + 41 22 919 02 11<br/>
|
27
|
+
Fax  + 41 22 919 03 00<br/>
|
28
|
+
info@iec.ch<br/>
|
29
|
+
www.iec.ch
|
30
|
+
{% endif %}
|
31
|
+
</p>
|
32
|
+
</clause>
|
33
|
+
</copyright-statement>
|
34
|
+
<legal-statement>
|
35
|
+
<clause>
|
36
|
+
<p>Attention is drawn to the possibility that some of the elements of this IEC Publication may be the subject of patent rights. IEC shall not be held responsible for identifying any or all such patent rights.</p>
|
37
|
+
</clause>
|
38
|
+
</legal-statement>
|
39
|
+
{% if unpublished %}
|
40
|
+
<license-statement>
|
41
|
+
<clause>
|
42
|
+
{% if stage_int < 50 %}
|
43
|
+
<p>This document is still under study and subject to change. It should not be used for reference purposes.</p>
|
44
|
+
until published as such.</p>
|
45
|
+
{% endif %}
|
46
|
+
{% if stage_int >= 50 %}
|
47
|
+
<p>This document is a draft distributed for approval. It may not be referred to as an International Standard
|
48
|
+
until published as such.</p>
|
49
|
+
{% endif %}
|
50
|
+
{% if stage_int >= 50 %}
|
51
|
+
<p>In addition to their evaluation as being acceptable for industrial, technological, commercial and user
|
52
|
+
purposes, Final Draft International Standards may on occasion have to be considered in the light of their
|
53
|
+
potential to become standards to which reference may be made in national regulations.</p>
|
54
|
+
{% endif %}
|
55
|
+
<p>Recipients of this document are invited to submit, with their comments, notification of any relevant
|
56
|
+
patent rights of which they are aware and to provide supporting documentation.</p>
|
57
|
+
</clause>
|
58
|
+
</license-statement>
|
59
|
+
{% endif %}
|
60
|
+
<feedback-statement>
|
61
|
+
{% if unpublished %}
|
62
|
+
<clause id="boilerplate-cenelec-attention">
|
63
|
+
<title>Attention IEC-CENELEC parallel voting</title>
|
64
|
+
<p>The attention of IEC National Committees, members of CENELEC, is drawn to the fact that this
|
65
|
+
{% if stage_int >= 30 and stage_int < 40 %}Committee Draft{% endif %}
|
66
|
+
{% if stage_int >= 40 and stage_int < 50 %}Committee Draft For Vote{% endif %}
|
67
|
+
{% if stage_int >= 50 and stage_int < 60 %}Final Draft International Standard{% endif %}
|
68
|
+
({{ stageabbr }})
|
69
|
+
is submitted for parallel voting.</p>
|
70
|
+
<p>The CENELEC members are invited to vote through the CENELEC voting system.</p>
|
71
|
+
</clause>
|
72
|
+
{% else %}
|
73
|
+
<clause>
|
74
|
+
<title>About the IEC</title>
|
75
|
+
<p>The International Electrotechnical Commission (IEC) is the leading global organization that prepares and publishes International Standards for all electrical, electronic and related technologies.</p>
|
76
|
+
</clause>
|
77
|
+
<clause>
|
78
|
+
<title>About IEC publications</title>
|
79
|
+
<p>The technical content of IEC publications is kept under constant review by the IEC. Please make sure that you have the latest edition, a corrigenda or an amendment might have been published.</p>
|
80
|
+
</clause>
|
81
|
+
<clause>
|
82
|
+
<clause>
|
83
|
+
<title>IEC Catalogue - <link target="https://webstore.iec.ch/catalogue">webstore.iec.ch/catalogue</link></title>
|
84
|
+
<p>The stand-alone application for consulting the entire bibliographical information on IEC International Standards, Technical Specifications, Technical Reports and other documents. Available for PC, Mac OS, Android Tablets and iPad.</p>
|
85
|
+
</clause>
|
86
|
+
<clause><title>IEC publications search - <link target="https://www.iec.ch/searchpub">www.iec.ch/searchpub</link></title>
|
87
|
+
<p>The advanced search enables to find IEC publications by a variety of criteria (reference number, text, technical committee,...). It also gives information on projects, replaced and withdrawn publications.</p>
|
88
|
+
</clause>
|
89
|
+
<clause><title>IEC Just Published - <link target="https://webstore.iec.ch/justpublished">webstore.iec.ch/justpublished</link></title>
|
90
|
+
<p>Stay up to date on all new IEC publications. Just Published details all new publications released. Available online and also once a month by email.</p>
|
91
|
+
</clause>
|
92
|
+
<clause><title>Electropedia - <link target="http://www.electropedia.org">www.electropedia.org</link></title>
|
93
|
+
<p>The world's leading online dictionary of electronic and electrical terms containing more than 30 000 terms and definitions in English and French, with equivalent terms in 14 additional languages. Also known as the International Electrotechnical Vocabulary (IEV) online.</p>
|
94
|
+
</clause>
|
95
|
+
<clause><title>IEC Glossary - <link target="http://std.iec.ch/glossary">std.iec.ch/glossary</link></title>
|
96
|
+
<p>More than 55 000 electrotechnical terminology entries in English and French extracted from the Terms and Definitions clause of IEC publications issued since 2002. Some entries have been collected from earlier publications of IEC TC 37, 77, 86 and CISPR.</p>
|
97
|
+
</clause>
|
98
|
+
<clause><title>IEC Customer Service Centre - <link target="https://webstore.iec.ch/csc">webstore.iec.ch/csc</link></title>
|
99
|
+
<p>If you wish to give us your feedback on this publication or need further assistance, please contact the Customer Service Centre: <link target="mailto://csc@iec.ch">csc@iec.ch</link>.</p>
|
100
|
+
</clause>
|
101
|
+
</clause>
|
102
|
+
{% endif %}
|
103
|
+
</feedback-statement>
|
104
|
+
</boilerplate>
|
105
|
+
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require_relative "cleanup_ref"
|
2
|
+
|
3
|
+
module Asciidoctor
|
4
|
+
module BSI
|
5
|
+
class Converter < ISO::Converter
|
6
|
+
def cleanup(xmldoc)
|
7
|
+
super
|
8
|
+
ol_cleanup(xmldoc)
|
9
|
+
commentary_cleanup(xmldoc)
|
10
|
+
xmldoc
|
11
|
+
end
|
12
|
+
|
13
|
+
def ol_cleanup(doc)
|
14
|
+
doc.xpath("//clause[not(.//clause)] | //annex | //preface/* | //note")
|
15
|
+
.each do |c|
|
16
|
+
(c.xpath(".//ol") - c.xpath(".//ul//ol | .//ol//ol"))
|
17
|
+
.each_with_index do |l, i|
|
18
|
+
ol_cleanup1(l, i)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def ol_cleanup1(list, idx)
|
24
|
+
styles = %w(alphabet arabic roman)
|
25
|
+
list["type"] = styles[idx % styles.size]
|
26
|
+
(list.xpath(".//ol") - list.xpath(".//ol//ol")).each do |l|
|
27
|
+
ol_cleanup1(l, idx + 1)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def commentary_cleanup(xmldoc)
|
32
|
+
@isodoc ||= isodoc(@lang, @script)
|
33
|
+
xmldoc.xpath("//admonition[@type = 'commentary'][not(@target)]")
|
34
|
+
.each do |a|
|
35
|
+
a["target"] = @isodoc.get_clause_id(a)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def get_id_prefix(xmldoc)
|
40
|
+
prefix = []
|
41
|
+
xmldoc.xpath("//bibdata/contributor[role/@type = 'publisher']"\
|
42
|
+
"/organization").each do |x|
|
43
|
+
x1 = x.at("abbreviation")&.text || x.at("name")&.text
|
44
|
+
x1 == "BSI" and prefix.unshift("BS") or prefix << x1
|
45
|
+
end
|
46
|
+
prefix
|
47
|
+
end
|
48
|
+
|
49
|
+
# BS as a prefix goes first
|
50
|
+
def docidentifier_cleanup(xmldoc)
|
51
|
+
prefix = get_id_prefix(xmldoc)
|
52
|
+
id = xmldoc.at("//bibdata/docidentifier[@type = 'BS']") or return
|
53
|
+
id.content = id_prefix(prefix, id)
|
54
|
+
id = xmldoc.at("//bibdata/ext/structuredidentifier/project-number") and
|
55
|
+
id.content = id_prefix(prefix, id)
|
56
|
+
end
|
57
|
+
|
58
|
+
def table_footnote_renumber1(fn, i, seen)
|
59
|
+
content = footnote_content(fn)
|
60
|
+
if seen[content] then outnum = seen[content]
|
61
|
+
else
|
62
|
+
i += 1
|
63
|
+
outnum = i
|
64
|
+
seen[content] = outnum
|
65
|
+
end
|
66
|
+
fn["reference"] = (outnum - 1 + "A".ord).chr
|
67
|
+
fn["table"] = true
|
68
|
+
[i, seen]
|
69
|
+
end
|
70
|
+
|
71
|
+
# TODO: Rules for structure 10.5 amendments:
|
72
|
+
# cite as BS 6380:2012+A1, reference as BS 6380:2012+A1:2016
|
73
|
+
|
74
|
+
# TODO: Rules for structure 16.5.2 wording of terms boilerplate:
|
75
|
+
# "British Standard (part of BS..)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,183 @@
|
|
1
|
+
module Asciidoctor
|
2
|
+
module BSI
|
3
|
+
class Converter < ISO::Converter
|
4
|
+
def biblio_cleanup(xmldoc)
|
5
|
+
biblio_metanorma_ids_informative(xmldoc)
|
6
|
+
super
|
7
|
+
xmldoc.xpath("//bibliography//references | //clause//references | "\
|
8
|
+
"//annex//references").each do |r|
|
9
|
+
next if r["normative"] == "true"
|
10
|
+
|
11
|
+
if r.at("./bibitem/docidentifier[@type = 'metanorma']") &&
|
12
|
+
r.at("./bibitem[not(docidentifier[@type = 'metanorma'])]")
|
13
|
+
split_ref(r, false)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Rules for Structure 15.4
|
19
|
+
def biblio_metanorma_ids_normative(xmldoc)
|
20
|
+
xmldoc.xpath("//references[@normative = 'true']/bibitem")
|
21
|
+
.each_with_index do |b, i|
|
22
|
+
biblio_metanorma_ids1(b, i)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def biblio_metanorma_ids_informative(xmldoc)
|
27
|
+
xmldoc.xpath("//references[@normative = 'false']/bibitem")
|
28
|
+
.each_with_index do |b, i|
|
29
|
+
biblio_metanorma_ids1(b, i)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def biblio_metanorma_ids1(bib, idx)
|
34
|
+
bib.at("./docidentifier[@type][not(@type = 'DOI' or "\
|
35
|
+
"@type = 'ISSN' or @type = 'ISBN')]") and return
|
36
|
+
bib&.at("./docidentifier[@type = 'metanorma']")&.remove
|
37
|
+
bib.at("./docidentifier").previous =
|
38
|
+
"<docidentifier type='metanorma'>[#{idx}]</docidentifier>"
|
39
|
+
end
|
40
|
+
|
41
|
+
# Rules for Structure 21.4
|
42
|
+
def biblio_metanorma_ids_informative(xmldoc)
|
43
|
+
xmldoc.xpath("//references[@normative = 'false']/bibitem")
|
44
|
+
.each_with_index do |b, i|
|
45
|
+
biblio_metanorma_ids1(b, i)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def biblio_reorder(xmldoc)
|
50
|
+
@sort_bib_by_appearance = true
|
51
|
+
xmldoc.xpath("//references[@normative = 'false']").each do |r|
|
52
|
+
biblio_reorder1(r)
|
53
|
+
end
|
54
|
+
@sort_bib_by_appearance = false
|
55
|
+
xmldoc.xpath("//references[@normative = 'true']").each do |r|
|
56
|
+
biblio_reorder1(r)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def sort_biblio(bib)
|
61
|
+
@sort_bib_by_appearance and sort_biblio_appearance(bib) or
|
62
|
+
sort_norm_appearance(bib)
|
63
|
+
end
|
64
|
+
|
65
|
+
def citation_order(bib)
|
66
|
+
return {} if bib.empty?
|
67
|
+
|
68
|
+
ids = bib.each_with_object({}) { |b, m| m[b["id"]] = nil }
|
69
|
+
bib.first.document.xpath(".//xref").each_with_index do |b, i|
|
70
|
+
next unless ids.has_key?(b["target"])
|
71
|
+
|
72
|
+
ids[b["target"]] ||= i + 1
|
73
|
+
end
|
74
|
+
ids
|
75
|
+
end
|
76
|
+
|
77
|
+
def id_to_num(bib, ids)
|
78
|
+
return "000000000" if bib["id"].nil?
|
79
|
+
|
80
|
+
sprintf("%09d", ids[bib["id"]] || 0)
|
81
|
+
end
|
82
|
+
|
83
|
+
def sort_biblio_appearance(bib)
|
84
|
+
ids = citation_order(bib)
|
85
|
+
bib.sort do |a, b|
|
86
|
+
id_to_num(a, ids) <=> id_to_num(b, ids)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def sort_norm_appearance(bib)
|
91
|
+
ids = citation_order(bib)
|
92
|
+
bib.each do |b|
|
93
|
+
ids[b["id"]] = 0 unless b.at("./docidentifier[@type = 'metanorma']")
|
94
|
+
end
|
95
|
+
bib.sort do |a, b|
|
96
|
+
"#{id_to_num(a, ids)} :: #{sort_biblio_key(a)}" <=>
|
97
|
+
"#{id_to_num(b, ids)} :: #{sort_biblio_key(b)}"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# Rules for Structure 15.4
|
102
|
+
# Normative references ordering
|
103
|
+
# sort by: alphanumeric
|
104
|
+
# prefix, then docnumber if present, numeric sort
|
105
|
+
# else alphanumeric metanorma id (abbreviation)
|
106
|
+
# then doc part number if present, numeric sort
|
107
|
+
# then doc id (not DOI &c)
|
108
|
+
# then title
|
109
|
+
def sort_biblio_key(bib)
|
110
|
+
num = bib&.at("./docnumber")&.text
|
111
|
+
id = bib&.at("./docidentifier[not(#{OTHERIDS})]")
|
112
|
+
metaid = bib&.at("./docidentifier[@type = 'metanorma']")&.text
|
113
|
+
abbrid = metaid unless /^\[\d+\]$/.match?(metaid)
|
114
|
+
/\d-(?<partid>\d+)/ =~ id&.text
|
115
|
+
type = id["type"] if id
|
116
|
+
title = bib&.at("./title[@type = 'main']")&.text ||
|
117
|
+
bib&.at("./title")&.text || bib&.at("./formattedref")&.text
|
118
|
+
"#{type} :: "\
|
119
|
+
"#{num.nil? ? abbrid : sprintf('%09d', num.to_i)} :: "\
|
120
|
+
"#{partid} :: #{id&.text} :: #{title}"
|
121
|
+
end
|
122
|
+
|
123
|
+
def biblio_renumber(xmldoc)
|
124
|
+
["true", "false"].each do |norm|
|
125
|
+
i = 0
|
126
|
+
xmldoc.xpath("//bibliography//references | //clause//references | "\
|
127
|
+
"//annex//references").each do |r|
|
128
|
+
next if r["normative"] != norm
|
129
|
+
|
130
|
+
r.xpath("./bibitem").each do |b|
|
131
|
+
next unless docid = b.at("./docidentifier[@type = 'metanorma']")
|
132
|
+
next unless /^\[\d+\]$/.match?(docid.text)
|
133
|
+
|
134
|
+
i += 1
|
135
|
+
docid.children = "[#{norm == 'true' ? 'N' : ''}#{i}]"
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
# Rules for Structure 15.4
|
142
|
+
def normref_cleanup(xmldoc)
|
143
|
+
biblio_metanorma_ids_normative(xmldoc)
|
144
|
+
super
|
145
|
+
xmldoc.xpath("//bibliography//references | //clause//references | "\
|
146
|
+
"//annex//references").each do |r|
|
147
|
+
next if r["normative"] == "false"
|
148
|
+
|
149
|
+
if r.at("./bibitem/docidentifier[@type = 'metanorma']") &&
|
150
|
+
r.at("./bibitem[not(docidentifier[@type = 'metanorma'])]")
|
151
|
+
split_ref(r, true)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def new_ref(title, norm)
|
157
|
+
"<references normative='#{norm}' unnumbered='true'>"\
|
158
|
+
"<title>#{title}</title></references>"
|
159
|
+
end
|
160
|
+
|
161
|
+
def split_ref(ref, norm)
|
162
|
+
std = ref.add_child(new_ref("Standards publications", norm)).first
|
163
|
+
other = ref.add_child(new_ref("Other publications", norm)).first
|
164
|
+
ref.xpath("./bibitem").each do |b|
|
165
|
+
b.parent =
|
166
|
+
b.at("./docidentifier[@type = 'metanorma']") ? other : std
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
def boilerplate_cleanup(xmldoc)
|
171
|
+
super
|
172
|
+
f = xmldoc.at("//bibliography//references[@normative = 'false']"\
|
173
|
+
"[not(references)]")
|
174
|
+
f and biblio_preface(f)
|
175
|
+
end
|
176
|
+
|
177
|
+
# Rules for Structure 21.5
|
178
|
+
def biblio_preface(ref)
|
179
|
+
ref.at("./title").next = "<p>#{@i18n.biblio_pref}</p>"
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|