dato 0.7.14 → 0.8.0

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: ffe0429654722ca0165930dc29c1a0350bb386cd73b6c824d2d43cc0af8bb13f
4
- data.tar.gz: fc124f52acef1d95d507dce6a9c45fa7556b9c5a018b9f630fbd688282015eb7
3
+ metadata.gz: 9777e0d266657c2dffa3e6651de719c8e24728e311bcb6ed745bc6a7a70d927a
4
+ data.tar.gz: 4d54c4e69249b7d3a30f9c289afe93f8f242c6026f8a62d7e6ae0e18ca8b8eb2
5
5
  SHA512:
6
- metadata.gz: 7981652ff2a86c8f6081bbb3b7c4fa3d148ba2b159009e5528df476f3ee0517f95c98f7bb8f035c0d09e694f562b06d50a3df44910930a478df3676940508f77
7
- data.tar.gz: 396828391163788c25f77da2d01c576d6c4cbad8993dda40d97b7700cb1896c7426897613dc9cc40c99177d7cdc8846a382d8ca9e2f37f0152abf3ff82636efe
6
+ metadata.gz: 99432305cdb85e390e2435913840f7d2c6a7bf93e7f9b1bfe9eb2b7c87a99da18ecad696f8f73704fc3776f2799206161fc8b9174b5c2aedb0e74efae34fbe48
7
+ data.tar.gz: 8539feabd9684b8c3f8824da200ab28527072468914dd8cbfe25117807bd835250043f22348c0259ed3257781bf3ca9149512b963a78637b4f9e36b9b093485c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.7.16
2
+
3
+ Fixes bug when launching `dato dump --watch` together with the `environment` option.
4
+
1
5
  # 0.7.13
2
6
 
3
7
  Add option to pass a project's environment:
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
+ ```
@@ -33,27 +33,54 @@ module Dato
33
33
  @extra_headers = options[:extra_headers] || {}
34
34
  end
35
35
 
36
- # FOR DEV
37
- # "http://#{subdomain}.lvh.me:3001/docs/#{subdomain}-hyperschema.json"
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
- "https://#{subdomain}.datocms.com/docs/#{subdomain}-hyperschema.json"
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.definitions.each do |type, obj|
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
- if relationships.any?
27
- data[:relationships] = serialized_relationships(resource)
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.map(&:to_sym) - %i[
91
- item_type
92
- id
93
- created_at
94
- updated_at
95
- creator
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
- (link_relationships.required || []).map(&:to_sym)
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(opts = {})
220
- file.to_url(opts)
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
@@ -44,7 +44,7 @@ module Dato
44
44
  return if pusher && pusher.connected
45
45
 
46
46
  channel_name = if client.environment
47
- "private-site-#{site_id}-environment-#{environment}"
47
+ "private-site-#{site_id}-environment-#{client.environment}"
48
48
  else
49
49
  "private-site-#{site_id}"
50
50
  end
@@ -72,7 +72,7 @@ module Dato
72
72
  end
73
73
  connection.get(url).body
74
74
  rescue Faraday::Error => e
75
- puts "Error during uploading #{url}"
75
+ puts "Error during upload of #{url}: #{e.message}"
76
76
  raise e
77
77
  end
78
78
  end
data/lib/dato/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dato
4
- VERSION = '0.7.14'
4
+ VERSION = '0.8.0'
5
5
  end
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.14
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: 2020-09-07 00:00:00.000000000 Z
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: []