metanorma-un 0.3.7 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,11 +13,6 @@ module IsoDoc
13
13
  @toc = options[:toc]
14
14
  end
15
15
 
16
- #def convert1(docxml, filename, dir)
17
- #FileUtils.cp html_doc_path('logo.jpg'), File.join(@localdir, "logo.jpg")
18
- #super
19
- #end
20
-
21
16
  def default_fonts(options)
22
17
  {
23
18
  bodyfont: (options[:script] == "Hans" ? '"SimSun",serif' : '"Times New Roman",serif'),
@@ -92,6 +87,7 @@ module IsoDoc
92
87
  end
93
88
 
94
89
  def middle(isoxml, out)
90
+ middle_admonitions(isoxml, out)
95
91
  clause isoxml, out
96
92
  annex isoxml, out
97
93
  bibliography isoxml, out
@@ -102,8 +98,8 @@ module IsoDoc
102
98
  if node["inline-header"] == "true"
103
99
  inline_header_title(out, node, c1)
104
100
  else
105
- div.send "h#{anchor(node['id'], :level, false) || '1'}" do |h|
106
- lbl = anchor(node['id'], :label, false)
101
+ div.send "h#{@xrefs.anchor(node['id'], :level, false) || '1'}" do |h|
102
+ lbl = @xrefs.anchor(node['id'], :label, false)
107
103
  if lbl && !@suppressheadingnumbers
108
104
  h << "#{lbl}. "
109
105
  insert_tab(h, 1)
@@ -0,0 +1,186 @@
1
+ require "roman-numerals"
2
+
3
+ module IsoDoc
4
+ module UN
5
+ class Xref < IsoDoc::Xref
6
+ def initial_anchor_names(d)
7
+ preface_names(d.at(ns("//preface/abstract")))
8
+ preface_names(d.at(ns("//foreword")))
9
+ preface_names(d.at(ns("//introduction")))
10
+ d.xpath(ns("//preface/clause")).each do |c|
11
+ preface_names(c)
12
+ end
13
+ preface_names(d.at(ns("//acknowledgements")))
14
+ sequential_asset_names(
15
+ d.xpath(ns("//preface/abstract | //foreword | //introduction | "\
16
+ "//preface/clause | //acknowledgements")))
17
+ middle_section_asset_names(d)
18
+ clause_names(d, 0)
19
+ termnote_anchor_names(d)
20
+ termexample_anchor_names(d)
21
+ end
22
+
23
+ def clause_names(docxml, sect_num)
24
+ q = "//clause[parent::sections]"
25
+ @paranumber = 0
26
+ docxml.xpath(ns(q)).each_with_index do |c, i|
27
+ section_names(c, (i + sect_num), 1)
28
+ end
29
+ end
30
+
31
+ def levelnumber(num, lvl)
32
+ case lvl % 3
33
+ when 1 then RomanNumerals.to_roman(num)
34
+ when 2 then ("A".ord + num - 1).chr
35
+ when 0 then num.to_s
36
+ end
37
+ end
38
+
39
+ def annex_levelnum(num, lvl)
40
+ case lvl % 3
41
+ when 0 then RomanNumerals.to_roman(num)
42
+ when 1 then ("A".ord + num - 1).chr
43
+ when 2 then num.to_s
44
+ end
45
+ end
46
+
47
+ NONTERMINAL =
48
+ "./clause | ./term | ./terms | ./definitions | ./references".freeze
49
+
50
+ def leaf_section?(clause)
51
+ !clause.at(ns(NONTERMINAL)) &&
52
+ !%w(definitions annex terms).include?(clause.name) &&
53
+ clause.at(ns("./p | ./bibitem"))
54
+ end
55
+
56
+ def label_leaf_section(clause, lvl)
57
+ @paranumber += 1
58
+ @anchors[clause["id"]] = {label: @paranumber.to_s,
59
+ xref: "paragraph #{@paranumber}",
60
+ level: lvl, type: "paragraph" }
61
+ end
62
+
63
+ def label_annex_leaf_section(clause, num, lvl)
64
+ @paranumber += 1
65
+ @anchors[clause["id"]] = {label: @paranumber.to_s,
66
+ xref: "paragraph #{num}.#{@paranumber}",
67
+ level: lvl, type: "paragraph" }
68
+ end
69
+
70
+ def section_names(clause, num, lvl)
71
+ return num if clause.nil?
72
+ leaf_section?(clause) and label_leaf_section(clause, lvl) and return
73
+ num = num + 1
74
+ lbl = levelnumber(num, 1)
75
+ @anchors[clause["id"]] = { label: lbl, level: lvl, type: "clause",
76
+ xref: l10n("#{@labels['clause']} #{lbl}") }
77
+ i = 1
78
+ clause.xpath(ns(NONTERMINAL)).each do |c|
79
+ next if c["unnumbered"] == "true"
80
+ section_names1(c, "#{lbl}.#{levelnumber(i, lvl + 1)}", lvl + 1)
81
+ i += 1 if !leaf_section?(c)
82
+ end
83
+ num
84
+ end
85
+
86
+ def section_names1(clause, num, level)
87
+ leaf_section?(clause) and label_leaf_section(clause, level) and return
88
+ /\.(?<leafnum>[^.]+$)/ =~ num
89
+ @anchors[clause["id"]] = { label: leafnum, level: level, type: "clause",
90
+ xref: l10n("#{@labels['clause']} #{num}") }
91
+ i = 1
92
+ clause.xpath(ns(NONTERMINAL)).each do |c|
93
+ next if c["unnumbered"] == "true"
94
+ section_names1(c, "#{num}.#{levelnumber(i, level + 1)}", level + 1)
95
+ i += 1 if !leaf_section?(c)
96
+ end
97
+ end
98
+
99
+ def annex_name_lbl(clause, num)
100
+ l10n("<b>#{@labels['annex']} #{num}</b>")
101
+ end
102
+
103
+ SUBCLAUSES =
104
+ "./clause | ./references | ./term | ./terms | ./definitions".freeze
105
+
106
+
107
+ def annex_names(clause, num)
108
+ hierarchical_asset_names(clause, num)
109
+ leaf_section?(clause) and
110
+ label_annex_leaf_section(clause, num, 1) and return
111
+ @anchors[clause["id"]] = { label: annex_name_lbl(clause, num),
112
+ type: "clause",
113
+ xref: "#{@labels['annex']} #{num}", level: 1 }
114
+ if a = single_annex_special_section(clause)
115
+ annex_names1(a, "#{num}", 1)
116
+ else
117
+ i = 1
118
+ clause.xpath(ns(SUBCLAUSES)).each do |c|
119
+ next if c["unnumbered"] == "true"
120
+ annex_names1(c, "#{num}.#{annex_levelnum(i, 2)}", 2)
121
+ i += 1 if !leaf_section?(c)
122
+ end
123
+ end
124
+ end
125
+
126
+ def annex_names1(clause, num, level)
127
+ leaf_section?(clause) and
128
+ label_annex_leaf_section(clause, num, level) and return
129
+ /\.(?<leafnum>[^.]+$)/ =~ num
130
+ @anchors[clause["id"]] = { label: leafnum, xref: "#{@labels['annex']} #{num}",
131
+ level: level, type: "clause" }
132
+ i = 1
133
+ clause.xpath(ns("./clause | ./references")).each do |c|
134
+ next if c["unnumbered"] == "true"
135
+ annex_names1(c, "#{num}.#{annex_levelnum(i, level + 1)}", level + 1)
136
+ i += 1 if !leaf_section?(c)
137
+ end
138
+ end
139
+
140
+ def back_anchor_names(docxml)
141
+ docxml.xpath(ns("//annex")).each_with_index do |c, i|
142
+ @paranumber = 0
143
+ annex_names(c, RomanNumerals.to_roman(i + 1))
144
+ end
145
+ docxml.xpath(ns("//bibliography/clause |"\
146
+ "//bibliography/references")).each do |b|
147
+ preface_names(b)
148
+ end
149
+ docxml.xpath(ns("//bibitem[not(ancestor::bibitem)]")).each do |ref|
150
+ reference_names(ref)
151
+ end
152
+ end
153
+
154
+ def sequential_admonition_names(clause)
155
+ i = 0
156
+ clause.xpath(ns(".//admonition")).each do |t|
157
+ next if t["id"].nil? || t["id"].empty?
158
+ i += 1 unless t["unnumbered"] == "true"
159
+ @anchors[t["id"]] = anchor_struct(i.to_s, nil, @labels["admonition"],
160
+ "box", t["unnumbered"])
161
+ end
162
+ end
163
+
164
+ def hierarchical_admonition_names(clause, num)
165
+ i = 0
166
+ clause.xpath(ns(".//admonition")).each do |t|
167
+ next if t["id"].nil? || t["id"].empty?
168
+ i += 1 unless t["unnumbered"] == "true"
169
+ @anchors[t["id"]] =
170
+ anchor_struct("#{num}.#{i}", nil, @labels["admonition"], "box",
171
+ t["unnumbered"])
172
+ end
173
+ end
174
+
175
+ def sequential_asset_names(clause)
176
+ super
177
+ sequential_admonition_names(clause)
178
+ end
179
+
180
+ def hierarchical_asset_names(clause, num)
181
+ super
182
+ hierarchical_admonition_names(clause, num)
183
+ end
184
+ end
185
+ end
186
+ end
@@ -2,8 +2,12 @@ require "metanorma/processor"
2
2
 
3
3
  module Metanorma
4
4
  module UN
5
- def self.pdf_fonts
6
- ["Arial", "Arial Black", "Courier", "Times New Roman", "HanSans"]
5
+ def self.fonts_used
6
+ {
7
+ html: ["Arial", "Arial Black", "Courier", "Times New Roman", "HanSans"],
8
+ doc: ["Arial", "Arial Black", "Courier", "Times New Roman", "HanSans"],
9
+ pdf: ["Arial", "Arial Black", "Courier", "Times New Roman", "HanSans"],
10
+ }
7
11
  end
8
12
 
9
13
  class Processor < Metanorma::Processor
@@ -30,14 +34,16 @@ module Metanorma
30
34
  Metanorma::UN::Input::Asciidoc.new.process(file, filename, @asciidoctor_backend)
31
35
  end
32
36
 
33
- def output(isodoc_node, outname, format, options={})
37
+ def output(isodoc_node, inname, outname, format, options={})
34
38
  case format
35
39
  when :html
36
- IsoDoc::UN::HtmlConvert.new(options).convert(outname, isodoc_node)
40
+ IsoDoc::UN::HtmlConvert.new(options).convert(inname, isodoc_node, nil, outname)
37
41
  when :doc
38
- IsoDoc::UN::WordConvert.new(options).convert(outname, isodoc_node)
42
+ IsoDoc::UN::WordConvert.new(options).convert(inname, isodoc_node, nil, outname)
39
43
  when :pdf
40
- IsoDoc::UN::PdfConvert.new(options).convert(outname, isodoc_node)
44
+ IsoDoc::UN::PdfConvert.new(options).convert(inname, isodoc_node, nil, outname)
45
+ when :presentation
46
+ IsoDoc::UN::PresentationXMLConvert.new(options).convert(inname, isodoc_node, nil, outname)
41
47
  else
42
48
  super
43
49
  end
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module UN
3
- VERSION = "0.3.7"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
@@ -32,8 +32,8 @@ Gem::Specification.new do |spec|
32
32
  spec.add_dependency "twitter_cldr"
33
33
  spec.add_dependency "iso-639"
34
34
 
35
- spec.add_dependency "metanorma-standoc", "~> 1.3.0"
36
- spec.add_dependency "isodoc", "~> 1.0.0"
35
+ spec.add_dependency "metanorma-standoc", "~> 1.4.0"
36
+ spec.add_dependency "isodoc", "~> 1.1.0"
37
37
 
38
38
  spec.add_development_dependency "byebug", "~> 9.1"
39
39
  spec.add_development_dependency "equivalent-xml", "~> 0.6"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-un
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-01 00:00:00.000000000 Z
11
+ date: 2020-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: htmlentities
@@ -86,28 +86,28 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 1.3.0
89
+ version: 1.4.0
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 1.3.0
96
+ version: 1.4.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: isodoc
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 1.0.0
103
+ version: 1.1.0
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 1.0.0
110
+ version: 1.1.0
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: byebug
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -276,7 +276,6 @@ files:
276
276
  - lib/isodoc/un/html/htmlstyle.scss
277
277
  - lib/isodoc/un/html/logo.jpg
278
278
  - lib/isodoc/un/html/scripts.html
279
- - lib/isodoc/un/html/scripts.pdf.html
280
279
  - lib/isodoc/un/html/unece.scss
281
280
  - lib/isodoc/un/html/word_unece_intro.html
282
281
  - lib/isodoc/un/html/word_unece_plenary_titlepage.html
@@ -285,9 +284,12 @@ files:
285
284
  - lib/isodoc/un/html_convert.rb
286
285
  - lib/isodoc/un/metadata.rb
287
286
  - lib/isodoc/un/pdf_convert.rb
287
+ - lib/isodoc/un/presentation_xml_convert.rb
288
+ - lib/isodoc/un/un.plenary-attachment.xsl
288
289
  - lib/isodoc/un/un.plenary.xsl
289
290
  - lib/isodoc/un/un.recommendation.xsl
290
291
  - lib/isodoc/un/word_convert.rb
292
+ - lib/isodoc/un/xref.rb
291
293
  - lib/metanorma-un.rb
292
294
  - lib/metanorma/un.rb
293
295
  - lib/metanorma/un/UN_emblem_blue.svg
@@ -299,7 +301,7 @@ homepage: https://github.com/metanorma/metanorma-un
299
301
  licenses:
300
302
  - BSD-2-Clause
301
303
  metadata: {}
302
- post_install_message:
304
+ post_install_message:
303
305
  rdoc_options: []
304
306
  require_paths:
305
307
  - lib
@@ -314,9 +316,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
314
316
  - !ruby/object:Gem::Version
315
317
  version: '0'
316
318
  requirements: []
317
- rubyforge_project:
318
- rubygems_version: 2.7.6
319
- signing_key:
319
+ rubygems_version: 3.0.3
320
+ signing_key:
320
321
  specification_version: 4
321
322
  summary: Metanorma for UN.
322
323
  test_files: []
@@ -1,72 +0,0 @@
1
- <script>
2
- //TOC generation
3
- $('#toc').toc({
4
- 'selectors': toclevel(), //elements to use as headings
5
- 'container': 'main', //element to find all selectors in
6
- 'smoothScrolling': true, //enable or disable smooth scrolling on click
7
- 'prefix': 'toc', //prefix for anchor tags and class names
8
- 'onHighlight': function(el) {}, //called when a new section is highlighted
9
- 'highlightOnScroll': false, //add class to heading that is currently in focus
10
- 'highlightOffset': 100, //offset to trigger the next headline
11
- 'anchorName': function(i, heading, prefix) { //custom function for anchor name
12
- return prefix+i;
13
- },
14
- 'headerText': function(i, heading, $heading) { //custom function building the header-item text
15
- return $heading.text();
16
- },
17
- 'itemClass': function(i, heading, $heading, prefix) { // custom function for item class
18
- return $heading[0].tagName.toLowerCase();
19
- }
20
- });
21
-
22
- </script>
23
-
24
- <script>
25
- //TOC toggle animation
26
- $('#toggle').on('click', function(){
27
- if( $('nav').is(':visible') ) {
28
- $('nav').animate({ 'left': '-353px' }, 'slow', function(){
29
- $('nav').hide();
30
- });
31
- $('.container').animate({ 'padding-left': '31px' }, 'slow');
32
- }
33
- else {
34
- $('nav').show();
35
- $('nav').animate({ 'left': '0px' }, 'slow');
36
- $('.container').animate({ 'padding-left': '360px' }, 'slow');
37
- }
38
- });
39
- </script>
40
-
41
- <script>
42
- // Scroll to top button
43
- window.onscroll = function() {scrollFunction()};
44
-
45
- function scrollFunction() {
46
- if (document.body.scrollTop > 100 || document.documentElement.scrollTop > 100) {
47
- document.getElementById("myBtn").style.display = "block";
48
- } else {
49
- document.getElementById("myBtn").style.display = "none";
50
- }
51
- }
52
-
53
- // When the user clicks on the button, scroll to the top of the document
54
- function topFunction() {
55
- document.body.scrollTop = 0;
56
- document.documentElement.scrollTop = 0;
57
- }
58
- </script>
59
-
60
- <script>
61
- /*
62
- $(document).ready(function() {
63
- $('[id^=toc]').each(function ()
64
- {
65
- var currentToc = $(this);
66
- var url = window.location.href;
67
- currentToc.wrap("<a href='" + url + "#" + currentToc.attr("id") + "' </a>");
68
- });
69
- });
70
- */
71
- </script>
72
-