dato 0.4.3 → 0.5.0
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 +5 -5
- data/.ruby-version +1 -1
- data/lib/dato/local/field_type/file.rb +33 -9
- data/lib/dato/local/field_type/seo.rb +1 -1
- data/lib/dato/local/loader.rb +9 -1
- data/lib/dato/local/site.rb +1 -1
- data/lib/dato/site/client.rb +2 -1
- data/lib/dato/upload/file.rb +24 -3
- data/lib/dato/upload/image.rb +1 -12
- data/lib/dato/utils/meta_tags/image.rb +2 -1
- data/lib/dato/version.rb +1 -1
- metadata +3 -4
- data/lib/dato/local/field_type/image.rb +0 -51
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8d26b49c17a15d3cf199eb8f61d41ff39ca047171c948fe3e9a8c399b333be9f
|
4
|
+
data.tar.gz: c106df7971a5a76deb4757f12dec298292d0d4210fa133dde8996fc2bc018f35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b79aa89dfa3390ed806c67dd1c22b8294b80087c482b68e0b041bf4e0d560dd515e72f87875bb81a9193a039d7420819f1a87eae29565d10d73c4da17d186f92
|
7
|
+
data.tar.gz: af030722407d485affdf563b368dd3963cad1c2e34a58f9f04574e32d12989db47122ad61d34e50ec19581ddc4d7e0346a7af0617a01b63eda5c37ed926a7ebd
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.5.0
|
@@ -5,22 +5,42 @@ module Dato
|
|
5
5
|
module Local
|
6
6
|
module FieldType
|
7
7
|
class File
|
8
|
-
attr_reader :path, :format, :size
|
8
|
+
attr_reader :path, :format, :size, :width, :height, :title, :alt
|
9
9
|
|
10
|
-
def self.parse(
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
10
|
+
def self.parse(upload_id, repo)
|
11
|
+
if upload_id
|
12
|
+
upload = repo.entities_repo.find_entity("upload", upload_id)
|
13
|
+
new(
|
14
|
+
upload.path,
|
15
|
+
upload.format,
|
16
|
+
upload.size,
|
17
|
+
upload.width,
|
18
|
+
upload.height,
|
19
|
+
upload.alt,
|
20
|
+
upload.title,
|
21
|
+
repo.site.entity.imgix_host
|
22
|
+
)
|
23
|
+
end
|
17
24
|
end
|
18
25
|
|
19
|
-
def initialize(
|
26
|
+
def initialize(
|
27
|
+
path,
|
28
|
+
format,
|
29
|
+
size,
|
30
|
+
width,
|
31
|
+
height,
|
32
|
+
alt,
|
33
|
+
title,
|
34
|
+
imgix_host
|
35
|
+
)
|
20
36
|
@path = path
|
21
37
|
@format = format
|
22
38
|
@size = size
|
23
39
|
@imgix_host = imgix_host
|
40
|
+
@width = width
|
41
|
+
@height = height
|
42
|
+
@alt = alt
|
43
|
+
@title = title
|
24
44
|
end
|
25
45
|
|
26
46
|
def file
|
@@ -39,6 +59,10 @@ module Dato
|
|
39
59
|
{
|
40
60
|
format: format,
|
41
61
|
size: size,
|
62
|
+
width: width,
|
63
|
+
height: height,
|
64
|
+
alt: alt,
|
65
|
+
title: title,
|
42
66
|
url: url
|
43
67
|
}
|
44
68
|
end
|
data/lib/dato/local/loader.rb
CHANGED
@@ -18,7 +18,7 @@ module Dato
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def load
|
21
|
-
@entities_repo = EntitiesRepo.new(site, all_items)
|
21
|
+
@entities_repo = EntitiesRepo.new(site, all_items, all_uploads)
|
22
22
|
@items_repo = ItemsRepo.new(@entities_repo)
|
23
23
|
end
|
24
24
|
|
@@ -36,6 +36,14 @@ module Dato
|
|
36
36
|
all_pages: true
|
37
37
|
)
|
38
38
|
end
|
39
|
+
|
40
|
+
def all_uploads
|
41
|
+
client.uploads.all(
|
42
|
+
{},
|
43
|
+
deserialize_response: false,
|
44
|
+
all_pages: true
|
45
|
+
)
|
46
|
+
end
|
39
47
|
end
|
40
48
|
end
|
41
49
|
end
|
data/lib/dato/local/site.rb
CHANGED
data/lib/dato/site/client.rb
CHANGED
@@ -94,7 +94,8 @@ module Dato
|
|
94
94
|
'Accept' => 'application/json',
|
95
95
|
'Content-Type' => 'application/json',
|
96
96
|
'Authorization' => "Bearer #{@token}",
|
97
|
-
'User-Agent' => "ruby-client v#{Dato::VERSION}"
|
97
|
+
'User-Agent' => "ruby-client v#{Dato::VERSION}",
|
98
|
+
'X-Api-Version' => "2"
|
98
99
|
)
|
99
100
|
}
|
100
101
|
|
data/lib/dato/upload/file.rb
CHANGED
@@ -3,10 +3,13 @@ require 'downloadr'
|
|
3
3
|
require 'tempfile'
|
4
4
|
require 'addressable'
|
5
5
|
require 'net/http'
|
6
|
+
require 'fastimage'
|
6
7
|
|
7
8
|
module Dato
|
8
9
|
module Upload
|
9
10
|
class File
|
11
|
+
IMAGE_FORMATS = %w(png jpg jpeg gif)
|
12
|
+
|
10
13
|
attr_reader :client, :source
|
11
14
|
|
12
15
|
def initialize(client, source)
|
@@ -56,15 +59,33 @@ module Dato
|
|
56
59
|
|
57
60
|
http.request(request)
|
58
61
|
|
59
|
-
|
62
|
+
uploads = client.uploads.create(
|
63
|
+
format_resource(upload_request)
|
64
|
+
)
|
65
|
+
|
66
|
+
uploads["id"]
|
60
67
|
end
|
61
68
|
|
62
69
|
def format_resource(upload_request)
|
63
|
-
|
70
|
+
extension = ::File.extname(::File.basename(file.path)).delete('.')
|
71
|
+
|
72
|
+
base_format = {
|
64
73
|
path: upload_request[:id],
|
65
74
|
size: ::File.size(file.path),
|
66
|
-
format:
|
75
|
+
format: extension
|
67
76
|
}
|
77
|
+
|
78
|
+
if IMAGE_FORMATS.include?(extension)
|
79
|
+
width, height = FastImage.size(file.path)
|
80
|
+
|
81
|
+
base_format.merge(
|
82
|
+
width: width,
|
83
|
+
height: height,
|
84
|
+
format: FastImage.type(file.path).to_s
|
85
|
+
)
|
86
|
+
else
|
87
|
+
base_format
|
88
|
+
end
|
68
89
|
end
|
69
90
|
end
|
70
91
|
end
|
data/lib/dato/upload/image.rb
CHANGED
@@ -1,19 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'dato/upload/file'
|
3
|
-
require 'fastimage'
|
4
3
|
|
5
4
|
module Dato
|
6
5
|
module Upload
|
7
|
-
|
8
|
-
def format_resource(upload_request)
|
9
|
-
width, height = FastImage.size(file.path)
|
10
|
-
|
11
|
-
super(upload_request).merge(
|
12
|
-
width: width,
|
13
|
-
height: height,
|
14
|
-
format: FastImage.type(file.path).to_s
|
15
|
-
)
|
16
|
-
end
|
17
|
-
end
|
6
|
+
Image = Dato::Upload::File
|
18
7
|
end
|
19
8
|
end
|
@@ -20,10 +20,11 @@ module Dato
|
|
20
20
|
|
21
21
|
def item_image
|
22
22
|
item && item.fields
|
23
|
-
.select { |field| field.field_type == '
|
23
|
+
.select { |field| field.field_type == 'file' }
|
24
24
|
.map { |field| item.send(field.api_key) }
|
25
25
|
.compact
|
26
26
|
.find do |image|
|
27
|
+
|
27
28
|
image.width && image.height &&
|
28
29
|
image.width >= 200 && image.height >= 200
|
29
30
|
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.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefano Verna
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -403,7 +403,6 @@ files:
|
|
403
403
|
- lib/dato/local/field_type/float.rb
|
404
404
|
- lib/dato/local/field_type/gallery.rb
|
405
405
|
- lib/dato/local/field_type/global_seo.rb
|
406
|
-
- lib/dato/local/field_type/image.rb
|
407
406
|
- lib/dato/local/field_type/integer.rb
|
408
407
|
- lib/dato/local/field_type/json.rb
|
409
408
|
- lib/dato/local/field_type/lat_lon.rb
|
@@ -474,7 +473,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
474
473
|
version: '0'
|
475
474
|
requirements: []
|
476
475
|
rubyforge_project:
|
477
|
-
rubygems_version: 2.
|
476
|
+
rubygems_version: 2.7.6
|
478
477
|
signing_key:
|
479
478
|
specification_version: 4
|
480
479
|
summary: Ruby client for DatoCMS API
|
@@ -1,51 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require 'dato/local/field_type/file'
|
3
|
-
|
4
|
-
module Dato
|
5
|
-
module Local
|
6
|
-
module FieldType
|
7
|
-
class Image < Dato::Local::FieldType::File
|
8
|
-
attr_reader :width, :height, :title, :alt
|
9
|
-
|
10
|
-
def self.parse(value, repo)
|
11
|
-
value && new(
|
12
|
-
value[:path],
|
13
|
-
value[:format],
|
14
|
-
value[:size],
|
15
|
-
value[:width],
|
16
|
-
value[:height],
|
17
|
-
value[:alt],
|
18
|
-
value[:title],
|
19
|
-
repo.site.entity.imgix_host
|
20
|
-
)
|
21
|
-
end
|
22
|
-
|
23
|
-
def initialize(
|
24
|
-
path,
|
25
|
-
format,
|
26
|
-
size,
|
27
|
-
width,
|
28
|
-
height,
|
29
|
-
alt,
|
30
|
-
title,
|
31
|
-
imgix_host
|
32
|
-
)
|
33
|
-
super(path, format, size, imgix_host)
|
34
|
-
@width = width
|
35
|
-
@height = height
|
36
|
-
@alt = alt
|
37
|
-
@title = title
|
38
|
-
end
|
39
|
-
|
40
|
-
def to_hash(*args)
|
41
|
-
super.merge(
|
42
|
-
width: width,
|
43
|
-
height: height,
|
44
|
-
alt: alt,
|
45
|
-
title: title
|
46
|
-
)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|