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.
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dato
2
4
  class JsonSchemaRelationships
3
5
  attr_reader :schema
@@ -7,46 +9,40 @@ module Dato
7
9
  end
8
10
 
9
11
  def relationships
10
- if !schema || !schema.properties['data']
11
- return {}
12
- end
12
+ return {} if !schema || !schema.properties["data"]
13
13
 
14
- entity = if schema.properties['data'].type.first == 'array'
15
- schema.properties['data'].items
14
+ entity = if schema.properties["data"].type.first == "array"
15
+ schema.properties["data"].items
16
16
  else
17
- schema.properties['data']
17
+ schema.properties["data"]
18
18
  end
19
19
 
20
- if !entity || !entity.properties['relationships'] || !entity.properties['relationships']
21
- return {}
22
- end
20
+ return {} if !entity || !entity.properties["relationships"] || !entity.properties["relationships"]
23
21
 
24
- relationships = entity.properties['relationships'].properties
22
+ relationships = entity.properties["relationships"].properties
25
23
 
26
24
  relationships.each_with_object({}) do |(relationship, schema), acc|
27
- is_collection = schema.properties['data'].type.first == 'array'
25
+ is_collection = schema.properties["data"].type.first == "array"
28
26
 
29
27
  types = if is_collection
30
- [type(schema.properties['data'].items)]
31
- elsif schema.properties['data'].type.first == 'object'
32
- [type(schema.properties['data'])]
33
- else
34
- schema.properties['data'].any_of.map do |option|
35
- type(option)
36
- end.compact
37
- end
28
+ [type(schema.properties["data"].items)]
29
+ elsif schema.properties["data"].type.first == "object"
30
+ [type(schema.properties["data"])]
31
+ else
32
+ schema.properties["data"].any_of.map do |option|
33
+ type(option)
34
+ end.compact
35
+ end
38
36
 
39
37
  acc[relationship.to_sym] = {
40
38
  collection: is_collection,
41
- types: types
39
+ types: types,
42
40
  }
43
41
  end
44
42
  end
45
43
 
46
44
  def type(definition)
47
- if definition.properties['type']
48
- definition.properties['type'].pattern.source.gsub(/(^\^|\$$)/, '')
49
- end
45
+ definition.properties["type"].pattern.source.gsub(/(^\^|\$$)/, "") if definition.properties["type"]
50
46
  end
51
47
  end
52
48
  end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dato
4
+ class JsonSchemaType
5
+ attr_reader :schema
6
+
7
+ def initialize(schema)
8
+ @schema = schema
9
+ end
10
+
11
+ def call
12
+ type_property = find_info_for_type_property
13
+
14
+ return nil unless type_property
15
+
16
+ type_property.pattern.to_s.gsub(/(^(\(\?-mix:\^)|(\$\))$)/, "")
17
+ end
18
+
19
+ private
20
+
21
+ def find_info_for_type_property
22
+ entity = find_entity_in_data
23
+
24
+ return nil unless entity
25
+
26
+ entity.properties["type"]
27
+ end
28
+
29
+ def find_entity_in_data
30
+ return nil if !schema || !schema.properties["data"]
31
+
32
+ if schema.properties["data"].type.first == "array"
33
+ return schema.properties["data"].items if schema.properties["data"].items
34
+
35
+ return nil
36
+ end
37
+
38
+ return schema.properties["data"] if schema.properties["data"].type.first == "object"
39
+
40
+ if schema.properties["data"].any_of
41
+ return schema.properties["data"].any_of.reject { |x| x.definitions.type.example == "job" }
42
+ end
43
+
44
+ nil
45
+ end
46
+ end
47
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dato/local/json_api_entity'
3
+ require "dato/local/json_api_entity"
4
4
 
5
5
  module Dato
6
6
  module Local
@@ -27,8 +27,8 @@ module Dato
27
27
  end
28
28
 
29
29
  def destroy_item_type(id)
30
- entities.fetch('item', {}).delete_if { |_item_id, item| item.item_type.id == id }
31
- entities.fetch('item_type', {}).delete(id)
30
+ entities.fetch("item", {}).delete_if { |_item_id, item| item.item_type.id == id }
31
+ entities.fetch("item_type", {}).delete(id)
32
32
  end
33
33
 
34
34
  def upsert_entities(*payloads)
@@ -4,14 +4,14 @@ module Dato
4
4
  module Local
5
5
  module FieldType
6
6
  class Color
7
- attr_reader :red, :green, :blue, :alpha
7
+ attr_reader :red, :green, :blue
8
8
 
9
9
  def self.parse(value, _repo)
10
10
  value && new(
11
11
  value[:red],
12
12
  value[:green],
13
13
  value[:blue],
14
- value[:alpha]
14
+ value[:alpha],
15
15
  )
16
16
  end
17
17
 
@@ -19,17 +19,21 @@ module Dato
19
19
  @red = red
20
20
  @green = green
21
21
  @blue = blue
22
- @alpha = alpha / 255.0
22
+ @alpha = alpha
23
23
  end
24
24
 
25
25
  def rgb
26
- if alpha == 1.0
26
+ if @alpha == 255
27
27
  "rgb(#{red}, #{green}, #{blue})"
28
28
  else
29
29
  "rgba(#{red}, #{green}, #{blue}, #{alpha})"
30
30
  end
31
31
  end
32
32
 
33
+ def alpha
34
+ @alpha / 255.0
35
+ end
36
+
33
37
  def hex
34
38
  r = red.to_s(16)
35
39
  g = green.to_s(16)
@@ -41,9 +45,9 @@ module Dato
41
45
  b = "0#{b}" if b.length == 1
42
46
  a = "0#{a}" if a.length == 1
43
47
 
44
- hex = '#' + r + g + b
48
+ hex = "##{r}#{g}#{b}"
45
49
 
46
- hex += a if a != 'ff'
50
+ hex += a if a != "ff"
47
51
 
48
52
  hex
49
53
  end
@@ -54,7 +58,7 @@ module Dato
54
58
  green: green,
55
59
  blue: blue,
56
60
  rgb: rgb,
57
- hex: hex
61
+ hex: hex,
58
62
  }
59
63
  end
60
64
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'imgix'
3
+ require "imgix"
4
4
 
5
5
  module Dato
6
6
  module Local
@@ -10,7 +10,7 @@ module Dato
10
10
  if value
11
11
  v = value.with_indifferent_access
12
12
 
13
- upload = repo.entities_repo.find_entity('upload', v[:upload_id])
13
+ upload = repo.entities_repo.find_entity("upload", v[:upload_id])
14
14
 
15
15
  if upload
16
16
  new(
@@ -19,7 +19,7 @@ module Dato
19
19
  v[:title],
20
20
  v[:custom_data],
21
21
  v[:focal_point],
22
- repo.site.entity.imgix_host
22
+ repo.site.entity.imgix_host,
23
23
  )
24
24
  end
25
25
  end
@@ -88,25 +88,25 @@ module Dato
88
88
  def alt
89
89
  default_metadata = @upload.default_field_metadata.deep_stringify_keys
90
90
  .fetch(I18n.locale.to_s, {})
91
- @alt || default_metadata['alt']
91
+ @alt || default_metadata["alt"]
92
92
  end
93
93
 
94
94
  def title
95
95
  default_metadata = @upload.default_field_metadata.deep_stringify_keys
96
96
  .fetch(I18n.locale.to_s, {})
97
- @title || default_metadata['title']
97
+ @title || default_metadata["title"]
98
98
  end
99
99
 
100
100
  def custom_data
101
101
  default_metadata = @upload.default_field_metadata.deep_stringify_keys
102
102
  .fetch(I18n.locale.to_s, {})
103
- @custom_data.merge(default_metadata.fetch('custom_data', {}))
103
+ @custom_data.merge(default_metadata.fetch("custom_data", {}))
104
104
  end
105
105
 
106
106
  def focal_point
107
107
  default_metadata = @upload.default_field_metadata.deep_stringify_keys
108
108
  .fetch(I18n.locale.to_s, {})
109
- @focal_point || default_metadata['focal_point']
109
+ @focal_point || default_metadata["focal_point"]
110
110
  end
111
111
 
112
112
  def tags
@@ -174,9 +174,7 @@ module Dato
174
174
  if options[:exact_res] == :low
175
175
  raw_mp4_url("low")
176
176
  elsif options[:exact_res] == :medium
177
- if %w[medium high].include?(@upload.mux_mp4_highest_res)
178
- raw_mp4_url("medium")
179
- end
177
+ raw_mp4_url("medium") if %w[medium high].include?(@upload.mux_mp4_highest_res)
180
178
  elsif @upload.mux_mp4_highest_res == :high
181
179
  raw_mp4_url("high")
182
180
  end
@@ -212,16 +210,14 @@ module Dato
212
210
  end
213
211
 
214
212
  def video
215
- if @upload.mux_playback_id
216
- VideoAttributes.new(@upload)
217
- end
213
+ VideoAttributes.new(@upload) if @upload.mux_playback_id
218
214
  end
219
215
 
220
216
  def file
221
217
  Imgix::Client.new(
222
218
  domain: @imgix_host,
223
219
  secure: true,
224
- include_library_param: false
220
+ include_library_param: false,
225
221
  ).path(path)
226
222
  end
227
223
 
@@ -229,12 +225,12 @@ module Dato
229
225
  query.deep_stringify_keys!
230
226
 
231
227
  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?
228
+ query["fit"] == "crop" &&
229
+ (query["h"] || query["height"]) &&
230
+ (query["w"] || query["width"]) &&
231
+ [nil, "focalpoint"].include?(query["crop"]) &&
232
+ query["fp-x"].nil? &&
233
+ query["fp-y"].nil?
238
234
 
239
235
  query.merge!(
240
236
  "crop" => "focalpoint",
@@ -252,9 +248,7 @@ module Dato
252
248
 
253
249
  response = Faraday.get(file.to_url(opts.merge(lqip: "blurhash")))
254
250
 
255
- if response.status == 200
256
- "data:image/jpeg;base64,#{Base64.strict_encode64(response.body)}"
257
- end
251
+ "data:image/jpeg;base64,#{Base64.strict_encode64(response.body)}" if response.status == 200
258
252
  end
259
253
 
260
254
  def to_hash(*_args)
@@ -279,7 +273,7 @@ module Dato
279
273
  mime_type: mime_type,
280
274
  colors: colors.map(&:to_hash),
281
275
  blurhash: blurhash,
282
- video: video && video.to_hash
276
+ video: video && video.to_hash,
283
277
  }
284
278
  end
285
279
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dato/local/field_type/file'
3
+ require "dato/local/field_type/file"
4
4
 
5
5
  module Dato
6
6
  module Local
@@ -1,15 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dato/local/field_type/seo'
3
+ require "dato/local/field_type/seo"
4
4
 
5
5
  module Dato
6
6
  module Local
7
7
  module FieldType
8
8
  class GlobalSeo
9
- attr_reader :site_name
10
- attr_reader :title_suffix
11
- attr_reader :twitter_account
12
- attr_reader :facebook_page_url
9
+ attr_reader :site_name, :title_suffix, :twitter_account, :facebook_page_url
13
10
 
14
11
  def self.parse(value, repo)
15
12
  value && new(
@@ -18,7 +15,7 @@ module Dato
18
15
  value[:twitter_account],
19
16
  value[:facebook_page_url],
20
17
  value[:fallback_seo],
21
- repo
18
+ repo,
22
19
  )
23
20
  end
24
21
 
@@ -48,7 +45,7 @@ module Dato
48
45
  title_suffix: title_suffix,
49
46
  twitter_account: twitter_account,
50
47
  facebook_page_url: facebook_page_url,
51
- fallback_seo: fallback_seo && fallback_seo.to_hash(*args)
48
+ fallback_seo: fallback_seo && fallback_seo.to_hash(*args),
52
49
  }
53
50
  end
54
51
  end
@@ -22,7 +22,7 @@ module Dato
22
22
  def to_hash(*_args)
23
23
  {
24
24
  latitude: latitude,
25
- longitude: longitude
25
+ longitude: longitude,
26
26
  }
27
27
  end
28
28
  end
@@ -26,7 +26,7 @@ module Dato
26
26
  {
27
27
  title: title,
28
28
  description: description,
29
- image: image && image.to_hash(*args)
29
+ image: image && image.to_hash(*args),
30
30
  }
31
31
  end
32
32
  end
@@ -13,9 +13,7 @@ module Dato
13
13
  @repo = repo
14
14
  end
15
15
 
16
- def value
17
- @value
18
- end
16
+ attr_reader :value
19
17
 
20
18
  def blocks
21
19
  find_all_nodes("block").map do |node|
@@ -24,23 +22,19 @@ module Dato
24
22
  end
25
23
 
26
24
  def links
27
- find_all_nodes(["inlineItem", "itemLink"]).map do |node|
25
+ find_all_nodes(%w[inlineItem itemLink]).map do |node|
28
26
  @repo.find(node["item"])
29
27
  end.uniq
30
28
  end
31
29
 
32
30
  def find_all_nodes(types)
33
- if value.nil?
34
- return []
35
- end
31
+ return [] if value.nil?
36
32
 
37
33
  types = Array(types)
38
34
  result = []
39
35
 
40
36
  visit(value["document"]) do |node|
41
- if node.is_a?(Hash) && types.include?(node["type"])
42
- result << node
43
- end
37
+ result << node if node.is_a?(Hash) && types.include?(node["type"])
44
38
  end
45
39
 
46
40
  result
@@ -13,7 +13,7 @@ module Dato
13
13
  value[:dark_color],
14
14
  value[:light_color],
15
15
  value[:accent_color],
16
- repo
16
+ repo,
17
17
  )
18
18
  end
19
19
 
@@ -36,7 +36,7 @@ module Dato
36
36
  dark_color: dark_color,
37
37
  light_color: light_color,
38
38
  accent_color: accent_color,
39
- logo: logo && logo.to_hash(*args)
39
+ logo: logo && logo.to_hash(*args),
40
40
  }
41
41
  end
42
42
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'imgix'
3
+ require "imgix"
4
4
 
5
5
  module Dato
6
6
  module Local
@@ -10,7 +10,7 @@ module Dato
10
10
 
11
11
  def self.parse(upload_id, repo)
12
12
  if upload_id
13
- upload = repo.entities_repo.find_entity('upload', upload_id)
13
+ upload = repo.entities_repo.find_entity("upload", upload_id)
14
14
 
15
15
  if upload
16
16
  new(
@@ -19,7 +19,7 @@ module Dato
19
19
  upload.size,
20
20
  upload.width,
21
21
  upload.height,
22
- repo.site.entity.imgix_host
22
+ repo.site.entity.imgix_host,
23
23
  )
24
24
  end
25
25
  end
@@ -45,7 +45,7 @@ module Dato
45
45
  Imgix::Client.new(
46
46
  domain: @imgix_host,
47
47
  secure: true,
48
- include_library_param: false
48
+ include_library_param: false,
49
49
  ).path(path)
50
50
  end
51
51
 
@@ -59,7 +59,7 @@ module Dato
59
59
  size: size,
60
60
  width: width,
61
61
  height: height,
62
- url: url
62
+ url: url,
63
63
  }
64
64
  end
65
65
  end