relaton-render 0.5.13 → 0.5.14
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a59266f60d60c8d152141f675eac858ef9f9b81e4c8d9ac2bfe9dd158db148d
|
4
|
+
data.tar.gz: 40d269013ae823a85f21c335b7157e13c6062572e6e06190e6a06688b5508061
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a084f59643670d47b6e237c00df3b831f7b50781aa39bbf153bf1fc6912dd6358c77d8d04f5ce6a8742d6c3586bd5d025c2a6ceddb70f5db8f0b0d4f2200f07e
|
7
|
+
data.tar.gz: 1ae9f86ae3ee701eeece1ac44c6cfcfd41ce34320ea263c413c3417609c0b919c2924bdafda02b0db828e9f16ce7de0aaec1f25bee3ec53a33a9da5ff14896d9
|
@@ -2,7 +2,9 @@ require_relative "render_classes"
|
|
2
2
|
require_relative "citations"
|
3
3
|
require "yaml"
|
4
4
|
require "liquid"
|
5
|
+
require "date"
|
5
6
|
require "relaton_bib"
|
7
|
+
require "net/http"
|
6
8
|
require_relative "../template/template"
|
7
9
|
require_relative "../../../isodoc/i18n"
|
8
10
|
|
@@ -133,6 +135,7 @@ module Relaton
|
|
133
135
|
def parse1(doc)
|
134
136
|
r = renderer(doc.type || "misc")
|
135
137
|
data = @parse.extract(doc)
|
138
|
+
enhance_data(data, r.template_raw)
|
136
139
|
data_liquid = @fieldsklass.new(renderer: self)
|
137
140
|
.compound_fields_format(data)
|
138
141
|
valid_parse(@i18n.l10n(r.render(data_liquid)))
|
@@ -173,6 +176,23 @@ module Relaton
|
|
173
176
|
end
|
174
177
|
end
|
175
178
|
|
179
|
+
# add to liquid data based on template
|
180
|
+
def enhance_data(data, template)
|
181
|
+
template.is_a?(String) or return
|
182
|
+
add_date_accessed(data, template)
|
183
|
+
end
|
184
|
+
|
185
|
+
def add_date_accessed(data, template)
|
186
|
+
(/\{\{\s*date_accessed\s*\}\}/.match?(template) &&
|
187
|
+
/\{\{\s*uri\s*\}\}/.match?(template) &&
|
188
|
+
data[:uri_raw] && !data[:date_accessed]) or return
|
189
|
+
if url_exist?(data[:uri_raw])
|
190
|
+
data[:date_accessed] = { on: ::Date.today.to_s }
|
191
|
+
else
|
192
|
+
warn "BIBLIOGRAPHY WARNING: cannot access #{data[:uri_raw]}"
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
176
196
|
private
|
177
197
|
|
178
198
|
def template_hash_fill(templates)
|
@@ -182,6 +202,23 @@ module Relaton
|
|
182
202
|
m[type] = template
|
183
203
|
end
|
184
204
|
end
|
205
|
+
|
206
|
+
def url_exist?(url_string)
|
207
|
+
res = access_url(url_string)
|
208
|
+
res.is_a?(Net::HTTPRedirection) and return url_exist?(res["location"])
|
209
|
+
res.code[0] != "4"
|
210
|
+
rescue Errno::ENOENT, SocketError
|
211
|
+
false # false if can't find the server
|
212
|
+
end
|
213
|
+
|
214
|
+
def access_url(url_string)
|
215
|
+
url = URI.parse(url_string)
|
216
|
+
req = Net::HTTP.new(url.host, url.port)
|
217
|
+
req.use_ssl = (url.scheme == "https")
|
218
|
+
path = url.path or return false
|
219
|
+
path.empty? and path = "/"
|
220
|
+
req.request_head(path)
|
221
|
+
end
|
185
222
|
end
|
186
223
|
end
|
187
224
|
end
|
@@ -5,6 +5,8 @@ module Relaton
|
|
5
5
|
module Render
|
6
6
|
module Template
|
7
7
|
class General
|
8
|
+
attr_reader :template_raw
|
9
|
+
|
8
10
|
def initialize(opt = {})
|
9
11
|
@htmlentities = HTMLEntities.new
|
10
12
|
customise_liquid
|
@@ -43,7 +45,7 @@ module Relaton
|
|
43
45
|
|
44
46
|
def punct_field?(name)
|
45
47
|
name or return false
|
46
|
-
name = name.gsub(
|
48
|
+
name = name.gsub("'", '"')
|
47
49
|
%w(labels["qq-open"] labels["qq-close"] labels["q-open"]
|
48
50
|
labels["q-close"]).include?(name)
|
49
51
|
end
|
@@ -60,7 +62,7 @@ module Relaton
|
|
60
62
|
a[3] = "}}#{FIELD_DELIM}"
|
61
63
|
end
|
62
64
|
a.join
|
63
|
-
end.join.gsub(
|
65
|
+
end.join.gsub("\t", " ")
|
64
66
|
t.gsub(/\}\}#{FIELD_DELIM}\|/o, "}}#{FIELD_DELIM}\t")
|
65
67
|
.gsub(/\|#{FIELD_DELIM}\{\{/o, "\t#{FIELD_DELIM}{{")
|
66
68
|
end
|
@@ -96,7 +98,7 @@ module Relaton
|
|
96
98
|
.sub(/^\s*[,.:;]\s*/, "")
|
97
99
|
.sub(/[,:;]\s*$/, "")
|
98
100
|
.gsub(/(?<!\\)_/, " ")
|
99
|
-
.gsub(
|
101
|
+
.gsub("\\_", "_")
|
100
102
|
.gsub(/#{NON_SPACING_DELIM}/o, "").gsub(/\s+/, " ")
|
101
103
|
end
|
102
104
|
|
@@ -110,7 +112,7 @@ module Relaton
|
|
110
112
|
when Array
|
111
113
|
hash.map { |v| liquid_hash(v) }
|
112
114
|
when String
|
113
|
-
hash.empty? ? nil : hash.gsub(
|
115
|
+
hash.empty? ? nil : hash.gsub("_", "\\_").gsub(/ /, "_")
|
114
116
|
else hash
|
115
117
|
end
|
116
118
|
end
|
@@ -165,7 +167,7 @@ module Relaton
|
|
165
167
|
t = nametemplate_split(template)
|
166
168
|
|
167
169
|
mid = (1..size - 2).each_with_object([]) do |i, m|
|
168
|
-
m << t[1].gsub(
|
170
|
+
m << t[1].gsub("[1]", "[#{i}]")
|
169
171
|
end
|
170
172
|
t[1] = mid.join
|
171
173
|
t[2].gsub!(/\[\d+\]/, "[#{size - 1}]")
|
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.5.
|
4
|
+
version: 0.5.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-08-
|
11
|
+
date: 2023-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|