dato 0.7.15 → 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.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +42 -5
  3. data/.travis.yml +1 -0
  4. data/CHANGELOG.md +4 -0
  5. data/Gemfile +1 -1
  6. data/Rakefile +2 -2
  7. data/TODO.md +28 -0
  8. data/bin/console +3 -3
  9. data/bin/rspec +6 -6
  10. data/dato.gemspec +1 -1
  11. data/exe/dato +3 -3
  12. data/lib/dato.rb +8 -8
  13. data/lib/dato/account/client.rb +2 -2
  14. data/lib/dato/api_client.rb +67 -44
  15. data/lib/dato/api_error.rb +10 -13
  16. data/lib/dato/cli.rb +18 -18
  17. data/lib/dato/dump/dsl/add_to_data_file.rb +1 -1
  18. data/lib/dato/dump/dsl/create_data_file.rb +1 -1
  19. data/lib/dato/dump/dsl/create_post.rb +1 -1
  20. data/lib/dato/dump/dsl/directory.rb +4 -4
  21. data/lib/dato/dump/dsl/root.rb +7 -7
  22. data/lib/dato/dump/format.rb +3 -3
  23. data/lib/dato/dump/format/json.rb +1 -1
  24. data/lib/dato/dump/format/toml.rb +6 -6
  25. data/lib/dato/dump/format/yaml.rb +3 -3
  26. data/lib/dato/dump/operation/add_to_data_file.rb +4 -4
  27. data/lib/dato/dump/operation/create_data_file.rb +3 -3
  28. data/lib/dato/dump/operation/create_post.rb +5 -6
  29. data/lib/dato/dump/operation/directory.rb +1 -1
  30. data/lib/dato/dump/runner.rb +5 -5
  31. data/lib/dato/dump/ssg_detector.rb +18 -20
  32. data/lib/dato/json_api_deserializer.rb +15 -16
  33. data/lib/dato/json_api_serializer.rb +39 -28
  34. data/lib/dato/json_schema_relationships.rb +19 -23
  35. data/lib/dato/json_schema_type.rb +47 -0
  36. data/lib/dato/local/entities_repo.rb +3 -3
  37. data/lib/dato/local/field_type/color.rb +11 -7
  38. data/lib/dato/local/field_type/file.rb +18 -24
  39. data/lib/dato/local/field_type/gallery.rb +1 -1
  40. data/lib/dato/local/field_type/global_seo.rb +4 -7
  41. data/lib/dato/local/field_type/lat_lon.rb +1 -1
  42. data/lib/dato/local/field_type/seo.rb +1 -1
  43. data/lib/dato/local/field_type/structured_text.rb +63 -0
  44. data/lib/dato/local/field_type/theme.rb +2 -2
  45. data/lib/dato/local/field_type/upload_id.rb +5 -5
  46. data/lib/dato/local/field_type/video.rb +9 -15
  47. data/lib/dato/local/item.rb +13 -12
  48. data/lib/dato/local/items_repo.rb +12 -18
  49. data/lib/dato/local/json_api_entity.rb +4 -3
  50. data/lib/dato/local/loader.rb +31 -32
  51. data/lib/dato/local/site.rb +5 -4
  52. data/lib/dato/paginator.rb +4 -4
  53. data/lib/dato/repo.rb +23 -30
  54. data/lib/dato/site/client.rb +5 -5
  55. data/lib/dato/upload/create_upload_path.rb +7 -10
  56. data/lib/dato/upload/file.rb +3 -3
  57. data/lib/dato/upload/image.rb +1 -1
  58. data/lib/dato/utils/build_modular_block.rb +4 -4
  59. data/lib/dato/utils/favicon_tags_builder.rb +10 -10
  60. data/lib/dato/utils/locale_value.rb +1 -1
  61. data/lib/dato/utils/meta_tags/article_modified_time.rb +3 -3
  62. data/lib/dato/utils/meta_tags/article_publisher.rb +2 -2
  63. data/lib/dato/utils/meta_tags/base.rb +6 -6
  64. data/lib/dato/utils/meta_tags/description.rb +4 -4
  65. data/lib/dato/utils/meta_tags/image.rb +4 -5
  66. data/lib/dato/utils/meta_tags/og_locale.rb +2 -2
  67. data/lib/dato/utils/meta_tags/og_site_name.rb +2 -2
  68. data/lib/dato/utils/meta_tags/og_type.rb +3 -3
  69. data/lib/dato/utils/meta_tags/robots.rb +2 -2
  70. data/lib/dato/utils/meta_tags/title.rb +6 -6
  71. data/lib/dato/utils/meta_tags/twitter_card.rb +2 -2
  72. data/lib/dato/utils/meta_tags/twitter_site.rb +2 -2
  73. data/lib/dato/utils/seo_tags_builder.rb +12 -12
  74. data/lib/dato/version.rb +1 -1
  75. metadata +9 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7779edc00921c84e0f98aee2008bb8fd3f89d893c02107d965db12d1f5bc7882
4
- data.tar.gz: 25ba5f84f8a6236c40d2846ef976987501f4977d481c9c445e298b666bc6b1ec
3
+ metadata.gz: 2fa3f3032c3681e2bf710b69ffe75eec9b47a27a494e63943909b91500785cb6
4
+ data.tar.gz: f5ee2896a63dab9a457c94d612fcd285544487df3c915d2dccc14951a4c304d0
5
5
  SHA512:
6
- metadata.gz: 955b67a6fadad2fb96e1342ec2e8907f5084085e0f18737655ebac56a4a8661e5d670ff9e662b3afc21381636139480f86ae48d47f268b571a21fcfa470de8c2
7
- data.tar.gz: 479fe2e231a44cdf9518961c98bfddbd67ac06d4cd511e37a7369d668e5f0fa4eeca195d8af09bd981277a5c195f01d5f368f6b134562ebdd8f43df0c47a8c91
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/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/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/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 '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
@@ -33,27 +33,52 @@ 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
+ 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
- "https://#{subdomain}.datocms.com/docs/#{subdomain}-hyperschema.json"
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.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
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['SSL_CERT_FILE'] == Cacert.pem
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]['x-ratelimit-reset'].to_i
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 'Validating items, waiting 1 second and retrying...'
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
- JSON.parse(response[:body])
117
- rescue JSON::ParserError => e
118
- nil
119
- end
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['data']
147
+ return false unless body["data"]
123
148
 
124
- body['data'].any? do |e|
125
- e['attributes']['code'] == 'BATCH_DATA_VALIDATION_IN_PROGRESS'
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
- 'Accept' => 'application/json',
134
- 'Content-Type' => 'application/json',
135
- 'Authorization' => "Bearer #{@token}",
136
- 'User-Agent' => "ruby-client v#{Dato::VERSION}",
137
- '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",
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|
@@ -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