relaton-render 0.9.1 → 0.9.3
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54bf3f59c3256133ee01beae991596ff8c6be10f44d23d06cc1b4e7c6b83341a
|
4
|
+
data.tar.gz: b187bf01f207fb03fe5ef351db816229417146dd4254d4a593ae211412b94596
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 698dc535088cec7578bc75f3f4811a5fd30e3300d205f41ae3abd5f3434db85efdb2231db8382a5aa17af9dedd9c0aaacab2572b90eaed518aec491b9806d6ab
|
7
|
+
data.tar.gz: 1671c424fce8b4642228eeddef8398675ac2c7a2fddf98e80301f3f0c6fa2c0fa76fe62278d022d6a3c144eb0aa91938db2e8e0690c4ef2baf01818dd088250e
|
data/.gitignore
ADDED
@@ -5,8 +5,9 @@ module Relaton
|
|
5
5
|
node.nil? and return node
|
6
6
|
node.content.is_a?(Array) and return node.content.map { |x| content(x) }
|
7
7
|
node.content.strip
|
8
|
-
|
9
|
-
#node.text? ?
|
8
|
+
.gsub("</title>", "").gsub("<title>", "")
|
9
|
+
# node.children.map { |n| n.text? ? n.content : n.to_xml }.join
|
10
|
+
# node.text? ? node.content.strip : node.to_xml.strip
|
10
11
|
end
|
11
12
|
|
12
13
|
def extract_orgname(org)
|
@@ -23,16 +24,19 @@ module Relaton
|
|
23
24
|
end
|
24
25
|
|
25
26
|
def given_and_middle_name(person)
|
26
|
-
forenames = person
|
27
|
-
|
28
|
-
|
27
|
+
forenames = forenames_parse(person)
|
28
|
+
initials = extract_initials(person)
|
29
|
+
forenames.empty? and initials.empty? and return [nil, nil, nil]
|
30
|
+
initials.empty? and initials = initials_from_forenames(forenames)
|
31
|
+
[forenames.first, forenames[1..-1], Array(initials)]
|
32
|
+
end
|
33
|
+
|
34
|
+
def extract_initials(person)
|
29
35
|
initials = content(person.name.initials)&.sub(/(.)\.?$/, "\\1.")
|
30
36
|
&.split /(?<=\.) /
|
31
37
|
initials ||= person.name.forename.map(&:initial)
|
32
38
|
.compact.map { |x| x.sub(/(.)\.?$/, "\\1.") }
|
33
|
-
|
34
|
-
initials.empty? and initials = forenames.map { |x| "#{x[0]}." }
|
35
|
-
[forenames.first, forenames[1..-1], Array(initials)]
|
39
|
+
initials
|
36
40
|
end
|
37
41
|
|
38
42
|
def forenames_parse(person)
|
@@ -51,6 +55,10 @@ module Relaton
|
|
51
55
|
.scan(/.+?\.(?=(?:$|\s|\p{Alpha}))/).map(&:strip)
|
52
56
|
end
|
53
57
|
|
58
|
+
def initials_from_forenames(forenames)
|
59
|
+
forenames.map(&:split).flatten.map { |x| "#{x[0]}." }
|
60
|
+
end
|
61
|
+
|
54
62
|
def extractname(contributor)
|
55
63
|
org = contributor.entity if contributor.entity
|
56
64
|
.is_a?(RelatonBib::Organization)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Relaton
|
2
2
|
module Render
|
3
3
|
module Template
|
4
|
-
module
|
4
|
+
module CustomFilters
|
5
5
|
def capitalize_first(words)
|
6
6
|
return nil if words.nil?
|
7
7
|
|
@@ -9,6 +9,33 @@ module Relaton
|
|
9
9
|
ret.first.capitalize! if ret.size.positive?
|
10
10
|
ret.join("_")
|
11
11
|
end
|
12
|
+
|
13
|
+
def selective_upcase(text)
|
14
|
+
return nil if text.nil?
|
15
|
+
|
16
|
+
ret = text.split(/(\+\+\+[^+]+?\+\+\+)/)
|
17
|
+
ret.map do |n|
|
18
|
+
if m = /^\+\+\+(.+)\+\+\+$/.match(n)
|
19
|
+
m[1]
|
20
|
+
else
|
21
|
+
n.upcase
|
22
|
+
end
|
23
|
+
end.join
|
24
|
+
end
|
25
|
+
|
26
|
+
def selective_tag(text, tag)
|
27
|
+
return nil if text.nil?
|
28
|
+
|
29
|
+
ret = text.split(/(\+\+\+[^+]+?\+\+\+)/)
|
30
|
+
ret.map do |n|
|
31
|
+
if m = /^\+\+\+(.+)\+\+\+$/.match(n)
|
32
|
+
m[1]
|
33
|
+
else
|
34
|
+
closetag = tag.sub(/^</, "</")
|
35
|
+
"#{tag}#{n}#{closetag}"
|
36
|
+
end
|
37
|
+
end.join
|
38
|
+
end
|
12
39
|
end
|
13
40
|
end
|
14
41
|
end
|
@@ -34,7 +34,7 @@ module Relaton
|
|
34
34
|
def initialize(opt = {})
|
35
35
|
@htmlentities = HTMLEntities.new
|
36
36
|
@templatecache = CacheManager.instance
|
37
|
-
|
37
|
+
@liquid_env = create_liquid_environment
|
38
38
|
parse_options(opt)
|
39
39
|
end
|
40
40
|
|
@@ -51,9 +51,10 @@ module Relaton
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
def
|
55
|
-
::Liquid::
|
56
|
-
|
54
|
+
def create_liquid_environment
|
55
|
+
env = ::Liquid::Environment.new
|
56
|
+
env.register_filter(::Relaton::Render::Template::CustomFilters)
|
57
|
+
env
|
57
58
|
end
|
58
59
|
|
59
60
|
# denote start and end of field,
|
@@ -81,7 +82,7 @@ module Relaton
|
|
81
82
|
@templatecache.mutex.synchronize do
|
82
83
|
unless t = @templatecache.retrieve(template)
|
83
84
|
t = ::Liquid::Template
|
84
|
-
.parse(add_field_delim_to_template(template))
|
85
|
+
.parse(add_field_delim_to_template(template), environment: @liquid_env)
|
85
86
|
@templatecache.store(template, t)
|
86
87
|
end
|
87
88
|
end
|
@@ -187,7 +188,7 @@ module Relaton
|
|
187
188
|
end
|
188
189
|
|
189
190
|
def template_select_etal(names)
|
190
|
-
if @etal_count && names[:surname].size
|
191
|
+
if @etal_count && names[:surname].size > @etal_count
|
191
192
|
expand_nametemplate(@template_raw[:etal], @etal_display)
|
192
193
|
else
|
193
194
|
expand_nametemplate(@template_raw[:more], names[:surname].size)
|
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: 0.9.
|
4
|
+
version: 0.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -215,6 +215,7 @@ extra_rdoc_files: []
|
|
215
215
|
files:
|
216
216
|
- ".github/workflows/rake.yml"
|
217
217
|
- ".github/workflows/release.yml"
|
218
|
+
- ".gitignore"
|
218
219
|
- ".hound.yml"
|
219
220
|
- ".rubocop.yml"
|
220
221
|
- Gemfile
|
@@ -270,7 +271,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
270
271
|
- !ruby/object:Gem::Version
|
271
272
|
version: '0'
|
272
273
|
requirements: []
|
273
|
-
rubygems_version: 3.
|
274
|
+
rubygems_version: 3.5.22
|
274
275
|
signing_key:
|
275
276
|
specification_version: 4
|
276
277
|
summary: Rendering of ISO 690 XML
|