metanorma-gb 1.4.0 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 50ae7327f236ecb70d2b98d3f9f0ea1ab142712089e9062ebd680561f2c40a2e
4
- data.tar.gz: b3b36dab86dbbaa96e215e276f60a80c81e268f2f305b40948a19afd6428630a
3
+ metadata.gz: a326bf40f513d695ec5b2e5c7dafa563de377ce6c3a1da84f721b60db3f29977
4
+ data.tar.gz: 77adddf3a6c12e3d57e40d8dcf9a646794ef16fb6e4abc5a930b31746ae664c9
5
5
  SHA512:
6
- metadata.gz: 2b6993e4a7030025b09f98bb5f0c16f998533cddd4916ee0ea8dc4a5be22dca7301c2eca96a64c2348d75490e43f1bbdf1df577aa0a6f19e98e7515d4172dcaf
7
- data.tar.gz: e03ae570fd22b11928d5c8bcbd50c25b017269da85e926a96db586d0e38d55bc9407de81a9720e23f5f087a9814602a34420abf8369c399d10f6e0367211d70b
6
+ metadata.gz: f221356ae97fc691544be1296f4bcaa48032ee8cce37d629f12e78b00eae4e0a7cce961acad2502101e4650a26b5649f548d8adfedd18e8ac450fada42ac091a
7
+ data.tar.gz: a03f8e0e1910bec1450504f40162cf9a5ac6c1537059217ab30f22278653712d0583810c295c583f714a32093fe22eaf615d74c6b3d0e61afc430e93304a14c8
@@ -29,7 +29,6 @@ jobs:
29
29
  uses: actions/setup-ruby@v1
30
30
  with:
31
31
  ruby-version: ${{ matrix.ruby }}
32
- architecture: 'x64'
33
32
  - name: Update gems
34
33
  run: |
35
34
  sudo gem install bundler --force
@@ -31,7 +31,6 @@ jobs:
31
31
  uses: actions/setup-ruby@v1
32
32
  with:
33
33
  ruby-version: ${{ matrix.ruby }}
34
- architecture: 'x64'
35
34
  - name: Update gems
36
35
  run: |
37
36
  gem install bundler
@@ -39,15 +38,19 @@ jobs:
39
38
  - name: Run specs
40
39
  run: |
41
40
  bundle exec rake
42
- - name: Trigger dependent repositories
43
- if: github.ref == 'refs/heads/master' && matrix.ruby == '2.6'
41
+ - name: Trigger repositories
42
+ if: matrix.ruby == '2.6'
44
43
  env:
45
- GH_USERNAME: ${{ secrets.PAT_USERNAME }}
46
- GH_ACCESS_TOKEN: ${{ secrets.PAT_TOKEN }}
44
+ GH_USERNAME: metanorma-ci
45
+ GH_ACCESS_TOKEN: ${{ secrets.METANORMA_CI_PAT_TOKEN }}
47
46
  run: |
48
47
  curl -LO --retry 3 https://raw.githubusercontent.com/metanorma/metanorma-build-scripts/master/trigger-gh-actions.sh
49
48
  [[ -f ".github/workflows/dependent_repos.env" ]] && source .github/workflows/dependent_repos.env
50
- for repo in $DEPENDENT_REPOS
49
+ CLIENT_PAYLOAD=$(cat <<EOF
50
+ "{ "ref": "${GITHUB_REF}", "repo": "${GITHUB_REPOSITORY}" }"
51
+ EOF
52
+ )
53
+ for repo in $REPOS
51
54
  do
52
- sh trigger-gh-actions.sh $ORGANISATION $repo $GH_USERNAME $GH_ACCESS_TOKEN $GITHUB_REPOSITORY "{ \"ref\": \"${GITHUB_REF}\" }"
55
+ sh trigger-gh-actions.sh $ORGANISATION $repo $GH_USERNAME $GH_ACCESS_TOKEN $GITHUB_REPOSITORY "$CLIENT_PAYLOAD"
53
56
  done
@@ -29,7 +29,6 @@ jobs:
29
29
  uses: actions/setup-ruby@v1
30
30
  with:
31
31
  ruby-version: ${{ matrix.ruby }}
32
- architecture: 'x64'
33
32
  - name: Update gems
34
33
  shell: pwsh
35
34
  run: |
data/.gitignore CHANGED
@@ -3,7 +3,5 @@ coverage/
3
3
  .rspec_status
4
4
  .tmp.xml
5
5
  gb-issuer-default.gif
6
- gb.css
7
- htmlstyle.css
8
6
  test.html
9
7
  test.xml
data/Gemfile CHANGED
@@ -3,7 +3,6 @@ Encoding.default_internal = Encoding::UTF_8
3
3
 
4
4
  source "https://rubygems.org"
5
5
  git_source(:github) { |repo| "https://github.com/#{repo}" }
6
-
7
6
  gemspec
8
7
 
9
8
  if File.exist? 'Gemfile.devel'
data/Rakefile CHANGED
@@ -1,6 +1,23 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
+ require 'isodoc/gem_tasks'
3
4
 
5
+ module IsoDoc
6
+ module GemTasks
7
+ module_function
8
+
9
+ def fonts_placeholder
10
+ <<~TEXT
11
+ $bodyfont: '{{bodyfont}}';
12
+ $headerfont: '{{headerfont}}';
13
+ $monospacefont: '{{monospacefont}}';
14
+ $titlefont: '{{titlefont}}';
15
+ TEXT
16
+ end
17
+ end
18
+ end
19
+
20
+ IsoDoc::GemTasks.install
4
21
  RSpec::Core::RakeTask.new(:spec)
5
22
 
6
23
  task :default => :spec
@@ -0,0 +1,130 @@
1
+ module Asciidoctor
2
+ module Gb
3
+ class Converter < ISO::Converter
4
+ def termdef_cleanup(xmldoc)
5
+ super
6
+ # TODO this should become variant tag
7
+ localisedstr(xmldoc)
8
+ end
9
+
10
+ ROMAN_TEXT = /\s*[a-z\u00c0-\u00d6\u00d8-\u00f0\u0100-\u0240]/i
11
+ HAN_TEXT = /\s*[\u4e00-\u9fff]+/
12
+
13
+ LOCALISED_ELEMS = "//admitted | //deprecates | //preferred | //prefix | "\
14
+ "//initial | //addition | //surname | //forename | //name | "\
15
+ "//abbreviation | //role/description | //affiliation/description | "\
16
+ "//bibdata/item | //bibitem/title | //bibdata/formattedref | "\
17
+ "//bibitem/formattedref | //bibdata/note | //bibitem/note | "\
18
+ "//bibdata/abstract | //bibitem/note ".freeze
19
+
20
+ MUST_LOCALISE_ELEMS = %w{admitted deprecates preferred}.freeze
21
+
22
+ def localisedstr(xmldoc)
23
+ xmldoc.xpath(LOCALISED_ELEMS).each do |zh|
24
+ if zh.at("./string")
25
+ extract_localisedstrings(zh)
26
+ elsif MUST_LOCALISE_ELEMS.include? zh.name
27
+ duplicate_localisedstrings(zh)
28
+ end
29
+ end
30
+ end
31
+
32
+ # element consists solely of localised strings, with no attributes
33
+ def extract_localisedstrings(elem)
34
+ elem.xpath("./string").each do |s|
35
+ s.name = elem.name
36
+ end
37
+ elem.replace(elem.children)
38
+ end
39
+
40
+ def text_clean(text)
41
+ text.gsub(/^\s*/, "").gsub(/</, "&lt;").gsub(/>/, "&gt;")
42
+ end
43
+
44
+ def duplicate_localisedstrings(zh)
45
+ en = zh.dup.remove
46
+ zh.after(en).after(" ")
47
+ zh["language"] = "zh"
48
+ en["language"] = "en"
49
+ en.traverse do |c|
50
+ c.text? && c.content = text_clean(c.text.gsub(HAN_TEXT, ""))
51
+ end
52
+ zh.traverse do |c|
53
+ c.text? && c.content = text_clean(c.text.gsub(ROMAN_TEXT, ""))
54
+ end
55
+ end
56
+
57
+ def termdef_boilerplate_cleanup(xmldoc)
58
+ return if @keepboilerplate
59
+ super
60
+ end
61
+
62
+ def cleanup(xmldoc)
63
+ lang = xmldoc.at("//language")&.text
64
+ @agencyclass = GbAgencies::Agencies.new(lang, {}, "")
65
+ super
66
+ contributor_cleanup(xmldoc)
67
+ xmldoc
68
+ end
69
+
70
+ def docidentifier_cleanup(xmldoc)
71
+ id = xmldoc.at("//bibdata/docidentifier[@type = 'gb']") or return
72
+ scope = xmldoc.at("//gbscope")&.text
73
+ prefix = xmldoc.at("//gbprefix")&.text
74
+ mand = xmldoc.at("//gbmandate")&.text || "mandatory"
75
+ idtext = @agencyclass.docidentifier(scope, prefix, mand, nil, id.text)
76
+ id.content = idtext&.gsub(/\&#x2002;/, " ")
77
+ id = xmldoc.at("//bibdata/ext/structuredidentifier/"\
78
+ "project-number") or return
79
+ idtext = @agencyclass.docidentifier(scope, prefix, mand, nil, id.text)
80
+ id.content = idtext&.gsub(/\&#x2002;/, " ")
81
+ end
82
+
83
+ def committee_cleanup(xmldoc)
84
+ xmldoc.xpath("//gbcommittee").each do |c|
85
+ xmldoc.at("//bibdata/contributor").next =
86
+ "<contributor><role type='technical-committee'/><organization>"\
87
+ "<name>#{c.text}</name></organization></contributor>"
88
+ end
89
+ end
90
+
91
+ def agency_value(issuer, scope, prefix, mandate)
92
+ agency = issuer.content
93
+ agency == "GB" and
94
+ agency = @agencyclass.standard_agency1(scope, prefix, mandate)
95
+ agency = "GB" if agency.nil? || agency.empty?
96
+ agency
97
+ end
98
+
99
+ def contributor_cleanup(xmldoc)
100
+ issuer = xmldoc.at("//bibdata/contributor[role/@type = 'issuer']/"\
101
+ "organization/name")
102
+ scope = xmldoc.at("//gbscope")&.text
103
+ prefix = xmldoc.at("//gbprefix")&.text
104
+ mandate = xmldoc.at("//gbmandate")&.text || "mandatory"
105
+ agency = agency_value(issuer, scope, prefix, mandate)
106
+ owner = xmldoc.at("//copyright/owner/organization/name")
107
+ owner.content = agency
108
+ issuer.content = agency
109
+ committee_cleanup(xmldoc)
110
+ end
111
+
112
+ def omit_docid_prefix(prefix)
113
+ IsoDoc::Gb::HtmlConvert.new({}).omit_docid_prefix(prefix)
114
+ end
115
+
116
+ def boilerplate_cleanup(xmldoc)
117
+ isodoc = boilerplate_isodoc(xmldoc)
118
+ initial_boilerplate(xmldoc, isodoc)
119
+ return if @keepboilerplate
120
+ xmldoc.xpath(self.class::TERM_CLAUSE).each do |f|
121
+ term_defs_boilerplate(f.at("./title"),
122
+ xmldoc.xpath(".//termdocsource"),
123
+ f.at(".//term"), f.at(".//p"), isodoc)
124
+ end
125
+ f = xmldoc.at(self.class::NORM_REF) and
126
+ norm_ref_preface(f)
127
+ end
128
+ end
129
+ end
130
+ end
@@ -1,6 +1,5 @@
1
1
  require "asciidoctor"
2
2
  require "asciidoctor/iso/converter"
3
- require "metanorma/gb/version"
4
3
  require "isodoc/gb/common"
5
4
  require "isodoc/gb/word_convert"
6
5
  require "isodoc/gb/pdf_convert"
@@ -9,6 +8,7 @@ require "gb_agencies"
9
8
  require_relative "./section_input.rb"
10
9
  require_relative "./front.rb"
11
10
  require_relative "./validate.rb"
11
+ require_relative "cleanup.rb"
12
12
  require "fileutils"
13
13
 
14
14
  module Asciidoctor
@@ -61,6 +61,7 @@ module Asciidoctor
61
61
  end
62
62
 
63
63
  def pdf_converter(node)
64
+ return nil if node.attr("no-pdf")
64
65
  node.nil? ? IsoDoc::Gb::PdfConvert.new({}) :
65
66
  IsoDoc::Gb::PdfConvert.new(doc_extract_attributes(node))
66
67
  end
@@ -73,62 +74,15 @@ module Asciidoctor
73
74
  def outputs(node, ret)
74
75
  File.open(@filename + ".xml", "w:UTF-8") { |f| f.write(ret) }
75
76
  presentation_xml_converter(node).convert(@filename + ".xml")
76
- html_compliant_converter(node).convert(@filename + ".presentation.xml", nil, false, "#{@filename}_compliant.html")
77
- html_converter(node).convert(@filename + ".presentation.xml", nil, false, "#{@filename}.html")
78
- doc_converter(node).convert(@filename + ".presentation.xml", nil, false, "#{@filename}.doc")
79
- pdf_converter(node)&.convert(@filename + ".presentation.xml", nil, false, "#{@filename}.pdf")
80
- end
81
-
82
- def termdef_cleanup(xmldoc)
83
- super
84
- localisedstr(xmldoc)
85
- end
86
-
87
- ROMAN_TEXT = /\s*[a-z\u00c0-\u00d6\u00d8-\u00f0\u0100-\u0240]/i
88
- HAN_TEXT = /\s*[\u4e00-\u9fff]+/
89
-
90
- LOCALISED_ELEMS = "//admitted | //deprecates | //preferred | //prefix | "\
91
- "//initial | //addition | //surname | //forename | //name | "\
92
- "//abbreviation | //role/description | //affiliation/description | "\
93
- "//bibdata/item | //bibitem/title | //bibdata/formattedref | "\
94
- "//bibitem/formattedref | //bibdata/note | //bibitem/note | "\
95
- "//bibdata/abstract | //bibitem/note ".freeze
96
-
97
- MUST_LOCALISE_ELEMS = %w{admitted deprecates preferred}.freeze
98
-
99
- def localisedstr(xmldoc)
100
- xmldoc.xpath(LOCALISED_ELEMS).each do |zh|
101
- if zh.at("./string")
102
- extract_localisedstrings(zh)
103
- elsif MUST_LOCALISE_ELEMS.include? zh.name
104
- duplicate_localisedstrings(zh)
105
- end
106
- end
107
- end
108
-
109
- # element consists solely of localised strings, with no attributes
110
- def extract_localisedstrings(elem)
111
- elem.xpath("./string").each do |s|
112
- s.name = elem.name
113
- end
114
- elem.replace(elem.children)
115
- end
116
-
117
- def text_clean(text)
118
- text.gsub(/^\s*/, "").gsub(/</, "&lt;").gsub(/>/, "&gt;")
119
- end
120
-
121
- def duplicate_localisedstrings(zh)
122
- en = zh.dup.remove
123
- zh.after(en).after(" ")
124
- zh["language"] = "zh"
125
- en["language"] = "en"
126
- en.traverse do |c|
127
- c.text? && c.content = text_clean(c.text.gsub(HAN_TEXT, ""))
128
- end
129
- zh.traverse do |c|
130
- c.text? && c.content = text_clean(c.text.gsub(ROMAN_TEXT, ""))
131
- end
77
+ html_compliant_converter(node).
78
+ convert(@filename + ".presentation.xml",
79
+ nil, false, "#{@filename}_compliant.html")
80
+ html_converter(node).convert(@filename + ".presentation.xml",
81
+ nil, false, "#{@filename}.html")
82
+ doc_converter(node).convert(@filename + ".presentation.xml",
83
+ nil, false, "#{@filename}.doc")
84
+ pdf_converter(node)&.convert(@filename + ".presentation.xml",
85
+ nil, false, "#{@filename}.pdf")
132
86
  end
133
87
 
134
88
  def inline_quoted(node)
@@ -148,11 +102,6 @@ module Asciidoctor
148
102
  super
149
103
  end
150
104
 
151
- def termdef_boilerplate_cleanup(xmldoc)
152
- return if @keepboilerplate
153
- super
154
- end
155
-
156
105
  GBCODE = "((AQ|BB|CB|CH|CJ|CY|DA|DB|DL|DZ|EJ|FZ|GA|GH|GM|GY|HB|HG|"\
157
106
  "HJ|HS|HY|JB|JC|JG|JR|JT|JY|LB|LD|LS|LY|MH|MT|MZ|NY|QB|QC|QJ|"\
158
107
  "QZ|SB|SC|SH|SJ|SN|SY|TB|TD|TJ|TY|WB|WH|WJ|WM|WS|WW|XB|YB|YC|"\
@@ -185,71 +134,12 @@ module Asciidoctor
185
134
  super
186
135
  end
187
136
 
188
- def cleanup(xmldoc)
189
- lang = xmldoc.at("//language")&.text
190
- @agencyclass = GbAgencies::Agencies.new(lang, {}, "")
137
+ def init(node)
138
+ node.attr("language") or node.set_attr("language", "zh")
139
+ node.attr("script") or
140
+ node.set_attr("script", node.attr("language") == "zh" ?
141
+ "Hans" : "Latn")
191
142
  super
192
- contributor_cleanup(xmldoc)
193
- xmldoc
194
- end
195
-
196
- def docidentifier_cleanup(xmldoc)
197
- id = xmldoc.at("//bibdata/docidentifier[@type = 'gb']") or return
198
- scope = xmldoc.at("//gbscope")&.text
199
- prefix = xmldoc.at("//gbprefix")&.text
200
- mand = xmldoc.at("//gbmandate")&.text || "mandatory"
201
- idtext = @agencyclass.docidentifier(scope, prefix, mand, nil, id.text)
202
- id.content = idtext&.gsub(/\&#x2002;/, " ")
203
- id = xmldoc.at("//bibdata/ext/structuredidentifier/"\
204
- "project-number") or return
205
- idtext = @agencyclass.docidentifier(scope, prefix, mand, nil, id.text)
206
- id.content = idtext&.gsub(/\&#x2002;/, " ")
207
- end
208
-
209
- def committee_cleanup(xmldoc)
210
- xmldoc.xpath("//gbcommittee").each do |c|
211
- xmldoc.at("//bibdata/contributor").next =
212
- "<contributor><role type='technical-committee'/><organization>"\
213
- "<name>#{c.text}</name></organization></contributor>"
214
- end
215
- end
216
-
217
- def agency_value(issuer, scope, prefix, mandate)
218
- agency = issuer.content
219
- agency == "GB" and
220
- agency = @agencyclass.standard_agency1(scope, prefix, mandate)
221
- agency = "GB" if agency.nil? || agency.empty?
222
- agency
223
- end
224
-
225
- def contributor_cleanup(xmldoc)
226
- issuer = xmldoc.at("//bibdata/contributor[role/@type = 'issuer']/"\
227
- "organization/name")
228
- scope = xmldoc.at("//gbscope")&.text
229
- prefix = xmldoc.at("//gbprefix")&.text
230
- mandate = xmldoc.at("//gbmandate")&.text || "mandatory"
231
- agency = agency_value(issuer, scope, prefix, mandate)
232
- owner = xmldoc.at("//copyright/owner/organization/name")
233
- owner.content = agency
234
- issuer.content = agency
235
- committee_cleanup(xmldoc)
236
- end
237
-
238
- def omit_docid_prefix(prefix)
239
- IsoDoc::Gb::HtmlConvert.new({}).omit_docid_prefix(prefix)
240
- end
241
-
242
- def boilerplate_cleanup(xmldoc)
243
- isodoc = boilerplate_isodoc(xmldoc)
244
- initial_boilerplate(xmldoc, isodoc)
245
- return if @keepboilerplate
246
- xmldoc.xpath(self.class::TERM_CLAUSE).each do |f|
247
- term_defs_boilerplate(f.at("./title"),
248
- xmldoc.xpath(".//termdocsource"),
249
- f.at(".//term"), f.at(".//p"), isodoc)
250
- end
251
- f = xmldoc.at(self.class::NORM_REF) and
252
- norm_ref_preface(f)
253
143
  end
254
144
  end
255
145
  end
@@ -1,7 +1,7 @@
1
1
  module Asciidoctor
2
2
  module Gb
3
3
  class Converter < ISO::Converter
4
- STAGE_ABBRS_CN = {
4
+ STAGE_ABBRS_CN = {
5
5
  "00": "新工作项目建议",
6
6
  "10": "新工作项目",
7
7
  "20": "标准草案工作组讨论稿",
@@ -15,7 +15,7 @@ module Asciidoctor
15
15
 
16
16
  def stage_name(stage, substage)
17
17
  return "Proof" if stage == "60" && substage == "00"
18
- @language == "en" ?
18
+ @lang == "en" ?
19
19
  STAGE_NAMES[stage.to_sym] : STAGE_ABBRS_CN[stage.to_sym]
20
20
  end
21
21
 
@@ -43,7 +43,7 @@ module Asciidoctor
43
43
 
44
44
  def id_stage_prefix(dn, node)
45
45
  if node.attr("docstage") && node.attr("docstage").to_i < 60
46
- abbr = IsoDoc::Gb::Metadata.new("en", "Latn", {}).
46
+ abbr = IsoDoc::Gb::Metadata.new("en", "Latn", @i18n).
47
47
  status_abbrev(node.attr("docstage"), nil, node.attr("iteration"),
48
48
  node.attr("draft"), node.attr("doctype"))
49
49
  dn = "/#{abbr} #{dn}" # prefixes added in cleanup
@@ -922,6 +922,9 @@
922
922
  <optional>
923
923
  <attribute name="script"/>
924
924
  </optional>
925
+ <optional>
926
+ <attribute name="type"/>
927
+ </optional>
925
928
  <optional>
926
929
  <attribute name="obligation">
927
930
  <choice>
@@ -961,9 +964,6 @@
961
964
  </define>
962
965
  <define name="content-subsection">
963
966
  <element name="clause">
964
- <optional>
965
- <attribute name="type"/>
966
- </optional>
967
967
  <ref name="Content-Section"/>
968
968
  </element>
969
969
  </define>
@@ -992,6 +992,9 @@
992
992
  </choice>
993
993
  </attribute>
994
994
  </optional>
995
+ <optional>
996
+ <attribute name="type"/>
997
+ </optional>
995
998
  <optional>
996
999
  <ref name="section-title"/>
997
1000
  </optional>
@@ -1011,9 +1014,6 @@
1011
1014
  </define>
1012
1015
  <define name="clause">
1013
1016
  <element name="clause">
1014
- <optional>
1015
- <attribute name="type"/>
1016
- </optional>
1017
1017
  <ref name="Clause-Section"/>
1018
1018
  </element>
1019
1019
  </define>
@@ -1042,6 +1042,9 @@
1042
1042
  </choice>
1043
1043
  </attribute>
1044
1044
  </optional>
1045
+ <optional>
1046
+ <attribute name="type"/>
1047
+ </optional>
1045
1048
  <optional>
1046
1049
  <ref name="section-title"/>
1047
1050
  </optional>
@@ -1180,6 +1183,9 @@
1180
1183
  <optional>
1181
1184
  <attribute name="script"/>
1182
1185
  </optional>
1186
+ <optional>
1187
+ <attribute name="type"/>
1188
+ </optional>
1183
1189
  <optional>
1184
1190
  <attribute name="obligation">
1185
1191
  <choice>