dato 0.7.14 → 0.8.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 +4 -4
- data/CHANGELOG.md +4 -0
- data/TODO.md +28 -0
- data/lib/dato/api_client.rb +46 -18
- data/lib/dato/json_api_serializer.rb +19 -11
- data/lib/dato/local/field_type/file.rb +29 -2
- data/lib/dato/local/field_type/structured_text.rb +69 -0
- 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 +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9777e0d266657c2dffa3e6651de719c8e24728e311bcb6ed745bc6a7a70d927a
|
4
|
+
data.tar.gz: 4d54c4e69249b7d3a30f9c289afe93f8f242c6026f8a62d7e6ae0e18ca8b8eb2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99432305cdb85e390e2435913840f7d2c6a7bf93e7f9b1bfe9eb2b7c87a99da18ecad696f8f73704fc3776f2799206161fc8b9174b5c2aedb0e74efae34fbe48
|
7
|
+
data.tar.gz: 8539feabd9684b8c3f8824da200ab28527072468914dd8cbfe25117807bd835250043f22348c0259ed3257781bf3ca9149512b963a78637b4f9e36b9b093485c
|
data/CHANGELOG.md
CHANGED
data/TODO.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
```ruby
|
2
|
+
StructuredTextRenderer.new(
|
3
|
+
foo.content,
|
4
|
+
adapter: Adapter.new(
|
5
|
+
render_text: lambda do |text|
|
6
|
+
text.gsub(/this/, "that")
|
7
|
+
end,
|
8
|
+
render_fragment: lambda do |children|
|
9
|
+
children.join("")
|
10
|
+
end,
|
11
|
+
render_node: lambda do |tagname, attrs, children|
|
12
|
+
# we could ActionView::Helpers::TagHelper
|
13
|
+
content_tag(tagname, children, attrs)
|
14
|
+
end,
|
15
|
+
)
|
16
|
+
custom_rules: {
|
17
|
+
heading: lambda do |node, children, adapter|
|
18
|
+
adapter.render_node("h#{node[:level] + 1}", {}, children)
|
19
|
+
end
|
20
|
+
},
|
21
|
+
render_link_to_record: lambda do |record, children, adapter|
|
22
|
+
end,
|
23
|
+
render_inline_record: lambda do |record, adapter|
|
24
|
+
end,
|
25
|
+
render_block: lambda do |record, adapter|
|
26
|
+
end
|
27
|
+
)
|
28
|
+
```
|
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,18 +84,20 @@ 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)
|
89
91
|
if type == 'item'
|
90
|
-
return resource.keys.
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
92
|
+
return resource.keys.reject do |key|
|
93
|
+
%i[
|
94
|
+
item_type
|
95
|
+
id
|
96
|
+
created_at
|
97
|
+
updated_at
|
98
|
+
creator
|
99
|
+
].include?(key.to_sym)
|
100
|
+
end
|
97
101
|
end
|
98
102
|
|
99
103
|
link_attributes['properties'].keys.map(&:to_sym)
|
@@ -110,7 +114,11 @@ module Dato
|
|
110
114
|
end
|
111
115
|
|
112
116
|
def required_relationships
|
113
|
-
|
117
|
+
if link.schema.properties['data'].required.include?("relationships")
|
118
|
+
(link_relationships.required || []).map(&:to_sym)
|
119
|
+
else
|
120
|
+
[]
|
121
|
+
end
|
114
122
|
end
|
115
123
|
|
116
124
|
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
|
@@ -216,8 +225,25 @@ module Dato
|
|
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)
|
221
247
|
end
|
222
248
|
|
223
249
|
def lqip_data_url(opts = {})
|
@@ -241,6 +267,7 @@ module Dato
|
|
241
267
|
alt: alt,
|
242
268
|
title: title,
|
243
269
|
custom_data: custom_data,
|
270
|
+
focal_point: focal_point,
|
244
271
|
url: url,
|
245
272
|
copyright: copyright,
|
246
273
|
tags: tags,
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Dato
|
4
|
+
module Local
|
5
|
+
module FieldType
|
6
|
+
class StructuredText
|
7
|
+
def self.parse(value, repo)
|
8
|
+
new(value, repo)
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(value, repo)
|
12
|
+
@value = value
|
13
|
+
@repo = repo
|
14
|
+
end
|
15
|
+
|
16
|
+
def value
|
17
|
+
@value
|
18
|
+
end
|
19
|
+
|
20
|
+
def blocks
|
21
|
+
find_all_nodes("block").map do |node|
|
22
|
+
@repo.find(node["item"])
|
23
|
+
end.uniq
|
24
|
+
end
|
25
|
+
|
26
|
+
def links
|
27
|
+
find_all_nodes(["inlineItem", "itemLink"]).map do |node|
|
28
|
+
@repo.find(node["item"])
|
29
|
+
end.uniq
|
30
|
+
end
|
31
|
+
|
32
|
+
def find_all_nodes(types)
|
33
|
+
if value.nil?
|
34
|
+
return []
|
35
|
+
end
|
36
|
+
|
37
|
+
types = Array(types)
|
38
|
+
result = []
|
39
|
+
|
40
|
+
visit(value["document"]) do |node|
|
41
|
+
if node.is_a?(Hash) && types.include?(node["type"])
|
42
|
+
result << node
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
result
|
47
|
+
end
|
48
|
+
|
49
|
+
def visit(node, &block)
|
50
|
+
if node.is_a?(Hash) && node["children"].is_a?(Array)
|
51
|
+
node["children"].each do |child|
|
52
|
+
visit(child, &block)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
block.call(node)
|
57
|
+
end
|
58
|
+
|
59
|
+
def to_hash(max_depth = 3, current_depth = 0)
|
60
|
+
{
|
61
|
+
value: value,
|
62
|
+
links: links.map { |item| item.to_hash(max_depth, current_depth) },
|
63
|
+
blocks: blocks.map { |item| item.to_hash(max_depth, current_depth) },
|
64
|
+
}
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
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.
|
4
|
+
version: 0.8.0
|
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:
|
11
|
+
date: 2021-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -380,6 +380,7 @@ files:
|
|
380
380
|
- LICENSE.txt
|
381
381
|
- README.md
|
382
382
|
- Rakefile
|
383
|
+
- TODO.md
|
383
384
|
- bin/console
|
384
385
|
- bin/rspec
|
385
386
|
- bin/setup
|
@@ -427,6 +428,7 @@ files:
|
|
427
428
|
- lib/dato/local/field_type/seo.rb
|
428
429
|
- lib/dato/local/field_type/slug.rb
|
429
430
|
- lib/dato/local/field_type/string.rb
|
431
|
+
- lib/dato/local/field_type/structured_text.rb
|
430
432
|
- lib/dato/local/field_type/text.rb
|
431
433
|
- lib/dato/local/field_type/theme.rb
|
432
434
|
- lib/dato/local/field_type/upload_id.rb
|
@@ -464,7 +466,7 @@ homepage: https://github.com/datocms/ruby-datocms-client
|
|
464
466
|
licenses:
|
465
467
|
- MIT
|
466
468
|
metadata: {}
|
467
|
-
post_install_message:
|
469
|
+
post_install_message:
|
468
470
|
rdoc_options: []
|
469
471
|
require_paths:
|
470
472
|
- lib
|
@@ -479,9 +481,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
479
481
|
- !ruby/object:Gem::Version
|
480
482
|
version: '0'
|
481
483
|
requirements: []
|
482
|
-
rubyforge_project:
|
484
|
+
rubyforge_project:
|
483
485
|
rubygems_version: 2.7.6
|
484
|
-
signing_key:
|
486
|
+
signing_key:
|
485
487
|
specification_version: 4
|
486
488
|
summary: Ruby client for DatoCMS API
|
487
489
|
test_files: []
|