relaton-render 0.1.0 → 0.3.1

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: 900cfb8e591fbbd83ee48c2dfa762a317a15c590fb89844b3ce7a759125d4f94
4
- data.tar.gz: 29c15ba8cfe1e2dcfafc8d6a4d9985ed298c4515d4c734e3505dfcca9cb11189
3
+ metadata.gz: 077a906da97ebd8417a856d6c5b73ae81cd3c5457ba8383094e752fd5c585bc0
4
+ data.tar.gz: 85c8446d1a644ba1b4cd28cfae099dddaa31867a376a9e484d387387ac7d0c7c
5
5
  SHA512:
6
- metadata.gz: ebd7be4d34144997dcee8593266b75eefca1781341b4f081df290a9df64cbb7d665985c1bd0807c1036b190f68d6877b2bf822281bdc6e7c3a332fce349ac612
7
- data.tar.gz: 8392d3b4d8c836b74cbf7a05435f55b274f24ae1004b247151481a34d86c104818926f3452c68f776a0adb521e9404b908f0d0fde25494014958bfd2c28005ac
6
+ metadata.gz: 3fb5003aaefb0915a9eebd6d021bdd20e92dcf2c2eb015aea68c102928f1b8702841624d356d14dc00912752df3a50f7e98222d2e9a84cda819d1ed755610aad
7
+ data.tar.gz: 5cd715d1b65f71d1e4126b8443dbcb99a4bf078145cd3bfaa9e9fff5c67bac96b9d6b9e97e55b995c6f63764997f1e703bc65e366fde5b1d2c376f4e7af384bf
data/README.adoc CHANGED
@@ -1,8 +1,8 @@
1
1
  = Relaton Render
2
2
 
3
- image:https://img.shields.io/gem/v/iso690render.svg["Gem Version", link="https://rubygems.org/gems/iso690render"]
4
- image:https://github.com/metanorma/iso690render/workflows/rake/badge.svg["Build Status", link="https://github.com/metanorma/iso690render/actions?workflow=rake"]
5
- image:https://codeclimate.com/github/metanorma/iso690render/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/metanorma/iso690render"]
3
+ image:https://img.shields.io/gem/v/relaton-render.svg["Gem Version", link="https://rubygems.org/gems/relaton-render"]
4
+ image:https://github.com/metanorma/relaton-render/workflows/rake/badge.svg["Build Status", link="https://github.com/metanorma/relaton-render/actions?workflow=rake"]
5
+ image:https://codeclimate.com/github/metanorma/relaton-render/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/metanorma/relaton-render"]
6
6
 
7
7
  Gem that takes a https://github.com/relaton/relaton[Relaton] bibliographic description and
8
8
  a configuration, and generates a https://www.metanorma.org[Metanorma] XML rendering of that description.
@@ -16,6 +16,8 @@ input = "<bibitem type='...'>....</bibitem>"
16
16
  Relaton::Render::General.new(template: ..., nametemplate: ..., seriestemplate: ..., language: "en", script: "Latn").render(input)
17
17
  ----
18
18
 
19
+ The gem processes either Relaton XML, or native Relaton classes.
20
+
19
21
  The gem is intended to be inherited from by Metanorma flavours, which may specialise it with their own
20
22
  code. The templates are however intended to determine much of the rendering.
21
23
 
@@ -32,6 +34,7 @@ The parameters are:
32
34
  `seriestemplate`:: template for rendering series
33
35
  `journaltemplate`:: template for rendering journals in article citations
34
36
  `extenttemplate`:: templates for rendering extents
37
+ `sizetemplate`:: templates for rendering sizes
35
38
  `edition_number`:: override formatting of edition number
36
39
  `edition`:: override formatting of edition
37
40
  `date`:: default date format (from Twitter CLDR)
@@ -120,6 +123,10 @@ drawn from the bibliographic item:
120
123
 
121
124
  Many fields are populated either by the description of the bibliographic item itself, or by the description of the item containing it (the _host_ item: `./relation[@type = 'includedIn']/bibitem`). For example, in a paper included in an edited volume, the edition will typically be given for the editor volume, rather than for the paper. Those fields are indicated by "Can come from host" in the table.
122
125
 
126
+ The Liquid templates use the filters defined in Liquid, such as `upcase`. We have defined some custom filters:
127
+
128
+ * `capitalize_first` capitalises only the first word in a string, and does not lowercase other words in the string. So "third edition" becomes "Third edition", but "3. Aufl." does not become "3. aufl."
129
+
123
130
  The Liquid template surrounds each field by preceding and following punctuation.
124
131
 
125
132
  * Fields are space-delimited. So `<em>{{ title }}</em> [{{medium}}]` are two separate fields.
@@ -152,7 +159,7 @@ draws on the following fields drawn from the bibliographic item:
152
159
  |===
153
160
  | Field | Relaton XPath | Multiple | Note
154
161
 
155
- | surname[0] | ./contributor[1]/person/name/surname \| ./contributor[1]/person/name/completename \| ./contributor[1]/organization/name | | i.e. surname is the name default
162
+ | surname[0] | ./contributor[1]/person/name/surname \| ./contributor[1]/person/name/completename | | i.e. surname is the name default
156
163
  | surname[1] | ./contributor[2]/name/surname | |
157
164
  | surname[2] | ./contributor[3]/name/surname | |
158
165
  | initials[0] | ./contributor[1]/name/initial | | If not supplied, the first letter of each given name is used instead
@@ -161,6 +168,8 @@ draws on the following fields drawn from the bibliographic item:
161
168
  | given[1] | ./contributor[2]/name/forename[1] | |
162
169
  | middle[0] | ./contributor[1]/name/forename[not(first())] | Y |
163
170
  | middle[1] | ./contributor[2]/name/forename[not(first())] | Y |
171
+ | nonpersonal[0] |./contributor[1]/organization/name | Y |
172
+ | nonpersonal[1] |./contributor[2]/organization/name | Y |
164
173
  |===
165
174
 
166
175
  There are at least three distinct `nametemplate` instances that need to be provided, one for a single contributor (`one:`), one for two contributors (`two:`), one for three or more (`more:`), and optionally one for "et al." (`etal:`). The number of contributors for which "et al." starts being used is indicated by `etal_count`.
@@ -168,10 +177,10 @@ There are at least three distinct `nametemplate` instances that need to be provi
168
177
  For example:
169
178
  ....
170
179
  {
171
- one: "{{ surname[0] }}, {{ given[0] }} {{ middle[0] | slice : 0 }}",
172
- two: "{{ surname[0] }}, {{ given[0] }} {{ middle[0] | slice : 0 }} &amp; {{ given[1] }} {{ middle[1] | slice : 0 }} {{ surname[1] }}",
173
- more: "{{ surname[0] }}, {{ given[0] }} {{ middle[0] | slice : 0 }}, {{ given[1] }} {{ middle[1] | slice : 0 }} {{ surname[1] }} &amp; {{ given[2] }} {{ middle[2] | slice : 0 }} {{ surname[2] }}",
174
- etal: "{{ surname[0] }}, {{ given[0] }} {{ middle[0] | slice : 0 }}, {{ given[1] }} {{ middle[1] | slice : 0 }} {{ surname[1] }} <em>et al.</em>",
180
+ one: "{% if nonpersonal[0] %}{{ nonpersonal[0] }}{% else %}{{ surname[0] }}, {{ given[0] }} {{ middle[0] | slice : 0 }}{% endif %}",
181
+ two: "{% if nonpersonal[0] %}{{ nonpersonal[0] }}{% else %}{{ surname[0] }}, {{ given[0] }} {{ middle[0] | slice : 0 }}{% endif %} &amp; {% if nonpersonal[1] %}{{ nonpersonal[1] }}{% else %}{{ given[1] }} {{ middle[1] | slice : 0 }} {{ surname[1] }}{% endif %}",
182
+ more: "{% if nonpersonal[0] %}{{ nonpersonal[0] }}{% else %}{{ surname[0] }}, {{ given[0] }} {{ middle[0] | slice : 0 }}{% endif %}, {% if nonpersonal[1] %}{{ nonpersonal[1] }}{% else %}{{ given[1] }} {{ middle[1] | slice : 0 }} {{ surname[1] }}{% endif %} &amp; {% if nonpersonal[2] %}{{ nonpersonal[2] }}{% else %}{{ given[2] }} {{ middle[2] | slice : 0 }} {{ surname[2] }}{% endif %}",
183
+ etal: "{% if nonpersonal[0] %}{{ nonpersonal[0] }}{% else %}{{ surname[0] }}, {{ given[0] }} {{ middle[0] | slice : 0 }}{% endif %}, {% if nonpersonal[1] %}{{ nonpersonal[1] }}{% else %}{{ given[1] }} {{ middle[1] | slice : 0 }} {{ surname[1] }}{% endif %} <em>et al.</em>",
175
184
  etal_count: 6
176
185
  }
177
186
  ....
@@ -209,7 +218,7 @@ A common template that drops those labels is:
209
218
 
210
219
  === Extent template
211
220
 
212
- The extent of a reference can be expressed differently depending on the type of bibliographic item. For example, the extent of a book is its page count, and is typically expressed as something like _59 pp._ On the other hand, the extent of an article is expressed as _pp. 9–20_, or just _9–20_.
221
+ The extent of a bibliographic item may be expressed differently depending on the type of bibliographic item. For example, the extent of a book chapter may be expressed as _pp. 9–20_, while the extent of an article may be expressed as just _9–20_.
213
222
 
214
223
  To capture this, a separate template is supplied under `extenttemplate` for each bibliographic item type. For those types where none is supplied, the template given for `misc` is used as the default.
215
224
 
@@ -217,25 +226,61 @@ The template draws on the defined types of locality of extents; the most common
217
226
 
218
227
  ....
219
228
  {
220
- book: "{{ volume }}_{{ label['extent']['volume'] }}, {{ page }}_{{ label['extent']['page'] }}"
221
- inbook: "{{ volume }}: {{ page }}"
222
- misc: "{{ label['extent']['volume'] }}_{{ volume }}, {{ label['extent']['page'] }}_{{ page }}"
229
+ article: "{{ volume_raw }}: {{ page_raw }}"
230
+ misc: "{{ volume }}, {{ page }}"
231
+ }
232
+ ....
233
+
234
+ The internationalisation files define a singular and a plural version of the locality types, under `labels['extent']`.
235
+
236
+ * The plural label is always used if the extent is a range (with a `<from>` and `<to>`).
237
+ * The singular label is used if the extent is not a range (_pp. 2–4_ vs. _p. 3_).
238
+ * The internationalisation files include a slot where the number or number range is inserted, indicated by `%`, since this varies by language. (For instance, English has `pp. %`, whereas Chinese has `第%页`.)
239
+ * The number of the volume or page, without accompanying labels, is given in `volume_raw` and `page_raw`.
240
+
241
+ === Size template
242
+
243
+ The size of a bibliographic item is distinct from the extent: the size is how large the item is (e.g. how many pages are in the book), whereas the extent is how much of the host item the item covers (e.g. which pages of the book are in the current chapter.) They can be displayed quite differently from extent; for example, while extent pages is given in English as _pp. 9–20_ or _p. 3_, size pages is given as _3 pp._.
244
+
245
+ To capture this, a separate template is supplied under `sizetemplate` for each bibliographic item type. Again, for those types where none is supplied, the template given for `misc` is used as the default.
246
+
247
+ The template draws on the defined types of locality of extents; the following are currently recognised:
248
+
249
+ |===
250
+ | Field | Relaton XPath | Note
251
+
252
+ | volume | ./medium/size[@type = 'volume'] | With internationalisation of label
253
+ | volume_raw | ./medium/size[@type = 'volume'] |
254
+ | page | ./medium/size[@type = 'page'] | With internationalisation of label
255
+ | page_raw | ./medium/size[@type = 'page'] |
256
+ | data | ./medium/size[@type = 'data'] | Unit of size is included in value
257
+ | duration | ./medium/size[@type = 'time'] | Expressed in ISO 8601 duration
258
+ |===
259
+
260
+
261
+ Locality types are the fields used in the Liquid templates; for example:
262
+
263
+ ....
264
+ {
265
+ dataset: "{{ data }}"
266
+ misc: "{{ volume }}, {{ page }}, {{ data }}, {{ duration }}"
223
267
  }
224
268
  ....
225
269
 
226
- The internationalisation files define a singular and a plural version of the locality types, under `labels['extent']`
270
+ The internationalisation files define a singular and a plural version of the locality types, under `labels['size']`.
227
271
 
228
- * The plural is always used if the extent is a range (with a `<from>` and `<to>`).
229
- * In a host type of bibliographic item, the extent is singular only if the value is `1`, else it is plural (_1 p._, _2 pp._)
230
- * In an included item (`inbook`, `incollection`, `inproceedings`, `article`, or any item with an `includedIn` relation),
231
- the singular is used if the extent is not a range (_pp. 2–4_ vs. _p. 3_)..
272
+ * The plural label is always used if the extent is a range (with a `<from>` and `<to>`).
273
+ * The label is singular only if the value is `1`, else it is plural (_1 p._, _2 pp._)
274
+ * Again, the internationalisation files include a slot where the number or number range is inserted, since this varies by language.
275
+ * The number of volumes or pages, without accompanying labels, is given in `volume_raw` and `page_raw`.
276
+ * Multiple spans of the same type are joined by `+`; e.g. _xlii + 76 pp._.
232
277
 
233
278
  === Other
234
279
 
235
280
  In addition, the configuration includes different configuration options for rendering:
236
281
 
237
282
  The internationalisation file sets the following variables, which can be overridden in configuration parameters:
238
- `edition_number`:: has following values corresponding to the rule-based number rules defined in https://github.com/twitter/twitter-cldr-rb[Twitter CLDR]
239
- for a language. For example, English _4th_ is defined as `["OrdinalRules", "digits-ordinal"]`, because under twitter-cldr, `4th` is generated as `4.localize(:en).to_rbnf_s("OrdinalRules", "digits-ordinal")`.
283
+ `edition_number`:: has following values corresponding to the rule-based number rules defined in https://github.com/twitter/twitter-cldr-rb[Twitter CLDR].
284
+ for a language. For example, English _4th_ is defined as `["OrdinalRules", "digits-ordinal"]`, because under twitter-cldr, `4th` is generated as `4.localize(:en).to_rbnf_s("OrdinalRules", "digits-ordinal")`. If missing, the raw number is given.
240
285
  `edition`:: is the localised expression for edition, with the edition number given as %. So _4th ed.` is generated with `edition` as `% ed.`.
241
286
  `date`:: date format default, taken from https://github.com/twitter/twitter-cldr-rb[Twitter CLDR]: `to_full_s`, `to_long_s`, `to_medium_s`, `to_short_s`, or one of the `to_additional_s` formats. One value is given for each of "month_year", "day_month_year", and "date_time"; e.g. `{ month_year: to_long_s, day_month_year: to_long_s, date_time: to_long_s }`.
data/lib/isodoc/i18n.rb CHANGED
@@ -2,7 +2,7 @@ require "yaml"
2
2
  require "isodoc-i18n"
3
3
 
4
4
  module IsoDoc
5
- class I18n
5
+ class RelatonRenderI18n < I18n
6
6
  def load_yaml1(lang, script)
7
7
  case lang
8
8
  when "en", "fr", "ru", "de", "es", "ar"
@@ -11,8 +11,7 @@ module IsoDoc
11
11
  if script == "Hans" then load_yaml2("zh-Hans")
12
12
  else load_yaml2("en")
13
13
  end
14
- else
15
- load_yaml2("en")
14
+ else load_yaml2("en")
16
15
  end
17
16
  end
18
17
 
@@ -20,5 +19,15 @@ module IsoDoc
20
19
  YAML.load_file(File.join(File.dirname(__FILE__),
21
20
  "../isodoc-yaml/i18n-#{str}.yaml"))
22
21
  end
22
+
23
+ # force bidi for all i18n strings in Arabic,
24
+ # because of the potential for script mixing
25
+ def cleanup_entities(hash, is_xml: true)
26
+ ret = super
27
+ if @lang == "ar" && /%/.match?(ret)
28
+ ret = "&#x61c;#{ret}&#x61c;"
29
+ end
30
+ ret
31
+ end
23
32
  end
24
33
  end
@@ -1,2 +1,31 @@
1
1
  in: في
2
2
  at: في
3
+ and: و
4
+ updated: محدث
5
+ viewed: ينظر
6
+ version: الإصدار
7
+ date:
8
+ month_year: yMMMM
9
+ day_month_year: to_long_s
10
+ date_time: to_long_s
11
+ edition_number: ["OrdinalRules", "digits-ordinal"]
12
+ edition: "الطبعة؜ %؜"
13
+ draft: "مشروع؜ %؜"
14
+ editor:
15
+ sg: محرر
16
+ pl: محرران
17
+ extent:
18
+ page:
19
+ sg: "% ص"
20
+ pl: "% ص"
21
+ volume:
22
+ sg: "% المجلد"
23
+ pl: "% المجلدين"
24
+ size:
25
+ page:
26
+ sg: "ص؜ %"
27
+ pl: "ص؜ %"
28
+ volume:
29
+ sg: "المجلد %"
30
+ pl: "المجلدين %"
31
+
@@ -1,2 +1,29 @@
1
1
  in: in
2
2
  at: bei
3
+ and: und
4
+ updated: aktualisiert
5
+ viewed: angesehen
6
+ version: Version
7
+ date:
8
+ month_year: yMMMM
9
+ day_month_year: to_long_s
10
+ date_time: to_long_s
11
+ draft: "Entwurf %"
12
+ edition: "% Aufl."
13
+ editor:
14
+ sg: Hrsg.
15
+ pl: Hrsg.
16
+ extent:
17
+ page:
18
+ sg: "S. %"
19
+ pl: "S. %"
20
+ volume:
21
+ sg: "Bd. %"
22
+ pl: "Bde. %"
23
+ size:
24
+ page:
25
+ sg: "% S."
26
+ pl: "% S."
27
+ volume:
28
+ sg: "% Bd."
29
+ pl: "% Bde."
@@ -5,18 +5,27 @@ updated: updated
5
5
  viewed: viewed
6
6
  version: version
7
7
  date:
8
- month_year: to_long_s
8
+ month_year: yMMMM
9
9
  day_month_year: to_long_s
10
10
  date_time: to_long_s
11
11
  edition_number: ["OrdinalRules", "digits-ordinal"]
12
12
  edition: "% edition"
13
+ draft: "draft %"
13
14
  editor:
14
15
  sg: ed.
15
16
  pl: eds.
16
17
  extent:
17
18
  page:
18
- sg: p.
19
- pl: pp.
19
+ sg: "p. %"
20
+ pl: "pp. %"
20
21
  volume:
21
- sg: vol.
22
- pl: vols.
22
+ sg: "vol. %"
23
+ pl: "vols. %"
24
+ size:
25
+ page:
26
+ sg: "% p."
27
+ pl: "% pp."
28
+ volume:
29
+ sg: "% vol."
30
+ pl: "% vols."
31
+
@@ -1,2 +1,30 @@
1
1
  in: en
2
2
  at: en
3
+ and: y
4
+ updated: actualizado
5
+ viewed: visto
6
+ version: versión
7
+ date:
8
+ month_year: yMMMM
9
+ day_month_year: to_long_s
10
+ date_time: to_long_s
11
+ edition_number: ["OrdinalRules", "digits-ordinal-feminine"]
12
+ edition: "% ed."
13
+ draft: "borrador %"
14
+ editor:
15
+ sg: ed.
16
+ pl: eds.
17
+ extent:
18
+ page:
19
+ sg: "pág. %"
20
+ pl: "págs. %"
21
+ volume:
22
+ sg: "vol. %"
23
+ pl: "vols. %"
24
+ size:
25
+ page:
26
+ sg: "% pág."
27
+ pl: "% págs."
28
+ volume:
29
+ sg: "% vol."
30
+ pl: "% vols."
@@ -1,2 +1,30 @@
1
1
  in: dans
2
2
  at: à
3
+ and: et
4
+ updated: mise à jour
5
+ viewed: vu
6
+ version: version
7
+ date:
8
+ month_year: yMMMM
9
+ day_month_year: to_long_s
10
+ date_time: to_long_s
11
+ edition_number: ["OrdinalRules", "digits-ordinal-feminine"]
12
+ edition: "% édition"
13
+ draft: "brouillon %"
14
+ editor:
15
+ sg: éd.
16
+ pl: éd.
17
+ extent:
18
+ page:
19
+ sg: "p. %"
20
+ pl: "p. %"
21
+ volume:
22
+ sg: "vol. %"
23
+ pl: "vol. %"
24
+ size:
25
+ page:
26
+ sg: "% p."
27
+ pl: "% p."
28
+ volume:
29
+ sg: "% vol."
30
+ pl: "% vol."
@@ -5,19 +5,27 @@ updated: обновлен
5
5
  viewed: просмотрено
6
6
  version: версия
7
7
  date:
8
- month_year: to_long_s
8
+ month_year: yMMMM
9
9
  day_month_year: to_long_s
10
10
  date_time: to_long_s
11
11
  edition_number: ["SpelloutRules", "spellout-ordinal-neuter"]
12
12
  edition: "% издание"
13
+ draft: "проект %"
13
14
  editor:
14
15
  sg: изд.
15
16
  pl: изд.
16
17
  extent:
17
18
  page:
18
- sg: стр.
19
- pl: стр.
19
+ sg: "стр. %"
20
+ pl: "стр. %"
20
21
  volume:
21
- sg: т.
22
- pl: тт.
22
+ sg: "т. %"
23
+ pl: "тт. %"
24
+ size:
25
+ page:
26
+ sg: "% стр."
27
+ pl: "% стр."
28
+ volume:
29
+ sg: "% т."
30
+ pl: "% тт."
23
31
 
@@ -1,2 +1,30 @@
1
1
  in: 在
2
2
  at: 在
3
+ and: 和
4
+ updated: 更新
5
+ viewed: 看过
6
+ version: 版本
7
+ date:
8
+ month_year: yMMMM
9
+ day_month_year: to_long_s
10
+ date_time: to_long_s
11
+ edition_number: ["OrdinalRules", "digits-ordinal"]
12
+ edition: "第%版"
13
+ draft: "草案%"
14
+ editor:
15
+ sg: 编辑
16
+ pl: 编辑
17
+ extent:
18
+ page:
19
+ sg: "第%页"
20
+ pl: "第%页"
21
+ volume:
22
+ sg: "第%卷"
23
+ pl: "第%卷"
24
+ size:
25
+ page:
26
+ sg: "%页"
27
+ pl: "%页"
28
+ volume:
29
+ sg: "%卷"
30
+ pl: "%卷"
@@ -0,0 +1,45 @@
1
+ module Relaton
2
+ module Render
3
+ class Date
4
+ def initialize(date, options)
5
+ @date = date
6
+ @r = options[:renderer]
7
+ end
8
+
9
+ def render
10
+ return @date if @date.nil? || /^\d+$/.match?(@date)
11
+
12
+ render1(granularity)
13
+ end
14
+
15
+ def render1(format)
16
+ datef = dateparse(format, @r.lang.to_sym)
17
+ case @r.date[format]
18
+ when "to_full_s", "to_long_s", "to_medium_s", "to_short_s"
19
+ datef.send @r.date[format]
20
+ else
21
+ datef.to_additional_s(@r.date[format])
22
+ end
23
+ end
24
+
25
+ def granularity
26
+ case @date
27
+ when /^\d+-\d+$/ then "month_year"
28
+ when /^\d+-\d+-\d+$/ then "day_month_year"
29
+ else "date_time"
30
+ end
31
+ end
32
+
33
+ def dateparse(format, lang)
34
+ case format
35
+ when "date_time"
36
+ DateTime.parse(@date).localize(lang, timezone: "Zulu")
37
+ when "day_month_year"
38
+ DateTime.parse(@date).localize(lang, timezone: "Zulu").to_date
39
+ when "month_year"
40
+ DateTime.parse("#{@date}-01").localize(lang, timezone: "Zulu").to_date
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end