dato 0.7.15 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +42 -5
- data/.travis.yml +1 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +1 -1
- data/Rakefile +2 -2
- data/TODO.md +28 -0
- data/bin/console +3 -3
- data/bin/rspec +6 -6
- data/dato.gemspec +1 -1
- data/exe/dato +3 -3
- data/lib/dato.rb +8 -8
- data/lib/dato/account/client.rb +2 -2
- data/lib/dato/api_client.rb +67 -44
- data/lib/dato/api_error.rb +10 -13
- data/lib/dato/cli.rb +18 -18
- data/lib/dato/dump/dsl/add_to_data_file.rb +1 -1
- data/lib/dato/dump/dsl/create_data_file.rb +1 -1
- data/lib/dato/dump/dsl/create_post.rb +1 -1
- data/lib/dato/dump/dsl/directory.rb +4 -4
- data/lib/dato/dump/dsl/root.rb +7 -7
- data/lib/dato/dump/format.rb +3 -3
- data/lib/dato/dump/format/json.rb +1 -1
- data/lib/dato/dump/format/toml.rb +6 -6
- data/lib/dato/dump/format/yaml.rb +3 -3
- data/lib/dato/dump/operation/add_to_data_file.rb +4 -4
- data/lib/dato/dump/operation/create_data_file.rb +3 -3
- data/lib/dato/dump/operation/create_post.rb +5 -6
- data/lib/dato/dump/operation/directory.rb +1 -1
- data/lib/dato/dump/runner.rb +5 -5
- data/lib/dato/dump/ssg_detector.rb +18 -20
- data/lib/dato/json_api_deserializer.rb +15 -16
- data/lib/dato/json_api_serializer.rb +39 -28
- data/lib/dato/json_schema_relationships.rb +19 -23
- data/lib/dato/json_schema_type.rb +47 -0
- data/lib/dato/local/entities_repo.rb +3 -3
- data/lib/dato/local/field_type/color.rb +11 -7
- data/lib/dato/local/field_type/file.rb +18 -24
- data/lib/dato/local/field_type/gallery.rb +1 -1
- data/lib/dato/local/field_type/global_seo.rb +4 -7
- data/lib/dato/local/field_type/lat_lon.rb +1 -1
- data/lib/dato/local/field_type/seo.rb +1 -1
- data/lib/dato/local/field_type/structured_text.rb +63 -0
- data/lib/dato/local/field_type/theme.rb +2 -2
- data/lib/dato/local/field_type/upload_id.rb +5 -5
- data/lib/dato/local/field_type/video.rb +9 -15
- data/lib/dato/local/item.rb +13 -12
- data/lib/dato/local/items_repo.rb +12 -18
- data/lib/dato/local/json_api_entity.rb +4 -3
- data/lib/dato/local/loader.rb +31 -32
- data/lib/dato/local/site.rb +5 -4
- data/lib/dato/paginator.rb +4 -4
- data/lib/dato/repo.rb +23 -30
- data/lib/dato/site/client.rb +5 -5
- data/lib/dato/upload/create_upload_path.rb +7 -10
- data/lib/dato/upload/file.rb +3 -3
- data/lib/dato/upload/image.rb +1 -1
- data/lib/dato/utils/build_modular_block.rb +4 -4
- data/lib/dato/utils/favicon_tags_builder.rb +10 -10
- data/lib/dato/utils/locale_value.rb +1 -1
- data/lib/dato/utils/meta_tags/article_modified_time.rb +3 -3
- data/lib/dato/utils/meta_tags/article_publisher.rb +2 -2
- data/lib/dato/utils/meta_tags/base.rb +6 -6
- data/lib/dato/utils/meta_tags/description.rb +4 -4
- data/lib/dato/utils/meta_tags/image.rb +4 -5
- data/lib/dato/utils/meta_tags/og_locale.rb +2 -2
- data/lib/dato/utils/meta_tags/og_site_name.rb +2 -2
- data/lib/dato/utils/meta_tags/og_type.rb +3 -3
- data/lib/dato/utils/meta_tags/robots.rb +2 -2
- data/lib/dato/utils/meta_tags/title.rb +6 -6
- data/lib/dato/utils/meta_tags/twitter_card.rb +2 -2
- data/lib/dato/utils/meta_tags/twitter_site.rb +2 -2
- data/lib/dato/utils/seo_tags_builder.rb +12 -12
- data/lib/dato/version.rb +1 -1
- metadata +9 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2fa3f3032c3681e2bf710b69ffe75eec9b47a27a494e63943909b91500785cb6
|
4
|
+
data.tar.gz: f5ee2896a63dab9a457c94d612fcd285544487df3c915d2dccc14951a4c304d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e61ffbd1f842f24bd2d28f0dfdf2b5bfcd835b94ba0081bc01e3338a7768838683e801e02623988ab7f8e7e251b275c6cd7ce29d317bb17d9898e63876ee0d8
|
7
|
+
data.tar.gz: 3914e863434597f8a29fe9379d881e149e970013363890619624eb6201e2b6ae1056d04340429d10472c96735b9ceb7193cb6e2509f1dc0dfcd28e568dfb4fe3
|
data/.rubocop.yml
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
|
2
2
|
AllCops:
|
3
|
-
TargetRubyVersion: 2.
|
3
|
+
TargetRubyVersion: 2.5
|
4
|
+
NewCops: enable
|
4
5
|
|
5
6
|
Exclude:
|
6
7
|
- "dato.gemspec"
|
@@ -11,9 +12,27 @@ Style/SafeNavigation:
|
|
11
12
|
Style/Documentation:
|
12
13
|
Enabled: false
|
13
14
|
|
15
|
+
Style/GuardClause:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
Naming/PredicateName:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Style/MissingRespondToMissing:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
Style/EvalWithLocation:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
Metrics/BlockNesting:
|
28
|
+
Enabled: false
|
29
|
+
|
14
30
|
Metrics/MethodLength:
|
15
31
|
Enabled: false
|
16
32
|
|
33
|
+
Metrics/BlockLength:
|
34
|
+
Enabled: false
|
35
|
+
|
17
36
|
Metrics/ClassLength:
|
18
37
|
Enabled: false
|
19
38
|
|
@@ -21,15 +40,15 @@ Metrics/ModuleLength:
|
|
21
40
|
Enabled: false
|
22
41
|
|
23
42
|
Metrics/CyclomaticComplexity:
|
24
|
-
|
43
|
+
Enabled: false
|
25
44
|
|
26
45
|
Metrics/AbcSize:
|
27
|
-
|
46
|
+
Enabled: false
|
28
47
|
|
29
48
|
Metrics/PerceivedComplexity:
|
30
|
-
|
49
|
+
Enabled: false
|
31
50
|
|
32
|
-
|
51
|
+
Layout/LineLength:
|
33
52
|
Exclude:
|
34
53
|
- "spec/**/*"
|
35
54
|
- "lib/dato/site/repo/*"
|
@@ -40,3 +59,21 @@ Metrics/LineLength:
|
|
40
59
|
Metrics/ParameterLists:
|
41
60
|
Exclude:
|
42
61
|
- "lib/dato/local/field_type/*"
|
62
|
+
|
63
|
+
Style/TrailingCommaInArrayLiteral:
|
64
|
+
EnforcedStyleForMultiline: comma
|
65
|
+
|
66
|
+
Style/TrailingCommaInArguments:
|
67
|
+
EnforcedStyleForMultiline: comma
|
68
|
+
|
69
|
+
Style/TrailingCommaInHashLiteral:
|
70
|
+
EnforcedStyleForMultiline: comma
|
71
|
+
|
72
|
+
Style/AndOr:
|
73
|
+
EnforcedStyle: conditionals
|
74
|
+
|
75
|
+
Style/StringLiterals:
|
76
|
+
EnforcedStyle: double_quotes
|
77
|
+
|
78
|
+
Style/StringLiteralsInInterpolation:
|
79
|
+
EnforcedStyle: double_quotes
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/Rakefile
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/bin/console
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require
|
5
|
-
require
|
4
|
+
require "bundler/setup"
|
5
|
+
require "dato"
|
6
6
|
|
7
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
8
8
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -11,5 +11,5 @@ require 'dato'
|
|
11
11
|
# require "pry"
|
12
12
|
# Pry.start
|
13
13
|
|
14
|
-
require
|
14
|
+
require "irb"
|
15
15
|
IRB.start
|
data/bin/rspec
CHANGED
@@ -8,11 +8,11 @@
|
|
8
8
|
# this file is here to facilitate running it.
|
9
9
|
#
|
10
10
|
|
11
|
-
require
|
12
|
-
ENV[
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
13
|
Pathname.new(__FILE__).realpath)
|
14
14
|
|
15
|
-
bundle_binstub = File.expand_path(
|
15
|
+
bundle_binstub = File.expand_path("bundle", __dir__)
|
16
16
|
|
17
17
|
if File.file?(bundle_binstub)
|
18
18
|
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
@@ -23,7 +23,7 @@ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
require
|
27
|
-
require
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
28
|
|
29
|
-
load Gem.bin_path(
|
29
|
+
load Gem.bin_path("rspec-core", "rspec")
|
data/dato.gemspec
CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency 'rake'
|
25
25
|
spec.add_development_dependency 'rspec'
|
26
26
|
spec.add_development_dependency 'rubyzip'
|
27
|
-
spec.add_development_dependency 'simplecov'
|
27
|
+
spec.add_development_dependency 'simplecov', '~> 0.17.0'
|
28
28
|
spec.add_development_dependency 'vcr'
|
29
29
|
spec.add_development_dependency 'webmock'
|
30
30
|
spec.add_development_dependency 'rubocop'
|
data/exe/dato
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
$LOAD_PATH.unshift File.expand_path(
|
4
|
+
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
|
5
5
|
|
6
|
-
require
|
6
|
+
require "dotenv"
|
7
7
|
Dotenv.load
|
8
8
|
|
9
|
-
require
|
9
|
+
require "dato"
|
10
10
|
Dato::Cli.start(ARGV)
|
data/lib/dato.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "dato/version"
|
4
4
|
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
5
|
+
require "dato/site/client"
|
6
|
+
require "dato/account/client"
|
7
|
+
require "dato/local/site"
|
8
|
+
require "dato/cli"
|
9
|
+
require "dato/utils/seo_tags_builder"
|
10
|
+
require "dato/utils/favicon_tags_builder"
|
11
|
+
require "dato/utils/build_modular_block"
|
12
12
|
|
13
13
|
module Dato
|
14
14
|
end
|
data/lib/dato/account/client.rb
CHANGED
data/lib/dato/api_client.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
3
|
+
require "faraday"
|
4
|
+
require "faraday_middleware"
|
5
|
+
require "json"
|
6
|
+
require "json_schema"
|
7
|
+
require "active_support/core_ext/hash/indifferent_access"
|
8
|
+
require "active_support/inflector"
|
9
9
|
|
10
|
-
require
|
11
|
-
require
|
10
|
+
require "dato/version"
|
11
|
+
require "dato/repo"
|
12
12
|
|
13
|
-
require
|
13
|
+
require "dato/api_error"
|
14
14
|
|
15
|
-
require
|
15
|
+
require "cacert"
|
16
16
|
|
17
17
|
module Dato
|
18
18
|
module ApiClient
|
@@ -33,27 +33,52 @@ 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
|
+
return true if method.to_s == namespace
|
47
|
+
end
|
48
|
+
|
49
|
+
super
|
50
|
+
end
|
51
|
+
|
52
|
+
def method_missing(method, *args, &block)
|
53
|
+
json_schema.definitions.each do |type, obj|
|
54
|
+
is_collection = obj.links.select { |x| x.rel == "instances" }.any?
|
55
|
+
namespace = is_collection ? type.pluralize : type
|
56
|
+
|
57
|
+
next unless method.to_s == namespace
|
58
|
+
|
59
|
+
instance_variable_set(
|
60
|
+
"@#{namespace}",
|
61
|
+
instance_variable_get("@#{namespace}") ||
|
62
|
+
Dato::Repo.new(self, type, obj),
|
63
|
+
)
|
64
|
+
|
65
|
+
return instance_variable_get("@#{namespace}")
|
66
|
+
end
|
67
|
+
|
68
|
+
super
|
69
|
+
end
|
70
|
+
|
71
|
+
def json_schema
|
72
|
+
@json_schema ||= begin
|
38
73
|
response = Faraday.get(
|
39
|
-
"
|
74
|
+
# "http://#{subdomain}.lvh.me:3001/docs/#{subdomain}-hyperschema.json"
|
75
|
+
"#{base_url}/docs/#{self.class.subdomain}-hyperschema.json",
|
40
76
|
)
|
41
77
|
|
42
78
|
schema = JsonSchema.parse!(JSON.parse(response.body))
|
43
79
|
schema.expand_references!
|
44
80
|
|
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
|
81
|
+
schema
|
57
82
|
end
|
58
83
|
end
|
59
84
|
|
@@ -82,7 +107,7 @@ module Dato
|
|
82
107
|
|
83
108
|
response.body.with_indifferent_access if response.body.is_a?(Hash)
|
84
109
|
rescue Faraday::SSLError => e
|
85
|
-
raise e if ENV[
|
110
|
+
raise e if ENV["SSL_CERT_FILE"] == Cacert.pem
|
86
111
|
|
87
112
|
Cacert.set_in_env
|
88
113
|
request(*args)
|
@@ -91,12 +116,12 @@ module Dato
|
|
91
116
|
raise e
|
92
117
|
rescue Faraday::ClientError => e
|
93
118
|
if e.response[:status] == 429
|
94
|
-
to_wait = e.response[:headers][
|
119
|
+
to_wait = e.response[:headers]["x-ratelimit-reset"].to_i
|
95
120
|
puts "Rate limit exceeded, waiting #{to_wait} seconds..."
|
96
121
|
sleep(to_wait + 1)
|
97
122
|
request(*args)
|
98
123
|
elsif e.response[:status] == 422 && batch_data_validation?(e.response)
|
99
|
-
puts
|
124
|
+
puts "Validating items, waiting 1 second and retrying..."
|
100
125
|
sleep(1)
|
101
126
|
request(*args)
|
102
127
|
else
|
@@ -113,16 +138,16 @@ module Dato
|
|
113
138
|
|
114
139
|
def batch_data_validation?(response)
|
115
140
|
body = begin
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
141
|
+
JSON.parse(response[:body])
|
142
|
+
rescue JSON::ParserError
|
143
|
+
nil
|
144
|
+
end
|
120
145
|
|
121
146
|
return false unless body
|
122
|
-
return false unless body[
|
147
|
+
return false unless body["data"]
|
123
148
|
|
124
|
-
body[
|
125
|
-
e[
|
149
|
+
body["data"].any? do |e|
|
150
|
+
e["attributes"]["code"] == "BATCH_DATA_VALIDATION_IN_PROGRESS"
|
126
151
|
end
|
127
152
|
rescue StandardError
|
128
153
|
false
|
@@ -130,20 +155,18 @@ module Dato
|
|
130
155
|
|
131
156
|
def connection
|
132
157
|
default_headers = {
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
158
|
+
"Accept" => "application/json",
|
159
|
+
"Content-Type" => "application/json",
|
160
|
+
"Authorization" => "Bearer #{@token}",
|
161
|
+
"User-Agent" => "ruby-client v#{Dato::VERSION}",
|
162
|
+
"X-Api-Version" => "3",
|
138
163
|
}
|
139
164
|
|
140
|
-
if environment
|
141
|
-
default_headers.merge!('X-Environment' => environment)
|
142
|
-
end
|
165
|
+
default_headers.merge!("X-Environment" => environment) if environment
|
143
166
|
|
144
167
|
options = {
|
145
168
|
url: base_url,
|
146
|
-
headers: default_headers.merge(extra_headers)
|
169
|
+
headers: default_headers.merge(extra_headers),
|
147
170
|
}
|
148
171
|
|
149
172
|
@connection ||= Faraday.new(options) do |c|
|
data/lib/dato/api_error.rb
CHANGED
@@ -2,25 +2,22 @@
|
|
2
2
|
|
3
3
|
module Dato
|
4
4
|
class ApiError < StandardError
|
5
|
-
attr_reader :response
|
5
|
+
attr_reader :response, :body
|
6
6
|
|
7
7
|
def initialize(response)
|
8
|
-
|
9
|
-
end
|
8
|
+
body = JSON.parse(response[:body]) if response[:body]
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
'DatoCMS API Error',
|
10
|
+
message = [
|
11
|
+
"DatoCMS API Error",
|
14
12
|
"Status: #{response[:status]}",
|
15
|
-
|
16
|
-
JSON.pretty_generate(body)
|
13
|
+
"Response:",
|
14
|
+
JSON.pretty_generate(body),
|
17
15
|
].join("\n")
|
18
|
-
end
|
19
16
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
17
|
+
super(message)
|
18
|
+
|
19
|
+
@response = response
|
20
|
+
@body = body
|
24
21
|
end
|
25
22
|
end
|
26
23
|
end
|