dato 0.8.0 → 0.8.1
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/.rubocop.yml +42 -5
- data/.travis.yml +1 -0
- data/Gemfile +1 -1
- data/Rakefile +2 -2
- 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 +39 -43
- 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 +30 -21
- 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 +4 -10
- 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 +30 -31
- 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 +7 -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/Gemfile
CHANGED
data/Rakefile
CHANGED
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
|
@@ -41,11 +41,9 @@ module Dato
|
|
41
41
|
|
42
42
|
def respond_to_missing?(method, include_private = false)
|
43
43
|
json_schema.definitions.each do |type, obj|
|
44
|
-
is_collection = obj.links.select { |x| x.rel ==
|
44
|
+
is_collection = obj.links.select { |x| x.rel == "instances" }.any?
|
45
45
|
namespace = is_collection ? type.pluralize : type
|
46
|
-
if method.to_s
|
47
|
-
return true
|
48
|
-
end
|
46
|
+
return true if method.to_s == namespace
|
49
47
|
end
|
50
48
|
|
51
49
|
super
|
@@ -53,18 +51,18 @@ module Dato
|
|
53
51
|
|
54
52
|
def method_missing(method, *args, &block)
|
55
53
|
json_schema.definitions.each do |type, obj|
|
56
|
-
is_collection = obj.links.select { |x| x.rel ==
|
54
|
+
is_collection = obj.links.select { |x| x.rel == "instances" }.any?
|
57
55
|
namespace = is_collection ? type.pluralize : type
|
58
56
|
|
59
|
-
|
60
|
-
instance_variable_set(
|
61
|
-
"@#{namespace}",
|
62
|
-
instance_variable_get("@#{namespace}") ||
|
63
|
-
Dato::Repo.new(self, type, obj)
|
64
|
-
)
|
57
|
+
next unless method.to_s == namespace
|
65
58
|
|
66
|
-
|
67
|
-
|
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}")
|
68
66
|
end
|
69
67
|
|
70
68
|
super
|
@@ -74,7 +72,7 @@ module Dato
|
|
74
72
|
@json_schema ||= begin
|
75
73
|
response = Faraday.get(
|
76
74
|
# "http://#{subdomain}.lvh.me:3001/docs/#{subdomain}-hyperschema.json"
|
77
|
-
"#{base_url}/docs/#{self.class.subdomain}-hyperschema.json"
|
75
|
+
"#{base_url}/docs/#{self.class.subdomain}-hyperschema.json",
|
78
76
|
)
|
79
77
|
|
80
78
|
schema = JsonSchema.parse!(JSON.parse(response.body))
|
@@ -109,7 +107,7 @@ module Dato
|
|
109
107
|
|
110
108
|
response.body.with_indifferent_access if response.body.is_a?(Hash)
|
111
109
|
rescue Faraday::SSLError => e
|
112
|
-
raise e if ENV[
|
110
|
+
raise e if ENV["SSL_CERT_FILE"] == Cacert.pem
|
113
111
|
|
114
112
|
Cacert.set_in_env
|
115
113
|
request(*args)
|
@@ -118,12 +116,12 @@ module Dato
|
|
118
116
|
raise e
|
119
117
|
rescue Faraday::ClientError => e
|
120
118
|
if e.response[:status] == 429
|
121
|
-
to_wait = e.response[:headers][
|
119
|
+
to_wait = e.response[:headers]["x-ratelimit-reset"].to_i
|
122
120
|
puts "Rate limit exceeded, waiting #{to_wait} seconds..."
|
123
121
|
sleep(to_wait + 1)
|
124
122
|
request(*args)
|
125
123
|
elsif e.response[:status] == 422 && batch_data_validation?(e.response)
|
126
|
-
puts
|
124
|
+
puts "Validating items, waiting 1 second and retrying..."
|
127
125
|
sleep(1)
|
128
126
|
request(*args)
|
129
127
|
else
|
@@ -140,16 +138,16 @@ module Dato
|
|
140
138
|
|
141
139
|
def batch_data_validation?(response)
|
142
140
|
body = begin
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
141
|
+
JSON.parse(response[:body])
|
142
|
+
rescue JSON::ParserError
|
143
|
+
nil
|
144
|
+
end
|
147
145
|
|
148
146
|
return false unless body
|
149
|
-
return false unless body[
|
147
|
+
return false unless body["data"]
|
150
148
|
|
151
|
-
body[
|
152
|
-
e[
|
149
|
+
body["data"].any? do |e|
|
150
|
+
e["attributes"]["code"] == "BATCH_DATA_VALIDATION_IN_PROGRESS"
|
153
151
|
end
|
154
152
|
rescue StandardError
|
155
153
|
false
|
@@ -157,20 +155,18 @@ module Dato
|
|
157
155
|
|
158
156
|
def connection
|
159
157
|
default_headers = {
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
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",
|
165
163
|
}
|
166
164
|
|
167
|
-
if environment
|
168
|
-
default_headers.merge!('X-Environment' => environment)
|
169
|
-
end
|
165
|
+
default_headers.merge!("X-Environment" => environment) if environment
|
170
166
|
|
171
167
|
options = {
|
172
168
|
url: base_url,
|
173
|
-
headers: default_headers.merge(extra_headers)
|
169
|
+
headers: default_headers.merge(extra_headers),
|
174
170
|
}
|
175
171
|
|
176
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
|
data/lib/dato/cli.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
3
|
+
require "thor"
|
4
|
+
require "dato/dump/runner"
|
5
|
+
require "dato/dump/ssg_detector"
|
6
|
+
require "listen"
|
7
7
|
module Dato
|
8
8
|
class Cli < Thor
|
9
|
-
package_name
|
9
|
+
package_name "DatoCMS"
|
10
10
|
|
11
|
-
desc
|
12
|
-
option :config, default:
|
13
|
-
option :token, default: ENV[
|
11
|
+
desc "dump", "dumps DatoCMS content into local files"
|
12
|
+
option :config, default: "dato.config.rb"
|
13
|
+
option :token, default: ENV["DATO_API_TOKEN"], required: true
|
14
14
|
option :environment, type: :string, required: false
|
15
15
|
option :preview, default: false, type: :boolean
|
16
16
|
option :watch, default: false, type: :boolean
|
@@ -24,12 +24,12 @@ module Dato
|
|
24
24
|
options[:token],
|
25
25
|
environment: options[:environment],
|
26
26
|
extra_headers: {
|
27
|
-
|
28
|
-
|
29
|
-
}
|
27
|
+
"X-Reason" => "dump",
|
28
|
+
"X-SSG" => Dump::SsgDetector.new(Dir.pwd).detect,
|
29
|
+
},
|
30
30
|
)
|
31
31
|
loader = Dato::Local::Loader.new(client, preview_mode)
|
32
|
-
print
|
32
|
+
print "Fetching content from DatoCMS... "
|
33
33
|
loader.load
|
34
34
|
|
35
35
|
if watch_mode
|
@@ -51,23 +51,23 @@ module Dato
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
desc
|
54
|
+
desc "check", "checks the presence of a DatoCMS token"
|
55
55
|
def check
|
56
|
-
exit 0 if ENV[
|
56
|
+
exit 0 if ENV["DATO_API_TOKEN"]
|
57
57
|
|
58
|
-
say
|
58
|
+
say "Site token is not specified!"
|
59
59
|
token = ask "Please paste your DatoCMS site read-only API token:\n>"
|
60
60
|
|
61
61
|
if !token || token.empty?
|
62
|
-
puts
|
62
|
+
puts "Missing token"
|
63
63
|
exit 1
|
64
64
|
end
|
65
65
|
|
66
|
-
File.open(
|
66
|
+
File.open(".env", "a") do |file|
|
67
67
|
file.puts "DATO_API_TOKEN=#{token}"
|
68
68
|
end
|
69
69
|
|
70
|
-
say
|
70
|
+
say "Token added to .env file."
|
71
71
|
|
72
72
|
exit 0
|
73
73
|
end
|