relaton 3.1.4 → 3.1.5

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: c2dcd5f1b916c7fe552e39b9376228255e2523385c8da7f91e1193b17ffb58d7
4
- data.tar.gz: e7331e3f2c069cda9567b518411dcb35e866700151987d9b4d4f14e17ef0f8b5
3
+ metadata.gz: 1ea5d8ada503e918f9bca0be141bc0ae76b7bdf89c634c2588b6609eb06251bf
4
+ data.tar.gz: 2b5578cd9fbb7907b1c9c4be0b3e066fbac0fa8884e59264a365cc55e5737f40
5
5
  SHA512:
6
- metadata.gz: 65781d01bf2cedf282a94e0275ebf7bcc187fe9d92f029e58768acd782fe05e04f0391ddc579bfce8d7d106242927ad54e9b371b58293dde2651f7e940e201ef
7
- data.tar.gz: 3f1e0879b62d13c363fd9d34bd02ffdc764a63f7ec8197d1614df983da34bcf02db5086679b68aa391b4fb52d91930be59cc2e58e7719c81ae21a2c9d9de3fa3
6
+ metadata.gz: a64557918b5ae5ab276bc3849f4c73bb20e31a3ddc618a7db33cce060c40a2f8780303181f2c6dfa94d0309d0e75146337690be7eb296ce469b298ecf6cd0641
7
+ data.tar.gz: 44d22a95a792c4396b37c223ad44077bd87562a4c8e5f26889504e86078a229357baacbe1bbc4217dbe4bfed55614dca7e64aaeee96c7c8804336cd517a06956
@@ -0,0 +1,118 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Relaton
4
+ module Bib
5
+ module Converter
6
+ module Endnote
7
+ class FromEndnote
8
+ TAG_LINE = /\A%([A-Z@]) (.*)\z/
9
+
10
+ # @param refer_str [String]
11
+ # @return [Hash{String=>Relaton::Bib::ItemData}] keyed by the
12
+ # first title (Refer has no identifier tag), falling back to
13
+ # the record position
14
+ def self.parse(refer_str)
15
+ refer_str.split(/\n\s*\n/).map(&:lines).reject(&:empty?)
16
+ .each_with_object({}).with_index do |(record_lines, hash), i|
17
+ item = new(record_lines).item
18
+ title = Array(item.title).first&.content.to_s
19
+ hash[title.empty? ? "record-#{i + 1}" : title] = item
20
+ end
21
+ end
22
+
23
+ # @param record_lines [Array<String>]
24
+ def initialize(record_lines)
25
+ @tags = Hash.new { |h, k| h[k] = [] }
26
+ record_lines.each do |line|
27
+ next unless (m = line.chomp.match(TAG_LINE))
28
+
29
+ @tags[m[1]] << m[2]
30
+ end
31
+ end
32
+
33
+ # @return [Relaton::Bib::ItemData]
34
+ def item
35
+ ItemData.new(
36
+ docidentifier: fetch_docid,
37
+ title: fetch_title,
38
+ date: fetch_date,
39
+ contributor: fetch_contributor,
40
+ edition: fetch_edition,
41
+ series: fetch_series,
42
+ keyword: fetch_keyword,
43
+ source: fetch_source,
44
+ )
45
+ end
46
+
47
+ private
48
+
49
+ # Refer has no identifier tag; a %R is some dialects' report
50
+ # number, not a docidentifier — none is invented here.
51
+ def fetch_docid
52
+ []
53
+ end
54
+
55
+ def fetch_title
56
+ @tags["T"].map { |v| Title.new(type: "title-main", content: v) }
57
+ end
58
+
59
+ # Refer dates are "YYYY" or a free-form date string.
60
+ def fetch_date
61
+ @tags["D"].map do |v|
62
+ on = v.match?(/\A\d{4}\z/) ? v : (::Date.parse(v).to_s rescue v)
63
+ Bib::Date.new(type: "published", at: on)
64
+ end
65
+ end
66
+
67
+ # "Surname, Forename" names a person; a bare token is an
68
+ # organization (the same convention the RIS importer applies to
69
+ # this converter's own output).
70
+ def fetch_contributor
71
+ contribs = []
72
+ @tags["A"].each do |name|
73
+ contribs << if name.include?(",")
74
+ person_contributor(name)
75
+ else
76
+ org_contributor(name, "author")
77
+ end
78
+ end
79
+ @tags["I"].each { |name| contribs << org_contributor(name, "publisher") }
80
+ contribs
81
+ end
82
+
83
+ def person_contributor(name)
84
+ parts = name.split(", ")
85
+ surname = LocalizedString.new(content: parts.first)
86
+ forename = (parts[1] || "").split.map { |fn| FullNameType::Forename.new(content: fn) }
87
+ person = Person.new(name: FullName.new(surname: surname, forename: forename))
88
+ Contributor.new(person: person, role: [Contributor::Role.new(type: "author")])
89
+ end
90
+
91
+ def org_contributor(name, role)
92
+ org = Organization.new(name: [TypedLocalizedString.new(content: name)])
93
+ Contributor.new(organization: org, role: [Contributor::Role.new(type: role)])
94
+ end
95
+
96
+ def fetch_edition
97
+ Edition.new(content: @tags["@"].first.to_s) if @tags["@"].any?
98
+ end
99
+
100
+ def fetch_series
101
+ series = []
102
+ @tags["J"].each { |v| series << Series.new(type: "journal", title: Title.new(content: v)) }
103
+ @tags["S"].each { |v| series << Series.new(title: Title.new(content: v)) }
104
+ series
105
+ end
106
+
107
+ def fetch_keyword
108
+ @tags["K"].map { |v| Keyword.new(vocab: LocalizedString.new(content: v)) }
109
+ end
110
+
111
+ def fetch_source
112
+ @tags["U"].map { |v| Uri.new(type: "src", content: v) }
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,107 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Relaton
4
+ module Bib
5
+ module Converter
6
+ module Endnote
7
+ class ToEndnote
8
+ # @param item [Relaton::Bib::ItemData]
9
+ def initialize(item)
10
+ @item = item
11
+ end
12
+
13
+ # @return [String] one Refer record (no trailing blank line)
14
+ def to_s
15
+ lines = []
16
+ add_authors(lines)
17
+ add_field(lines, "%T", primary_title)
18
+ add_field(lines, "%D", published_year)
19
+ add_field(lines, "%@", @item.edition&.to_s)
20
+ add_field(lines, "%I", publisher_name)
21
+ add_journal(lines)
22
+ add_series(lines)
23
+ Array(@item.keyword).each { |k| add_field(lines, "%K", k.vocab.content.to_s) }
24
+ add_field(lines, "%U", source_uri)
25
+ lines.join("\n") + "\n"
26
+ end
27
+
28
+ private
29
+
30
+ def add_field(lines, tag, value)
31
+ lines << "#{tag} #{value}" if value && !value.empty?
32
+ end
33
+
34
+ # The same authorish/publisher split the RIS renderer makes.
35
+ def add_authors(lines)
36
+ Array(@item.contributor).each do |c|
37
+ roles = Array(c.role).map(&:type).compact
38
+ authorish = (roles & %w[author performer editor]).any?
39
+ if authorish && c.person
40
+ out = person_display_name(c.person.name)
41
+ add_field(lines, "%A", out) unless out.empty?
42
+ elsif authorish && c.organization
43
+ out = org_name(c.organization)
44
+ add_field(lines, "%A", out) unless out.empty?
45
+ end
46
+ end
47
+ end
48
+
49
+ def person_display_name(name)
50
+ return "" unless name
51
+
52
+ fore = Array(name.forename).map { |f| f.respond_to?(:content) ? f.content.to_s : f.to_s }.join(" ")
53
+ sur = name.surname.respond_to?(:content) ? name.surname.content.to_s : name.surname.to_s
54
+ complete = name.completename.respond_to?(:content) ? name.completename.content.to_s : name.completename.to_s
55
+ return "#{sur}, #{fore}" unless fore.empty? || sur.empty?
56
+ return sur unless sur.empty?
57
+
58
+ complete
59
+ end
60
+
61
+ def org_name(org)
62
+ name = Array(org.name).map { |n| n.respond_to?(:content) ? n.content.to_s : n.to_s }.find(&:itself)
63
+ name || org.abbreviation.to_s
64
+ end
65
+
66
+ def publisher_name
67
+ pub = Array(@item.contributor).find do |c|
68
+ Array(c.role).map(&:type).include?("publisher") && c.organization
69
+ end
70
+ pub && org_name(pub.organization)
71
+ end
72
+
73
+ # %J is the journal series; %S a plain series. An item carries at
74
+ # most one of each in this mapping.
75
+ def add_journal(lines)
76
+ journal = Array(@item.series).find { |s| s.type == "journal" }
77
+ add_field(lines, "%J", series_title(journal)) if journal
78
+ end
79
+
80
+ def add_series(lines)
81
+ series = Array(@item.series).reject { |s| s.type == "journal" }.first
82
+ add_field(lines, "%S", series_title(series)) if series
83
+ end
84
+
85
+ def series_title(series)
86
+ Array(series.title).map { |t| t.respond_to?(:content) ? t.content.to_s : t.to_s }.find(&:itself)
87
+ end
88
+
89
+ def primary_title
90
+ Titles.of(@item)
91
+ end
92
+
93
+ def published_year
94
+ date = Array(@item.date).find { |d| %w[published issued].include?(d.type.to_s) } || @item.date.first
95
+ value = date && (date.at || date.from || date.to)
96
+ value.to_s[/\d{4}/]
97
+ end
98
+
99
+ def source_uri
100
+ Array(@item.source).map { |s| s.respond_to?(:content) ? s.content.to_s : s.to_s }
101
+ .find { |u| u.start_with?("http") }
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "endnote/from_endnote"
4
+ require_relative "endnote/to_endnote"
5
+
6
+ module Relaton
7
+ module Bib
8
+ module Converter
9
+ module Endnote
10
+ # Refer-format field tags (the EndNote "tagged format"): one
11
+ # `%X value` line per field, records separated by a blank line.
12
+ TAGS = {
13
+ author: "%A", title: "%T", date: "%D", publisher: "%I",
14
+ edition: "%@", keyword: "%K", url: "%U", journal: "%J",
15
+ series: "%S",
16
+ }.freeze
17
+
18
+ # ItemData -> Refer string
19
+ def self.from_item(item)
20
+ ToEndnote.new(item).to_s
21
+ end
22
+
23
+ # Refer string -> Hash{String=>ItemData}
24
+ def self.to_item(refer_str)
25
+ FromEndnote.parse(refer_str)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,144 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Relaton
4
+ module Bib
5
+ module Converter
6
+ module Ris
7
+ # One TY..ER record per entry; tags are `XX - value` lines.
8
+ class FromRis
9
+ # ELEC backs two entry types; the reverse pairs it with the
10
+ # webresource face the renderer's default pairs with.
11
+ REVERSE_ENTRY_TYPES = {
12
+ "STD" => "standard", "BOOK" => "book", "JOUR" => "article",
13
+ "CHAP" => "inbook", "CONF" => "inproceedings", "RPRT" => "report",
14
+ "THES" => "thesis", "ELEC" => "webresource",
15
+ }.freeze
16
+
17
+ TAG_LINE = /\A([A-Z0-9]{2}) - ?(.*)\z/
18
+
19
+ # @param ris_str [String]
20
+ # @return [Hash{String=>Relaton::Bib::ItemData}] keyed by the ID
21
+ # tag (falling back to the docidentifier, then the record
22
+ # position)
23
+ def self.parse(ris_str)
24
+ records = []
25
+ current = nil
26
+ ris_str.each_line do |line|
27
+ line = line.chomp
28
+ if line.start_with?("TY - ")
29
+ current = [line]
30
+ elsif current
31
+ current << line
32
+ # The renderer writes "ER - " with a trailing space; real
33
+ # files commonly stop at the dash.
34
+ if line.start_with?("ER -")
35
+ records << current
36
+ current = nil
37
+ end
38
+ end
39
+ end
40
+ records.each_with_object({}).with_index do |(record, hash), i|
41
+ item = new(record).item
42
+ hash[record_key(item) || "record-#{i + 1}"] = item
43
+ end
44
+ end
45
+
46
+ # @param record_lines [Array<String>]
47
+ def initialize(record_lines)
48
+ @tags = Hash.new { |h, k| h[k] = [] }
49
+ record_lines.each do |line|
50
+ next unless (m = line.chomp.match(TAG_LINE))
51
+
52
+ @tags[m[1]] << m[2]
53
+ end
54
+ end
55
+
56
+ # @return [Relaton::Bib::ItemData]
57
+ def item
58
+ ItemData.new(
59
+ type: entry_type,
60
+ docidentifier: fetch_docid,
61
+ title: fetch_title,
62
+ date: fetch_date,
63
+ contributor: fetch_contributor,
64
+ edition: fetch_edition,
65
+ language: @tags["LA"].map(&:itself),
66
+ keyword: fetch_keyword,
67
+ source: fetch_source,
68
+ )
69
+ end
70
+
71
+ # @return [String, nil] the primary docidentifier's content
72
+ def self.record_key(item)
73
+ ids = Array(item.docidentifier)
74
+ primary = (ids.find(&:primary) || ids.first)&.content.to_s
75
+ primary unless primary.empty?
76
+ end
77
+
78
+ private
79
+
80
+ def entry_type
81
+ REVERSE_ENTRY_TYPES.fetch(@tags["TY"].first, "standard")
82
+ end
83
+
84
+ def fetch_docid
85
+ @tags["ID"].map { |v| Docidentifier.new(content: v, primary: true) }
86
+ end
87
+
88
+ def fetch_title
89
+ @tags["TI"].map { |v| Title.new(type: "title-main", content: v) }
90
+ end
91
+
92
+ # RIS dates are "YYYY" or "YYYY/MM/DD".
93
+ def fetch_date
94
+ @tags["PY"].map do |v|
95
+ on = v.match?(/\A\d{4}\z/) ? v : (::Date.parse(v.tr("/", "-")).to_s rescue v)
96
+ Bib::Date.new(type: "published", at: on)
97
+ end
98
+ end
99
+
100
+ # The renderer emits "Surname, Forename" for persons and a bare
101
+ # name for organizations under the same AU tag; a comma splits a
102
+ # person, a bare token is an organization name.
103
+ def fetch_contributor # rubocop:disable Metrics/AbcSize
104
+ contribs = []
105
+ @tags["AU"].each do |name|
106
+ contribs << if name.include?(",")
107
+ person_contributor(name)
108
+ else
109
+ org_contributor(name, "author")
110
+ end
111
+ end
112
+ @tags["PB"].each { |name| contribs << org_contributor(name, "publisher") }
113
+ contribs
114
+ end
115
+
116
+ def person_contributor(name)
117
+ parts = name.split(", ")
118
+ surname = LocalizedString.new(content: parts.first)
119
+ forename = (parts[1] || "").split.map { |fn| FullNameType::Forename.new(content: fn) }
120
+ person = Person.new(name: FullName.new(surname: surname, forename: forename))
121
+ Contributor.new(person: person, role: [Contributor::Role.new(type: "author")])
122
+ end
123
+
124
+ def org_contributor(name, role)
125
+ org = Organization.new(name: [TypedLocalizedString.new(content: name)])
126
+ Contributor.new(organization: org, role: [Contributor::Role.new(type: role)])
127
+ end
128
+
129
+ def fetch_edition
130
+ Edition.new(content: @tags["ET"].first.to_s) if @tags["ET"].any?
131
+ end
132
+
133
+ def fetch_keyword
134
+ @tags["KW"].map { |v| Keyword.new(vocab: LocalizedString.new(content: v)) }
135
+ end
136
+
137
+ def fetch_source
138
+ @tags["UR"].map { |v| Uri.new(type: "src", content: v) }
139
+ end
140
+ end
141
+ end
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Relaton
4
+ module Bib
5
+ module Converter
6
+ module Ris
7
+ class ToRis
8
+ def initialize(item)
9
+ @item = item
10
+ end
11
+
12
+ # @return [String]
13
+ def to_s
14
+ lines = ["TY - #{ENTRY_TYPES[@item.type.to_s] || 'STD'}"]
15
+ add_authors(lines)
16
+ add_field(lines, "TI", primary_title)
17
+ add_field(lines, "ID", primary_docid)
18
+ add_field(lines, "PY", published_year)
19
+ add_field(lines, "ET", @item.edition&.to_s)
20
+ lang = Array(@item.language).first
21
+ add_field(lines, "LA", lang.to_s)
22
+ Array(@item.keyword).each { |k| add_field(lines, "KW", k.content.to_s) }
23
+ add_field(lines, "UR", source_uri)
24
+ lines << "ER - "
25
+ lines.join("\r\n") + "\r\n"
26
+ end
27
+
28
+ private
29
+
30
+ def add_field(lines, tag, value)
31
+ lines << "#{tag} - #{value}" if value && !value.empty?
32
+ end
33
+
34
+ def add_authors(lines)
35
+ Array(@item.contributor).each do |c|
36
+ roles = Array(c.role).map(&:type).compact
37
+ authorish = (roles & %w[author performer editor]).any?
38
+ publisher = roles.include?("publisher")
39
+ if authorish && c.person
40
+ out = person_display_name(c.person.name)
41
+ lines << "AU - #{out}" unless out.empty?
42
+ elsif authorish && c.organization
43
+ out = org_name(c.organization)
44
+ lines << "AU - #{out}" unless out.empty?
45
+ elsif publisher && c.organization
46
+ out = org_name(c.organization)
47
+ lines << "PB - #{out}" unless out.empty? || lines.any? { |l| l.start_with?("PB - ") }
48
+ end
49
+ end
50
+ end
51
+
52
+ def person_display_name(name)
53
+ return "" unless name
54
+
55
+ fore = Array(name.forename).map { |f| f.respond_to?(:content) ? f.content.to_s : f.to_s }.join(" ")
56
+ sur = name.surname.respond_to?(:content) ? name.surname.content.to_s : name.surname.to_s
57
+ complete = name.completename.respond_to?(:content) ? name.completename.content.to_s : name.completename.to_s
58
+ return "#{sur}, #{fore}" unless fore.empty? || sur.empty?
59
+ return sur unless sur.empty?
60
+
61
+ complete
62
+ end
63
+
64
+ def org_name(org)
65
+ name = Array(org.name).map { |n| n.respond_to?(:content) ? n.content.to_s : n.to_s }.find(&:itself)
66
+ name || org.abbreviation.to_s
67
+ end
68
+
69
+ def primary_title
70
+ Titles.of(@item)
71
+ end
72
+
73
+ def primary_docid
74
+ ids = Array(@item.docidentifier)
75
+ (ids.find(&:primary) || ids.first)&.content.to_s
76
+ end
77
+
78
+ def published_year
79
+ date = Array(@item.date).find { |d| %w[published issued].include?(d.type.to_s) } || @item.date.first
80
+ value = date && (date.at || date.from || date.to)
81
+ value.to_s[/\d{4}/]
82
+ end
83
+
84
+ def source_uri
85
+ Array(@item.source).map { |s| s.respond_to?(:content) ? s.content.to_s : s.to_s }
86
+ .find { |u| u.start_with?("http") }
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "ris/from_ris"
4
+ require_relative "ris/to_ris"
3
5
 
4
6
  module Relaton
5
7
  module Bib
@@ -13,90 +15,14 @@ module Relaton
13
15
  "thesis" => "THES", "website" => "ELEC", "webresource" => "ELEC",
14
16
  }.freeze
15
17
 
18
+ # ItemData -> RIS string
16
19
  def self.from_item(item)
17
- Renderer.new(item).to_s
20
+ ToRis.new(item).to_s
18
21
  end
19
22
 
20
- class Renderer
21
- def initialize(item)
22
- @item = item
23
- end
24
-
25
- def to_s
26
- lines = ["TY - #{ENTRY_TYPES[@item.type.to_s] || 'STD'}"]
27
- add_authors(lines)
28
- add_field(lines, "TI", primary_title)
29
- add_field(lines, "ID", primary_docid)
30
- add_field(lines, "PY", published_year)
31
- add_field(lines, "ET", @item.edition&.to_s)
32
- lang = Array(@item.language).first
33
- add_field(lines, "LA", lang.to_s)
34
- Array(@item.keyword).each { |k| add_field(lines, "KW", k.content.to_s) }
35
- add_field(lines, "UR", source_uri)
36
- lines << "ER - "
37
- lines.join("\r\n") + "\r\n"
38
- end
39
-
40
- private
41
-
42
- def add_field(lines, tag, value)
43
- lines << "#{tag} - #{value}" if value && !value.empty?
44
- end
45
-
46
- def add_authors(lines)
47
- Array(@item.contributor).each do |c|
48
- roles = Array(c.role).map(&:type).compact
49
- authorish = (roles & %w[author performer editor]).any?
50
- publisher = roles.include?("publisher")
51
- if authorish && c.person
52
- out = person_display_name(c.person.name)
53
- lines << "AU - #{out}" unless out.empty?
54
- elsif authorish && c.organization
55
- out = org_name(c.organization)
56
- lines << "AU - #{out}" unless out.empty?
57
- elsif publisher && c.organization
58
- out = org_name(c.organization)
59
- lines << "PB - #{out}" unless out.empty? || lines.any? { |l| l.start_with?("PB - ") }
60
- end
61
- end
62
- end
63
-
64
- def person_display_name(name)
65
- return "" unless name
66
-
67
- fore = Array(name.forename).map { |f| f.respond_to?(:content) ? f.content.to_s : f.to_s }.join(" ")
68
- sur = name.surname.respond_to?(:content) ? name.surname.content.to_s : name.surname.to_s
69
- complete = name.completename.respond_to?(:content) ? name.completename.content.to_s : name.completename.to_s
70
- return "#{sur}, #{fore}" unless fore.empty? || sur.empty?
71
- return sur unless sur.empty?
72
-
73
- complete
74
- end
75
-
76
- def org_name(org)
77
- name = Array(org.name).map { |n| n.respond_to?(:content) ? n.content.to_s : n.to_s }.find(&:itself)
78
- name || org.abbreviation.to_s
79
- end
80
-
81
- def primary_title
82
- Titles.of(@item)
83
- end
84
-
85
- def primary_docid
86
- ids = Array(@item.docidentifier)
87
- (ids.find(&:primary) || ids.first)&.content.to_s
88
- end
89
-
90
- def published_year
91
- date = Array(@item.date).find { |d| %w[published issued].include?(d.type.to_s) } || @item.date.first
92
- value = date && (date.at || date.from || date.to)
93
- value.to_s[/\d{4}/]
94
- end
95
-
96
- def source_uri
97
- Array(@item.source).map { |s| s.respond_to?(:content) ? s.content.to_s : s.to_s }
98
- .find { |u| u.start_with?("http") }
99
- end
23
+ # RIS string -> Hash{String=>ItemData}
24
+ def self.to_item(ris_str)
25
+ FromRis.parse(ris_str)
100
26
  end
101
27
  end
102
28
  end
@@ -166,6 +166,10 @@ module Relaton
166
166
  Converter::Ris.from_item(self)
167
167
  end
168
168
 
169
+ def to_endnote
170
+ Converter::Endnote.from_item(self)
171
+ end
172
+
169
173
  def to_csl_json
170
174
  Converter::Csl.from_item(self)
171
175
  end
data/lib/relaton/bib.rb CHANGED
@@ -25,6 +25,7 @@ module Relaton
25
25
  module Bib
26
26
  module Converter
27
27
  autoload :Ris, "relaton/bib/converter/ris"
28
+ autoload :Endnote, "relaton/bib/converter/endnote"
28
29
  autoload :Csl, "relaton/bib/converter/csl"
29
30
  autoload :Titles, "relaton/bib/converter/titles"
30
31
  end
@@ -1,4 +1,6 @@
1
1
  require "fileutils"
2
+ require "json"
3
+ require "yaml"
2
4
  require_relative "../bibdata"
3
5
  require_relative "../bibcollection"
4
6
  require_relative "xml_to_html_renderer"
@@ -34,15 +36,28 @@ module Relaton
34
36
  # @param template [String] The liquid tempalte directory
35
37
  #
36
38
  # @return [String] HTML
37
- def self.to_html(file, style = nil, template = nil)
39
+ def self.to_html(file, style = nil, template = nil, context = nil)
38
40
  new(
39
41
  file,
40
42
  style: style || File.join(File.dirname(__FILE__), "templates/index-style.css"),
41
43
  template: template || File.join(File.dirname(__FILE__), "templates/"),
42
- extension: "html"
44
+ extension: "html",
45
+ context: context && load_context(context)
43
46
  ).to_html
44
47
  end
45
48
 
49
+ # A YAML or JSON file whose contents merge into the Liquid template
50
+ # context (#455).
51
+ #
52
+ # @param file [String] path to the context file
53
+ # @return [Hash]
54
+ def self.load_context(file)
55
+ case File.extname(file)
56
+ when ".json" then JSON.parse(File.read(file, encoding: "utf-8"))
57
+ else YAML.safe_load(File.read(file, encoding: "utf-8"))
58
+ end
59
+ end
60
+
46
61
  private
47
62
 
48
63
  attr_reader :file, :outdir, :options, :writable, :overwrite
@@ -52,7 +67,8 @@ module Relaton
52
67
  Relaton::Cli::XmlToHtmlRenderer.render(
53
68
  xml_content(file),
54
69
  stylesheet: options[:style],
55
- liquid_dir: options[:template]
70
+ liquid_dir: options[:template],
71
+ context: options[:context]
56
72
  )
57
73
  end
58
74
 
@@ -139,9 +139,14 @@ module Relaton
139
139
  "rendering Relaton items and collection"
140
140
  option :overwrite, aliases: :f, type: :boolean, default: false,
141
141
  desc: "Overwrite the existing file"
142
+ option :context, aliases: :c,
143
+ desc: "YAML or JSON file whose contents merge into " \
144
+ "the Liquid template context; the renderer's " \
145
+ "own keys cannot be overridden"
142
146
 
143
147
  def xml2html(file, style = nil, template = nil)
144
- Relaton::Cli::XMLConvertor.to_html(file, style, template)
148
+ Relaton::Cli::XMLConvertor.to_html(file, style, template,
149
+ options[:context])
145
150
  end
146
151
 
147
152
  desc "yaml2html RELATON-INDEX-YAML", "Concatenate Relaton Collection " \
@@ -152,9 +157,14 @@ module Relaton
152
157
  "rendering Relaton items and collection"
153
158
  option :overwrite, aliases: :f, type: :boolean, default: false,
154
159
  desc: "Overwrite the existing file"
160
+ option :context, aliases: :c,
161
+ desc: "YAML or JSON file whose contents merge into " \
162
+ "the Liquid template context; the renderer's " \
163
+ "own keys cannot be overridden"
155
164
 
156
165
  def yaml2html(file, style = nil, template = nil)
157
- Relaton::Cli::YAMLConvertor.to_html(file, style, template)
166
+ Relaton::Cli::YAMLConvertor.to_html(file, style, template,
167
+ options[:context])
158
168
  end
159
169
 
160
170
  desc "index [DATA-DIR]",
@@ -3,9 +3,14 @@ require "liquid"
3
3
 
4
4
  module Relaton::Cli
5
5
  class XmlToHtmlRenderer
6
- def initialize(liquid_dir: nil, stylesheet: nil)
6
+ def initialize(liquid_dir: nil, stylesheet: nil, context: nil)
7
7
  @liquid_dir = liquid_dir
8
8
  @stylesheet = read_file(stylesheet)
9
+ # Extra template data (#455). Merged under the renderer's own keys:
10
+ # a context entry can add to the Liquid document (a deployed site's
11
+ # domain for canonical-URL construction) but never clobber the
12
+ # engine's document model (title/css/date/author/documents).
13
+ @context = context || {}
9
14
  init_liquid_template_and_filesystem
10
15
  end
11
16
 
@@ -47,12 +52,14 @@ module Relaton::Cli
47
52
  def build_liquid_document(source)
48
53
  bibcollection = build_bibcollection(source)
49
54
  hash_to_liquid(
50
- depth: 2,
51
- css: stylesheet,
52
- title: bibcollection.title,
53
- date: DateTime.now.to_s,
54
- author: bibcollection.author,
55
- documents: document_items(bibcollection)
55
+ @context.merge(
56
+ depth: 2,
57
+ css: stylesheet,
58
+ title: bibcollection.title,
59
+ date: DateTime.now.to_s,
60
+ author: bibcollection.author,
61
+ documents: document_items(bibcollection)
62
+ )
56
63
  )
57
64
  end
58
65
 
@@ -1,10 +1,10 @@
1
1
  # The metanorma-jis CitationStyle instance, English forms
2
2
  # (relaton-render 3.0.0.pre Iso690 engine): the ISO 690 order with the
3
3
  # Latin punctuation of the en language pack.
4
- name: "ISO 690 (JIS, en)"
4
+ name: "ISO 690 (metanorma-jis flavour, en)"
5
5
  scheme:
6
6
  system: name-date
7
- shortFromReference: true
7
+ shortFromReference: false
8
8
  homeDocidType: []
9
9
  nameForm:
10
10
  initials: true
@@ -19,9 +19,22 @@ scheme:
19
19
  locale:
20
20
  availableAt: "Available at:"
21
21
  labels:
22
- "and": "&amp;"
23
22
  oxford_comma: ""
24
23
  series_no: ""
24
+ edition_1: "第1版"
25
+ edition_2: "第2版"
26
+ edition_3: "第3版"
27
+ edition_4: "第4版"
28
+ edition_5: "第5版"
29
+ edition_6: "第6版"
30
+ edition_7: "第7版"
31
+ edition_8: "第8版"
32
+ edition_9: "第9版"
33
+ edition_10: "第10版"
34
+ rules:
35
+ component_part: jis_component_part
36
+ series: jis_series
37
+ extent: jis_extent
25
38
  templates:
26
39
  titleOpen: ""
27
40
  titleClose: ""
@@ -39,14 +52,17 @@ perType:
39
52
  - type: report
40
53
  fallbacks:
41
54
  date: "n.d"
42
- template: "{{creator}}. {{title}}. {{edition}}. {{production}}. {{authorizer}}. {{location}}"
55
+ template: "{{creator}}. {{title}}{{authorizer}}{{production}}. {{location}}"
56
+ authorizer: ". {{authorizer}}"
57
+ production: ", {{production}}"
43
58
  short: "{{creator}}. <span class='stddocTitle'>{{title}}</span>. {{edition}}. {{production}}"
44
59
  title: "<span class='stddocTitle'>{{title}}</span>"
45
60
  - type: monograph
46
61
  noPlace: true
47
62
  fallbacks:
48
63
  date: "n.d"
49
- template: "{{creator}}{{role}}. {{title}}. {{edition}}. ({{series}}). {{production}}. {{date}}. {{size}}. {{location}}"
64
+ template: "{{creator}}{{role}} {{title}}. {{edition}}. ({{series}}). {{production}}. {{date}}. {{size}}. {{location}}"
65
+ title: "_{{title}}_"
50
66
  - type: continuing
51
67
  template: "{{title}}. {{date}}"
52
68
  - type: online
@@ -1,10 +1,10 @@
1
1
  # The metanorma-jis CitationStyle instance, Japanese forms
2
2
  # (relaton-render 3.0.0.pre Iso690 engine): the ISO 690 order with the
3
3
  # Latin punctuation of the en language pack.
4
- name: "ISO 690 (JIS, ja)"
4
+ name: "ISO 690 (metanorma-jis flavour, ja)"
5
5
  scheme:
6
6
  system: name-date
7
- shortFromReference: true
7
+ shortFromReference: false
8
8
  homeDocidType: []
9
9
  nameForm:
10
10
  initials: true
@@ -21,6 +21,10 @@ scheme:
21
21
  "and": ""
22
22
  oxford_comma: ""
23
23
  series_no: ""
24
+ rules:
25
+ component_part: jis_component_part
26
+ series: jis_series
27
+ extent: jis_extent
24
28
  templates:
25
29
  titleOpen: ""
26
30
  titleClose: ""
@@ -38,14 +42,17 @@ perType:
38
42
  - type: report
39
43
  fallbacks:
40
44
  date: "日付なし"
41
- template: "{{creator}}。 {{title}}。 {{edition}}。 {{production}}。 {{authorizer}}。 {{location}}"
45
+ template: "{{creator}}。 {{title}}{{edition}}{{authorizer}}{{production}}。 {{location}}"
46
+ authorizer: "。 {{authorizer}}"
47
+ production: "、{{production}}"
42
48
  short: "{{creator}}。 <span class='stddocTitle'>{{title}}</span>。 {{edition}}。 {{production}}"
43
49
  title: "<span class='stddocTitle'>{{title}}</span>"
44
50
  - type: monograph
45
51
  noPlace: true
46
52
  fallbacks:
47
53
  date: "日付なし"
48
- template: "{{creator}}{{role}}。 {{title}}。 {{edition}}。({{series}})。 {{production}}。 {{date}}。 {{size}}。 {{location}}"
54
+ template: "{{creator}}{{role}} {{title}}。 {{edition}}。({{series}})。 {{production}}。 {{date}}。 {{size}}。 {{location}}"
55
+ title: "_{{title}}_"
49
56
  - type: continuing
50
57
  template: "{{title}}。 {{date}}"
51
58
  - type: online
@@ -1,3 +1,3 @@
1
1
  module Relaton
2
- VERSION = "3.1.4".freeze
2
+ VERSION = "3.1.5".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.4
4
+ version: 3.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-11-15 00:00:00.000000000 Z
11
+ date: 2026-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -506,14 +506,14 @@ dependencies:
506
506
  requirements:
507
507
  - - "~>"
508
508
  - !ruby/object:Gem::Version
509
- version: 1.3.129
509
+ version: 1.5.0
510
510
  type: :runtime
511
511
  prerelease: false
512
512
  version_requirements: !ruby/object:Gem::Requirement
513
513
  requirements:
514
514
  - - "~>"
515
515
  - !ruby/object:Gem::Version
516
- version: 1.3.129
516
+ version: 1.5.0
517
517
  - !ruby/object:Gem::Dependency
518
518
  name: pubid
519
519
  requirement: !ruby/object:Gem::Requirement
@@ -655,7 +655,12 @@ files:
655
655
  - lib/relaton/bib/converter/bibxml/to_rfcxml_v3.rb
656
656
  - lib/relaton/bib/converter/csl.rb
657
657
  - lib/relaton/bib/converter/csl/from_csl.rb
658
+ - lib/relaton/bib/converter/endnote.rb
659
+ - lib/relaton/bib/converter/endnote/from_endnote.rb
660
+ - lib/relaton/bib/converter/endnote/to_endnote.rb
658
661
  - lib/relaton/bib/converter/ris.rb
662
+ - lib/relaton/bib/converter/ris/from_ris.rb
663
+ - lib/relaton/bib/converter/ris/to_ris.rb
659
664
  - lib/relaton/bib/converter/titles.rb
660
665
  - lib/relaton/bib/hash_parser_v1.rb
661
666
  - lib/relaton/bib/item_data.rb