metanorma-gb 1.0.1 → 1.0.2

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: fdf2ed427e67746d3a8ad50fb1604080f019ca3947d60730ad1c4c3cc6984b46
4
- data.tar.gz: c7f36372bb587490c34d476f7395231373b91756a46cf1e73259ade1574b2c0f
3
+ metadata.gz: 110b6ef6b6a174d04c98ba1a7275a6c0bb3e9f5c5b97e2690b5b4f718c2fec0a
4
+ data.tar.gz: f063c6f9f38981719d774166a816d3a507126a05ad083be5021cf68984aee149
5
5
  SHA512:
6
- metadata.gz: '0082cc59718a8bd8f3dbb2f41e75793c86cfb64fb1bb56b754160a73ed5938d0445fd4a872fe845270eebd21c5fcb451af1d3184a3e48c6ec907630f699a7b39'
7
- data.tar.gz: 752d9bf92f918b18699b818f64838ebf9a462a4cd3a625a7913dc987c8a14470426ef8a1173cb4fee6320994be26d982c469a46d176654819b2d745497e870ed
6
+ metadata.gz: 0adbf79cf6b413d962d5aa9bde4101b81f8ed89797a7a00bda80e448b14a0c4d3029e9a3e23f0e28da7bc2655a9b25347ff1161ffb2f5c26eb8b6b80452df141
7
+ data.tar.gz: fce8f2ff2f7de990f91210065eaada65cfe789661a0845b3714ea406810977a5a53d67c269ba0a6a76b42e4c8f2e2ede2d7cf74047ab16288372ace3cd07c925
data/README.adoc CHANGED
@@ -211,6 +211,15 @@ If absent (default), any paragraphs supplied at the start of the Terms and Defin
211
211
  section are deleted, and replaced with standard boilerplate. If present, any such
212
212
  paragraphs in the text are retained.
213
213
 
214
+ `:standard-logo-img:`::
215
+ User-supplied graphic to overwrite the logo for the standard on the title page.
216
+
217
+ `:standard-class-img:`::
218
+ User-supplied graphic to overwrite the name of the standard class on the title page.
219
+
220
+ `:standard-issuer-img:`::
221
+ User-supplied graphic to overwrite the name of the standard issuer on the title page.
222
+
214
223
  === Language macros
215
224
 
216
225
  In Terms and Definitions, preferred terms, alternate terms and deprecated terms
@@ -384,7 +384,7 @@
384
384
  </define>
385
385
  <define name="LocalityType">
386
386
  <data type="string">
387
- <param name="pattern">section|clause|part|paragraph|chapter|page|whole|table|annex|figure|note|example|volume|issue|locality:[a-zA-Z0-9_]+</param>
387
+ <param name="pattern">section|clause|part|paragraph|chapter|page|whole|table|annex|figure|note|list|example|volume|issue|locality:[a-zA-Z0-9_]+</param>
388
388
  </data>
389
389
  </define>
390
390
  <define name="referenceFrom">
@@ -700,8 +700,12 @@
700
700
  <ref name="btitle"/>
701
701
  <ref name="formattedref"/>
702
702
  </choice>
703
- <ref name="bplace"/>
704
- <ref name="seriesorganization"/>
703
+ <optional>
704
+ <ref name="bplace"/>
705
+ </optional>
706
+ <optional>
707
+ <ref name="seriesorganization"/>
708
+ </optional>
705
709
  <optional>
706
710
  <ref name="abbreviation"/>
707
711
  </optional>
@@ -32,24 +32,37 @@ module Asciidoctor
32
32
  ret1
33
33
  end
34
34
 
35
+ def gb_attributes(node)
36
+ {
37
+ standardlogoimg: node.attr("standard-logo-img"),
38
+ standardclassimg: node.attr("standard-class-img"),
39
+ standardissuerimg: node.attr("standard-issuer-img"),
40
+ titlefont: node.attr("title-font"),
41
+ }
42
+ end
43
+
44
+ def html_extract_attributes(node)
45
+ super.merge(gb_attributes(node))
46
+ end
47
+
48
+ def doc_extract_attributes(node)
49
+ super.merge(gb_attributes(node))
50
+ end
51
+
35
52
  def html_converter(node)
36
53
  node.nil? ? IsoDoc::Gb::HtmlConvert.new({}) :
37
- IsoDoc::Gb::HtmlConvert.new(
38
- html_extract_attributes(node).merge(titlefont:
39
- node.attr("title-font")))
54
+ IsoDoc::Gb::HtmlConvert.new(html_extract_attributes(node))
40
55
  end
41
56
 
42
57
  def html_compliant_converter(node)
43
58
  node.nil? ? IsoDoc::Gb::HtmlConvert.new({}) :
44
59
  IsoDoc::Gb::HtmlConvert.new(html_extract_attributes(node).
45
- merge(compliant: true,
46
- titlefont: node.attr("title-font")))
60
+ merge(compliant: true))
47
61
  end
48
62
 
49
63
  def doc_converter(node)
50
64
  node.nil? ? IsoDoc::Gb::WordConvert.new({}) :
51
- IsoDoc::Gb::WordConvert.new(doc_extract_attributes(node).
52
- merge(titlefont: node.attr("title-font")))
65
+ IsoDoc::Gb::WordConvert.new(doc_extract_attributes(node))
53
66
  end
54
67
 
55
68
  def document(node)
@@ -956,6 +956,11 @@
956
956
  </define>
957
957
  <define name="li">
958
958
  <element name="li">
959
+ <optional>
960
+ <attribute name="id">
961
+ <data type="ID"/>
962
+ </attribute>
963
+ </optional>
959
964
  <oneOrMore>
960
965
  <ref name="paragraph-with-footnote"/>
961
966
  </oneOrMore>
@@ -999,7 +1004,9 @@
999
1004
  </define>
1000
1005
  <define name="dt">
1001
1006
  <element name="dt">
1002
- <ref name="TextElement"/>
1007
+ <zeroOrMore>
1008
+ <ref name="TextElement"/>
1009
+ </zeroOrMore>
1003
1010
  </element>
1004
1011
  </define>
1005
1012
  <define name="dd">
@@ -20,6 +20,9 @@
20
20
  <!-- add type to docidentifier in isodoc? -->
21
21
  <define name="docidentifier">
22
22
  <element name="docidentifier">
23
+ <optional>
24
+ <attribute name="type"/>
25
+ </optional>
23
26
  <choice>
24
27
  <text/>
25
28
  <group>
@@ -108,6 +111,27 @@
108
111
  <zeroOrMore>
109
112
  <ref name="docrelation"/>
110
113
  </zeroOrMore>
114
+ <zeroOrMore>
115
+ <ref name="series"/>
116
+ </zeroOrMore>
117
+ <optional>
118
+ <ref name="medium"/>
119
+ </optional>
120
+ <zeroOrMore>
121
+ <ref name="bplace"/>
122
+ </zeroOrMore>
123
+ <zeroOrMore>
124
+ <ref name="extent"/>
125
+ </zeroOrMore>
126
+ <zeroOrMore>
127
+ <ref name="accesslocation"/>
128
+ </zeroOrMore>
129
+ <optional>
130
+ <ref name="bclassification"/>
131
+ </optional>
132
+ <optional>
133
+ <ref name="validity"/>
134
+ </optional>
111
135
  <optional>
112
136
  <ref name="editorialgroup"/>
113
137
  </optional>
@@ -164,6 +188,27 @@
164
188
  <zeroOrMore>
165
189
  <ref name="docrelation"/>
166
190
  </zeroOrMore>
191
+ <zeroOrMore>
192
+ <ref name="series"/>
193
+ </zeroOrMore>
194
+ <optional>
195
+ <ref name="medium"/>
196
+ </optional>
197
+ <zeroOrMore>
198
+ <ref name="bplace"/>
199
+ </zeroOrMore>
200
+ <zeroOrMore>
201
+ <ref name="extent"/>
202
+ </zeroOrMore>
203
+ <zeroOrMore>
204
+ <ref name="accesslocation"/>
205
+ </zeroOrMore>
206
+ <optional>
207
+ <ref name="bclassification"/>
208
+ </optional>
209
+ <optional>
210
+ <ref name="validity"/>
211
+ </optional>
167
212
  <ref name="editorialgroup"/>
168
213
  <zeroOrMore>
169
214
  <ref name="ics"/>
@@ -548,10 +593,17 @@
548
593
  </define>
549
594
  <define name="li">
550
595
  <element name="li">
551
- <oneOrMore>
552
- <!-- ( paragraph-with-footnote | table | note | formula | admonition | ol | ul | dl | quote | sourcecode | review | example )+ -->
553
- <ref name="BasicBlock"/>
554
- </oneOrMore>
596
+ <group>
597
+ <optional>
598
+ <!-- ( paragraph-with-footnote | table | note | formula | admonition | ol | ul | dl | quote | sourcecode | review | example )+ -->
599
+ <attribute name="id">
600
+ <data type="ID"/>
601
+ </attribute>
602
+ </optional>
603
+ <oneOrMore>
604
+ <ref name="BasicBlock"/>
605
+ </oneOrMore>
606
+ </group>
555
607
  <!-- exclude figures? -->
556
608
  </element>
557
609
  </define>
@@ -859,7 +911,7 @@
859
911
  </element>
860
912
  </define>
861
913
  <define name="allParts">
862
- <element name="allParts">
914
+ <element name="allparts">
863
915
  <data type="boolean"/>
864
916
  </element>
865
917
  </define>
@@ -947,17 +999,13 @@
947
999
  <optional>
948
1000
  <ref name="section-title"/>
949
1001
  </optional>
950
- <choice>
951
- <oneOrMore>
1002
+ <zeroOrMore>
1003
+ <choice>
952
1004
  <ref name="term-clause"/>
953
- </oneOrMore>
954
- <zeroOrMore>
955
- <choice>
956
- <ref name="terms"/>
957
- <ref name="definitions"/>
958
- </choice>
959
- </zeroOrMore>
960
- </choice>
1005
+ <ref name="terms"/>
1006
+ <ref name="definitions"/>
1007
+ </choice>
1008
+ </zeroOrMore>
961
1009
  </element>
962
1010
  </define>
963
1011
  <define name="reference-clause">
@@ -7,8 +7,9 @@ module Asciidoctor
7
7
  # schema encapsulation of the document for validation
8
8
  class Converter < ISO::Converter
9
9
 
10
+ # subclause contains subclauses
10
11
  def term_def_subclause_parse(attrs, xml, node)
11
- # subclause contains subclauses
12
+ return clause_parse(attrs, xml, node) if node.role == "nonterm"
12
13
  sub = node.find_by(context: :section) {|s| s.level == node.level + 1 }
13
14
  sub.empty? || (return term_def_parse(attrs, xml, node, false))
14
15
  (node.title.downcase == "symbols and abbreviated terms" ||
@@ -24,29 +25,30 @@ module Asciidoctor
24
25
  a = { id: Asciidoctor::Standoc::Utils::anchor_or_uuid(node) }
25
26
  noko do |xml|
26
27
  case sectiontype(node)
27
- when "引言", "introduction" then
28
- if node.level == 1 then introduction_parse(a, xml, node)
29
- else
30
- clause_parse(a, xml, node)
31
- end
28
+ when "引言", "introduction" then introduction_parse(a, xml, node)
32
29
  when "patent notice" then patent_notice_parse(xml, node)
33
30
  when "范围", "scope" then scope_parse(a, xml, node)
34
31
  when "规范性引用文件", "normative references"
35
32
  norm_ref_parse(a, xml, node)
36
33
  when "术语和定义", "terms and definitions",
37
34
  "术语、定义、符号、代号和缩略语",
38
- "terms, definitions, symbols and abbreviated terms"
35
+ "terms, definitions, symbols and abbreviated terms",
36
+ "terms, definitions, symbols and abbreviations",
37
+ "terms, definitions and symbols",
38
+ "terms, definitions and abbreviations",
39
+ "terms, definitions and abbreviated terms"
39
40
  @term_def = true
40
41
  term_def_parse(a, xml, node, true)
41
42
  @term_def = false
42
- when "符号、代号和缩略语", "symbols and abbreviated terms"
43
+ when "符号、代号和缩略语", "symbols and abbreviated terms",
44
+ "abbreviated terms", "abbreviations", "symbols"
43
45
  symbols_parse(a, xml, node)
44
46
  when "参考文献", "bibliography"
45
47
  bibliography_parse(a, xml, node)
46
48
  else
47
49
  if @term_def then term_def_subclause_parse(a, xml, node)
48
50
  elsif @biblio then bibliography_parse(a, xml, node)
49
- elsif node.attr("style") == "bibliography" && node.level == 1
51
+ elsif node.attr("style") == "bibliography" && node.level == 1
50
52
  bibliography_parse(a, xml, node)
51
53
  elsif node.attr("style") == "appendix" && node.level == 1
52
54
  annex_parse(a, xml, node)
@@ -57,19 +59,6 @@ module Asciidoctor
57
59
  end.join("\n")
58
60
  end
59
61
 
60
- # @param xml [Nokogiri::XML::Builder]
61
- # @param code [String]
62
- #def fetch_ref(xml, code, _year, **opts)
63
- #warn "fetching #{code}..."
64
- #result = Gbbib::GbBibliography.search code
65
- #hit = result.first
66
- #if hit&.title&.match(%r{^[^\s]+\s[\d-]+}).to_s == code
67
- ## hit.fetch.to_xml xml, opts
68
- #xml.parent.add_child hit.fetch.to_xml(xml, opts)
69
- #xml
70
- #end
71
- #end
72
-
73
62
  =begin
74
63
  # spec of permissible section sequence
75
64
  SEQ = [
@@ -1,5 +1,5 @@
1
1
  module Asciidoctor
2
2
  module Gb
3
- VERSION = "1.0.1"
3
+ VERSION = "1.0.2"
4
4
  end
5
5
  end
@@ -8,8 +8,13 @@ module IsoDoc
8
8
  # A {Converter} implementation that generates GB output, and a document
9
9
  # schema encapsulation of the document for validation
10
10
  class Common < IsoDoc::Common
11
+ attr_accessor :meta
12
+
11
13
  def initialize(options)
12
14
  @meta = options[:meta]
15
+ @standardlogoimg = options[:standardlogoimg]
16
+ @standardclassimg = options[:standardclassimg]
17
+ @standardissuerimg = options[:standardissuerimg]
13
18
  end
14
19
 
15
20
  def fileloc(loc)
@@ -17,6 +22,7 @@ module IsoDoc
17
22
  end
18
23
 
19
24
  def format_agency(agency, format)
25
+ return "<img src='#{@standardissuerimg}' alt='#{agency.join(",")}'></img>" if @standardissuerimg
20
26
  return agency unless agency.is_a?(Array)
21
27
  if agency == ["中华人民共和国国家质量监督检验检疫总局", "中国国家标准化管理委员会"]
22
28
  logo = "gb-issuer-default.gif"
@@ -36,8 +42,9 @@ module IsoDoc
36
42
  end
37
43
 
38
44
  def format_logo(prefix, scope, _format)
39
- return "" if %w(enterprise social-group).include? scope
40
45
  logo = @meta.standard_logo(prefix)
46
+ return format_logo1(logo, prefix, scope) if @standardlogoimg
47
+ return "" if %w(enterprise social-group).include? scope
41
48
  if logo.nil?
42
49
  "<span style='font-size:36pt;font-weight:bold'>#{prefix}</span>"
43
50
  else
@@ -53,10 +60,11 @@ module IsoDoc
53
60
 
54
61
 
55
62
  def format_logo1(logo, prefix, scope)
63
+ local = local_logo_suffix(scope)
64
+ return "<img width='113' height='56' src='#{@standardlogoimg}' alt='#{prefix}'></img>"\
65
+ "#{local}" if @standardlogoimg
56
66
  logo += ".gif"
57
- #system "cp #{fileloc(File.join('html/gb-logos', logo))} #{logo}"
58
67
  FileUtils.cp fileloc(File.join('html/gb-logos', logo)), logo
59
- local = local_logo_suffix(scope)
60
68
  #@files_to_delete << logo
61
69
  "<img width='113' height='56' src='#{logo}' alt='#{prefix}'></img>"\
62
70
  "#{local}"
@@ -11,6 +11,7 @@ module IsoDoc
11
11
  class HtmlConvert < IsoDoc::HtmlConvert
12
12
  def initialize(options)
13
13
  @common = IsoDoc::Gb::Common.new(options)
14
+ @standardclassimg = options[:standardclassimg]
14
15
  @libdir = File.dirname(__FILE__)
15
16
  super
16
17
  @lang = "zh"
@@ -52,7 +53,8 @@ module IsoDoc
52
53
  script = "Hans"
53
54
  end
54
55
  @meta = Metadata.new(lang, script, labels)
55
- @common = IsoDoc::Gb::Common.new(meta: @meta)
56
+ @meta.set(:standardclassimg, @standardclassimg)
57
+ @common.meta = @meta
56
58
  end
57
59
 
58
60
  def cleanup(docxml)
@@ -199,7 +199,8 @@ module IsoDoc
199
199
  isopub = ref.at(ns(ISO_PUBLISHER_XPATH))
200
200
  docid = ref.at(ns("./docidentifier"))
201
201
  date = ref.at(ns("./date[@type = 'published']"))
202
- reference = format_ref(docid.text, isopub, date)
202
+ allparts = ref.at(ns("./allparts"))
203
+ reference = format_ref(docid.text, isopub, date, allparts)
203
204
  @anchors[ref["id"]] = { xref: reference }
204
205
  end
205
206
  end
@@ -13,12 +13,13 @@ module IsoDoc
13
13
  class WordConvert < IsoDoc::WordConvert
14
14
  def initialize(options)
15
15
  @common = IsoDoc::Gb::Common.new(options)
16
+ @standardclassimg = options[:standardclassimg]
16
17
  @libdir = File.dirname(__FILE__)
17
18
  super
18
19
  @lang = "zh"
19
20
  @script = "Hans"
20
21
  end
21
-
22
+
22
23
  def default_fonts(options)
23
24
  script = options[:script] || "Hans"
24
25
  scope = options[:scope] || "national"
@@ -27,10 +28,10 @@ module IsoDoc
27
28
  headerfont: (script == "Hans" ? '"SimHei",sans-serif' : '"Calibri",sans-serif'),
28
29
  monospacefont: '"Courier New",monospace',
29
30
  titlefont: (scope == "national" ? (script != "Hans" ? '"Cambria",serif' : '"SimSun",serif' ) :
30
- (script == "Hans" ? '"SimHei",sans-serif' : '"Calibri",sans-serif' ))
31
+ (script == "Hans" ? '"SimHei",sans-serif' : '"Calibri",sans-serif' ))
31
32
  }
32
33
  end
33
-
34
+
34
35
  def default_file_locations(options)
35
36
  {
36
37
  wordstylesheet: html_doc_path("wordstyle.scss"),
@@ -42,7 +43,7 @@ module IsoDoc
42
43
  olstyle: "l10",
43
44
  }
44
45
  end
45
-
46
+
46
47
  def extract_fonts(options)
47
48
  b = options[:bodyfont] || "Arial"
48
49
  h = options[:headerfont] || "Arial"
@@ -57,7 +58,8 @@ module IsoDoc
57
58
  script = "Hans"
58
59
  end
59
60
  @meta = Metadata.new(lang, script, labels)
60
- @common = IsoDoc::Gb::Common.new(meta: @meta)
61
+ @meta.set(:standardclassimg, @standardclassimg)
62
+ @common.meta = @meta
61
63
  end
62
64
 
63
65
  def cleanup(docxml)
@@ -159,6 +159,13 @@ module IsoDoc
159
159
  end
160
160
  end
161
161
 
162
+ def standard_class(scope, prefix, mandate)
163
+ standardclassimg = get[:standardclassimg]
164
+ ret = @agencies.standard_class(scope, prefix, mandate)
165
+ return "<img src='#{standardclassimg}' alt='#{ret}'></img>" if standardclassimg
166
+ ret
167
+ end
168
+
162
169
  def gb_identifier(isoxml)
163
170
  scope = isoxml.at(ns("//gbscope"))&.text || "national"
164
171
  mandate = isoxml.at(ns("//gbmandate"))&.text || "mandatory"
@@ -167,10 +174,9 @@ module IsoDoc
167
174
  issuer = isoxml&.at(ns("//bibdata/contributor[role/@type = 'issuer']/"\
168
175
  "organization/name"))&.text || "GB"
169
176
  @agencies = GbAgencies::Agencies.new(@lang, @labels, issuer)
170
- #set(:docidentifier, @agencies.docidentifier(scope, prefix, mandate, docyear, get[:docnumber]))
171
177
  set(:docidentifier, @agencies.docidentifier(nil, nil, nil, docyear, get[:docnumber]))
172
178
  set(:issuer, issuer)
173
- set(:standard_class, @agencies.standard_class(scope, prefix, mandate))
179
+ set(:standard_class, standard_class(scope, prefix, mandate))
174
180
  set(:standard_agency, @agencies.standard_agency(scope, prefix, mandate))
175
181
  if scope == "local"
176
182
  set(:gbprefix, "DB")
@@ -26,6 +26,21 @@ module Metanorma
26
26
  Metanorma::Input::Asciidoc.new.process(file, @asciidoctor_backend)
27
27
  end
28
28
 
29
+ def extract_options(file)
30
+ head = file.sub(/\n\n.*$/m, "\n")
31
+ /\n:standard-logo-img: (?<standardlogoimg>[^\n]+)\n/ =~ head
32
+ /\n:standard-class-img: (?<standardclassimg>[^\n]+)\n/ =~ head
33
+ /\n:standard-issuer-img: (?<standardissuerimg>[^\n]+)\n/ =~ head
34
+ /\n:title-font: (?<titlefont>[^\n]+)\n/ =~ head
35
+ new_options = {
36
+ standardlogoimg: defined(standardlogoimg) ? standardlogoimg : nil,
37
+ standardclassimg: defined(standardclassimg) ? standardclassimg : nil,
38
+ standardissuerimg: defined(standardissuerimg) ? standardissuerimg : nil,
39
+ titlefont: defined(titlefont) ? titlefont : nil,
40
+ }.reject { |_, val| val.nil? }
41
+ super.merge(new_options)
42
+ end
43
+
29
44
  def output(isodoc_node, outname, format, options={})
30
45
  case format
31
46
  when :html
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-gb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-15 00:00:00.000000000 Z
11
+ date: 2018-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: metanorma-iso