isodoc 1.6.1 → 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -51,6 +51,7 @@ module IsoDoc::Function
51
51
 
52
52
  def tcaption(node, t)
53
53
  return unless node["summary"]
54
+
54
55
  t.caption do |c|
55
56
  c.span **{ style: "display:none" } do |s|
56
57
  s << node["summary"]
@@ -18,19 +18,19 @@ module IsoDoc::Function
18
18
 
19
19
  def init_file(filename, debug)
20
20
  filepath = Pathname.new(filename)
21
- filename = filepath.sub_ext('').sub(/\.presentation$/, "").to_s
21
+ filename = filepath.sub_ext("").sub(/\.presentation$/, "").to_s
22
22
  dir = init_dir(filename, debug)
23
23
  @filename = filename
24
- @localdir = filepath.parent.to_s + '/'
24
+ @localdir = filepath.parent.to_s + "/"
25
25
  @sourcedir = @localdir
26
- @sourcefilename and @sourcedir = Pathname.new(@sourcefilename).parent.to_s + '/'
26
+ @sourcefilename and @sourcedir = Pathname.new(@sourcefilename).parent.to_s + "/"
27
27
  [filename, dir]
28
28
  end
29
29
 
30
30
  def init_dir(filename, debug)
31
31
  dir = "#{filename}_files"
32
32
  unless debug
33
- Dir.mkdir(dir, 0777) unless File.exists?(dir)
33
+ Dir.mkdir(dir, 0o777) unless File.exists?(dir)
34
34
  FileUtils.rm_rf "#{dir}/*"
35
35
  end
36
36
  dir
@@ -51,9 +51,7 @@ module IsoDoc::Function
51
51
  if @standardstylesheet
52
52
  head.style do |style|
53
53
  @standardstylesheet.open
54
- stylesheet = @standardstylesheet.read.gsub(
55
- "FILENAME", File.basename(filename).sub(/\.presentation$/, "")
56
- )
54
+ stylesheet = @standardstylesheet.read
57
55
  style.comment "\n#{stylesheet}\n"
58
56
  end
59
57
  end
@@ -78,7 +76,7 @@ module IsoDoc::Function
78
76
  section_break(body)
79
77
  end
80
78
 
81
- def make_body2(body, docxml)
79
+ def make_body2(body, _docxml)
82
80
  body.div **{ class: "prefatory-section" } do |div2|
83
81
  div2.p { |p| p << "&nbsp;" } # placeholder
84
82
  end
@@ -117,16 +115,6 @@ module IsoDoc::Function
117
115
  @meta.get
118
116
  end
119
117
 
120
- def middle_title(_isoxml, out)
121
- out.p(**{ class: "zzSTDTitle1" }) { |p| p << @meta.get[:doctitle] }
122
- end
123
-
124
- def middle_admonitions(isoxml, out)
125
- isoxml.xpath(ns("//sections/note | //sections/admonition")).each do |x|
126
- parse(x, out)
127
- end
128
- end
129
-
130
118
  def middle(isoxml, out)
131
119
  middle_title(isoxml, out)
132
120
  middle_admonitions(isoxml, out)
@@ -147,16 +135,14 @@ module IsoDoc::Function
147
135
  s.h1 do |h|
148
136
  n.children.each { |nn| parse(nn, h) }
149
137
  end
150
- else
151
- parse(n, s)
138
+ else parse(n, s)
152
139
  end
153
140
  end
154
141
  end
155
142
  end
156
143
 
157
144
  def parse(node, out)
158
- if node.text?
159
- text_parse(node, out)
145
+ if node.text? then text_parse(node, out)
160
146
  else
161
147
  case node.name
162
148
  when "em" then em_parse(node, out)
@@ -236,8 +222,13 @@ module IsoDoc::Function
236
222
  when "svg" then svg_parse(node, out) # in Presentation XML only
237
223
  when "add" then add_parse(node, out)
238
224
  when "del" then del_parse(node, out)
239
- else
240
- error_parse(node, out)
225
+ when "form" then form_parse(node, out)
226
+ when "input" then input_parse(node, out)
227
+ when "select" then select_parse(node, out)
228
+ when "label" then label_parse(node, out)
229
+ when "option" then option_parse(node, out)
230
+ when "textarea" then textarea_parse(node, out)
231
+ else error_parse(node, out)
241
232
  end
242
233
  end
243
234
  end
@@ -1,6 +1,7 @@
1
1
  require_relative "html_function/comments"
2
2
  require_relative "html_function/footnotes"
3
3
  require_relative "html_function/html"
4
+ require_relative "html_function/form"
4
5
  require_relative "html_function/postprocess"
5
6
 
6
7
  module IsoDoc
@@ -8,6 +9,7 @@ module IsoDoc
8
9
 
9
10
  include HtmlFunction::Comments
10
11
  include HtmlFunction::Footnotes
12
+ include HtmlFunction::Form
11
13
  include HtmlFunction::Html
12
14
 
13
15
  def tmpimagedir_suffix
@@ -0,0 +1,62 @@
1
+ module IsoDoc::HtmlFunction
2
+ module Form
3
+ def form_parse(node, out)
4
+ out.form **attr_code(id: node["id"], name: node["name"],
5
+ action: node["action"]) do |div|
6
+ node.children.each do |n|
7
+ parse(n, div)
8
+ end
9
+ end
10
+ end
11
+
12
+ def input_parse(node, out)
13
+ out.input nil, **attr_code(
14
+ id: node["id"], name: node["name"], type: node["type"],
15
+ value: node["value"], disabled: node["disabled"],
16
+ readonly: node["readonly"], checked: node["checked"],
17
+ maxlength: node["maxlength"], minlength: node["minlength"]
18
+ )
19
+ end
20
+
21
+ def select_parse(node, out)
22
+ selected = node.at(ns("./option[@value = '#{node['value']}']"))
23
+ selected and selected["selected"] = true
24
+ out.select **attr_code(
25
+ id: node["id"], name: node["name"], size: node["size"],
26
+ disabled: node["disabled"], multiple: node["multiple"]
27
+ ) do |div|
28
+ node.children.each do |n|
29
+ parse(n, div)
30
+ end
31
+ end
32
+ end
33
+
34
+ def label_parse(node, out)
35
+ out.label **attr_code(for: node["for"]) do |div|
36
+ node.children.each do |n|
37
+ parse(n, div)
38
+ end
39
+ end
40
+ end
41
+
42
+ def option_parse(node, out)
43
+ out.option **attr_code(
44
+ disabled: node["disabled"], selected: node["selected"],
45
+ value: node["value"]
46
+ ) do |o|
47
+ node.children.each do |n|
48
+ parse(n, o)
49
+ end
50
+ end
51
+ end
52
+
53
+ def textarea_parse(node, out)
54
+ out.textarea **attr_code(
55
+ id: node["id"], name: node["name"], rows: node["rows"],
56
+ cols: node["cols"]
57
+ ) do |div|
58
+ node["value"] and div << node["value"]
59
+ end
60
+ end
61
+ end
62
+ end
data/lib/isodoc/i18n.rb CHANGED
@@ -23,21 +23,23 @@ module IsoDoc
23
23
  end
24
24
 
25
25
  def load_yaml1(lang, script)
26
- if lang == "en"
27
- YAML.load_file(File.join(File.dirname(__FILE__),
28
- "../isodoc-yaml/i18n-en.yaml"))
29
- elsif lang == "fr"
30
- YAML.load_file(File.join(File.dirname(__FILE__),
31
- "../isodoc-yaml/i18n-fr.yaml"))
32
- elsif lang == "zh" && script == "Hans"
33
- YAML.load_file(File.join(File.dirname(__FILE__),
34
- "../isodoc-yaml/i18n-zh-Hans.yaml"))
26
+ case lang
27
+ when "en", "fr", "ru", "de", "es", "ar"
28
+ load_yaml2(lang)
29
+ when "zh"
30
+ if script == "Hans" then load_yaml2("zh-Hans")
31
+ else load_yaml2("en")
32
+ end
35
33
  else
36
- YAML.load_file(File.join(File.dirname(__FILE__),
37
- "../isodoc-yaml/i18n-en.yaml"))
34
+ load_yaml2("en")
38
35
  end
39
36
  end
40
37
 
38
+ def load_yaml2(str)
39
+ YAML.load_file(File.join(File.dirname(__FILE__),
40
+ "../isodoc-yaml/i18n-#{str}.yaml"))
41
+ end
42
+
41
43
  def get
42
44
  @labels
43
45
  end
@@ -1,28 +1,28 @@
1
- require "twitter_cldr"
2
- require "bigdecimal"
3
-
4
1
  module IsoDoc
5
2
  class PresentationXMLConvert < ::IsoDoc::Convert
6
3
  def prefix_container(container, linkend, _target)
7
- l10n(@xrefs.anchor(container, :xref) + ", " + linkend)
4
+ l10n("#{@xrefs.anchor(container, :xref)}, #{linkend}")
8
5
  end
9
6
 
10
7
  def anchor_linkend(node, linkend)
11
8
  if node["citeas"].nil? && node["bibitemid"]
12
- return @xrefs.anchor(node["bibitemid"] ,:xref) || "???"
9
+ return @xrefs.anchor(node["bibitemid"], :xref) || "???"
13
10
  elsif node["target"] && node["droploc"]
14
- return @xrefs.anchor(node["target"], :value) || @xrefs.anchor(node["target"], :label) ||
11
+ return @xrefs.anchor(node["target"], :value) ||
12
+ @xrefs.anchor(node["target"], :label) ||
15
13
  @xrefs.anchor(node["target"], :xref) || "???"
16
14
  elsif node["target"] && !/.#./.match(node["target"])
17
15
  linkend = anchor_linkend1(node)
18
16
  end
17
+
19
18
  linkend || "???"
20
19
  end
21
20
 
22
21
  def anchor_linkend1(node)
23
22
  linkend = @xrefs.anchor(node["target"], :xref)
24
23
  container = @xrefs.anchor(node["target"], :container, false)
25
- (container && get_note_container_id(node) != container && @xrefs.get[node["target"]]) &&
24
+ (container && get_note_container_id(node) != container &&
25
+ @xrefs.get[node["target"]]) and
26
26
  linkend = prefix_container(container, linkend, node["target"])
27
27
  capitalise_xref(node, linkend)
28
28
  end
@@ -31,31 +31,38 @@ module IsoDoc
31
31
  return linkend unless %w(Latn Cyrl Grek).include? @script
32
32
  return linkend&.capitalize if node["case"] == "capital"
33
33
  return linkend&.downcase if node["case"] == "lowercase"
34
- return linkend if linkend[0,1].match(/\p{Upper}/)
34
+ return linkend if linkend[0, 1].match?(/\p{Upper}/)
35
+
35
36
  prec = nearest_block_parent(node).xpath("./descendant-or-self::text()") &
36
37
  node.xpath("./preceding::text()")
37
- (prec.empty? || /(?!<[^.].)\.\s+$/.match(prec.map { |p| p.text }.join)) ? linkend&.capitalize : linkend
38
+ if prec.empty? || /(?!<[^.].)\.\s+$/.match(prec.map(&:text).join)
39
+ linkend&.capitalize
40
+ else linkend
41
+ end
38
42
  end
39
43
 
40
44
  def nearest_block_parent(node)
41
- until %w(p title td th name formula li dt dd sourcecode pre).include?(node.name)
42
- node = node.parent
45
+ until %w(p title td th name formula li dt dd sourcecode pre)
46
+ .include?(node.name)
47
+ node = node.parent
43
48
  end
44
49
  node
45
50
  end
46
51
 
47
52
  def non_locality_elems(node)
48
- node.children.select do |c|
49
- !%w{locality localityStack}.include? c.name
53
+ node.children.reject do |c|
54
+ %w{locality localityStack}.include? c.name
50
55
  end
51
56
  end
52
57
 
53
58
  def get_linkend(node)
54
- contents = non_locality_elems(node).select { |c| !c.text? || /\S/.match(c) }
55
- return unless contents.empty?
59
+ c1 = non_locality_elems(node).select { |c| !c.text? || /\S/.match(c) }
60
+ return unless c1.empty?
61
+
56
62
  link = anchor_linkend(node, docid_l10n(node["target"] || node["citeas"]))
57
- link += eref_localities(node.xpath(ns("./locality | ./localityStack")), link, node)
58
- non_locality_elems(node).each { |n| n.remove }
63
+ link += eref_localities(node.xpath(ns("./locality | ./localityStack")),
64
+ link, node)
65
+ non_locality_elems(node).each(&:remove)
59
66
  node.add_child(link)
60
67
  end
61
68
  # so not <origin bibitemid="ISO7301" citeas="ISO 7301">
@@ -65,25 +72,25 @@ module IsoDoc
65
72
  ret = ""
66
73
  refs.each_with_index do |r, i|
67
74
  delim = ","
68
- delim = ";" if r.name == "localityStack" && i>0
75
+ delim = ";" if r.name == "localityStack" && i.positive?
69
76
  ret = eref_locality_stack(r, i, target, delim, ret, n)
70
77
  end
71
78
  ret
72
79
  end
73
80
 
74
- def eref_locality_stack(r, i, target, delim, ret, n)
81
+ def eref_locality_stack(r, idx, target, delim, ret, n)
75
82
  if r.name == "localityStack"
76
83
  r.elements.each_with_index do |rr, j|
77
84
  ret += eref_localities0(rr, j, target, delim, n)
78
85
  delim = ","
79
86
  end
80
87
  else
81
- ret += eref_localities0(r, i, target, delim, n)
88
+ ret += eref_localities0(r, idx, target, delim, n)
82
89
  end
83
90
  ret
84
91
  end
85
92
 
86
- def eref_localities0(r, i, target, delim, n)
93
+ def eref_localities0(r, _i, target, delim, n)
87
94
  if r["type"] == "whole" then l10n("#{delim} #{@i18n.wholeoftext}")
88
95
  else
89
96
  eref_localities1(target, r["type"], r.at(ns("./referenceFrom")),
@@ -92,10 +99,10 @@ module IsoDoc
92
99
  end
93
100
 
94
101
  # TODO: move to localization file
95
- def eref_localities1_zh(target, type, from, to, n, delim)
102
+ def eref_localities1_zh(_target, type, from, to, n, delim)
96
103
  ret = "#{delim} 第#{from.text}" if from
97
104
  ret += "&ndash;#{to.text}" if to
98
- loc = (@i18n.locality[type] || type.sub(/^locality:/, "").capitalize )
105
+ loc = (@i18n.locality[type] || type.sub(/^locality:/, "").capitalize)
99
106
  ret += " #{loc}" unless n["droploc"] == "true"
100
107
  ret
101
108
  end
@@ -103,7 +110,9 @@ module IsoDoc
103
110
  # TODO: move to localization file
104
111
  def eref_localities1(target, type, from, to, delim, n, lang = "en")
105
112
  return "" if type == "anchor"
106
- lang == "zh" and return l10n(eref_localities1_zh(target, type, from, to, n, delim))
113
+
114
+ lang == "zh" and
115
+ return l10n(eref_localities1_zh(target, type, from, to, n, delim))
107
116
  ret = delim
108
117
  ret += eref_locality_populate(type, n)
109
118
  ret += " #{from.text}" if from
@@ -111,10 +120,11 @@ module IsoDoc
111
120
  l10n(ret)
112
121
  end
113
122
 
114
- def eref_locality_populate(type, n)
115
- return "" if n["droploc"] == "true"
123
+ def eref_locality_populate(type, node)
124
+ return "" if node["droploc"] == "true"
125
+
116
126
  loc = @i18n.locality[type] || type.sub(/^locality:/, "")
117
- loc = case n["case"]
127
+ loc = case node["case"]
118
128
  when "capital" then loc.capitalize
119
129
  when "lowercase" then loc.downcase
120
130
  else
@@ -139,8 +149,8 @@ module IsoDoc
139
149
  docxml.xpath(ns("//quote/source")).each { |f| xref1(f) }
140
150
  end
141
151
 
142
- def xref1(f)
143
- get_linkend(f)
152
+ def xref1(node)
153
+ get_linkend(node)
144
154
  end
145
155
 
146
156
  def concept(docxml)
@@ -151,95 +161,27 @@ module IsoDoc
151
161
  content = node.first_element_child.children.select do |c|
152
162
  !%w{locality localityStack}.include? c.name
153
163
  end.select { |c| !c.text? || /\S/.match(c) }
154
- node.replace content.empty? ?
164
+ node.replace content.empty? ?
155
165
  @i18n.term_defined_in.sub(/%/, node.first_element_child.to_xml) :
156
166
  "<em>#{node.children.to_xml}</em>"
157
167
  end
158
168
 
159
-
160
- MATHML = { "m" => "http://www.w3.org/1998/Math/MathML" }.freeze
161
-
162
- def mathml(docxml)
163
- locale = twitter_cldr_localiser()
164
- docxml.xpath("//m:math", MATHML).each do |f|
165
- mathml1(f, locale)
166
- end
167
- end
168
-
169
- # symbols is merged into
170
- # TwitterCldr::DataReaders::NumberDataReader.new(locale).symbols
171
- def localize_maths(f, locale)
172
- f.xpath(".//m:mn", MATHML).each do |x|
173
- num = BigDecimal(x.text)
174
- precision = /\./.match(x.text) ? x.text.sub(/^.*\./, "").size : 0
175
- x.children = localized_number(num, locale, precision)
176
- end
177
- end
178
-
179
- # By itself twitter-cldr does not support fraction part digits grouping
180
- # and custom delimeter, will decorate fraction part manually
181
- def localized_number(num, locale, precision)
182
- localized = (precision == 0) ? num.localize(locale).to_s :
183
- num.localize(locale).to_decimal.to_s(:precision => precision)
184
- twitter_cldr_reader_symbols = twitter_cldr_reader(locale)
185
- return localized unless twitter_cldr_reader_symbols[:decimal]
186
- integer, fraction = localized.split(twitter_cldr_reader_symbols[:decimal])
187
- return localized if fraction.nil? || fraction.length.zero?
188
- [integer, decorate_fraction_part(fraction, locale)].join(twitter_cldr_reader_symbols[:decimal])
189
- end
190
-
191
- def decorate_fraction_part(fract, locale)
192
- result = []
193
- twitter_cldr_reader_symbols = twitter_cldr_reader(locale)
194
- fract = fract.slice(0..(twitter_cldr_reader_symbols[:precision] || -1))
195
- fr_group_digits = twitter_cldr_reader_symbols[:fraction_group_digits] || 1
196
- until fract.empty?
197
- result.push(fract.slice!(0, fr_group_digits))
198
- end
199
- result.join(twitter_cldr_reader_symbols[:fraction_group].to_s)
200
- end
201
-
202
- def twitter_cldr_localiser_symbols
203
- {}
204
- end
205
-
206
- def twitter_cldr_reader(locale)
207
- num = TwitterCldr::DataReaders::NumberDataReader.new(locale)
208
- num.symbols.merge!(twitter_cldr_localiser_symbols)
209
- end
210
-
211
- def twitter_cldr_localiser()
212
- locale = TwitterCldr.supported_locale?(@lang.to_sym) ? @lang.to_sym : :en
213
- twitter_cldr_reader(locale)
214
- locale
215
- end
216
-
217
- def mathml1(f, locale)
218
- localize_maths(f, locale)
219
- return unless f.elements.size == 1 && f.elements.first.name == "mn"
220
- if f.parent.name == "stem"
221
- f.parent.replace(f.at("./m:mn", MATHML).children)
222
- else
223
- f.replace(f.at("./m:mn", MATHML).children)
224
- end
225
- end
226
-
227
169
  def variant(docxml)
228
170
  docxml.xpath(ns("//variant")).each { |f| variant1(f) }
229
- docxml.xpath(ns("//variant[@remove = 'true']")).each { |f| f.remove }
171
+ docxml.xpath(ns("//variant[@remove = 'true']")).each(&:remove)
230
172
  docxml.xpath(ns("//variant")).each do |v|
231
173
  next unless v&.next&.name == "variant"
174
+
232
175
  v.next = "/"
233
176
  end
234
177
  docxml.xpath(ns("//variant")).each { |f| f.replace(f.children) }
235
178
  end
236
179
 
237
180
  def variant1(node)
238
- if (!node["lang"] || node["lang"] == @lang) && (!node["script"] || node["script"] == @script)
181
+ if (!node["lang"] || node["lang"] == @lang) &&
182
+ (!node["script"] || node["script"] == @script)
239
183
  elsif found_matching_variant_sibling(node)
240
184
  node["remove"] = "true"
241
- else
242
- #return unless !node.at("./preceding-sibling::xmlns:variant")
243
185
  end
244
186
  end
245
187
 
@@ -250,7 +192,8 @@ module IsoDoc
250
192
  foll = node.xpath("./following-sibling::xmlns:variant")
251
193
  found = false
252
194
  (prev + foll).each do |n|
253
- found = true if n["lang"] == @lang && (!n["script"] || n["script"] == @script)
195
+ found = true if n["lang"] == @lang &&
196
+ (!n["script"] || n["script"] == @script)
254
197
  end
255
198
  found
256
199
  end