metanorma-gb 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.hound.yml +3 -0
  4. data/.oss-guides.rubocop.yml +1077 -0
  5. data/.rubocop.ribose.yml +65 -0
  6. data/.rubocop.tb.yml +650 -0
  7. data/.rubocop.yml +15 -0
  8. data/.travis.yml +15 -0
  9. data/CODE_OF_CONDUCT.md +74 -0
  10. data/Gemfile +9 -0
  11. data/LICENSE +25 -0
  12. data/README.adoc +369 -0
  13. data/Rakefile +6 -0
  14. data/asciidoctor-gb.gemspec.old +47 -0
  15. data/bin/console +14 -0
  16. data/bin/rspec +18 -0
  17. data/bin/setup +8 -0
  18. data/lib/asciidoctor-gb.rb +11 -0
  19. data/lib/asciidoctor/gb.rb +7 -0
  20. data/lib/asciidoctor/gb/biblio.rng +836 -0
  21. data/lib/asciidoctor/gb/converter.rb +224 -0
  22. data/lib/asciidoctor/gb/front.rb +228 -0
  23. data/lib/asciidoctor/gb/gbstandard.rng +409 -0
  24. data/lib/asciidoctor/gb/html/blank.png +0 -0
  25. data/lib/asciidoctor/gb/html/footer.png +0 -0
  26. data/lib/asciidoctor/gb/html/gb-logos/gb-issuer-default.png +0 -0
  27. data/lib/asciidoctor/gb/html/gb-logos/gb-issuer-default.svg +980 -0
  28. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-db.gif +0 -0
  29. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-db.png +0 -0
  30. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-db.svg +1 -0
  31. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-gb.gif +0 -0
  32. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-gb.png +0 -0
  33. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-gb.svg +1 -0
  34. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-gjb.gif +0 -0
  35. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-gjb.png +0 -0
  36. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-gjb.svg +1 -0
  37. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-gm.gif +0 -0
  38. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-gm.png +0 -0
  39. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-gm.svg +1 -0
  40. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-jjf.gif +0 -0
  41. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-jjf.png +0 -0
  42. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-jjf.svg +1 -0
  43. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-zb.gif +0 -0
  44. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-zb.png +0 -0
  45. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-zb.svg +13 -0
  46. data/lib/asciidoctor/gb/html/gb.scss +556 -0
  47. data/lib/asciidoctor/gb/html/header.html +216 -0
  48. data/lib/asciidoctor/gb/html/html_gb_intro.html +9 -0
  49. data/lib/asciidoctor/gb/html/html_gb_titlepage.html +99 -0
  50. data/lib/asciidoctor/gb/html/htmlstyle.scss +269 -0
  51. data/lib/asciidoctor/gb/html/logo.png +0 -0
  52. data/lib/asciidoctor/gb/html/word_gb_intro.html +3 -0
  53. data/lib/asciidoctor/gb/html/word_gb_titlepage.html +388 -0
  54. data/lib/asciidoctor/gb/html/wordstyle.scss +2543 -0
  55. data/lib/asciidoctor/gb/isodoc.rng +1059 -0
  56. data/lib/asciidoctor/gb/isostandard.rng +1001 -0
  57. data/lib/asciidoctor/gb/section_input.rb +150 -0
  58. data/lib/asciidoctor/gb/validate.rb +115 -0
  59. data/lib/asciidoctor/gb/version.rb +5 -0
  60. data/lib/isodoc/gb/gbcleanup.rb +90 -0
  61. data/lib/isodoc/gb/gbconvert.rb +66 -0
  62. data/lib/isodoc/gb/gbhtmlconvert.rb +84 -0
  63. data/lib/isodoc/gb/gbhtmlrender.rb +208 -0
  64. data/lib/isodoc/gb/gbwordconvert.rb +136 -0
  65. data/lib/isodoc/gb/gbwordrender.rb +206 -0
  66. data/lib/isodoc/gb/html/blank.png +0 -0
  67. data/lib/isodoc/gb/html/footer.png +0 -0
  68. data/lib/isodoc/gb/html/gb-logos/gb-issuer-default.png +0 -0
  69. data/lib/isodoc/gb/html/gb-logos/gb-issuer-default.svg +980 -0
  70. data/lib/isodoc/gb/html/gb-logos/gb-standard-db.gif +0 -0
  71. data/lib/isodoc/gb/html/gb-logos/gb-standard-db.png +0 -0
  72. data/lib/isodoc/gb/html/gb-logos/gb-standard-db.svg +1 -0
  73. data/lib/isodoc/gb/html/gb-logos/gb-standard-gb.gif +0 -0
  74. data/lib/isodoc/gb/html/gb-logos/gb-standard-gb.png +0 -0
  75. data/lib/isodoc/gb/html/gb-logos/gb-standard-gb.svg +1 -0
  76. data/lib/isodoc/gb/html/gb-logos/gb-standard-gjb.gif +0 -0
  77. data/lib/isodoc/gb/html/gb-logos/gb-standard-gjb.png +0 -0
  78. data/lib/isodoc/gb/html/gb-logos/gb-standard-gjb.svg +1 -0
  79. data/lib/isodoc/gb/html/gb-logos/gb-standard-gm.gif +0 -0
  80. data/lib/isodoc/gb/html/gb-logos/gb-standard-gm.png +0 -0
  81. data/lib/isodoc/gb/html/gb-logos/gb-standard-gm.svg +1 -0
  82. data/lib/isodoc/gb/html/gb-logos/gb-standard-jjf.gif +0 -0
  83. data/lib/isodoc/gb/html/gb-logos/gb-standard-jjf.png +0 -0
  84. data/lib/isodoc/gb/html/gb-logos/gb-standard-jjf.svg +1 -0
  85. data/lib/isodoc/gb/html/gb-logos/gb-standard-zb.gif +0 -0
  86. data/lib/isodoc/gb/html/gb-logos/gb-standard-zb.png +0 -0
  87. data/lib/isodoc/gb/html/gb-logos/gb-standard-zb.svg +13 -0
  88. data/lib/isodoc/gb/html/gb.scss +556 -0
  89. data/lib/isodoc/gb/html/header.html +216 -0
  90. data/lib/isodoc/gb/html/html_compliant_gb_titlepage.html +116 -0
  91. data/lib/isodoc/gb/html/html_gb_intro.html +6 -0
  92. data/lib/isodoc/gb/html/html_gb_titlepage.html +94 -0
  93. data/lib/isodoc/gb/html/htmlcompliantstyle.scss +1220 -0
  94. data/lib/isodoc/gb/html/htmlstyle.scss +1007 -0
  95. data/lib/isodoc/gb/html/logo.png +0 -0
  96. data/lib/isodoc/gb/html/scripts.html +71 -0
  97. data/lib/isodoc/gb/html/word_gb_intro.html +3 -0
  98. data/lib/isodoc/gb/html/word_gb_titlepage.html +388 -0
  99. data/lib/isodoc/gb/html/wordstyle.scss +2543 -0
  100. data/lib/isodoc/gb/i18n-en.yaml +12 -0
  101. data/lib/isodoc/gb/i18n-zh-Hans.yaml +12 -0
  102. data/lib/isodoc/gb/metadata.rb +232 -0
  103. data/lib/metanorma/gb.rb +7 -0
  104. data/lib/metanorma/gb/processor.rb +43 -0
  105. data/metanorma-gb.gemspec +48 -0
  106. metadata +380 -0
@@ -0,0 +1,150 @@
1
+ require "gbbib"
2
+
3
+ module Asciidoctor
4
+ module Gb
5
+
6
+ # A {Converter} implementation that generates GB output, and a document
7
+ # schema encapsulation of the document for validation
8
+ class Converter < ISO::Converter
9
+
10
+ def term_def_subclause_parse(attrs, xml, node)
11
+ # subclause contains subclauses
12
+ sub = node.find_by(context: :section) {|s| s.level == node.level + 1 }
13
+ sub.empty? || (return term_def_parse(attrs, xml, node, false))
14
+ (node.title.downcase == "symbols and abbreviated terms" ||
15
+ node.title == "符号、代号和缩略语") &&
16
+ (return symbols_parse(attrs, xml, node))
17
+ xml.term **attr_code(attrs) do |xml_section|
18
+ xml_section.preferred { |name| name << node.title }
19
+ xml_section << node.content
20
+ end
21
+ end
22
+
23
+ def section(node)
24
+ a = { id: Asciidoctor::Standoc::Utils::anchor_or_uuid(node) }
25
+ noko do |xml|
26
+ 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
32
+ when "patent notice" then patent_notice_parse(xml, node)
33
+ when "范围", "scope" then scope_parse(a, xml, node)
34
+ when "规范性引用文件", "normative references"
35
+ norm_ref_parse(a, xml, node)
36
+ when "术语和定义", "terms and definitions",
37
+ "术语、定义、符号、代号和缩略语",
38
+ "terms, definitions, symbols and abbreviated terms"
39
+ @term_def = true
40
+ term_def_parse(a, xml, node, true)
41
+ @term_def = false
42
+ when "符号、代号和缩略语", "symbols and abbreviated terms"
43
+ symbols_parse(a, xml, node)
44
+ when "参考文献", "bibliography"
45
+ bibliography_parse(a, xml, node)
46
+ else
47
+ if @term_def then term_def_subclause_parse(a, xml, node)
48
+ elsif @biblio then bibliography_parse(a, xml, node)
49
+ elsif node.attr("style") == "bibliography" && node.level == 1
50
+ bibliography_parse(a, xml, node)
51
+ elsif node.attr("style") == "appendix" && node.level == 1
52
+ annex_parse(a, xml, node)
53
+ else
54
+ clause_parse(a, xml, node)
55
+ end
56
+ end
57
+ end.join("\n")
58
+ end
59
+
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
+ =begin
74
+ # spec of permissible section sequence
75
+ SEQ = [
76
+ { msg: "Initial section must be (content) 前言",
77
+ val: [{ tag: "foreword", title: "前言" }], },
78
+ { msg: "Prefatory material must be followed by (clause) 范围",
79
+ val: [{ tag: "introduction", title: "引言" },
80
+ { tag: "clause", title: "范围" }], },
81
+ { msg: "Prefatory material must be followed by (clause) 范围",
82
+ val: [{ tag: "clause", title: "范围" }], },
83
+ { msg: "规范性引用文件 must be followed by "\
84
+ "术语和定义",
85
+ val: [
86
+ { tag: "terms", title: "术语和定义" },
87
+ { tag: "clause", title: "术语和定义" },
88
+ { tag: "clause",
89
+ title: "术语、定义、符号、代号和缩略语" },
90
+ { tag: "terms",
91
+ title: "术语、定义、符号、代号和缩略语" }
92
+ ] },
93
+ ]
94
+
95
+ SECTIONS_XPATH =
96
+ "//foreword | //introduction | //sections/terms | .//annex | "\
97
+ "//definitions | //sections/clause | //references[not(parent::clause)] | "\
98
+ "//clause[descendant::references][not(parent::clause)]".freeze
99
+
100
+ def sections_sequence_validate(root)
101
+ f = root.xpath(SECTIONS_XPATH)
102
+ names = f.map { |s| { tag: s.name, title: s&.at("./title")&.text } }
103
+ names = seqcheck(names, SEQ[0][:msg], SEQ[0][:val]) || return
104
+ n = names[0]
105
+ names = seqcheck(names, SEQ[1][:msg], SEQ[1][:val]) || return
106
+ if n == { tag: "introduction", title: "引言" }
107
+ names = seqcheck(names, SEQ[2][:msg], SEQ[2][:val]) || return
108
+ end
109
+ names = seqcheck(names, SEQ[3][:msg], SEQ[3][:val]) || return
110
+ n = names.shift
111
+ if n == { tag: "definitions", title: nil }
112
+ n = names.shift || return
113
+ end
114
+ unless n
115
+ warn "ISO style: Document must contain at least one clause"
116
+ return
117
+ end
118
+ n[:tag] == "clause" or
119
+ warn "ISO style: Document must contain clause after Terms and Definitions"
120
+ (n == { tag: "clause", title: "范围" }) &&
121
+ warn("ISO style: 范围 must occur before 术语和定义")
122
+ n = names.shift or return
123
+ while n[:tag] == "clause"
124
+ (n[:title] == "范围") &&
125
+ warn("ISO style: 范围 must occur before 术语和定义")
126
+ n = names.shift or return
127
+ end
128
+ unless n[:tag] == "annex" or n[:tag] == "references"
129
+ warn "ISO style: Only annexes and references can follow clauses"
130
+ end
131
+ while n[:tag] == "annex"
132
+ n = names.shift
133
+ if n.nil?
134
+ warn("ISO style: Document must include (references) "\
135
+ "Normative References")
136
+ return
137
+ end
138
+ end
139
+ n == { tag: "references", title: "规范性引用文件" } or
140
+ warn "ISO style: Document must include (references) 规范性引用文件"
141
+ n = names.shift
142
+ n == { tag: "references", title: "参考文献" } or
143
+ warn "ISO style: Final section must be (references) 参考文献"
144
+ names.empty? or
145
+ warn "ISO style: There are sections after the final Bibliography"
146
+ end
147
+ =end
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,115 @@
1
+ module Asciidoctor
2
+ module Gb
3
+ class Converter < ISO::Converter
4
+
5
+ def validate(doc)
6
+ content_validate(doc)
7
+ schema_validate(formattedstr_strip(doc.dup),
8
+ File.join(File.dirname(__FILE__), "gbstandard.rng"))
9
+ end
10
+
11
+ def content_validate(doc)
12
+ super
13
+ bilingual_terms_validate(doc.root)
14
+ issuer_validate(doc.root)
15
+ prefix_validate(doc.root)
16
+ @agencyclass.gbtype_validate(doc.root.at("//gbscope")&.text, doc.root.at("//gbprefix")&.text)
17
+ end
18
+
19
+ def prefix_validate(root)
20
+ prefix = root&.at("//gbprefix")&.text
21
+ scope = root&.at("//gbscope")&.text
22
+ case scope
23
+ when "social-group"
24
+ /^[A-Za-z]{3,6}$/.match? prefix or
25
+ warn("#{prefix} is improperly formatted for social standards")
26
+ when "enterprise"
27
+ /^[A-Z0-9]{3,}$/.match? prefix or
28
+ warn("#{prefix} is improperly formatted for enterprise standards")
29
+ when "sector"
30
+ %w(AQ BB CB CH CJ CY DA DB DL DZ EJ FZ GA GH GM GY HB HG HJ HS HY
31
+ JB JC JG JR JT JY LB LD LS LY MH MT MZ NY QB QC QJ QX SB SC SH
32
+ SJ SL SN SY TB TD TJ TY WB WH WJ WM WS WW XB YB YC YD YS YY YZ
33
+ ZY).include? prefix or
34
+ warn("#{prefix} is not a legal sector standard prefix")
35
+ when "local"
36
+ %w(11 12 13 14 15 21 22 23 31 32 33 34 35 36 37 41 42 43 44 45 46
37
+ 50 51 52 53 54 61 62 63 64 65 71 81 82 end).include? prefix or
38
+ warn("#{prefix} is not a legal local standard prefix")
39
+ when "national"
40
+ %w(GB GBZ GJB GBn GHZB GWPB JJF JJG).include? prefix or
41
+ warn("#{prefix} is not a legal national standard prefix")
42
+ end
43
+ end
44
+
45
+ def issuer_validate(root)
46
+ issuer = root&.at("//bibdata/contributor[role/@type = 'issuer']/"\
47
+ "organization/name")&.text
48
+ scope = root&.at("//gbscope")&.text
49
+ if %w(enterprise social).include?(scope) && issuer == "GB"
50
+ warn "No issuer provided for #{scope} standard"
51
+ end
52
+ end
53
+
54
+ def check_bilingual(t, element)
55
+ zh = t.at(".//#{element}[@language = 'zh']")
56
+ en = t.at(".//#{element}[@language = 'en']")
57
+ (en.nil? || en.text.empty?) && !(zh.nil? || zh.text.empty?) &&
58
+ warn("GB: #{element} term #{zh.text} has no English counterpart")
59
+ !(en.nil? || en.text.empty?) && (zh.nil? || zh.text.empty?) &&
60
+ warn("GB: #{element} term #{en.text} has no Chinese counterpart")
61
+ end
62
+
63
+ def bilingual_terms_validate(root)
64
+ root.xpath("//term").each do |t|
65
+ check_bilingual(t, "preferred")
66
+ check_bilingual(t, "admitted")
67
+ check_bilingual(t, "deprecates")
68
+ end
69
+ end
70
+
71
+ def title_intro_validate(root)
72
+ title_intro_en = root.at("//title-intro[@language='en']")
73
+ title_intro_zh = root.at("//title-intro[@language='zh']")
74
+ if title_intro_en.nil? && !title_intro_zh.nil?
75
+ warn "No English Title Intro!"
76
+ end
77
+ if !title_intro_en.nil? && title_intro_zh.nil?
78
+ warn "No Chinese Title Intro!"
79
+ end
80
+ end
81
+
82
+ def title_main_validate(root)
83
+ title_main_en = root.at("//title-main[@language='en']")
84
+ title_main_zh = root.at("//title-main[@language='zh']")
85
+ if title_main_en.nil? && !title_main_zh.nil?
86
+ warn "No English Title!"
87
+ end
88
+ if !title_main_en.nil? && title_main_zh.nil?
89
+ warn "No Chinese Title!"
90
+ end
91
+ end
92
+
93
+ def title_part_validate(root)
94
+ title_part_en = root.at("//title-part[@language='en']")
95
+ title_part_zh = root.at("//title-part[@language='zh']")
96
+ if title_part_en.nil? && !title_part_zh.nil?
97
+ warn "No English Title Part!"
98
+ end
99
+ if !title_part_en.nil? && title_part_zh.nil?
100
+ warn "No Chinese Title Part!"
101
+ end
102
+ end
103
+
104
+ def norm_bibitem_style(root)
105
+ root.xpath(NORM_BIBITEMS).each do |b|
106
+ if b.at(Asciidoctor::Standoc::Converter::ISO_PUBLISHER_XPATH).nil?
107
+ unless /^#{GBCODE}(?![A-Z])/.match? b.at("./docidentifier").text
108
+ Asciidoctor::Standoc::Utils::warning(b, NORM_ISO_WARN, b.text)
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,5 @@
1
+ module Asciidoctor
2
+ module Gb
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,90 @@
1
+ module IsoDoc
2
+ module Gb
3
+ class Cleanup
4
+ def initialize(script, deprecated_lbl)
5
+ @script = script
6
+ @deprecated_lbl = deprecated_lbl
7
+ end
8
+
9
+ def cleanup(docxml)
10
+ terms_cleanup(docxml)
11
+ formula_cleanup(docxml)
12
+ title_cleanup(docxml)
13
+ docxml
14
+ end
15
+
16
+ def formula_cleanup(docxml)
17
+ docxml.xpath("//table[@class = 'dl']//p[not(@class)]").each do |p|
18
+ p["class"] = "dl"
19
+ end
20
+ docxml
21
+ end
22
+
23
+ def example_cleanup(docxml)
24
+ docxml.xpath("//table[@class = 'Note']//p[not(@class)]").each do |p|
25
+ p["class"] = "Note"
26
+ end
27
+ docxml
28
+ end
29
+
30
+ def spaerdruck(x, return_on_br)
31
+ x.traverse do |n|
32
+ n.text? and n.content = n.text.gsub(/(.)/, "\\1\u00a0\u00a0").
33
+ gsub(/\u00a0+$/, "")
34
+ return_on_br and n.element? and n.name == "br" and return
35
+ end
36
+ end
37
+
38
+ def title_cleanup(docxml)
39
+ @script == "Hans" or return
40
+ docxml.xpath("//*[@class = 'zzContents' or @class = 'ForewordTitle' or "\
41
+ "@class = 'IntroTitle'] | "\
42
+ "//h1[@class = 'Sections3']").each do |x|
43
+ spaerdruck(x, false)
44
+ end
45
+ docxml.xpath("//h1[@class = 'Annex']").each do |x|
46
+ spaerdruck(x, true)
47
+ end
48
+ docxml
49
+ end
50
+
51
+ def term_merge(docxml, term_class)
52
+ docxml.xpath("//p[@class = '#{term_class}']").each do |t|
53
+ t1 = t.next_element || next
54
+ if t1.name == "p" && t1["class"] == term_class
55
+ t.add_child("&#x3000;")
56
+ t.add_child(t1.remove.children)
57
+ end
58
+ end
59
+ end
60
+
61
+ def deprecated_single_label(docxml)
62
+ docxml.xpath("//p[@class = 'DeprecatedTerms']").each do |d|
63
+ t1 = d.previous_element
64
+ next unless t1 && t1.name == "p" && t1["class"] == "DeprecatedTerms"
65
+ d.children.first.content =
66
+ d.children.first.content.sub(/^#{@deprecated_lbl}:\s*/, "")
67
+ end
68
+ end
69
+
70
+ def terms_cleanup(docxml)
71
+ term_merge(docxml, "Terms")
72
+ term_merge(docxml, "AltTerms")
73
+ deprecated_single_label(docxml)
74
+ term_merge(docxml, "DeprecatedTerms")
75
+ docxml
76
+ end
77
+
78
+ =begin
79
+ def intro_cleanup(docxml)
80
+ # insert tab for purposes of ToC lining up
81
+ docxml.xpath("//h1[@class = 'IntroTitle']").each do |h1|
82
+ if h1.content == "引言"
83
+ h1.add_child('<span style="mso-tab-count:1">&#xA0; </span>')
84
+ end
85
+ end
86
+ end
87
+ =end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,66 @@
1
+ require "isodoc"
2
+ require_relative "./gbcleanup.rb"
3
+ require_relative "./metadata.rb"
4
+ require "fileutils"
5
+
6
+ module IsoDoc
7
+ module Gb
8
+ # A {Converter} implementation that generates GB output, and a document
9
+ # schema encapsulation of the document for validation
10
+ class Common < IsoDoc::Common
11
+ def initialize(options)
12
+ @meta = options[:meta]
13
+ end
14
+
15
+ def fileloc(loc)
16
+ File.join(File.dirname(__FILE__), loc)
17
+ end
18
+
19
+ def format_agency(agency, format)
20
+ return agency unless agency.is_a?(Array)
21
+ if agency == ["中华人民共和国国家质量监督检验检疫总局", "中国国家标准化管理委员会"]
22
+ logo = "gb-issuer-default.gif"
23
+ #system "cp #{fileloc(File.join('html/gb-logos', logo))} #{logo}"
24
+ FileUtils.cp fileloc(File.join('html/gb-logos', logo)), logo
25
+ return "<img src='#{logo}' alt='#{agency.join(",")}'></img>"
26
+ end
27
+ format_agency1(agency, format)
28
+ end
29
+
30
+ def format_agency1(agency, format)
31
+ ret = "<table>"
32
+ agency.each { |a| ret += "<tr><td>#{a}</td></tr>" }
33
+ ret += "</table>"
34
+ ret.gsub!(/<table>/, "<table width='100%'>") if format == :word
35
+ ret
36
+ end
37
+
38
+ def format_logo(prefix, scope, _format)
39
+ return "" if %w(enterprise social-group).include? scope
40
+ logo = @meta.standard_logo(prefix)
41
+ if logo.nil?
42
+ "<span style='font-size:36pt;font-weight:bold'>#{prefix}</span>"
43
+ else
44
+ format_logo1(logo, prefix, scope)
45
+ end
46
+ end
47
+
48
+ def local_logo_suffix(scope)
49
+ return "" if scope != "local"
50
+ local = @meta.get[:gblocalcode]
51
+ "<span style='font-weight:bold'>#{local}</span>"
52
+ end
53
+
54
+
55
+ def format_logo1(logo, prefix, scope)
56
+ logo += ".gif"
57
+ #system "cp #{fileloc(File.join('html/gb-logos', logo))} #{logo}"
58
+ FileUtils.cp fileloc(File.join('html/gb-logos', logo)), logo
59
+ local = local_logo_suffix(scope)
60
+ #@files_to_delete << logo
61
+ "<img width='113' height='56' src='#{logo}' alt='#{prefix}'></img>"\
62
+ "#{local}"
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,84 @@
1
+ require_relative "gbconvert"
2
+ require "gb_agencies"
3
+ require_relative "gbcleanup"
4
+ require_relative "metadata"
5
+ require_relative "gbhtmlrender"
6
+
7
+ module IsoDoc
8
+ module Gb
9
+ # A {Converter} implementation that generates GB output, and a document
10
+ # schema encapsulation of the document for validation
11
+ class HtmlConvert < IsoDoc::HtmlConvert
12
+ def initialize(options)
13
+ @common = IsoDoc::Gb::Common.new(options)
14
+ @libdir = File.dirname(__FILE__)
15
+ super
16
+ @lang = "zh"
17
+ @script = "Hans"
18
+ end
19
+
20
+ def default_fonts(options)
21
+ script = options[:script] || "Hans"
22
+ scope = options[:scope] || "national"
23
+ {
24
+ bodyfont: (script == "Hans" ? '"SimSun",serif' : '"Cambria",serif'),
25
+ headerfont: (script == "Hans" ? '"SimHei",sans-serif' : '"Calibri",sans-serif'),
26
+ monospacefont: '"Courier New",monospace',
27
+ titlefont: (scope == "national" ? (script != "Hans" ? '"Cambria",serif' : '"SimSun",serif' ) :
28
+ (script == "Hans" ? '"SimHei",sans-serif' : '"Calibri",sans-serif' ))
29
+ }
30
+ end
31
+
32
+ def default_file_locations(options)
33
+ {
34
+ htmlstylesheet: options[:compliant] ? html_doc_path("htmlcompliantstyle.scss") : html_doc_path("htmlstyle.scss"),
35
+ htmlcoverpage: html_doc_path("html_compliant_gb_titlepage.html"),
36
+ htmlintropage: html_doc_path("html_gb_intro.html"),
37
+ scripts: html_doc_path("scripts.html"),
38
+ }
39
+ end
40
+
41
+ def extract_fonts(options)
42
+ b = options[:bodyfont] || "Arial"
43
+ h = options[:headerfont] || "Arial"
44
+ m = options[:monospacefont] || "Courier"
45
+ t = options[:titlefont] || "Arial"
46
+ "$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n$titlefont: #{t};\n"
47
+ end
48
+
49
+ def metadata_init(lang, script, labels)
50
+ unless ["en", "zh"].include? lang
51
+ lang = "zh"
52
+ script = "Hans"
53
+ end
54
+ @meta = Metadata.new(lang, script, labels)
55
+ @common = IsoDoc::Gb::Common.new(meta: @meta)
56
+ end
57
+
58
+ def cleanup(docxml)
59
+ @cleanup = Cleanup.new(@script, @deprecated_lbl)
60
+ super
61
+ @cleanup.cleanup(docxml)
62
+ docxml
63
+ end
64
+
65
+ def example_cleanup(docxml)
66
+ super
67
+ @cleanup.example_cleanup(docxml)
68
+ end
69
+
70
+ def i18n_init(lang, script)
71
+ super
72
+ y = if lang == "en"
73
+ YAML.load_file(File.join(File.dirname(__FILE__), "i18n-en.yaml"))
74
+ elsif lang == "zh" && script == "Hans"
75
+ YAML.load_file(File.join(File.dirname(__FILE__),
76
+ "i18n-zh-Hans.yaml"))
77
+ else
78
+ YAML.load_file(File.join(File.dirname(__FILE__), "i18n-zh-Hans.yaml"))
79
+ end
80
+ @labels = @labels.merge(y)
81
+ end
82
+ end
83
+ end
84
+ end