relaton-render 1.0.5 → 1.1.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: b834b958e0a0c893b641087a171141972d18626cd01c66bce85e29a898d4fa40
4
- data.tar.gz: 44b06318fdd7c00cca50fb0b309a84faaa26f914bade814f2a4389998076e7a1
3
+ metadata.gz: d4f484dc0f8b679d7aa4e200ea5288c7b08120ed482eb50dbb4feb6d8f4ebc18
4
+ data.tar.gz: 5775265c429b2861268f838b794d8a2a874c6caa789b73d77b4e1e6983b7a57e
5
5
  SHA512:
6
- metadata.gz: cd66e65e6a282d5926701f28965bcb6e857acc4fb675936effd18e7c40b957c9ec645522bdbea2ff50f7f12b5db44bddb1a3d66b1ca986b113b9cba38bd0a8fc
7
- data.tar.gz: ad226183da8ff58d03f8b8cc75e9795b20a503f5c73adb6df6210f5c95382da1992a51d86a19acd526c38977d010437bc64171943704ce15f8c7586af9558af1
6
+ metadata.gz: 4fd197eee29210c266c87a38b195a6358d8446aefac03baac057b15a93524b2f590c5470ed1ae419595b986067d20f725878e058574acd146b0435e4eebce8be
7
+ data.tar.gz: b53ec5cadb07fe27883468c83b1799ed0191efaa56cf5bf11715f0320a4d9c0329ce99e7447e8b558b2ae1ebac953f42c20e6f83f7a3831bee952c27452992bf
@@ -4,7 +4,7 @@ require_relative "uri"
4
4
  require "yaml"
5
5
  require "liquid"
6
6
  require "date"
7
- require "relaton_bib"
7
+ require "relaton/bib"
8
8
  require "metanorma-utils"
9
9
  require_relative "../template/template"
10
10
  require_relative "../../../isodoc/i18n"
@@ -162,11 +162,25 @@ module Relaton
162
162
  end
163
163
 
164
164
  def xml2relaton(bib)
165
- bib.is_a?(Nokogiri::XML::Element) and
166
- bib = bib.to_xml(encoding: "UTF-8", indent: 0,
167
- save_with: Nokogiri::XML::Node::SaveOptions::AS_XML)
168
- bib.is_a?(String) && Nokogiri::XML(bib).errors.empty? and
169
- bib = RelatonBib::XMLParser.from_xml(bib) or bib
165
+ bib.is_a?(Relaton::Bib::ItemData) and return bib
166
+ xml = xml_string2noko(bib)
167
+ bib = xml.to_xml(encoding: "UTF-8", indent: 0,
168
+ save_with: Nokogiri::XML::Node::SaveOptions::AS_XML)
169
+ .gsub(/ xmlns="[^"]*"/, "")
170
+ Relaton::Bib::Bibitem.from_xml(bib)
171
+ end
172
+
173
+ def xml_string2noko(bib)
174
+ case bib
175
+ when String
176
+ xml = Nokogiri::XML(bib)
177
+ xml.errors.empty? or return bib
178
+ xml.root
179
+ when Nokogiri::XML::Element
180
+ bib
181
+ when Nokogiri::XML::Document
182
+ bib.root
183
+ end
170
184
  end
171
185
 
172
186
  def fmtref(doc)
@@ -198,7 +212,7 @@ module Relaton
198
212
  end
199
213
 
200
214
  def also_pub_as(doc)
201
- r = doc.relation.select { |x| x.type == "hasRepresentation" }
215
+ r = Array(doc.relation).select { |x| x.type == "hasRepresentation" }
202
216
  r.map do |x|
203
217
  _, out = render_single_bibitem(x.bibitem)
204
218
  @i18n.select(nil).also_pub_as + out
@@ -252,7 +266,7 @@ module Relaton
252
266
  p = Nokogiri::XML(bib) or return
253
267
  (p.errors.empty? && p.root.at("./bibitem")) or return nil
254
268
  p.root.xpath("./bibitem").each_with_object([]) do |b, m|
255
- m << RelatonBib::XMLParser.from_xml(b.to_xml)
269
+ m << Relaton::Bib::Bibitem.from_xml(b.to_xml)
256
270
  end
257
271
  end
258
272
 
@@ -3,6 +3,9 @@ module Relaton
3
3
  class Parse
4
4
  def content(node)
5
5
  node.nil? and return node
6
+ node.is_a?(String) and
7
+ return node.strip.gsub("</title>", "").gsub("<title>", "")
8
+ .gsub(/>\n\s*</, "><").gsub(/\n\s*/, " ")
6
9
  node.content.is_a?(Array) and return node.content.map { |x| content(x) }
7
10
  ret = node.content.strip
8
11
  .gsub("</title>", "").gsub("<title>", "")
@@ -35,7 +38,7 @@ module Relaton
35
38
  end
36
39
 
37
40
  def extract_initials(person)
38
- initials = content(person.name.initials)&.sub(/(.)\.?$/, "\\1.")
41
+ initials = content(person.name.formatted_initials)&.sub(/(.)\.?$/, "\\1.")
39
42
  &.split /(?<=\.) /
40
43
  initials ||= person.name.forename.map(&:initial)
41
44
  .compact.map { |x| x.sub(/(.)\.?$/, "\\1.") }
@@ -44,13 +47,13 @@ module Relaton
44
47
 
45
48
  def forenames_parse(person)
46
49
  person.name.forename.map do |x|
47
- x.content.empty? ? esc("#{x.initial}.") : content(x)
50
+ x.content.nil? || x.content.empty? ? esc("#{x.initial}.") : content(x)
48
51
  end
49
52
  end
50
53
 
51
54
  # de S. => one initial, M.-J. => one initial
52
55
  def initials_parse(person)
53
- i = content(person.name.initials) or
56
+ i = content(person.name.formatted_initials) or
54
57
  return person.name.forename.map(&:initial)
55
58
  .compact.map { |x| x.sub(/(.)\.?$/, "\\1.") }
56
59
 
@@ -63,10 +66,8 @@ module Relaton
63
66
  end
64
67
 
65
68
  def extractname(contributor)
66
- org = contributor.entity if contributor.entity
67
- .is_a?(RelatonBib::Organization)
68
- person = contributor.entity if contributor.entity
69
- .is_a?(RelatonBib::Person)
69
+ org = contributor.organization
70
+ person = contributor.person
70
71
  return { nonpersonal: extract_orgname(org) } if org
71
72
  return extract_personname(person) if person
72
73
 
@@ -75,8 +76,9 @@ module Relaton
75
76
 
76
77
  def contributor_role(contributors)
77
78
  contributors.length.positive? or return nil
78
- desc = contributors[0].role.first.description.join("\n")
79
- type = contributors[0].role.first.type
79
+ role = contributors[0].role.first
80
+ desc = Array(role&.description).map(&:content).join("\n")
81
+ type = role&.type
80
82
  desc.empty? ? type : desc
81
83
  end
82
84
 
@@ -98,17 +100,17 @@ module Relaton
98
100
  add.nil? and next
99
101
  cr = add and break
100
102
  end
101
- cr.nil? and cr = doc.contributor
103
+ cr.nil? and cr = Array(doc.contributor)
102
104
  cr
103
105
  end
104
106
 
105
107
  def datepick(date)
106
108
  date.nil? and return nil
107
- on = date.on
109
+ at = date.at
108
110
  from = date.from
109
111
  to = date.to
110
- on and return { on: on }
111
- from and return { from: from, to: to }
112
+ at and return { on: at.to_s }
113
+ from and return { from: from.to_s, to: to&.to_s }
112
114
  nil
113
115
  end
114
116
 
@@ -122,22 +124,22 @@ module Relaton
122
124
 
123
125
  # year-only
124
126
  def date(doc, host)
125
- ret = date1(doc.date)
126
- host and ret ||= date1(host.date)
127
+ ret = date1(Array(doc.date))
128
+ host and ret ||= date1(Array(host.date))
127
129
  datepick(ret)&.transform_values do |v|
128
130
  v&.sub(/-.*$/, "")
129
131
  end
130
132
  end
131
133
 
132
134
  def date_updated(doc, host)
133
- ret = doc.date.detect { |x| x.type == "updated" }
134
- host and ret ||= host.date.detect { |x| x.type == "updated" }
135
+ ret = Array(doc.date).detect { |x| x.type == "updated" }
136
+ host and ret ||= Array(host.date).detect { |x| x.type == "updated" }
135
137
  datepick(ret)
136
138
  end
137
139
 
138
140
  def date_accessed(doc, host)
139
- ret = doc.date.detect { |x| x.type == "accessed" }
140
- host and ret ||= host.date.detect { |x| x.type == "accessed" }
141
+ ret = Array(doc.date).detect { |x| x.type == "accessed" }
142
+ host and ret ||= Array(host.date).detect { |x| x.type == "accessed" }
141
143
  datepick(ret)
142
144
  end
143
145
 
@@ -153,8 +155,8 @@ module Relaton
153
155
  host and x ||= pick_contributor(host, "publisher")
154
156
  x.nil? and return nil
155
157
  x.map do |c|
156
- content(c.entity.abbreviation) ||
157
- content(c.entity.name.first)
158
+ content(c.organization.abbreviation) ||
159
+ content(c.organization.name.first)
158
160
  end
159
161
  end
160
162
 
@@ -175,8 +177,8 @@ module Relaton
175
177
  end
176
178
 
177
179
  def pick_contributor(doc, role)
178
- ret = doc.contributor.select do |c|
179
- c.role.any? { |r| r.type == role }
180
+ ret = Array(doc.contributor).select do |c|
181
+ Array(c.role).any? { |r| r.type == role }
180
182
  end
181
183
  ret.empty? ? nil : ret
182
184
  end
@@ -2,18 +2,18 @@ module Relaton
2
2
  module Render
3
3
  class Parse
4
4
  def host(doc)
5
- doc.relation.detect { |r| r.type == "includedIn" }&.bibitem
5
+ doc.relation&.detect { |r| r.type == "includedIn" }&.bibitem
6
6
  end
7
7
 
8
8
  # TODO : first is naive choice
9
9
  def title(doc)
10
- doc.nil? || doc.title.empty? and return nil
11
- t = doc.title.select { |x| x.title.language&.include? @lang }
12
- t.empty? and t = doc.title
10
+ doc.nil? || doc.title.nil? || doc.title.empty? and return nil
11
+ t = Array(doc.title).select { |x| x.language == @lang }
12
+ t.empty? and t = Array(doc.title)
13
13
  t1 = t.select { |x| x.type == "main" }
14
14
  t1.empty? and t1 = t
15
15
  t1.first or return
16
- esc(content(t1.first.title))
16
+ esc(content(t1.first))
17
17
  end
18
18
 
19
19
  def medium(doc, host)
@@ -25,9 +25,9 @@ module Relaton
25
25
 
26
26
  def size(doc)
27
27
  x = doc.size or return nil
28
- x.size.each_with_object({}) do |v, m|
28
+ x.value.each_with_object({}) do |v, m|
29
29
  m[v.type] ||= []
30
- m[v.type] << v.value
30
+ m[v.type] << v.content
31
31
  end
32
32
  end
33
33
 
@@ -42,8 +42,8 @@ module Relaton
42
42
  end
43
43
 
44
44
  def place(doc, host)
45
- x = doc.place
46
- x.empty? && host and x = host.place
45
+ x = Array(doc.place)
46
+ x.empty? && host and x = Array(host.place)
47
47
  x.empty? and return x
48
48
  x.map { |p| place1(p) }
49
49
  end
@@ -52,26 +52,24 @@ module Relaton
52
52
  c = place.city
53
53
  r = place.region
54
54
  n = place.country
55
- c.nil? && r.empty? && n.empty? and return place.name
56
- ret = [c] + r.map(&:name) + n.map(&:name)
57
- ret.compact
58
- #@i18n.l10n(ret.compact.join(", "))
55
+ c.nil? && r.empty? && n.empty? and return place.formatted_place
56
+ [c, *r.map(&:content), *n.map(&:content)].compact.join(", ")
59
57
  end
60
58
 
61
59
  def series(doc)
62
- doc.series.detect { |s| s.type == "main" } ||
63
- doc.series.detect { |s| s.type.nil? } ||
64
- doc.series.first
60
+ doc.series&.detect { |s| s.type == "main" } ||
61
+ doc.series&.detect { |s| s.type.nil? } ||
62
+ doc.series&.first
65
63
  end
66
64
 
67
65
  def series_title(series, _doc)
68
66
  series.nil? and return nil
69
- series.title.respond_to?(:titles) && !series.title.titles.empty? and
70
- return content(series.title.titles.first.title)
71
- series.title.respond_to?(:title) and
72
- return content(series.title.title)
73
- series.title.respond_to?(:formattedref) and
74
- content(series.formattedref)
67
+ t = Array(series.title).select { |x| x.language == @lang }
68
+ t.empty? and t = Array(series.title)
69
+ t1 = t.select { |x| x.type == "main" }
70
+ t1.empty? and t1 = t
71
+ t1.first.nil? and return nil
72
+ content(t1.first)
75
73
  end
76
74
 
77
75
  def series_formatted(series, _doc)
@@ -99,7 +97,8 @@ module Relaton
99
97
  end
100
98
 
101
99
  def series_place(series, _doc)
102
- series.place
100
+ p = series.place or return nil
101
+ place1(p)
103
102
  end
104
103
 
105
104
  def series_dates(series, _doc)
@@ -112,7 +111,7 @@ module Relaton
112
111
  def access_location(doc, host)
113
112
  x = doc.accesslocation || host&.accesslocation or
114
113
  return nil
115
- x.first
114
+ Array(x).first
116
115
  end
117
116
 
118
117
  def included(type)
@@ -121,7 +120,7 @@ module Relaton
121
120
 
122
121
  def type(doc)
123
122
  type = doc.type and return type
124
- doc.relation.any? { |r| r.type == "includedIn" } and return "inbook"
123
+ doc.relation&.any? { |r| r.type == "includedIn" } and return "inbook"
125
124
  "book"
126
125
  end
127
126
 
@@ -149,25 +148,34 @@ module Relaton
149
148
 
150
149
  def localized_string_or_text(str)
151
150
  case str
152
- when RelatonBib::LocalizedString then content(str)
151
+ when Relaton::Bib::LocalizedString then content(str)
153
152
  when String then str
154
153
  end
155
154
  end
156
155
 
157
156
  def extent(doc)
158
- doc.extent.each_with_object([]) do |e, acc|
157
+ Array(doc.extent).each_with_object([]) do |e, acc|
159
158
  case e
160
- when RelatonBib::Extent, RelatonBib::LocalityStack
161
- a = e.locality.each_with_object([]) do |e1, m|
162
- if e1.is_a?(RelatonBib::LocalityStack)
163
- m << extent1(e1.locality)
164
- else
165
- m.empty? and m << {}
166
- m[-1].merge!(extent1(Array(e1)))
159
+ when Relaton::Bib::Extent, Relaton::Bib::LocalityStack
160
+ if e.locality.any?
161
+ a = e.locality.each_with_object([]) do |e1, m|
162
+ if e1.is_a?(Relaton::Bib::LocalityStack)
163
+ m << extent1(e1.locality)
164
+ else
165
+ m.empty? and m << {}
166
+ m[-1].merge!(extent1(Array(e1)))
167
+ end
168
+ end
169
+ acc << a
170
+ else
171
+ Array(e.locality_stack).each do |stack|
172
+ a = stack.locality.each_with_object([{}]) do |e1, m|
173
+ m[-1].merge!(extent1(Array(e1)))
174
+ end
175
+ acc << a
167
176
  end
168
177
  end
169
- acc << a
170
- when RelatonBib::Locality
178
+ when Relaton::Bib::Locality
171
179
  acc << extent1(Array(e))
172
180
  end
173
181
  end
@@ -184,7 +192,7 @@ module Relaton
184
192
  end
185
193
 
186
194
  def status(doc)
187
- v = doc&.status&.stage&.value
195
+ v = doc&.status&.stage&.content
188
196
  #@i18n.get.dig("stage", v) || v
189
197
  end
190
198
  end
@@ -2,7 +2,7 @@ module Relaton
2
2
  module Render
3
3
  class Parse
4
4
  # filter applied across full list of auth_id
5
- def auth_id_filter(ids)
5
+ def auth_id_filter(ids = [])
6
6
  id_scope_filter(ids)
7
7
  end
8
8
 
@@ -44,12 +44,12 @@ module Relaton
44
44
 
45
45
  def authoritative_identifier(doc)
46
46
  out = []
47
- [auth_id_filter(doc.docidentifier), doc.docidentifier].each do |a|
47
+ [auth_id_filter(Array(doc.docidentifier)), Array(doc.docidentifier)].each do |a|
48
48
  out = authoritative_identifier_select(a)
49
49
  out.empty? or break
50
50
  end
51
51
  # prevent l10n of identifier contents
52
- out.map(&:id).map { |i| esc(i.strip) }
52
+ out.map(&:content).map { |i| esc(i.strip) }
53
53
  end
54
54
 
55
55
  def authoritative_identifier_select(idents)
@@ -70,10 +70,10 @@ module Relaton
70
70
  end
71
71
 
72
72
  def other_identifier(doc)
73
- doc.docidentifier.each_with_object([]) do |id, ret|
73
+ Array(doc.docidentifier).each_with_object([]) do |id, ret|
74
74
  type = id_type_norm(id)
75
75
  other_identifier_include.include? type or next
76
- ret << [type, id.id]
76
+ ret << [type, id.content]
77
77
  end
78
78
  end
79
79
 
@@ -82,10 +82,10 @@ module Relaton
82
82
  end
83
83
 
84
84
  def doi(doc)
85
- out = doc.docidentifier.each_with_object([]) do |id, ret|
85
+ out = Array(doc.docidentifier).each_with_object([]) do |id, ret|
86
86
  type = id.type&.sub(/^(DOI)\..*$/i, "\\1") or next
87
87
  type.casecmp("doi").zero? or next
88
- ret << id.id
88
+ ret << id.content
89
89
  end
90
90
  out.empty? ? nil : out.map { |i| esc(i.strip) }
91
91
  end
@@ -97,10 +97,10 @@ module Relaton
97
97
  end
98
98
 
99
99
  def biblio_tag(doc)
100
- ret = doc.docidentifier.detect do |id|
100
+ ret = Array(doc.docidentifier).detect do |id|
101
101
  id.scope&.downcase == "biblio-tag"
102
102
  end
103
- ret&.id
103
+ ret&.content
104
104
  end
105
105
 
106
106
  def uri(doc)
@@ -108,19 +108,19 @@ module Relaton
108
108
  %w(citation uri src).each do |t|
109
109
  uri = uri_type_select(doc, t) and break
110
110
  end
111
- uri ||= doc.link.detect do |u|
111
+ uri ||= Array(doc.source).detect do |u|
112
112
  u.language == @lang && !u.type&.casecmp("doi")&.zero?
113
113
  end
114
- uri ||= doc.link.detect { |u| !u.type&.casecmp("doi")&.zero? }
114
+ uri ||= Array(doc.source).detect { |u| !u.type&.casecmp("doi")&.zero? }
115
115
  uri or return nil
116
116
  uri.content.to_s.strip
117
117
  end
118
118
 
119
119
  def uri_type_select(doc, type)
120
- uri = doc.link.detect do |u|
120
+ uri = Array(doc.source).detect do |u|
121
121
  u.type&.downcase == type && u.language == @lang
122
122
  end and return uri
123
- uri = doc.link.detect { |u| u.type&.downcase == type } and return uri
123
+ uri = Array(doc.source).detect { |u| u.type&.downcase == type } and return uri
124
124
  nil
125
125
  end
126
126
  end
@@ -1,5 +1,5 @@
1
1
  module Relaton
2
2
  module Render
3
- VERSION = "1.0.5".freeze
3
+ VERSION = "1.1.0".freeze
4
4
  end
5
5
  end
@@ -36,7 +36,7 @@ Gem::Specification.new do |spec|
36
36
  spec.add_dependency "liquid", "~> 5"
37
37
  spec.add_dependency "metanorma-utils", "~> 2"
38
38
  spec.add_dependency "nokogiri"
39
- spec.add_dependency "relaton-bib", ">= 1.20.0"
39
+ spec.add_dependency "relaton-bib", ">= 2.0.0.pre.alpha.6", "< 3"
40
40
  spec.add_dependency "twitter_cldr"
41
41
  spec.add_dependency "tzinfo-data" # we need this for windows only
42
42
  # spec.metadata["rubygems_mfa_required"] = "true"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-render
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-03-30 00:00:00.000000000 Z
11
+ date: 2026-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -212,14 +212,20 @@ dependencies:
212
212
  requirements:
213
213
  - - ">="
214
214
  - !ruby/object:Gem::Version
215
- version: 1.20.0
215
+ version: 2.0.0.pre.alpha.6
216
+ - - "<"
217
+ - !ruby/object:Gem::Version
218
+ version: '3'
216
219
  type: :runtime
217
220
  prerelease: false
218
221
  version_requirements: !ruby/object:Gem::Requirement
219
222
  requirements:
220
223
  - - ">="
221
224
  - !ruby/object:Gem::Version
222
- version: 1.20.0
225
+ version: 2.0.0.pre.alpha.6
226
+ - - "<"
227
+ - !ruby/object:Gem::Version
228
+ version: '3'
223
229
  - !ruby/object:Gem::Dependency
224
230
  name: twitter_cldr
225
231
  requirement: !ruby/object:Gem::Requirement