dato 0.7.13 → 0.7.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Rakefile +4 -1
- data/dato.gemspec +2 -1
- data/lib/dato/api_client.rb +46 -18
- data/lib/dato/json_api_serializer.rb +10 -4
- data/lib/dato/local/field_type/file.rb +41 -3
- data/lib/dato/local/field_type/upload_id.rb +1 -1
- data/lib/dato/local/loader.rb +1 -1
- data/lib/dato/upload/create_upload_path.rb +1 -1
- data/lib/dato/version.rb +1 -1
- metadata +24 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43d5a65257051385168de064d1b162bbd0bc5d0ef8523a2079d2f9051dc6b509
|
4
|
+
data.tar.gz: 23a9293ed05685fd635de711d3b98084dcb9efc92735d0e379b7640798e8a959
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd30a74fe816ab8d4a3683d62ddfecd1ce350f94c94a4f4bbbcaaabaf88a94677f939c8d7cfaf0c9769040d03adc7da829229d5e8762610491ca7d199244e082
|
7
|
+
data.tar.gz: 47ebdc307a2c8ae71cd28f0b7ce60c4e2f14802951bbed9b90bd93ff359bd41c240dc3dc4c834febafd32ebe81b4f735f05f9d01a2f7ea245ad9df4324938501
|
data/CHANGELOG.md
CHANGED
data/Rakefile
CHANGED
data/dato.gemspec
CHANGED
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.add_development_dependency 'rubocop'
|
31
31
|
spec.add_development_dependency 'coveralls'
|
32
32
|
spec.add_development_dependency 'pry'
|
33
|
+
spec.add_development_dependency 'pry-byebug'
|
33
34
|
spec.add_development_dependency 'front_matter_parser'
|
34
35
|
|
35
36
|
spec.add_runtime_dependency 'faraday', ['>= 0.9.0']
|
@@ -37,7 +38,7 @@ Gem::Specification.new do |spec|
|
|
37
38
|
spec.add_runtime_dependency 'activesupport', ['>= 4.2.7']
|
38
39
|
spec.add_runtime_dependency 'addressable'
|
39
40
|
spec.add_runtime_dependency 'thor'
|
40
|
-
spec.add_runtime_dependency 'imgix', ['
|
41
|
+
spec.add_runtime_dependency 'imgix', ['~> 4']
|
41
42
|
spec.add_runtime_dependency 'toml'
|
42
43
|
spec.add_runtime_dependency 'cacert'
|
43
44
|
spec.add_runtime_dependency 'dotenv'
|
data/lib/dato/api_client.rb
CHANGED
@@ -33,27 +33,54 @@ module Dato
|
|
33
33
|
@extra_headers = options[:extra_headers] || {}
|
34
34
|
end
|
35
35
|
|
36
|
-
|
37
|
-
|
36
|
+
define_singleton_method(:subdomain) do
|
37
|
+
subdomain
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def respond_to_missing?(method, include_private = false)
|
43
|
+
json_schema.definitions.each do |type, obj|
|
44
|
+
is_collection = obj.links.select { |x| x.rel == 'instances' }.any?
|
45
|
+
namespace = is_collection ? type.pluralize : type
|
46
|
+
if method.to_s === namespace
|
47
|
+
return true
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
super
|
52
|
+
end
|
53
|
+
|
54
|
+
def method_missing(method, *args, &block)
|
55
|
+
json_schema.definitions.each do |type, obj|
|
56
|
+
is_collection = obj.links.select { |x| x.rel == 'instances' }.any?
|
57
|
+
namespace = is_collection ? type.pluralize : type
|
58
|
+
|
59
|
+
if method.to_s === namespace
|
60
|
+
instance_variable_set(
|
61
|
+
"@#{namespace}",
|
62
|
+
instance_variable_get("@#{namespace}") ||
|
63
|
+
Dato::Repo.new(self, type, obj)
|
64
|
+
)
|
65
|
+
|
66
|
+
return instance_variable_get("@#{namespace}")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
super
|
71
|
+
end
|
72
|
+
|
73
|
+
def json_schema
|
74
|
+
@json_schema ||= begin
|
38
75
|
response = Faraday.get(
|
39
|
-
"
|
76
|
+
# "http://#{subdomain}.lvh.me:3001/docs/#{subdomain}-hyperschema.json"
|
77
|
+
"#{base_url}/docs/#{self.class.subdomain}-hyperschema.json"
|
40
78
|
)
|
41
79
|
|
42
80
|
schema = JsonSchema.parse!(JSON.parse(response.body))
|
43
81
|
schema.expand_references!
|
44
82
|
|
45
|
-
schema
|
46
|
-
is_collection = obj.links.select { |x| x.rel == 'instances' }.any?
|
47
|
-
namespace = is_collection ? type.pluralize : type
|
48
|
-
|
49
|
-
define_method(namespace) do
|
50
|
-
instance_variable_set(
|
51
|
-
"@#{namespace}",
|
52
|
-
instance_variable_get("@#{namespace}") ||
|
53
|
-
Dato::Repo.new(self, type, obj)
|
54
|
-
)
|
55
|
-
end
|
56
|
-
end
|
83
|
+
schema
|
57
84
|
end
|
58
85
|
end
|
59
86
|
|
@@ -100,10 +127,11 @@ module Dato
|
|
100
127
|
sleep(1)
|
101
128
|
request(*args)
|
102
129
|
else
|
130
|
+
# puts body.inspect
|
131
|
+
# puts '===='
|
132
|
+
# puts error.message
|
133
|
+
# puts '===='
|
103
134
|
error = ApiError.new(e.response)
|
104
|
-
puts '===='
|
105
|
-
puts error.message
|
106
|
-
puts '===='
|
107
135
|
raise error
|
108
136
|
end
|
109
137
|
end
|
@@ -23,8 +23,10 @@ module Dato
|
|
23
23
|
data[:type] = type
|
24
24
|
data[:attributes] = serialized_attributes(resource)
|
25
25
|
|
26
|
-
|
27
|
-
|
26
|
+
serialized_relationships = serialized_relationships(resource)
|
27
|
+
|
28
|
+
if serialized_relationships
|
29
|
+
data[:relationships] = serialized_relationships
|
28
30
|
end
|
29
31
|
|
30
32
|
{ data: data }
|
@@ -82,7 +84,7 @@ module Dato
|
|
82
84
|
end
|
83
85
|
end
|
84
86
|
|
85
|
-
result
|
87
|
+
result.empty? ? nil : result
|
86
88
|
end
|
87
89
|
|
88
90
|
def attributes(resource)
|
@@ -110,7 +112,11 @@ module Dato
|
|
110
112
|
end
|
111
113
|
|
112
114
|
def required_relationships
|
113
|
-
|
115
|
+
if link.schema.properties['data'].required.include?("relationships")
|
116
|
+
(link_relationships.required || []).map(&:to_sym)
|
117
|
+
else
|
118
|
+
[]
|
119
|
+
end
|
114
120
|
end
|
115
121
|
|
116
122
|
def link_attributes
|
@@ -18,6 +18,7 @@ module Dato
|
|
18
18
|
v[:alt],
|
19
19
|
v[:title],
|
20
20
|
v[:custom_data],
|
21
|
+
v[:focal_point],
|
21
22
|
repo.site.entity.imgix_host
|
22
23
|
)
|
23
24
|
end
|
@@ -29,12 +30,14 @@ module Dato
|
|
29
30
|
alt,
|
30
31
|
title,
|
31
32
|
custom_data,
|
33
|
+
focal_point,
|
32
34
|
imgix_host
|
33
35
|
)
|
34
36
|
@upload = upload
|
35
37
|
@alt = alt
|
36
38
|
@title = title
|
37
39
|
@custom_data = custom_data
|
40
|
+
@focal_point = focal_point
|
38
41
|
@imgix_host = imgix_host
|
39
42
|
end
|
40
43
|
|
@@ -100,6 +103,12 @@ module Dato
|
|
100
103
|
@custom_data.merge(default_metadata.fetch('custom_data', {}))
|
101
104
|
end
|
102
105
|
|
106
|
+
def focal_point
|
107
|
+
default_metadata = @upload.default_field_metadata.deep_stringify_keys
|
108
|
+
.fetch(I18n.locale.to_s, {})
|
109
|
+
@focal_point || default_metadata['focal_point']
|
110
|
+
end
|
111
|
+
|
103
112
|
def tags
|
104
113
|
@upload.tags
|
105
114
|
end
|
@@ -210,14 +219,42 @@ module Dato
|
|
210
219
|
|
211
220
|
def file
|
212
221
|
Imgix::Client.new(
|
213
|
-
|
222
|
+
domain: @imgix_host,
|
214
223
|
secure: true,
|
215
224
|
include_library_param: false
|
216
225
|
).path(path)
|
217
226
|
end
|
218
227
|
|
219
|
-
def url(
|
220
|
-
|
228
|
+
def url(query = {})
|
229
|
+
query.deep_stringify_keys!
|
230
|
+
|
231
|
+
if focal_point &&
|
232
|
+
query["fit"] == "crop" &&
|
233
|
+
(query["h"] || query["height"]) &&
|
234
|
+
(query["w"] || query["width"]) &&
|
235
|
+
[nil, "focalpoint"].include?(query["crop"]) &&
|
236
|
+
query["fp-x"].nil? &&
|
237
|
+
query["fp-y"].nil?
|
238
|
+
|
239
|
+
query.merge!(
|
240
|
+
"crop" => "focalpoint",
|
241
|
+
"fp-x" => focal_point[:x],
|
242
|
+
"fp-y" => focal_point[:y],
|
243
|
+
)
|
244
|
+
end
|
245
|
+
|
246
|
+
file.to_url(query)
|
247
|
+
end
|
248
|
+
|
249
|
+
def lqip_data_url(opts = {})
|
250
|
+
@imgix_host != "www.datocms-assets.com" and
|
251
|
+
raise "#lqip_data_url can only be used with www.datocms-assets.com domain"
|
252
|
+
|
253
|
+
response = Faraday.get(file.to_url(opts.merge(lqip: "blurhash")))
|
254
|
+
|
255
|
+
if response.status == 200
|
256
|
+
"data:image/jpeg;base64,#{Base64.strict_encode64(response.body)}"
|
257
|
+
end
|
221
258
|
end
|
222
259
|
|
223
260
|
def to_hash(*_args)
|
@@ -230,6 +267,7 @@ module Dato
|
|
230
267
|
alt: alt,
|
231
268
|
title: title,
|
232
269
|
custom_data: custom_data,
|
270
|
+
focal_point: focal_point,
|
233
271
|
url: url,
|
234
272
|
copyright: copyright,
|
235
273
|
tags: tags,
|
data/lib/dato/local/loader.rb
CHANGED
data/lib/dato/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dato
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefano Verna
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -150,6 +150,20 @@ dependencies:
|
|
150
150
|
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: pry-byebug
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
153
167
|
- !ruby/object:Gem::Dependency
|
154
168
|
name: front_matter_parser
|
155
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -238,16 +252,16 @@ dependencies:
|
|
238
252
|
name: imgix
|
239
253
|
requirement: !ruby/object:Gem::Requirement
|
240
254
|
requirements:
|
241
|
-
- - "
|
255
|
+
- - "~>"
|
242
256
|
- !ruby/object:Gem::Version
|
243
|
-
version:
|
257
|
+
version: '4'
|
244
258
|
type: :runtime
|
245
259
|
prerelease: false
|
246
260
|
version_requirements: !ruby/object:Gem::Requirement
|
247
261
|
requirements:
|
248
|
-
- - "
|
262
|
+
- - "~>"
|
249
263
|
- !ruby/object:Gem::Version
|
250
|
-
version:
|
264
|
+
version: '4'
|
251
265
|
- !ruby/object:Gem::Dependency
|
252
266
|
name: toml
|
253
267
|
requirement: !ruby/object:Gem::Requirement
|
@@ -450,7 +464,7 @@ homepage: https://github.com/datocms/ruby-datocms-client
|
|
450
464
|
licenses:
|
451
465
|
- MIT
|
452
466
|
metadata: {}
|
453
|
-
post_install_message:
|
467
|
+
post_install_message:
|
454
468
|
rdoc_options: []
|
455
469
|
require_paths:
|
456
470
|
- lib
|
@@ -465,9 +479,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
465
479
|
- !ruby/object:Gem::Version
|
466
480
|
version: '0'
|
467
481
|
requirements: []
|
468
|
-
rubyforge_project:
|
482
|
+
rubyforge_project:
|
469
483
|
rubygems_version: 2.7.6
|
470
|
-
signing_key:
|
484
|
+
signing_key:
|
471
485
|
specification_version: 4
|
472
486
|
summary: Ruby client for DatoCMS API
|
473
487
|
test_files: []
|