metanorma-jis 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.hound.yml +5 -0
  3. data/.rubocop.yml +10 -0
  4. data/CODE_OF_CONDUCT.md +74 -0
  5. data/Gemfile +12 -0
  6. data/LICENSE +25 -0
  7. data/README.adoc +81 -0
  8. data/lib/html2doc/lists.rb +166 -0
  9. data/lib/isodoc/jis/base_convert.rb +41 -0
  10. data/lib/isodoc/jis/html/header.html +934 -0
  11. data/lib/isodoc/jis/html/html_jis_intro.html +8 -0
  12. data/lib/isodoc/jis/html/html_jis_titlepage.html +79 -0
  13. data/lib/isodoc/jis/html/htmlstyle.css +47 -0
  14. data/lib/isodoc/jis/html/htmlstyle.scss +45 -0
  15. data/lib/isodoc/jis/html/isodoc.css +12080 -0
  16. data/lib/isodoc/jis/html/isodoc.scss +11551 -0
  17. data/lib/isodoc/jis/html/style-human.css +1107 -0
  18. data/lib/isodoc/jis/html/style-human.scss +783 -0
  19. data/lib/isodoc/jis/html/style-iso.css +1133 -0
  20. data/lib/isodoc/jis/html/style-iso.scss +800 -0
  21. data/lib/isodoc/jis/html/word_jis_intro.html +14 -0
  22. data/lib/isodoc/jis/html/word_jis_titlepage.html +128 -0
  23. data/lib/isodoc/jis/html/wordstyle.css +3477 -0
  24. data/lib/isodoc/jis/html/wordstyle.scss +3378 -0
  25. data/lib/isodoc/jis/html_convert.rb +37 -0
  26. data/lib/isodoc/jis/i18n-ja.yaml +214 -0
  27. data/lib/isodoc/jis/i18n.rb +15 -0
  28. data/lib/isodoc/jis/init.rb +34 -0
  29. data/lib/isodoc/jis/metadata.rb +52 -0
  30. data/lib/isodoc/jis/pdf_convert.rb +17 -0
  31. data/lib/isodoc/jis/presentation_xml_convert.rb +11 -0
  32. data/lib/isodoc/jis/word_convert.rb +153 -0
  33. data/lib/isodoc/jis/xref.rb +6 -0
  34. data/lib/metanorma/jis/basicdoc.rng +1125 -0
  35. data/lib/metanorma/jis/biblio-standoc.rng +164 -0
  36. data/lib/metanorma/jis/biblio.rng +1461 -0
  37. data/lib/metanorma/jis/converter.rb +71 -0
  38. data/lib/metanorma/jis/front.rb +51 -0
  39. data/lib/metanorma/jis/isodoc.rng +2450 -0
  40. data/lib/metanorma/jis/isostandard.rng +316 -0
  41. data/lib/metanorma/jis/jis.rng +63 -0
  42. data/lib/metanorma/jis/processor.rb +53 -0
  43. data/lib/metanorma/jis/relaton-jis.rng +231 -0
  44. data/lib/metanorma/jis/reqt.rng +226 -0
  45. data/lib/metanorma/jis/version.rb +6 -0
  46. data/lib/metanorma/jis.rb +6 -0
  47. data/lib/metanorma-jis.rb +16 -0
  48. data/metanorma-jis.gemspec +49 -0
  49. metadata +303 -0
@@ -0,0 +1,37 @@
1
+ require "isodoc"
2
+ require "metanorma-iso"
3
+ require_relative "base_convert"
4
+ require_relative "init"
5
+
6
+ module IsoDoc
7
+ module JIS
8
+ class HtmlConvert < IsoDoc::Iso::HtmlConvert
9
+ def initialize(options)
10
+ super
11
+ @libdir = File.dirname(__FILE__)
12
+ end
13
+
14
+ def default_fonts(options)
15
+ {
16
+ bodyfont: (options[:script] == "Jpan" ? '"MS Mincho",serif' : '"Times New Roman",serif'),
17
+ headerfont: (options[:script] == "Jpan" ? '"MS Gothic",sans-serif' : '"Arial",sans-serif'),
18
+ monospacefont: '"Courier New",monospace',
19
+ monospacefontsize: "1.0em",
20
+ footnotefontsize: "0.9em",
21
+ }
22
+ end
23
+
24
+ def default_file_locations(_options)
25
+ @libdir = File.dirname(__FILE__)
26
+ {
27
+ htmlstylesheet: html_doc_path("htmlstyle.scss"),
28
+ htmlcoverpage: html_doc_path("html_jis_titlepage.html"),
29
+ htmlintropage: html_doc_path("html_jis_intro.html"),
30
+ }
31
+ end
32
+
33
+ include BaseConvert
34
+ include Init
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,214 @@
1
+ term_def_boilerplate:
2
+ scope: 適用範囲
3
+ symbolsabbrev: 記号及び略語
4
+ abbrev: Abbreviated terms
5
+ symbols: Symbols
6
+ table_of_contents: 目次
7
+ introduction: 序文
8
+ foreword: まえがき
9
+ abstract: Abstract
10
+ acknowledgements: Acknowledgements
11
+ termsdef: 用語及び定義
12
+ termsdefsymbolsabbrev: Terms, definitions, symbols and abbreviated terms
13
+ termsdefsymbols: Terms, definitions and symbols
14
+ termsdefabbrev: Terms, definitions and abbreviated terms
15
+ normref: 引用規格
16
+ bibliography: 参考文献
17
+ preface: Preface
18
+ clause: 箇条
19
+ annex: 附属書
20
+ appendix: Appendix
21
+ no_terms_boilerplate: |
22
+ <p>この規格には,定義する用語はない。</p>
23
+ internal_terms_boilerplate: |
24
+ <p>この規格で用いる主な用語及び定義は,次による。</p>
25
+ norm_with_refs_pref:
26
+ 次に掲げる引用規格は,この規格に引用されることによって,その一部又は全部がこの規格の要 求事項を構成している。これらの引用規格のうち,西暦年を付記してあるものは,記載の年の版を適 用し,その後の改正版(追補を含む。)は適用しない。西暦年の付記がない引用規格は,その最新版(追 補を含む。)を適用する。
27
+ norm_empty_pref:
28
+ この規格には,引用規格はない。
29
+ external_terms_boilerplate: |
30
+ <p>この規格で用いる主な用語及び定義は,% による。</p>
31
+ internal_external_terms_boilerplate: |
32
+ <p>この規格で用いる主な用語及び定義は,次によるほか,% による。</p>
33
+ term_defined_in: "[term defined in %]"
34
+ binary_and: "%1 and %2"
35
+ multiple_and: "%1, and %2"
36
+ binary_or: "%1 or %2"
37
+ multiple_or: "%1, or %2"
38
+ chain_and: "%1 and %2"
39
+ chain_or: "%1 or %2"
40
+ chain_from: "%1 from %2"
41
+ chain_to: "%1 to %2"
42
+ ordinal_keys: []
43
+ SpelloutRules: spellout-ordinal
44
+ note: 注記
45
+ note_xref: 注記
46
+ termnote: 注釈%
47
+ list: List
48
+ deflist: Definition List
49
+ figure: 図
50
+ diagram: Diagram
51
+ formula: 式
52
+ inequality: Formula
53
+ table: 表
54
+ requirement: 要求事項
55
+ recommendation: 推奨事項
56
+ permission: 許容事項
57
+ box: Box
58
+ index: 索引
59
+ standard_no: 規格番号
60
+ number: 番号
61
+ # Modspec
62
+ recommendationtest: Recommendation test
63
+ requirementtest: Requirement test
64
+ permissiontest: Permission test
65
+ recommendationclass: Recommendations class
66
+ requirementclass: Requirements class
67
+ permissionclass: Permissions class
68
+ abstracttest: Abstract test
69
+ conformanceclass: Conformance class
70
+ key: 記号説明
71
+ example: 例
72
+ example_xref: 例
73
+ where: ここで,
74
+ where_one: ここで,
75
+ wholeoftext: Whole of text
76
+ draft_label: draft
77
+ inform_annex: 参考
78
+ norm_annex: 規定
79
+ modified: modified
80
+ deprecated: DEPRECATED
81
+ source: 出典
82
+ and: and
83
+ all_parts: 規格群
84
+ edition_ordinal: "%Spellout edition"
85
+ edition: edition
86
+ version: version
87
+ toc_figures: List of figures
88
+ toc_tables: List of tables
89
+ toc_recommendations: List of recommendations
90
+ month_january: January
91
+ month_february: February
92
+ month_march: March
93
+ month_april: April
94
+ month_may: May
95
+ month_june: June
96
+ month_july: July
97
+ month_august: August
98
+ month_september: September
99
+ month_october: October
100
+ month_november: November
101
+ month_december: December
102
+ obligation: Obligation
103
+ admonition: {
104
+ danger: Danger,
105
+ warning: Warning,
106
+ caution: Caution,
107
+ important: Important,
108
+ safety precautions: Safety Precautions,
109
+ editorial: Editorial Note
110
+ }
111
+ locality: {
112
+ section: Section,
113
+ clause: 箇条,
114
+ subclause: 細分箇条,
115
+ part: 部,
116
+ paragraph: 段落,
117
+ chapter: Chapter,
118
+ page: Page,
119
+ table: 表,
120
+ annex: 附属書,
121
+ figure: 図,
122
+ example: 例,
123
+ note: 注記,
124
+ formula: 式,
125
+ }
126
+ grammar_abbrevs:
127
+ masculine: m
128
+ feminine: f
129
+ neuter: n
130
+ common: common
131
+ singular: sg
132
+ dual: dual
133
+ pl: pl
134
+ isPreposition: prep
135
+ isParticiple: part
136
+ isAdjective: adj
137
+ isAdverb: adv
138
+ isNoun: noun
139
+ isVerb: verb
140
+ relatedterms:
141
+ deprecates: deprecates
142
+ supersedes: supersedes
143
+ narrower: narrower
144
+ broader: broader
145
+ equivalent: equivalent
146
+ compare: compare
147
+ contrast: contrast
148
+ see: see
149
+ seealso: see also
150
+ inflection:
151
+ Clause:
152
+ sg: Clause
153
+ pl: Clauses
154
+ Annex:
155
+ sg: Annex
156
+ pl: Annexes
157
+ Appendix:
158
+ sg: Appendix
159
+ pl: Appendixes
160
+ Note:
161
+ sg: Note
162
+ pl: Notes
163
+ "Note % to entry":
164
+ sg: Note % to entry
165
+ pl: Notes % to entry
166
+ List:
167
+ sg: List
168
+ pl: Lists
169
+ Figure:
170
+ sg: Figure
171
+ pl: Figures
172
+ Formula:
173
+ sg: Formula
174
+ pl: Formulas
175
+ Table:
176
+ sg: Table
177
+ pl: Tables
178
+ Requirement:
179
+ sg: Requirement
180
+ pl: Requirements
181
+ Recommendation:
182
+ sg: Recommendation
183
+ pl: Recommendations
184
+ Permission:
185
+ sg: Permission
186
+ pl: Permissions
187
+ Example:
188
+ sg: Example
189
+ pl: Examples
190
+ Part:
191
+ sg: Part
192
+ pl: Parts
193
+ Section:
194
+ sg: Section
195
+ pl: Sections
196
+ Paragraph:
197
+ sg: Paragraph
198
+ pl: Paragraphs
199
+ Chapter:
200
+ sg: Chapter
201
+ pl: Chapters
202
+ Page:
203
+ sg: Page
204
+ pl: Pages
205
+ doctype_dict:
206
+ international-standard: 日本産業規格
207
+ technical-specification: 標準仕様書
208
+ technical-report: 標準報告書
209
+ publicly-available-specification: Publicly Available Specification
210
+ international-workshop-agreement: International Workshop Agreement
211
+ guide: Guide
212
+ amendment: 追補
213
+ technical-corrigendum: Technical Corrigendum
214
+ directive: Directive
@@ -0,0 +1,15 @@
1
+ module IsoDoc
2
+ module JIS
3
+ class I18n < IsoDoc::Iso::I18n
4
+ def load_yaml1(lang, script)
5
+ y = if lang == "ja"
6
+ YAML.load_file(File.join(File.dirname(__FILE__), "i18n-ja.yaml"))
7
+ else
8
+ YAML.load_file(File.join(File.dirname(__FILE__), "i18n-ja.yaml"))
9
+ end
10
+ super.deep_merge(y)
11
+ end
12
+ end
13
+ end
14
+ end
15
+
@@ -0,0 +1,34 @@
1
+ require "isodoc"
2
+ require_relative "metadata"
3
+ require_relative "i18n"
4
+
5
+ module IsoDoc
6
+ module JIS
7
+ module Init
8
+ def metadata_init(lang, script, locale, labels)
9
+ @meta = Metadata.new(lang, script, locale, labels)
10
+ end
11
+
12
+ def xref_init(lang, script, _klass, labels, options)
13
+ @xrefs = Xref.new(lang, script,
14
+ HtmlConvert.new(language: lang, script: script),
15
+ labels, options)
16
+ end
17
+
18
+ def i18n_init(lang, script, locale, i18nyaml = nil)
19
+ @i18n = I18n.new(lang, script, locale: locale,
20
+ i18nyaml: i18nyaml || @i18nyaml)
21
+ end
22
+
23
+ def omit_docid_prefix(prefix)
24
+ return true if prefix.nil? || prefix.empty?
25
+
26
+ super || %w(JIS).include?(prefix)
27
+ end
28
+
29
+ def std_docid_semantic(text)
30
+ text
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,52 @@
1
+ require "isodoc"
2
+ require "metanorma-iso"
3
+
4
+ module IsoDoc
5
+ module JIS
6
+ class Metadata < IsoDoc::Iso::Metadata
7
+ def title(isoxml, _out)
8
+ lang = case @lang
9
+ when "ja", "en" then @lang
10
+ else "ja"
11
+ end
12
+ # intro, main, part, amd = title_parts(isoxml, lang)
13
+ tp = title_parts(isoxml, lang)
14
+ tn = title_nums(isoxml)
15
+
16
+ set(:doctitlemain,
17
+ @c.encode(tp[:main] ? tp[:main].text : "", :hexadecimal))
18
+ main = compose_title(tp, tn, lang)
19
+ set(:doctitle, main)
20
+ tp[:intro] and
21
+ set(:doctitleintro,
22
+ @c.encode(tp[:intro] ? tp[:intro].text : "", :hexadecimal))
23
+ set(:doctitlepartlabel, part_prefix(tn, lang))
24
+ set(:doctitlepart, @c.encode(tp[:part].text, :hexadecimal)) if tp[:part]
25
+ set(:doctitleamdlabel, amd_prefix(tn, lang)) if tn[:amd]
26
+ set(:doctitleamd, @c.encode(tp[:amd].text, :hexadecimal)) if tp[:amd]
27
+ set(:doctitlecorrlabel, corr_prefix(tn, lang)) if tn[:corr]
28
+ end
29
+
30
+ def subtitle(isoxml, _out)
31
+ lang = @lang == "ja" ? "en" : "ja"
32
+ tp = title_parts(isoxml, lang)
33
+ tn = title_nums(isoxml)
34
+
35
+ set(:docsubtitlemain,
36
+ @c.encode(tp[:main] ? tp[:main].text : "", :hexadecimal))
37
+ main = compose_title(tp, tn, lang)
38
+ set(:docsubtitle, main)
39
+ tp[:intro] and
40
+ set(:docsubtitleintro,
41
+ @c.encode(tp[:intro] ? tp[:intro].text : "", :hexadecimal))
42
+ set(:docsubtitlepartlabel, part_prefix(tn, lang))
43
+ tp[:part] and
44
+ set(:docsubtitlepart,
45
+ @c.encode(tp[:part].text, :hexadecimal))
46
+ set(:docsubtitleamdlabel, amd_prefix(tn, lang)) if tn[:amd]
47
+ set(:docsubtitleamd, @c.encode(tp[:amd].text, :hexadecimal)) if tp[:amd]
48
+ set(:docsubtitlecorrlabel, corr_prefix(tn, lang)) if tn[:corr]
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,17 @@
1
+ require_relative "base_convert"
2
+ require "isodoc"
3
+
4
+ module IsoDoc
5
+ module JIS
6
+ class PdfConvert < IsoDoc::XslfoPdfConvert
7
+ def initialize(options)
8
+ @libdir = File.dirname(__FILE__)
9
+ super
10
+ end
11
+
12
+ def pdf_stylesheet(_docxml)
13
+ "jis.international-standard.xsl"
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ require_relative "init"
2
+ require "isodoc"
3
+
4
+ module IsoDoc
5
+ module JIS
6
+ class PresentationXMLConvert < IsoDoc::Iso::PresentationXMLConvert
7
+
8
+ include Init
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,153 @@
1
+ require_relative "../../html2doc/lists"
2
+ require_relative "base_convert"
3
+ require "isodoc"
4
+ require_relative "init"
5
+
6
+ module IsoDoc
7
+ module JIS
8
+ class WordConvert < IsoDoc::WordConvert
9
+ def initialize(options)
10
+ @libdir = File.dirname(__FILE__)
11
+ super
12
+ end
13
+
14
+ def default_fonts(options)
15
+ { bodyfont: (options[:script] == "Jpan" ? '"MS Mincho",serif' : '"Times New Roman",serif'),
16
+ headerfont: (options[:script] == "Jpan" ? '"MS Gothic",sans-serif' : '"Arial",sans-serif'),
17
+ monospacefont: '"Courier New",monospace',
18
+ normalfontsize: "10.0pt",
19
+ monospacefontsize: "9.0pt",
20
+ smallerfontsize: "10.0pt",
21
+ footnotefontsize: "10.0pt" }
22
+ end
23
+
24
+ def default_file_locations(_options)
25
+ { htmlstylesheet: html_doc_path("htmlstyle.scss"),
26
+ htmlcoverpage: html_doc_path("html_jis_titlepage.html"),
27
+ htmlintropage: html_doc_path("html_jis_intro.html"),
28
+ wordstylesheet: html_doc_path("wordstyle.scss"),
29
+ standardstylesheet: html_doc_path("isodoc.scss"),
30
+ header: html_doc_path("header.html"),
31
+ wordcoverpage: html_doc_path("word_jis_titlepage.html"),
32
+ wordintropage: html_doc_path("word_jis_intro.html"),
33
+ ulstyle: "l9",
34
+ olstyle: "l8" }
35
+ end
36
+
37
+ def postprocess(result, filename, dir)
38
+ filename = filename.sub(/\.doc$/, "")
39
+ header = generate_header(filename, dir)
40
+ result = from_xhtml(cleanup(to_xhtml(textcleanup(result))))
41
+ toWord(result, filename, dir, header)
42
+ @files_to_delete.each { |f| FileUtils.rm_f f }
43
+ end
44
+
45
+ def word_cleanup(docxml)
46
+ word_note_cleanup(docxml)
47
+ boldface(docxml)
48
+ super
49
+ end
50
+
51
+ def word_note_cleanup(docxml)
52
+ docxml.xpath("//p[@class = 'Note']").each do |p|
53
+ p.xpath("//following-sibling::p").each do |p2|
54
+ p2["class"] == "Note" and
55
+ p2["class"] = "NoteCont"
56
+ end
57
+ end
58
+ end
59
+
60
+ def boldface(docxml)
61
+ docxml.xpath("//h1 | h2 | h3 | h4 | h5 | h6").each do |h|
62
+ h.children = "<b>#{to_xml(h.children)}</b>"
63
+ end
64
+ docxml.xpath("//b").each do |b|
65
+ b.name = "span"
66
+ b["class"] = "Strong"
67
+ end
68
+ end
69
+
70
+ def toWord(result, filename, dir, header)
71
+ result = word_split(word_cleanup(to_xhtml(result)))
72
+ @wordstylesheet = wordstylesheet_update
73
+ result.each do |k, v|
74
+ to_word1(v, "#{filename}#{k}", dir, header)
75
+ end
76
+ header&.unlink
77
+ @wordstylesheet.unlink if @wordstylesheet.is_a?(Tempfile)
78
+ end
79
+
80
+ def to_word1(result, filename, dir, header)
81
+ result or return
82
+ result = from_xhtml(result).gsub(/-DOUBLE_HYPHEN_ESCAPE-/, "--")
83
+ ::Html2Doc::JIS.new(
84
+ filename: filename, imagedir: @localdir,
85
+ stylesheet: @wordstylesheet&.path,
86
+ header_file: header&.path, dir: dir,
87
+ asciimathdelims: [@openmathdelim, @closemathdelim],
88
+ liststyles: { ul: @ulstyle, ol: @olstyle }
89
+ ).process(result)
90
+ end
91
+
92
+ def word_split(xml)
93
+ b = xml.dup
94
+ { _cover: cover_split(xml), "": main_split(b) }
95
+ end
96
+
97
+ def cover_split(xml)
98
+ xml.at("//body").elements.each do |e|
99
+ e.name == "div" && e["class"] == "WordSection1" and next
100
+ e.remove
101
+ end
102
+ xml
103
+ end
104
+
105
+ def main_split(xml)
106
+ c = xml.at("//div[@class = 'WordSection1']")
107
+ c.next_element&.remove
108
+ c.remove
109
+ xml
110
+ end
111
+
112
+ def norm_ref(isoxml, out, num)
113
+ (f = isoxml.at(ns(norm_ref_xpath)) and f["hidden"] != "true") or
114
+ return num
115
+ out.div class: "normref" do |div|
116
+ num += 1
117
+ clause_name(f, f.at(ns("./title")), div, nil)
118
+ if f.name == "clause"
119
+ f.elements.each { |e| parse(e, div) unless e.name == "title" }
120
+ else biblio_list(f, div, false)
121
+ end
122
+ end
123
+ num
124
+ end
125
+
126
+ def bibliography(isoxml, out)
127
+ (f = isoxml.at(ns(bibliography_xpath)) and f["hidden"] != "true") or
128
+ return
129
+ page_break(out)
130
+ out.div class: "bibliography" do |div|
131
+ div.h1 class: "Section3" do |h1|
132
+ f.at(ns("./title"))&.children&.each { |c2| parse(c2, h1) }
133
+ end
134
+ biblio_list(f, div, true)
135
+ end
136
+ end
137
+
138
+ def new_styles(docxml)
139
+ super
140
+ biblio_paras(docxml)
141
+ end
142
+
143
+ def biblio_paras(docxml)
144
+ docxml.xpath("//div[@class = 'normref']//p[not(@class)]").each do |p|
145
+ p["class"] = "NormRefText"
146
+ end
147
+ end
148
+
149
+ include BaseConvert
150
+ include Init
151
+ end
152
+ end
153
+ end
@@ -0,0 +1,6 @@
1
+ module IsoDoc
2
+ module JIS
3
+ class Xref < IsoDoc::Iso::Xref
4
+ end
5
+ end
6
+ end