dato 0.7.10 → 0.7.17
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 +4 -4
- data/CHANGELOG.md +43 -0
- data/Rakefile +4 -1
- data/dato.gemspec +2 -1
- data/lib/dato.rb +1 -0
- data/lib/dato/api_client.rb +23 -23
- data/lib/dato/cli.rb +3 -0
- 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 +9 -2
- data/lib/dato/upload/create_upload_path.rb +1 -1
- data/lib/dato/utils/build_modular_block.rb +31 -0
- data/lib/dato/version.rb +1 -1
- metadata +25 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe8a9078fb6f9d6b37f6d9e371dbfcd417b2be9d2108395ad742a37b1f361262
|
4
|
+
data.tar.gz: 3466ff70f311f4c7208ff37ce20c2b2753cfd9eac05ac912cc42412748be3244
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23adcec27891f974552ee201cddc28b982579f849ffbaaaf88c4fad678460ce10effec7a52a65a4cd548253f79bfbe22c98b6f78caf8c95fb6dba3005b4eab3d
|
7
|
+
data.tar.gz: 32aea1391ce6f54ab64af0de2ec95619b7a3ece9644dfa98ed0b6bcefa819de797ea3b6b87741235b561a73aab952643cb9ecf47e7fae97cc9d323700f60360e
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,46 @@
|
|
1
|
+
# 0.7.16
|
2
|
+
|
3
|
+
Fixes bug when launching `dato dump --watch` together with the `environment` option.
|
4
|
+
|
5
|
+
# 0.7.13
|
6
|
+
|
7
|
+
Add option to pass a project's environment:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
require "dato"
|
11
|
+
client = Dato::Site::Client.new("YOUR-API-KEY", environment: 'sandbox-foobar')
|
12
|
+
```
|
13
|
+
|
14
|
+
# 0.7.12
|
15
|
+
|
16
|
+
Introduces `Dato::Utils::BuildModularBlock` class to help creating modular blocks.
|
17
|
+
|
18
|
+
An example usage can be:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
description = [
|
22
|
+
Dato::Utils::BuildModularBlock.build(
|
23
|
+
item_type: "1235",
|
24
|
+
name: "Best dog in the world",
|
25
|
+
year: "2020",
|
26
|
+
picture: picture
|
27
|
+
)
|
28
|
+
]
|
29
|
+
|
30
|
+
record = client.items.create(
|
31
|
+
item_type: "1234", # model ID
|
32
|
+
name: "Gigio",
|
33
|
+
description: description
|
34
|
+
)
|
35
|
+
```
|
36
|
+
|
37
|
+
Find more info [on the documentation](https://www.datocms.com/docs/content-management-api/resources/item/create).
|
38
|
+
|
39
|
+
# 0.7.11 (not released)
|
40
|
+
|
41
|
+
* Updated specs cassettes after `appeareance -> appearance` typo fix
|
42
|
+
* Some style changes
|
43
|
+
|
1
44
|
# 0.7.10
|
2
45
|
|
3
46
|
* Fixed SEO title retrieval. Now it fallbacks to default SEO title is item title is blank
|
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.rb
CHANGED
data/lib/dato/api_client.rb
CHANGED
@@ -20,7 +20,7 @@ module Dato
|
|
20
20
|
base.extend ClassMethods
|
21
21
|
|
22
22
|
base.class_eval do
|
23
|
-
attr_reader :token, :base_url, :schema, :extra_headers
|
23
|
+
attr_reader :token, :environment, :base_url, :schema, :extra_headers
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -29,27 +29,28 @@ module Dato
|
|
29
29
|
define_method(:initialize) do |token, options = {}|
|
30
30
|
@token = token
|
31
31
|
@base_url = options[:base_url] || "https://#{subdomain}.datocms.com"
|
32
|
+
@environment = options[:environment]
|
32
33
|
@extra_headers = options[:extra_headers] || {}
|
33
34
|
end
|
34
35
|
|
36
|
+
# FOR DEV
|
37
|
+
# "http://#{subdomain}.lvh.me:3001/docs/#{subdomain}-hyperschema.json"
|
35
38
|
response = Faraday.get(
|
36
|
-
# FOR DEV
|
37
|
-
# "http://#{subdomain}.lvh.me:3001/docs/#{subdomain}-hyperschema.json"
|
38
39
|
"https://#{subdomain}.datocms.com/docs/#{subdomain}-hyperschema.json"
|
39
40
|
)
|
40
41
|
|
41
42
|
schema = JsonSchema.parse!(JSON.parse(response.body))
|
42
43
|
schema.expand_references!
|
43
44
|
|
44
|
-
schema.definitions.each do |type,
|
45
|
-
is_collection =
|
45
|
+
schema.definitions.each do |type, obj|
|
46
|
+
is_collection = obj.links.select { |x| x.rel == 'instances' }.any?
|
46
47
|
namespace = is_collection ? type.pluralize : type
|
47
48
|
|
48
49
|
define_method(namespace) do
|
49
50
|
instance_variable_set(
|
50
51
|
"@#{namespace}",
|
51
52
|
instance_variable_get("@#{namespace}") ||
|
52
|
-
Dato::Repo.new(self, type,
|
53
|
+
Dato::Repo.new(self, type, obj)
|
53
54
|
)
|
54
55
|
end
|
55
56
|
end
|
@@ -76,16 +77,10 @@ module Dato
|
|
76
77
|
method, absolute_path, body, params = args
|
77
78
|
|
78
79
|
response = connection.send(method, absolute_path, body) do |c|
|
79
|
-
if params
|
80
|
-
c.params = params
|
81
|
-
end
|
80
|
+
c.params = params if params
|
82
81
|
end
|
83
82
|
|
84
|
-
if response.body.is_a?(Hash)
|
85
|
-
response.body.with_indifferent_access
|
86
|
-
else
|
87
|
-
nil
|
88
|
-
end
|
83
|
+
response.body.with_indifferent_access if response.body.is_a?(Hash)
|
89
84
|
rescue Faraday::SSLError => e
|
90
85
|
raise e if ENV['SSL_CERT_FILE'] == Cacert.pem
|
91
86
|
|
@@ -101,14 +96,15 @@ module Dato
|
|
101
96
|
sleep(to_wait + 1)
|
102
97
|
request(*args)
|
103
98
|
elsif e.response[:status] == 422 && batch_data_validation?(e.response)
|
104
|
-
puts
|
99
|
+
puts 'Validating items, waiting 1 second and retrying...'
|
105
100
|
sleep(1)
|
106
101
|
request(*args)
|
107
102
|
else
|
103
|
+
# puts body.inspect
|
104
|
+
# puts '===='
|
105
|
+
# puts error.message
|
106
|
+
# puts '===='
|
108
107
|
error = ApiError.new(e.response)
|
109
|
-
puts "===="
|
110
|
-
puts error.message
|
111
|
-
puts "===="
|
112
108
|
raise error
|
113
109
|
end
|
114
110
|
end
|
@@ -123,12 +119,12 @@ module Dato
|
|
123
119
|
end
|
124
120
|
|
125
121
|
return false unless body
|
126
|
-
return false unless body[
|
122
|
+
return false unless body['data']
|
127
123
|
|
128
|
-
body[
|
129
|
-
e[
|
124
|
+
body['data'].any? do |e|
|
125
|
+
e['attributes']['code'] == 'BATCH_DATA_VALIDATION_IN_PROGRESS'
|
130
126
|
end
|
131
|
-
rescue
|
127
|
+
rescue StandardError
|
132
128
|
false
|
133
129
|
end
|
134
130
|
|
@@ -141,9 +137,13 @@ module Dato
|
|
141
137
|
'X-Api-Version' => '3'
|
142
138
|
}
|
143
139
|
|
140
|
+
if environment
|
141
|
+
default_headers.merge!('X-Environment' => environment)
|
142
|
+
end
|
143
|
+
|
144
144
|
options = {
|
145
145
|
url: base_url,
|
146
|
-
headers: default_headers.merge(extra_headers)
|
146
|
+
headers: default_headers.merge(extra_headers)
|
147
147
|
}
|
148
148
|
|
149
149
|
@connection ||= Faraday.new(options) do |c|
|
data/lib/dato/cli.rb
CHANGED
@@ -11,8 +11,10 @@ module Dato
|
|
11
11
|
desc 'dump', 'dumps DatoCMS content into local files'
|
12
12
|
option :config, default: 'dato.config.rb'
|
13
13
|
option :token, default: ENV['DATO_API_TOKEN'], required: true
|
14
|
+
option :environment, type: :string, required: false
|
14
15
|
option :preview, default: false, type: :boolean
|
15
16
|
option :watch, default: false, type: :boolean
|
17
|
+
|
16
18
|
def dump
|
17
19
|
config_file = File.expand_path(options[:config])
|
18
20
|
watch_mode = options[:watch]
|
@@ -20,6 +22,7 @@ module Dato
|
|
20
22
|
|
21
23
|
client = Dato::Site::Client.new(
|
22
24
|
options[:token],
|
25
|
+
environment: options[:environment],
|
23
26
|
extra_headers: {
|
24
27
|
'X-Reason' => 'dump',
|
25
28
|
'X-SSG' => Dump::SsgDetector.new(Dir.pwd).detect
|
@@ -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
@@ -43,7 +43,13 @@ module Dato
|
|
43
43
|
|
44
44
|
return if pusher && pusher.connected
|
45
45
|
|
46
|
-
|
46
|
+
channel_name = if client.environment
|
47
|
+
"private-site-#{site_id}-environment-#{client.environment}"
|
48
|
+
else
|
49
|
+
"private-site-#{site_id}"
|
50
|
+
end
|
51
|
+
|
52
|
+
pusher.subscribe(channel_name)
|
47
53
|
|
48
54
|
bind_on_site_upsert(&block)
|
49
55
|
bind_on_item_destroy(&block)
|
@@ -66,7 +72,8 @@ module Dato
|
|
66
72
|
bind_on("site:upsert", block) do |data|
|
67
73
|
threads = [
|
68
74
|
Thread.new { Thread.current[:output] = site },
|
69
|
-
Thread.new { Thread.current[:output] = all_items }
|
75
|
+
Thread.new { Thread.current[:output] = all_items },
|
76
|
+
Thread.new { Thread.current[:output] = all_uploads }
|
70
77
|
]
|
71
78
|
|
72
79
|
results = threads.map do |t|
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dato/json_api_serializer'
|
4
|
+
|
5
|
+
module Dato
|
6
|
+
module Utils
|
7
|
+
module BuildModularBlock
|
8
|
+
def self.build(unserialized_body)
|
9
|
+
json_api_serializer = JsonApiSerializer.new('item', nil)
|
10
|
+
attributes = json_api_serializer.serialized_attributes(unserialized_body)
|
11
|
+
|
12
|
+
payload = {
|
13
|
+
type: 'item',
|
14
|
+
attributes: attributes,
|
15
|
+
relationships: {
|
16
|
+
item_type: {
|
17
|
+
data: {
|
18
|
+
id: unserialized_body[:item_type],
|
19
|
+
type: 'item_type',
|
20
|
+
},
|
21
|
+
},
|
22
|
+
},
|
23
|
+
}
|
24
|
+
|
25
|
+
payload[:id] = unserialized_body[:id] if unserialized_body[:id]
|
26
|
+
|
27
|
+
payload
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
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.17
|
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-07 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
|
@@ -429,6 +443,7 @@ files:
|
|
429
443
|
- lib/dato/upload/create_upload_path.rb
|
430
444
|
- lib/dato/upload/file.rb
|
431
445
|
- lib/dato/upload/image.rb
|
446
|
+
- lib/dato/utils/build_modular_block.rb
|
432
447
|
- lib/dato/utils/favicon_tags_builder.rb
|
433
448
|
- lib/dato/utils/locale_value.rb
|
434
449
|
- lib/dato/utils/meta_tags/article_modified_time.rb
|
@@ -449,7 +464,7 @@ homepage: https://github.com/datocms/ruby-datocms-client
|
|
449
464
|
licenses:
|
450
465
|
- MIT
|
451
466
|
metadata: {}
|
452
|
-
post_install_message:
|
467
|
+
post_install_message:
|
453
468
|
rdoc_options: []
|
454
469
|
require_paths:
|
455
470
|
- lib
|
@@ -464,9 +479,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
464
479
|
- !ruby/object:Gem::Version
|
465
480
|
version: '0'
|
466
481
|
requirements: []
|
467
|
-
rubyforge_project:
|
482
|
+
rubyforge_project:
|
468
483
|
rubygems_version: 2.7.6
|
469
|
-
signing_key:
|
484
|
+
signing_key:
|
470
485
|
specification_version: 4
|
471
486
|
summary: Ruby client for DatoCMS API
|
472
487
|
test_files: []
|