dato 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +42 -5
  3. data/.travis.yml +1 -0
  4. data/Gemfile +1 -1
  5. data/Rakefile +2 -2
  6. data/bin/console +3 -3
  7. data/bin/rspec +6 -6
  8. data/dato.gemspec +1 -1
  9. data/exe/dato +3 -3
  10. data/lib/dato.rb +8 -8
  11. data/lib/dato/account/client.rb +2 -2
  12. data/lib/dato/api_client.rb +39 -43
  13. data/lib/dato/api_error.rb +10 -13
  14. data/lib/dato/cli.rb +18 -18
  15. data/lib/dato/dump/dsl/add_to_data_file.rb +1 -1
  16. data/lib/dato/dump/dsl/create_data_file.rb +1 -1
  17. data/lib/dato/dump/dsl/create_post.rb +1 -1
  18. data/lib/dato/dump/dsl/directory.rb +4 -4
  19. data/lib/dato/dump/dsl/root.rb +7 -7
  20. data/lib/dato/dump/format.rb +3 -3
  21. data/lib/dato/dump/format/json.rb +1 -1
  22. data/lib/dato/dump/format/toml.rb +6 -6
  23. data/lib/dato/dump/format/yaml.rb +3 -3
  24. data/lib/dato/dump/operation/add_to_data_file.rb +4 -4
  25. data/lib/dato/dump/operation/create_data_file.rb +3 -3
  26. data/lib/dato/dump/operation/create_post.rb +5 -6
  27. data/lib/dato/dump/operation/directory.rb +1 -1
  28. data/lib/dato/dump/runner.rb +5 -5
  29. data/lib/dato/dump/ssg_detector.rb +18 -20
  30. data/lib/dato/json_api_deserializer.rb +15 -16
  31. data/lib/dato/json_api_serializer.rb +30 -21
  32. data/lib/dato/json_schema_relationships.rb +19 -23
  33. data/lib/dato/json_schema_type.rb +47 -0
  34. data/lib/dato/local/entities_repo.rb +3 -3
  35. data/lib/dato/local/field_type/color.rb +11 -7
  36. data/lib/dato/local/field_type/file.rb +18 -24
  37. data/lib/dato/local/field_type/gallery.rb +1 -1
  38. data/lib/dato/local/field_type/global_seo.rb +4 -7
  39. data/lib/dato/local/field_type/lat_lon.rb +1 -1
  40. data/lib/dato/local/field_type/seo.rb +1 -1
  41. data/lib/dato/local/field_type/structured_text.rb +4 -10
  42. data/lib/dato/local/field_type/theme.rb +2 -2
  43. data/lib/dato/local/field_type/upload_id.rb +5 -5
  44. data/lib/dato/local/field_type/video.rb +9 -15
  45. data/lib/dato/local/item.rb +13 -12
  46. data/lib/dato/local/items_repo.rb +12 -18
  47. data/lib/dato/local/json_api_entity.rb +4 -3
  48. data/lib/dato/local/loader.rb +30 -31
  49. data/lib/dato/local/site.rb +5 -4
  50. data/lib/dato/paginator.rb +4 -4
  51. data/lib/dato/repo.rb +23 -30
  52. data/lib/dato/site/client.rb +5 -5
  53. data/lib/dato/upload/create_upload_path.rb +7 -10
  54. data/lib/dato/upload/file.rb +3 -3
  55. data/lib/dato/upload/image.rb +1 -1
  56. data/lib/dato/utils/build_modular_block.rb +4 -4
  57. data/lib/dato/utils/favicon_tags_builder.rb +10 -10
  58. data/lib/dato/utils/locale_value.rb +1 -1
  59. data/lib/dato/utils/meta_tags/article_modified_time.rb +3 -3
  60. data/lib/dato/utils/meta_tags/article_publisher.rb +2 -2
  61. data/lib/dato/utils/meta_tags/base.rb +6 -6
  62. data/lib/dato/utils/meta_tags/description.rb +4 -4
  63. data/lib/dato/utils/meta_tags/image.rb +4 -5
  64. data/lib/dato/utils/meta_tags/og_locale.rb +2 -2
  65. data/lib/dato/utils/meta_tags/og_site_name.rb +2 -2
  66. data/lib/dato/utils/meta_tags/og_type.rb +3 -3
  67. data/lib/dato/utils/meta_tags/robots.rb +2 -2
  68. data/lib/dato/utils/meta_tags/title.rb +6 -6
  69. data/lib/dato/utils/meta_tags/twitter_card.rb +2 -2
  70. data/lib/dato/utils/meta_tags/twitter_site.rb +2 -2
  71. data/lib/dato/utils/seo_tags_builder.rb +12 -12
  72. data/lib/dato/version.rb +1 -1
  73. metadata +7 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9777e0d266657c2dffa3e6651de719c8e24728e311bcb6ed745bc6a7a70d927a
4
- data.tar.gz: 4d54c4e69249b7d3a30f9c289afe93f8f242c6026f8a62d7e6ae0e18ca8b8eb2
3
+ metadata.gz: 2fa3f3032c3681e2bf710b69ffe75eec9b47a27a494e63943909b91500785cb6
4
+ data.tar.gz: f5ee2896a63dab9a457c94d612fcd285544487df3c915d2dccc14951a4c304d0
5
5
  SHA512:
6
- metadata.gz: 99432305cdb85e390e2435913840f7d2c6a7bf93e7f9b1bfe9eb2b7c87a99da18ecad696f8f73704fc3776f2799206161fc8b9174b5c2aedb0e74efae34fbe48
7
- data.tar.gz: 8539feabd9684b8c3f8824da200ab28527072468914dd8cbfe25117807bd835250043f22348c0259ed3257781bf3ca9149512b963a78637b4f9e36b9b093485c
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
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
- Max: 8
43
+ Enabled: false
25
44
 
26
45
  Metrics/AbcSize:
27
- Max: 30
46
+ Enabled: false
28
47
 
29
48
  Metrics/PerceivedComplexity:
30
- Max: 8
49
+ Enabled: false
31
50
 
32
- Metrics/LineLength:
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
@@ -7,3 +7,4 @@ before_install:
7
7
  - gem install bundler -v 1.13.5
8
8
  - echo 'puts "ruby \"#{RUBY_VERSION}\""' | ruby >> Gemfile
9
9
  - cat Gemfile
10
+ script: rubocop && rake
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source 'https://rubygems.org'
3
+ source "https://rubygems.org"
4
4
 
5
5
  # Specify your gem's dependencies in dato.gemspec
6
6
  gemspec
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bundler/gem_tasks'
4
- require 'rspec/core/rake_task'
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
5
 
6
6
  RSpec::Core::RakeTask.new(:spec) do |t|
7
7
  t.rspec_opts = "-b"
data/bin/console CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'bundler/setup'
5
- require 'dato'
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 'irb'
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 'pathname'
12
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
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('bundle', __dir__)
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 'rubygems'
27
- require 'bundler/setup'
26
+ require "rubygems"
27
+ require "bundler/setup"
28
28
 
29
- load Gem.bin_path('rspec-core', 'rspec')
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('../lib', __dir__)
4
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
5
5
 
6
- require 'dotenv'
6
+ require "dotenv"
7
7
  Dotenv.load
8
8
 
9
- require 'dato'
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 'dato/version'
3
+ require "dato/version"
4
4
 
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'
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
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dato/api_client'
3
+ require "dato/api_client"
4
4
 
5
5
  module Dato
6
6
  module Account
7
7
  class Client
8
8
  include ApiClient
9
9
 
10
- json_schema 'account-api'
10
+ json_schema "account-api"
11
11
  end
12
12
  end
13
13
  end
@@ -1,18 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
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'
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 'dato/version'
11
- require 'dato/repo'
10
+ require "dato/version"
11
+ require "dato/repo"
12
12
 
13
- require 'dato/api_error'
13
+ require "dato/api_error"
14
14
 
15
- require 'cacert'
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 == 'instances' }.any?
44
+ is_collection = obj.links.select { |x| x.rel == "instances" }.any?
45
45
  namespace = is_collection ? type.pluralize : type
46
- if method.to_s === namespace
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 == 'instances' }.any?
54
+ is_collection = obj.links.select { |x| x.rel == "instances" }.any?
57
55
  namespace = is_collection ? type.pluralize : type
58
56
 
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
- )
57
+ next unless method.to_s == namespace
65
58
 
66
- return instance_variable_get("@#{namespace}")
67
- end
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['SSL_CERT_FILE'] == Cacert.pem
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]['x-ratelimit-reset'].to_i
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 'Validating items, waiting 1 second and retrying...'
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
- JSON.parse(response[:body])
144
- rescue JSON::ParserError => e
145
- nil
146
- end
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['data']
147
+ return false unless body["data"]
150
148
 
151
- body['data'].any? do |e|
152
- e['attributes']['code'] == 'BATCH_DATA_VALIDATION_IN_PROGRESS'
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
- 'Accept' => 'application/json',
161
- 'Content-Type' => 'application/json',
162
- 'Authorization' => "Bearer #{@token}",
163
- 'User-Agent' => "ruby-client v#{Dato::VERSION}",
164
- 'X-Api-Version' => '3'
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|
@@ -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
- @response = response
9
- end
8
+ body = JSON.parse(response[:body]) if response[:body]
10
9
 
11
- def message
12
- [
13
- 'DatoCMS API Error',
10
+ message = [
11
+ "DatoCMS API Error",
14
12
  "Status: #{response[:status]}",
15
- 'Response:',
16
- JSON.pretty_generate(body)
13
+ "Response:",
14
+ JSON.pretty_generate(body),
17
15
  ].join("\n")
18
- end
19
16
 
20
- def body
21
- if response[:body]
22
- JSON.parse(response[:body])
23
- end
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 'thor'
4
- require 'dato/dump/runner'
5
- require 'dato/dump/ssg_detector'
6
- require 'listen'
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 'DatoCMS'
9
+ package_name "DatoCMS"
10
10
 
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
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
- 'X-Reason' => 'dump',
28
- 'X-SSG' => Dump::SsgDetector.new(Dir.pwd).detect
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 'Fetching content from DatoCMS... '
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 'check', 'checks the presence of a DatoCMS token'
54
+ desc "check", "checks the presence of a DatoCMS token"
55
55
  def check
56
- exit 0 if ENV['DATO_API_TOKEN']
56
+ exit 0 if ENV["DATO_API_TOKEN"]
57
57
 
58
- say 'Site token is not specified!'
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 'Missing token'
62
+ puts "Missing token"
63
63
  exit 1
64
64
  end
65
65
 
66
- File.open('.env', 'a') do |file|
66
+ File.open(".env", "a") do |file|
67
67
  file.puts "DATO_API_TOKEN=#{token}"
68
68
  end
69
69
 
70
- say 'Token added to .env file.'
70
+ say "Token added to .env file."
71
71
 
72
72
  exit 0
73
73
  end