metanorma-jis 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,43 @@
1
+ module Metanorma
2
+ module JIS
3
+ class Converter < ISO::Converter
4
+ def norm_ref_preface(ref)
5
+ if ref.at("./note[@type = 'boilerplate']")
6
+ unwrap_boilerplate_clauses(ref, ".")
7
+ else
8
+ pref = if ref_empty?(ref) then @i18n.norm_empty_pref
9
+ else @i18n.get[ref_dated(ref)]
10
+ end
11
+ ref.at("./title").next = "<p>#{pref}</p>"
12
+ end
13
+ end
14
+
15
+ def ref_empty?(ref)
16
+ ref.xpath(".//bibitem").empty?
17
+ end
18
+
19
+ def ref_dated(ref)
20
+ refs = ref.xpath("./bibitem").each_with_object({}) do |e, m|
21
+ if e.at("./date") then m[:dated] = true
22
+ else m[:undated] = true
23
+ end
24
+ end
25
+ refs[:dated] && refs[:undated] and return "norm_with_refs_pref"
26
+ refs[:dated] and return "norm_with_refs_pref_all_dated"
27
+ "norm_with_refs_pref_none_dated"
28
+ end
29
+
30
+ def table_footnote_renumber(xmldoc)
31
+ xmldoc.xpath("//table | //figure").each do |t|
32
+ seen = {}
33
+ i = 0
34
+ t.xpath(".//fn").each do |fn|
35
+ i, seen = table_footnote_renumber1(fn, i, seen)
36
+ end
37
+ end
38
+ end
39
+
40
+ def docidentifier_cleanup(xmldoc); end
41
+ end
42
+ end
43
+ end
@@ -1,6 +1,8 @@
1
1
  require "asciidoctor"
2
2
  require "metanorma-iso"
3
3
  require_relative "./front"
4
+ require_relative "./validate"
5
+ require_relative "./cleanup"
4
6
 
5
7
  module Metanorma
6
8
  module JIS
@@ -16,10 +18,27 @@ module Metanorma
16
18
  super
17
19
  end
18
20
 
21
+ def doctype(node)
22
+ ret = node.attr("doctype")&.gsub(/\s+/, "-")&.downcase ||
23
+ "japanese-industrial-standard"
24
+ ret = "japanese-industrial-standard" if ret == "article"
25
+ ret
26
+ end
27
+
19
28
  def boilerplate_file(_x_orig)
20
29
  File.join(@libdir, "jis_intro_jp.xml")
21
30
  end
22
31
 
32
+ def section_attributes(node)
33
+ ret = super
34
+ if node.attr("style") == "appendix" && node.level == 1 &&
35
+ node.option?("commentary")
36
+ ret[:commentary] = true
37
+ node.set_attr("obligation", "informative")
38
+ end
39
+ ret
40
+ end
41
+
23
42
  def html_converter(node)
24
43
  if node.nil?
25
44
  IsoDoc::JIS::HtmlConvert.new({})
@@ -39,8 +58,6 @@ module Metanorma
39
58
  def pdf_converter(node)
40
59
  return if node.attr("no-pdf")
41
60
 
42
- return
43
-
44
61
  if node.nil?
45
62
  IsoDoc::JIS::PdfConvert.new({})
46
63
  else
@@ -55,19 +72,6 @@ module Metanorma
55
72
  IsoDoc::JIS::PresentationXMLConvert.new(doc_extract_attributes(node))
56
73
  end
57
74
  end
58
-
59
- def script_validate(xmldoc)
60
- script = xmldoc&.at("//bibdata/script")&.text
61
- %w(Jpan Latn).include?(script) or
62
- @log.add("Document Attributes", nil,
63
- "#{script} is not a recognised script")
64
- end
65
-
66
- def validate(doc)
67
- content_validate(doc)
68
- schema_validate(formattedstr_strip(doc.dup),
69
- File.join(File.dirname(__FILE__), "jis.rng"))
70
- end
71
75
  end
72
76
  end
73
77
  end
@@ -1,3 +1,5 @@
1
+ require "pubid-jis"
2
+
1
3
  module Metanorma
2
4
  module JIS
3
5
  class Converter < ISO::Converter
@@ -57,6 +59,71 @@ module Metanorma
57
59
  title_amd(node, xml, lang, at) if @amd
58
60
  end
59
61
  end
62
+
63
+ def metadata_id(node, xml)
64
+ node.attr("docidentifier") || node.attr("docnumber") or
65
+ @fatalerror << "No docnumber attribute supplied"
66
+ if id = node.attr("docidentifier")
67
+ xml.docidentifier id.sub(/^JIS /, ""), **attr_code(type: "JIS")
68
+ else iso_id(node, xml)
69
+ end
70
+ xml.docnumber node.attr("docnumber")
71
+ end
72
+
73
+ def get_typeabbr(node, amd: false)
74
+ amd || node.attr("amendment-number") and return :amd
75
+ case doctype(node)
76
+ when "technical-report" then :tr
77
+ when "technical-specification" then :ts
78
+ when "amendment" then :amd
79
+ end
80
+ end
81
+
82
+ def iso_id(node, xml)
83
+ (!@amd && node.attr("docnumber")) || (@amd && node.attr("updates")) or
84
+ return
85
+ params = iso_id_params(node)
86
+ iso_id_out(xml, params, true)
87
+ end
88
+
89
+ def iso_id_params(node)
90
+ params = iso_id_params_core(node)
91
+ params2 = iso_id_params_add(node)
92
+ if node.attr("updates")
93
+ orig_id = Pubid::Jis::Identifier::Base.parse(node.attr("updates"))
94
+ orig_id.edition ||= 1
95
+ end
96
+ iso_id_params_resolve(params, params2, node, orig_id)
97
+ end
98
+
99
+ def iso_id_params_core(node)
100
+ pub = (node.attr("publisher") || "JIS").split(/[;,]/)
101
+ ret = { number: node.attr("docnumber") || "0",
102
+ part: node.attr("partnumber"),
103
+ series: node.attr("docseries"),
104
+ language: node.attr("language") == "en" ? "E" : nil,
105
+ type: get_typeabbr(node),
106
+ publisher: pub[0],
107
+ copublisher: pub[1..-1] }.compact
108
+ ret[:copublisher].empty? and ret.delete(:copublisher)
109
+ ret
110
+ end
111
+
112
+ def iso_id_params_add(node)
113
+ { number: node.attr("amendment-number"),
114
+ year: iso_id_year(node) }.compact
115
+ end
116
+
117
+ def iso_id_out(xml, params, _with_prf)
118
+ id = iso_id_default(params).to_s(with_publisher: false)
119
+ xml.docidentifier id.strip, type: "JIS"
120
+ end
121
+
122
+ def iso_id_default(params)
123
+ Pubid::Jis::Identifier.create(**params)
124
+ rescue StandardError => e
125
+ clean_abort("Document identifier: #{e}", xml)
126
+ end
60
127
  end
61
128
  end
62
129
  end
@@ -382,6 +382,9 @@
382
382
  <optional>
383
383
  <ref name="dl"/>
384
384
  </optional>
385
+ <optional>
386
+ <ref name="source"/>
387
+ </optional>
385
388
  </element>
386
389
  </define>
387
390
  <define name="figure">
@@ -404,9 +407,6 @@
404
407
  <attribute name="class"/>
405
408
  </optional>
406
409
  <ref name="BlockAttributes"/>
407
- <optional>
408
- <ref name="source"/>
409
- </optional>
410
410
  <optional>
411
411
  <ref name="tname"/>
412
412
  </optional>
@@ -431,6 +431,20 @@
431
431
  <zeroOrMore>
432
432
  <ref name="note"/>
433
433
  </zeroOrMore>
434
+ <optional>
435
+ <ref name="source"/>
436
+ </optional>
437
+ </element>
438
+ </define>
439
+ <define name="source">
440
+ <element name="source">
441
+ <attribute name="status">
442
+ <ref name="SourceStatusType"/>
443
+ </attribute>
444
+ <ref name="origin"/>
445
+ <optional>
446
+ <ref name="modification"/>
447
+ </optional>
434
448
  </element>
435
449
  </define>
436
450
  <define name="sourcecode">
@@ -2099,10 +2113,7 @@
2099
2113
  <define name="termsource">
2100
2114
  <element name="termsource">
2101
2115
  <attribute name="status">
2102
- <choice>
2103
- <value>identical</value>
2104
- <value>modified</value>
2105
- </choice>
2116
+ <ref name="SourceStatusType"/>
2106
2117
  </attribute>
2107
2118
  <attribute name="type">
2108
2119
  <choice>
@@ -2116,6 +2127,17 @@
2116
2127
  </optional>
2117
2128
  </element>
2118
2129
  </define>
2130
+ <define name="SourceStatusType">
2131
+ <choice>
2132
+ <value>identical</value>
2133
+ <value>modified</value>
2134
+ <value>restyled</value>
2135
+ <value>context-added</value>
2136
+ <value>generalisation</value>
2137
+ <value>specialisation</value>
2138
+ <value>unspecified</value>
2139
+ </choice>
2140
+ </define>
2119
2141
  <define name="origin">
2120
2142
  <element name="origin">
2121
2143
  <choice>
@@ -6,6 +6,16 @@
6
6
  <start>
7
7
  <ref name="jis-standard"/>
8
8
  </start>
9
+ <define name="annex">
10
+ <element name="annex">
11
+ <optional>
12
+ <attribute name="commentary">
13
+ <data type="boolean"/>
14
+ </attribute>
15
+ </optional>
16
+ <ref name="Annex-Section"/>
17
+ </element>
18
+ </define>
9
19
  </include>
10
20
  <!-- end overrides -->
11
21
  <define name="floating-section-title">
@@ -13,7 +13,7 @@ module Metanorma
13
13
  def output_formats
14
14
  super.merge(
15
15
  html: "html",
16
- # pdf: "pdf",
16
+ pdf: "pdf",
17
17
  doc: "doc",
18
18
  )
19
19
  end
@@ -21,8 +21,8 @@ module Metanorma
21
21
  def fonts_manifest
22
22
  {
23
23
  "STIX Two Math" => nil,
24
- "MS Gothic" => nil,
25
- "MS Mincho" => nil,
24
+ "IPAexGothic" => nil,
25
+ "IPAexMincho" => nil,
26
26
  "Courier New" => nil,
27
27
  "Cambria Math" => nil,
28
28
  "Times New Roman" => nil,
@@ -6,9 +6,6 @@
6
6
  <attribute name="schema-version"/>
7
7
  </optional>
8
8
  <ref name="doctype"/>
9
- <optional>
10
- <ref name="docsubtype"/>
11
- </optional>
12
9
  <ref name="editorialgroup"/>
13
10
  <zeroOrMore>
14
11
  <ref name="ics"/>
@@ -18,93 +15,12 @@
18
15
  <ref name="stagename"/>
19
16
  </optional>
20
17
  </define>
21
- <define name="bdate">
22
- <element name="date">
23
- <attribute name="type">
24
- <choice>
25
- <ref name="BibliographicDateType"/>
26
- <text/>
27
- </choice>
28
- </attribute>
29
- <choice>
30
- <group>
31
- <element name="from">
32
- <ref name="ISO8601Date"/>
33
- </element>
34
- <optional>
35
- <element name="to">
36
- <ref name="ISO8601Date"/>
37
- </element>
38
- </optional>
39
- </group>
40
- <element name="on">
41
- <choice>
42
- <ref name="ISO8601Date"/>
43
- <value>--</value>
44
- <value>–</value>
45
- </choice>
46
- </element>
47
- </choice>
48
- </element>
49
- </define>
50
- <define name="organization">
51
- <element name="organization">
52
- <oneOrMore>
53
- <ref name="orgname"/>
54
- </oneOrMore>
55
- <optional>
56
- <ref name="abbreviation"/>
57
- </optional>
58
- <optional>
59
- <ref name="uri"/>
60
- </optional>
61
- <zeroOrMore>
62
- <ref name="org-identifier"/>
63
- </zeroOrMore>
64
- <zeroOrMore>
65
- <ref name="contact"/>
66
- </zeroOrMore>
67
- <optional>
68
- <ref name="technical-committee"/>
69
- </optional>
70
- <optional>
71
- <ref name="subcommittee"/>
72
- </optional>
73
- <optional>
74
- <ref name="workgroup"/>
75
- </optional>
76
- <optional>
77
- <ref name="secretariat"/>
78
- </optional>
79
- </element>
80
- </define>
81
18
  <define name="DocumentType">
82
19
  <choice>
83
- <value>british-standard</value>
84
- <value>draft-for-development</value>
85
- <value>published-document</value>
86
- <value>privately-subscribed-standard</value>
87
- <value>publicly-available-specification</value>
88
- <value>flex-standard</value>
89
- <value>international-standard</value>
90
- <value>technical-specification</value>
20
+ <value>japanese-industrial-standard</value>
91
21
  <value>technical-report</value>
92
- <value>guide</value>
93
- <value>international-workshop-agreement</value>
94
- <value>industry-technical-agreement</value>
95
- <value>standard</value>
96
- <value>european-workshop-agreement</value>
97
- <value>fast-track-standard</value>
98
- <value>expert-commentary</value>
99
- </choice>
100
- </define>
101
- <define name="DocumentSubtype">
102
- <choice>
103
- <value>specification</value>
104
- <value>method-of-test</value>
105
- <value>method-of-specifying</value>
106
- <value>vocabulary</value>
107
- <value>code-of-practice</value>
22
+ <value>technical-specification</value>
23
+ <value>amendment</value>
108
24
  </choice>
109
25
  </define>
110
26
  <define name="structuredidentifier">
@@ -126,11 +42,6 @@
126
42
  </element>
127
43
  </define>
128
44
  </include>
129
- <define name="updates_document_type">
130
- <element name="updates-document-type">
131
- <ref name="DocumentType"/>
132
- </element>
133
- </define>
134
45
  <define name="ISOProjectGroup">
135
46
  <zeroOrMore>
136
47
  <ref name="agency"/>
@@ -148,21 +59,11 @@
148
59
  <ref name="secretariat"/>
149
60
  </optional>
150
61
  </define>
151
- <define name="approvalgroup">
152
- <element name="approvalgroup">
153
- <ref name="ISOProjectGroup"/>
154
- </element>
155
- </define>
156
62
  <define name="agency">
157
63
  <element name="agency">
158
64
  <text/>
159
65
  </element>
160
66
  </define>
161
- <define name="horizontal">
162
- <element name="horizontal">
163
- <data type="boolean"/>
164
- </element>
165
- </define>
166
67
  <define name="documentnumber">
167
68
  <element name="project-number">
168
69
  <optional>
@@ -221,11 +122,4 @@
221
122
  <text/>
222
123
  </element>
223
124
  </define>
224
- <define name="coverimages">
225
- <element name="coverimages">
226
- <oneOrMore>
227
- <ref name="image"/>
228
- </oneOrMore>
229
- </element>
230
- </define>
231
125
  </grammar>
@@ -0,0 +1,26 @@
1
+ module Metanorma
2
+ module JIS
3
+ class Converter < ISO::Converter
4
+ def doctype_validate(xmldoc)
5
+ doctype = xmldoc&.at("//bibdata/ext/doctype")&.text
6
+ %w(japanese-industrial-standard technical-report
7
+ technical-specification amendment).include? doctype or
8
+ @log.add("Document Attributes", nil,
9
+ "#{doctype} is not a recognised document type")
10
+ end
11
+
12
+ def script_validate(xmldoc)
13
+ script = xmldoc&.at("//bibdata/script")&.text
14
+ %w(Jpan Latn).include?(script) or
15
+ @log.add("Document Attributes", nil,
16
+ "#{script} is not a recognised script")
17
+ end
18
+
19
+ def validate(doc)
20
+ content_validate(doc)
21
+ schema_validate(formattedstr_strip(doc.dup),
22
+ File.join(File.dirname(__FILE__), "jis.rng"))
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,6 +1,6 @@
1
1
  module Metanorma
2
2
  module JIS
3
- VERSION = "0.0.2".freeze
3
+ VERSION = "0.0.4".freeze
4
4
  end
5
5
  end
6
6
 
@@ -30,8 +30,8 @@ Gem::Specification.new do |spec|
30
30
  spec.test_files = `git ls-files -- {spec}/*`.split("\n")
31
31
  spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
32
32
 
33
- spec.add_dependency "metanorma-iso", "~> 2.4.0"
34
- spec.add_dependency "ruby-jing"
33
+ spec.add_dependency "metanorma-iso", "~> 2.4.2"
34
+ spec.add_dependency "pubid-jis"
35
35
 
36
36
  spec.add_development_dependency "debug"
37
37
  spec.add_development_dependency "equivalent-xml", "~> 0.6"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-jis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-20 00:00:00.000000000 Z
11
+ date: 2023-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: metanorma-iso
@@ -16,16 +16,16 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.4.0
19
+ version: 2.4.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.4.0
26
+ version: 2.4.2
27
27
  - !ruby/object:Gem::Dependency
28
- name: ruby-jing
28
+ name: pubid-jis
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -238,6 +238,7 @@ files:
238
238
  - README.adoc
239
239
  - lib/html2doc/lists.rb
240
240
  - lib/isodoc/jis/base_convert.rb
241
+ - lib/isodoc/jis/figure.rb
241
242
  - lib/isodoc/jis/html/header.html
242
243
  - lib/isodoc/jis/html/html_jis_intro.html
243
244
  - lib/isodoc/jis/html/html_jis_titlepage.html
@@ -258,9 +259,12 @@ files:
258
259
  - lib/isodoc/jis/i18n-ja.yaml
259
260
  - lib/isodoc/jis/i18n.rb
260
261
  - lib/isodoc/jis/init.rb
262
+ - lib/isodoc/jis/jis.international-standard.xsl
261
263
  - lib/isodoc/jis/metadata.rb
262
264
  - lib/isodoc/jis/pdf_convert.rb
263
265
  - lib/isodoc/jis/presentation_xml_convert.rb
266
+ - lib/isodoc/jis/table.rb
267
+ - lib/isodoc/jis/word_cleanup.rb
264
268
  - lib/isodoc/jis/word_convert.rb
265
269
  - lib/isodoc/jis/xref.rb
266
270
  - lib/metanorma-jis.rb
@@ -268,6 +272,7 @@ files:
268
272
  - lib/metanorma/jis/basicdoc.rng
269
273
  - lib/metanorma/jis/biblio-standoc.rng
270
274
  - lib/metanorma/jis/biblio.rng
275
+ - lib/metanorma/jis/cleanup.rb
271
276
  - lib/metanorma/jis/converter.rb
272
277
  - lib/metanorma/jis/front.rb
273
278
  - lib/metanorma/jis/isodoc.rng
@@ -276,6 +281,7 @@ files:
276
281
  - lib/metanorma/jis/processor.rb
277
282
  - lib/metanorma/jis/relaton-jis.rng
278
283
  - lib/metanorma/jis/reqt.rng
284
+ - lib/metanorma/jis/validate.rb
279
285
  - lib/metanorma/jis/version.rb
280
286
  - metanorma-jis.gemspec
281
287
  homepage: https://github.com/metanorma/metanorma-jis