relaton-render 0.3.2 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2495f2c083785da7e91cb8a512af90c47a1b47cc3e1f3fc2749453008e50255b
4
- data.tar.gz: 73ec9b1aad3fa6dea3473a842f3cc5b91a99beb978fb32481b286a2c2fad5b04
3
+ metadata.gz: ba6bd04a097e0a57a1b55548d1775f54297d707271da779330c679e1a1e3fc8f
4
+ data.tar.gz: 39115748cd3ffea7793a2d662c22c26a4219baa4969e42b048aec0bc7c8a157f
5
5
  SHA512:
6
- metadata.gz: 7fe97369899d14717f7f7cefbdd5fa5f0cf3b297005e0a30b7172b4a7f001f1586dc9088c90a6025733b680cf09041b3adf5206dff429e4ad712b2a35208a775
7
- data.tar.gz: 7f3e4c19809cbfa730fab9aa844891a879844279e6a95808f77541edce3e9d1b5986d3d20e5b9a6b618e984dfb9ddcdfa399181e4cc191cf1058dc9773723b00
6
+ metadata.gz: ce06415c2964c88e26eea1db635bca0928c381e40f18f395a8a227ea848d65d0c025decba2df2141ff411e542d244724146834744024bd24b2b8e9e7a4eb0a51
7
+ data.tar.gz: b0e94d253c820e8afb429ee8512de473c7a1a1f536ec6643efc7a7411bb46fba29ec104bcff7e764f4cd9cf2661023374521cf1fc5907b97ca9e564cf1e5bd52
data/README.adoc CHANGED
@@ -35,8 +35,7 @@ The parameters are:
35
35
  `journaltemplate`:: template for rendering journals in article citations
36
36
  `extenttemplate`:: templates for rendering extents
37
37
  `sizetemplate`:: templates for rendering sizes
38
- `edition_number`:: override formatting of edition number
39
- `edition`:: override formatting of edition
38
+ `edition_ordinal`:: override formatting of edition with ordinal
40
39
  `date`:: default date format (from Twitter CLDR)
41
40
 
42
41
  == Configuration
@@ -133,6 +132,7 @@ The Liquid template surrounds each field by preceding and following punctuation.
133
132
  * If fields are not space-delimited, this is indicated by inserting `|`. So `{{ title }}|{{ medium}}` is two fields, rendered with no space separation.
134
133
  * If the field is empty, its surrounding markup is also removed. So if there is no medium, then `[{{medium}}]` is not rendered, and the brackets will be stripped.
135
134
  * Underscore is treated as space, attaching to the preceding or following field. So `,_{{ edition }}_{{ labels['edition'] }}` is treated as the one field.
135
+ * Underscore is escaped by \. So `<span_class="std\_note">` maps to `<span class="std_note">`.
136
136
  * If punctuation is space delimited, it is inserted regardless of preceding content. So `{{ creatornames }} ({{date}}) .` will insert the full stop whether or not the date is present.
137
137
  * Space between punctuation and before punctuation is automatically removed.
138
138
 
@@ -8,8 +8,10 @@ date:
8
8
  month_year: yMMMM
9
9
  day_month_year: to_long_s
10
10
  date_time: to_long_s
11
- edition_number: ["OrdinalRules", "digits-ordinal"]
12
- edition: "الطبعة؜ %؜"
11
+ ordinal_keys: []
12
+ OrdinalRules: digits-ordinal
13
+ edition_ordinal: "الطبعة؜ %Ordinal"
14
+ edition: الطبعة؜ ؜
13
15
  draft: "مشروع؜ %؜"
14
16
  editor:
15
17
  sg: محرر
@@ -28,4 +30,7 @@ size:
28
30
  volume:
29
31
  sg: "المجلد %"
30
32
  pl: "المجلدين %"
33
+ inflection:
34
+ الطبعة؜:
35
+ gender: f
31
36
 
@@ -9,7 +9,9 @@ date:
9
9
  day_month_year: to_long_s
10
10
  date_time: to_long_s
11
11
  draft: "Entwurf %"
12
- edition: "% Aufl."
12
+ edition_ordinal: "% Aufl."
13
+ ordinal_keys: []
14
+ edition: Auflage
13
15
  editor:
14
16
  sg: Hrsg.
15
17
  pl: Hrsg.
@@ -27,3 +29,7 @@ size:
27
29
  volume:
28
30
  sg: "% Bd."
29
31
  pl: "% Bde."
32
+ inflection:
33
+ Auflage:
34
+ gender: f
35
+
@@ -8,8 +8,10 @@ date:
8
8
  month_year: yMMMM
9
9
  day_month_year: to_long_s
10
10
  date_time: to_long_s
11
- edition_number: ["OrdinalRules", "digits-ordinal"]
12
- edition: "% edition"
11
+ ordinal_keys: []
12
+ OrdinalRules: digits-ordinal
13
+ edition: edition
14
+ edition_ordinal: "%Ordinal edition"
13
15
  draft: "draft %"
14
16
  editor:
15
17
  sg: ed.
@@ -8,8 +8,12 @@ date:
8
8
  month_year: yMMMM
9
9
  day_month_year: to_long_s
10
10
  date_time: to_long_s
11
- edition_number: ["OrdinalRules", "digits-ordinal-feminine"]
12
- edition: "% ed."
11
+ ordinal_keys: [gender]
12
+ OrdinalRules:
13
+ m: digits-ordinal-masculine
14
+ f: digits-ordinal-feminine
15
+ edition_ordinal: "%Ordinal ed."
16
+ edition: edición
13
17
  draft: "borrador %"
14
18
  editor:
15
19
  sg: ed.
@@ -28,3 +32,7 @@ size:
28
32
  volume:
29
33
  sg: "% vol."
30
34
  pl: "% vols."
35
+ inflection:
36
+ edición:
37
+ gender: f
38
+
@@ -8,8 +8,14 @@ date:
8
8
  month_year: yMMMM
9
9
  day_month_year: to_long_s
10
10
  date_time: to_long_s
11
- edition_number: ["OrdinalRules", "digits-ordinal-feminine"]
12
- edition: "% édition"
11
+ ordinal_keys: [gender,number]
12
+ OrdinalRules:
13
+ m.sg: digits-ordinal-masculine
14
+ f.sg: digits-ordinal-feminine
15
+ m.pl: digits-ordinal-masculine-plural
16
+ f.pl: digits-ordinal-feminine-plural
17
+ edition_ordinal: "%Ordinal édition"
18
+ edition: édition
13
19
  draft: "brouillon %"
14
20
  editor:
15
21
  sg: éd.
@@ -28,3 +34,7 @@ size:
28
34
  volume:
29
35
  sg: "% vol."
30
36
  pl: "% vol."
37
+ inflection:
38
+ édition:
39
+ gender: f
40
+
@@ -8,8 +8,16 @@ date:
8
8
  month_year: yMMMM
9
9
  day_month_year: to_long_s
10
10
  date_time: to_long_s
11
- edition_number: ["SpelloutRules", "spellout-ordinal-neuter"]
12
- edition: "% издание"
11
+ ordinal_keys: [gender,number]
12
+ SpelloutRules:
13
+ m.sg: spellout-ordinal-masculine
14
+ f.sg: spellout-ordinal-feminine
15
+ n.sg: spellout-ordinal-neuter
16
+ m.pl: spellout-ordinal-plural
17
+ f.pl: spellout-ordinal-plural
18
+ n.pl: spellout-ordinal-plural
19
+ edition_ordinal: "%Spellout издание"
20
+ edition: издание
13
21
  draft: "проект %"
14
22
  editor:
15
23
  sg: изд.
@@ -28,4 +36,7 @@ size:
28
36
  volume:
29
37
  sg: "% т."
30
38
  pl: "% тт."
39
+ inflection:
40
+ издание:
41
+ gender: n
31
42
 
@@ -8,8 +8,10 @@ date:
8
8
  month_year: yMMMM
9
9
  day_month_year: to_long_s
10
10
  date_time: to_long_s
11
- edition_number: ["OrdinalRules", "digits-ordinal"]
12
- edition: "第%版"
11
+ ordinal_keys: []
12
+ OrdinalRules: digits-ordinal
13
+ edition_ordinal: "第%Ordinal版"
14
+ edition: 版
13
15
  draft: "草案%"
14
16
  editor:
15
17
  sg: 编辑
@@ -24,6 +24,7 @@ module Relaton
24
24
  .each do |k|
25
25
  hash[k[0]] = nameformat(hash[k[1]])
26
26
  end
27
+ hash[:publisher_abbrev] = hash[:publisher_abbrev_raw]&.join(", ")
27
28
  end
28
29
 
29
30
  def role_fields_format(hash)
@@ -97,10 +98,20 @@ module Relaton
97
98
  def editionformat(edn)
98
99
  return edn unless /^\d+$/.match?(edn)
99
100
 
100
- num = edn
101
- @r.edition_number and num = edn.to_i.localize(tw_cldr_lang)
102
- .to_rbnf_s(*@r.edition_number)
103
- @r.edition.sub(/%/, num)
101
+ num = edition_translate1(edn.to_i)
102
+ @r.edition_ordinal.sub(/%(Spellout|Ordinal)?/, num)
103
+ end
104
+
105
+ def edition_translate1(num)
106
+ ruleset = case @r.i18n.edition_ordinal
107
+ when /%Spellout/ then "SpelloutRules"
108
+ when /%Ordinal/ then "OrdinalRules"
109
+ else "Digit"
110
+ end
111
+ ruleset == "Digit" and return num.to_s
112
+ ed = HTMLEntities.new.decode(@r.i18n.edition)
113
+ @r.i18n.inflect_ordinal(num, @r.i18n.inflection&.dig(ed) || {},
114
+ ruleset)
104
115
  end
105
116
 
106
117
  def draftformat(num, _hash)
@@ -10,7 +10,7 @@ module Relaton
10
10
  class General
11
11
  attr_reader :template, :journaltemplate, :seriestemplate, :nametemplate,
12
12
  :extenttemplate, :sizetemplate, :lang, :script, :i18n,
13
- :edition, :edition_number, :date
13
+ :edition, :edition_ordinal, :date
14
14
 
15
15
  def initialize(opt = {})
16
16
  options = read_config.merge(Utils::string_keys(opt))
@@ -53,7 +53,7 @@ module Relaton
53
53
  @lang = opt["language"]
54
54
  @script = opt["script"]
55
55
  @i18n = i18n_klass(opt["language"], opt["script"])
56
- @edition_number = opt["edition_number"] || @i18n.edition_number
56
+ @edition_ordinal = opt["edition_ordinal"] || @i18n.edition_ordinal
57
57
  @edition = opt["edition"] || @i18n.edition
58
58
  @date = opt["date"] || @i18n.date
59
59
  end
@@ -29,6 +29,7 @@ module Relaton
29
29
  def simple_or_host_xml2hash(doc, host)
30
30
  { edition_raw: edition(doc, host), medium_raw: medium(doc, host),
31
31
  place_raw: place(doc, host), publisher_raw: publisher(doc, host),
32
+ publisher_abbrev_raw: publisher_abbrev(doc, host),
32
33
  distributor_raw: distributor(doc, host), draft_raw: draft(doc, host),
33
34
  access_location: access_location(doc, host),
34
35
  date: date(doc, host), date_updated: date_updated(doc, host),
@@ -48,17 +48,20 @@ module Relaton
48
48
  [cr.map { |x| extractname(x) }, contributor_role(cr)]
49
49
  end
50
50
 
51
+ def creatornames_roles_allowed
52
+ %w(author performer adapter translator editor publisher distributor)
53
+ end
54
+
51
55
  def creatornames1(doc)
52
56
  cr = []
53
57
  return [] if doc.nil?
54
58
 
55
- %w(author performer adapter translator editor publisher distributor)
56
- .each do |r|
57
- add = pick_contributor(doc, r)
58
- next if add.nil?
59
+ creatornames_roles_allowed.each do |r|
60
+ add = pick_contributor(doc, r)
61
+ next if add.nil?
59
62
 
60
- cr = add and break
61
- end
63
+ cr = add and break
64
+ end
62
65
  cr.nil? and cr = doc.contributor
63
66
  cr
64
67
  end
@@ -100,6 +103,27 @@ module Relaton
100
103
  host and ret ||= host.date.detect { |x| x.type == "accessed" }
101
104
  datepick(ret)
102
105
  end
106
+
107
+ def publisher(doc, host)
108
+ x = pick_contributor(doc, "publisher")
109
+ host and x ||= pick_contributor(host, "publisher")
110
+ x.nil? and return nil
111
+ x.map { |c| extractname(c) }
112
+ end
113
+
114
+ def publisher_abbrev(doc, host)
115
+ x = pick_contributor(doc, "publisher")
116
+ host and x ||= pick_contributor(host, "publisher")
117
+ x.nil? and return nil
118
+ x.map { |c| c.entity.abbreviation&.content }
119
+ end
120
+
121
+ def distributor(doc, host)
122
+ x = pick_contributor(doc, "distributor")
123
+ host and x ||= pick_contributor(host, "distributor")
124
+ x.nil? and return nil
125
+ x.map { |c| extractname(c) }
126
+ end
103
127
  end
104
128
  end
105
129
  end
@@ -43,20 +43,6 @@ module Relaton
43
43
  x.map(&:name)
44
44
  end
45
45
 
46
- def publisher(doc, host)
47
- x = pick_contributor(doc, "publisher")
48
- host and x ||= pick_contributor(host, "publisher")
49
- x.nil? and return nil
50
- x.map { |c| extractname(c) }
51
- end
52
-
53
- def distributor(doc, host)
54
- x = pick_contributor(doc, "distributor")
55
- host and x ||= pick_contributor(host, "distributor")
56
- x.nil? and return nil
57
- x.map { |c| extractname(c) }
58
- end
59
-
60
46
  def series(doc)
61
47
  doc.series.detect { |s| s.type == "main" } ||
62
48
  doc.series.detect { |s| s.type.nil? } ||
@@ -103,7 +89,7 @@ module Relaton
103
89
 
104
90
  def uri(doc)
105
91
  uri = nil
106
- %i(doi uri src).each do |t|
92
+ %w(doi uri src).each do |t|
107
93
  uri = doc.link.detect { |u| u.type == t } and break
108
94
  end
109
95
  uri ||= doc.link.first
@@ -79,7 +79,9 @@ module Relaton
79
79
  .gsub(/(:\s+)(&\s)/, "\\2")
80
80
  .gsub(/\s+([,.:;)])/, "\\1")
81
81
  .sub(/^\s*[,.:;]\s*/, "")
82
- .gsub(/_/, " ")
82
+ .sub(/[,:;]\s*$/, "")
83
+ .gsub(/(?<!\\)_/, " ")
84
+ .gsub(/\\_/, "_")
83
85
  .gsub(/#{NON_SPACING_DELIM}/o, "").gsub(/\s+/, " ")
84
86
  end
85
87
 
@@ -133,9 +135,9 @@ module Relaton
133
135
  end
134
136
 
135
137
  def template_select_etal(names)
136
- if @etal_count && names.size >= @etal_count
138
+ if @etal_count && names[:surname].size >= @etal_count
137
139
  @template[:etal]
138
- else expand_nametemplate(@template_raw[:more], names.size)
140
+ else expand_nametemplate(@template_raw[:more], names[:surname].size)
139
141
  end
140
142
  end
141
143
 
@@ -1,5 +1,5 @@
1
1
  module Relaton
2
2
  module Render
3
- VERSION = "0.3.2".freeze
3
+ VERSION = "0.3.5".freeze
4
4
  end
5
5
  end
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.3.2
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-04-22 00:00:00.000000000 Z
11
+ date: 2022-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler