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: ff9e0dafe6ba6d6df3cd7f3e98057a96400abe99c90e8f8a14525b18d019d673
4
- data.tar.gz: 450df19a0aec2275174c164559838023a977ffdfb435f0e07730081c46f4bcfb
3
+ metadata.gz: 4a59266f60d60c8d152141f675eac858ef9f9b81e4c8d9ac2bfe9dd158db148d
4
+ data.tar.gz: 40d269013ae823a85f21c335b7157e13c6062572e6e06190e6a06688b5508061
5
5
  SHA512:
6
- metadata.gz: 1f408ad815ea069f7bf8eca30461eaa1965f6303e57a37698d66135159d70e93bcc90ffaf5f49bb3dc173a4e689e7d5090baa60b510aca95b5fe2d50cf0bb196
7
- data.tar.gz: 070304e5689852b644ff5d072e18d7354e5d274196afa4b1f85f89e3edfb865c93642bcce1bd18a9d195217e9ec1cbe1a63782549382308ee67632a1d9dcc108
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
@@ -109,7 +109,7 @@ module Relaton
109
109
  ret = date.detect { |x| x.type == t } and
110
110
  return ret
111
111
  end
112
- date.first
112
+ date.reject { |x| x.type == "accessed" }.first
113
113
  end
114
114
 
115
115
  # year-only
@@ -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(/\t/, " ")
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(/_/, "\\_").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(/\[1\]/, "[#{i}]")
170
+ m << t[1].gsub("[1]", "[#{i}]")
169
171
  end
170
172
  t[1] = mid.join
171
173
  t[2].gsub!(/\[\d+\]/, "[#{size - 1}]")
@@ -1,5 +1,5 @@
1
1
  module Relaton
2
2
  module Render
3
- VERSION = "0.5.13".freeze
3
+ VERSION = "0.5.14".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.5.13
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-10 00:00:00.000000000 Z
11
+ date: 2023-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler