isodoc 2.11.4 → 2.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9890e0801befbe1a13b4138f01f702537e46d4cc482ac99f03f1faf1e7ac532b
4
- data.tar.gz: 69ba3b17b78d0a464cae75213d0eadca3047d0cb7c55a148db7d014b25f2bbd0
3
+ metadata.gz: f7b57ce9e119a72a5611931503d20a6a6eb525b9f07cbc06b0e8794a80db8da2
4
+ data.tar.gz: 51a4d399f9ab8b7730a08d15deaa52b0526efbbe27cea41e355fca92ce0768ba
5
5
  SHA512:
6
- metadata.gz: 1db6e8c07945fb2ad57b19094279d0e26f8638e1e6fefaa261ec9230438dfaf0cea0c7ec6b49276f4108332d41d875c23fd8aa57295bdbbaaee88846f1375ce2
7
- data.tar.gz: 0e127ca60d5841b344d0e3b399475fb5adfb9b72b4df6ae5a2943df95b39f40ab56f486f3eae669b26b2fd239e13d02503e97834fea758575324af7795ca2584
6
+ metadata.gz: 280cf748d5411c671d3e9f7d6e4b949611f1567766bddcdea160b5eff1bf49d6b61df5b706092f0775812515fb78ccf4812edfb79a98f47d0bcfef9e6215fe70
7
+ data.tar.gz: 3af9ba5dec2db7b37542f8dab65bc90cdf19f1298110fc230aac03187814c88bffeed194d3d9de7a2e1892f82767d24cab970f780a3655985dfa7f0482d851d1
@@ -15,7 +15,7 @@ module IsoDoc
15
15
 
16
16
  def initialize(lang, script, locale, i18n, fonts_options = {})
17
17
  @metadata = { lang:, script: }
18
- DATETYPES.each { |w| @metadata["#{w.gsub('-', '_')}date".to_sym] = "XXX" }
18
+ DATETYPES.each { |w| @metadata["#{w.tr('-', '_')}date".to_sym] = "XXX" }
19
19
  @lang = lang
20
20
  @script = script
21
21
  @locale = locale
@@ -1,3 +1,3 @@
1
1
  module IsoDoc
2
- VERSION = "2.11.4".freeze
2
+ VERSION = "2.12.0".freeze
3
3
  end
@@ -31,7 +31,7 @@ module IsoDoc
31
31
 
32
32
  def anchor_struct_label(lbl, elem)
33
33
  case elem
34
- when @labels["appendix"] then l10n("#{elem} #{lbl}")
34
+ when @labels["appendix"] then "#{elem} #{lbl}"
35
35
  else
36
36
  lbl.to_s
37
37
  end
@@ -1,4 +1,5 @@
1
1
  require "roman-numerals"
2
+ require "twitter_cldr"
2
3
 
3
4
  module IsoDoc
4
5
  module XrefGen
@@ -26,6 +27,7 @@ module IsoDoc
26
27
  @style = opts[:numerals]
27
28
  @skip_i = opts[:skip_i]
28
29
  @prefix = opts[:prefix]
30
+ @separator = opts[:separator] || "."
29
31
  @base = ""
30
32
  if num.is_a? String
31
33
  if /^\d+$/.match?(num)
@@ -139,7 +141,8 @@ module IsoDoc
139
141
  end
140
142
 
141
143
  def increment(node)
142
- @unnumbered = node["unnumbered"] == "true" || node["hidden"] == "true" and return self
144
+ @unnumbered = node["unnumbered"] == "true" ||
145
+ node["hidden"] == "true" and return self
143
146
  reset_overrides
144
147
  if node["subsequence"] != @subseq &&
145
148
  !(blank?(node["subsequence"]) && blank?(@subseq))
@@ -150,12 +153,23 @@ module IsoDoc
150
153
  self
151
154
  end
152
155
 
156
+ def style_number(num)
157
+ num.nil? and return num
158
+ case @style
159
+ when :roman then RomanNumerals.to_roman(num)
160
+ when :japanese then num.localize(:ja).spellout
161
+ else num
162
+ end
163
+ end
164
+
153
165
  def print
154
166
  @unnumbered and return nil
155
167
  @prefix_override and return @prefix_override
156
168
  num = @number_override || @num
157
- out = @style == :roman && !num.nil? ? RomanNumerals.to_roman(num) : num
158
- "#{@prefix}#{@base}#{out}#{@letter_override || @letter}"
169
+ out = style_number(num)
170
+ prefix = @prefix
171
+ prefix &&= "#{prefix}#{@separator}"
172
+ "#{prefix}#{@base}#{out}#{@letter_override || @letter}"
159
173
  end
160
174
 
161
175
  def ol_type(list, depth)
@@ -176,6 +190,7 @@ module IsoDoc
176
190
  when :alphabet_upper then (64 + @num).chr.to_s
177
191
  when :roman then RomanNumerals.to_roman(@num).downcase
178
192
  when :roman_upper then RomanNumerals.to_roman(@num).upcase
193
+ when :japanese then num.localize(:ja).spellout
179
194
  end
180
195
  end
181
196
  end
@@ -0,0 +1,13 @@
1
+ require_relative "xref_counter"
2
+
3
+ module IsoDoc
4
+ class Xref
5
+ def clause_counter(num = 0, opts = { numerals: :arabic })
6
+ ::IsoDoc::XrefGen::Counter.new(num, opts)
7
+ end
8
+
9
+ def list_counter(num = 0, opts = { numerals: :arabic })
10
+ ::IsoDoc::XrefGen::Counter.new(num, opts)
11
+ end
12
+ end
13
+ end
@@ -33,8 +33,7 @@ module IsoDoc
33
33
  end
34
34
 
35
35
  def increment_label(elems, node, counter, increment: true)
36
- return "" if elems.size == 1 && !node["number"]
37
-
36
+ elems.size == 1 && !node["number"] and return ""
38
37
  counter.increment(node) if increment
39
38
  " #{counter.print}"
40
39
  end
@@ -48,7 +47,7 @@ module IsoDoc
48
47
  { label: termnote_label(c.print), type: "termnote",
49
48
  value: c.print, elem: @labels["termnote"],
50
49
  container: t["id"],
51
- xref: l10n("#{@labels['note_xref']} #{c.print}") }
50
+ xref: "#{@labels['note_xref']} #{c.print}" }
52
51
  end
53
52
  end
54
53
  end
@@ -64,7 +63,7 @@ module IsoDoc
64
63
  { label: idx, type: "termexample",
65
64
  value: idx, elem: @labels["example_xref"],
66
65
  container: t["id"],
67
- xref: l10n("#{@labels['example_xref']} #{idx}") }
66
+ xref: "#{@labels['example_xref']} #{idx}" }
68
67
  end
69
68
  end
70
69
  end
@@ -123,7 +122,7 @@ module IsoDoc
123
122
  sections.each do |s|
124
123
  notes = s.xpath(ns(".//ol")) - s.xpath(ns(".//clause//ol")) -
125
124
  s.xpath(ns(".//appendix//ol")) - s.xpath(ns(".//ol//ol"))
126
- c = Counter.new
125
+ c = list_counter
127
126
  notes.noblank.each do |n|
128
127
  @anchors[n["id"]] = anchor_struct(increment_label(notes, n, c), n,
129
128
  @labels["list"], "list", false)
@@ -134,7 +133,7 @@ module IsoDoc
134
133
  end
135
134
 
136
135
  def list_item_anchor_names(list, list_anchor, depth, prev_label, refer_list)
137
- c = Counter.new(list["start"] ? list["start"].to_i - 1 : 0)
136
+ c = list_counter(list["start"] ? list["start"].to_i - 1 : 0)
138
137
  list.xpath(ns("./li")).each do |li|
139
138
  bare_label, label =
140
139
  list_item_value(li, c, depth, { list_anchor:, prev_label:,
@@ -188,7 +187,7 @@ module IsoDoc
188
187
 
189
188
  def deflist_term_anchor_names(list, list_anchor)
190
189
  list.xpath(ns("./dt")).each do |li|
191
- label = l10n("#{list_anchor[:xref]}: #{dt2xreflabel(li)}")
190
+ label = "#{list_anchor[:xref]}: #{dt2xreflabel(li)}"
192
191
  li["id"] and @anchors[li["id"]] =
193
192
  { xref: label, type: "deflistitem",
194
193
  container: list_anchor[:container] }
@@ -56,7 +56,7 @@ module IsoDoc
56
56
  end
57
57
 
58
58
  def main_anchor_names(xml)
59
- n = Counter.new
59
+ n = clause_counter
60
60
  clause_order_main(xml).each do |a|
61
61
  xml.xpath(ns(a[:path])).each do |c|
62
62
  section_names(c, n, 1)
@@ -144,7 +144,7 @@ module IsoDoc
144
144
  num.increment(clause)
145
145
  section_name_anchors(clause, num.print, lvl)
146
146
  clause.xpath(ns(SUBCLAUSES))
147
- .each_with_object(Counter.new(0, prefix: "#{num.print}.")) do |c, i|
147
+ .each_with_object(clause_counter(0, prefix: num.print)) do |c, i|
148
148
  section_names1(c, i.increment(c).print, lvl + 1)
149
149
  end
150
150
  num
@@ -153,7 +153,7 @@ module IsoDoc
153
153
  def section_names1(clause, num, level)
154
154
  unnumbered_section_name?(clause) and return num
155
155
  section_name_anchors(clause, num, level)
156
- i = Counter.new(0, prefix: "#{num}.")
156
+ i = clause_counter(0, prefix: num)
157
157
  clause.xpath(ns(SUBCLAUSES)).each do |c|
158
158
  section_names1(c, i.increment(c).print, level + 1)
159
159
  end
@@ -170,18 +170,18 @@ module IsoDoc
170
170
 
171
171
  def section_name_anchors(clause, num, level)
172
172
  @anchors[clause["id"]] =
173
- { label: num, xref: l10n("#{@labels['clause']} #{num}"),
173
+ { label: num, xref: "#{@labels['clause']} #{num}",
174
174
  title: clause_title(clause), level:, type: "clause",
175
175
  elem: @labels["clause"] }
176
176
  end
177
177
 
178
178
  def annex_name_lbl(clause, num)
179
- obl = l10n("(#{@labels['inform_annex']})")
179
+ obl = "(#{@labels['inform_annex']})"
180
180
  clause["obligation"] == "normative" and
181
- obl = l10n("(#{@labels['norm_annex']})")
181
+ obl = "(#{@labels['norm_annex']})"
182
182
  title = Common::case_with_markup(@labels["annex"], "capital",
183
183
  @script)
184
- l10n("<strong>#{title} #{num}</strong><br/>#{obl}")
184
+ "<strong>#{title} #{num}</strong><br/>#{obl}"
185
185
  end
186
186
 
187
187
  def annex_name_anchors(clause, num, level)
@@ -203,7 +203,7 @@ module IsoDoc
203
203
  num.to_s, 1)
204
204
  else
205
205
  clause.xpath(ns(SUBCLAUSES))
206
- .each_with_object(Counter.new(0, prefix: "#{num}.")) do |c, i|
206
+ .each_with_object(clause_counter(0, prefix: num)) do |c, i|
207
207
  annex_names1(c, i.increment(c).print, 2)
208
208
  end
209
209
  end
@@ -212,7 +212,7 @@ module IsoDoc
212
212
 
213
213
  def annex_names1(clause, num, level)
214
214
  annex_name_anchors(clause, num, level)
215
- i = Counter.new(0, prefix: "#{num}.")
215
+ i = clause_counter(0, prefix: num)
216
216
  clause.xpath(ns(SUBCLAUSES)).each do |c|
217
217
  annex_names1(c, i.increment(c).print, level + 1)
218
218
  end
data/lib/isodoc/xref.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require_relative "xref/xref_anchor"
2
2
  require_relative "xref/xref_counter"
3
+ require_relative "xref/xref_counter_types"
3
4
  require_relative "xref/xref_gen_seq"
4
5
  require_relative "xref/xref_gen"
5
6
  require_relative "xref/xref_sect_gen"
@@ -17,25 +18,31 @@ module IsoDoc
17
18
 
18
19
  # Note: if bibrender is no passed in, do not parse references
19
20
  def initialize(lang, script, klass, i18n, options = {})
20
- @anchors = {}
21
+ initialize_empty
21
22
  @lang = lang
22
23
  @script = script
23
24
  @klass = klass
24
25
  @options = options
25
- @i18n = i18n
26
- @labels = @i18n.get
27
- @klass.i18n = @i18n
26
+ initialize_i18n(i18n)
28
27
  @klass.bibrender ||= options[:bibrender]
29
- @locale = options[:locale]
30
28
  @reqt_models = @klass.requirements_processor
31
- .new({
32
- default: "default", lang:, script:,
33
- labels: @i18n.get
34
- })
35
- @i18n
29
+ .new({ default: "default", lang:, script:,
30
+ labels: @i18n.get })
31
+ end
32
+
33
+ def initialize_empty
34
+ @c = HTMLEntities.new
35
+ @anchors = {}
36
36
  @parse_settings = {}
37
37
  end
38
38
 
39
+ def initialize_i18n(i18n)
40
+ @i18n = i18n
41
+ @labels = @i18n.get
42
+ @klass.i18n = @i18n
43
+ @locale = @options[:locale]
44
+ end
45
+
39
46
  def get
40
47
  @anchors
41
48
  end
@@ -66,9 +73,18 @@ module IsoDoc
66
73
  initial_anchor_names(docxml)
67
74
  back_anchor_names(docxml)
68
75
  asset_anchor_names(docxml)
76
+ localise_anchors
69
77
  @parse_settings = {}
70
78
  end
71
79
 
80
+ def localise_anchors
81
+ @anchors.each_value do |v|
82
+ v[:label] &&= l10n(v[:label])
83
+ v[:value] &&= l10n(v[:value])
84
+ v[:xref] &&= l10n(v[:xref])
85
+ end
86
+ end
87
+
72
88
  def ns(xpath)
73
89
  Common::ns(xpath)
74
90
  end
@@ -96,18 +96,18 @@ version: version
96
96
  toc_figures: List of figures
97
97
  toc_tables: List of tables
98
98
  toc_recommendations: List of recommendations
99
- month_january: January
100
- month_february: February
101
- month_march: March
102
- month_april: April
103
- month_may: May
104
- month_june: June
105
- month_july: July
106
- month_august: August
107
- month_september: September
108
- month_october: October
109
- month_november: November
110
- month_december: December
99
+ month_january: 1月
100
+ month_february: 2月
101
+ month_march: 3月
102
+ month_april: 4月
103
+ month_may: 5月
104
+ month_june: 6月
105
+ month_july: 7月
106
+ month_august: 8月
107
+ month_september: 9月
108
+ month_october: 10月
109
+ month_november: 11月
110
+ month_december: 12月
111
111
  obligation: Obligation
112
112
  admonition: {
113
113
  danger: 危険です,
@@ -118,7 +118,7 @@ admonition: {
118
118
  editorial: 編集者注
119
119
  }
120
120
  locality: {
121
- section: Section,
121
+ section: セクション,
122
122
  clause: 箇条,
123
123
  subclause: 細分箇条,
124
124
  part: 部,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isodoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.11.4
4
+ version: 2.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-09-30 00:00:00.000000000 Z
11
+ date: 2024-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64
@@ -451,6 +451,7 @@ files:
451
451
  - lib/isodoc/xref/clause_order.rb
452
452
  - lib/isodoc/xref/xref_anchor.rb
453
453
  - lib/isodoc/xref/xref_counter.rb
454
+ - lib/isodoc/xref/xref_counter_types.rb
454
455
  - lib/isodoc/xref/xref_gen.rb
455
456
  - lib/isodoc/xref/xref_gen_seq.rb
456
457
  - lib/isodoc/xref/xref_sect_gen.rb