dato 0.7.15 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'forwardable'
4
- require 'active_support/inflector/transliterate'
5
- require 'active_support/hash_with_indifferent_access'
6
- require 'dato/utils/locale_value'
3
+ require "forwardable"
4
+ require "active_support/inflector/transliterate"
5
+ require "active_support/hash_with_indifferent_access"
6
+ require "dato/utils/locale_value"
7
7
 
8
8
  module Dato
9
9
  module Local
@@ -11,6 +11,7 @@ module Dato
11
11
  extend Forwardable
12
12
 
13
13
  attr_reader :entity
14
+
14
15
  def_delegators :entity, :id, :name, :locales, :domain,
15
16
  :internal_domain, :no_index, :frontend_url
16
17
 
@@ -12,7 +12,7 @@ module Dato
12
12
  items_per_page = 100
13
13
 
14
14
  base_response = @client.get(
15
- @base_endpoint, @filters.dup.merge('page[limit]' => items_per_page)
15
+ @base_endpoint, @filters.dup.merge("page[limit]" => items_per_page)
16
16
  )
17
17
 
18
18
  extra_pages = (
@@ -23,9 +23,9 @@ module Dato
23
23
  base_response[:data] += @client.get(
24
24
  @base_endpoint,
25
25
  @filters.dup.merge(
26
- 'page[offset]' => items_per_page * (page + 1),
27
- 'page[limit]' => items_per_page
28
- )
26
+ "page[offset]" => items_per_page * (page + 1),
27
+ "page[limit]" => items_per_page,
28
+ ),
29
29
  )[:data]
30
30
  end
31
31
 
data/lib/dato/repo.rb CHANGED
@@ -1,18 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dato/json_api_serializer'
4
- require 'dato/json_api_deserializer'
5
- require 'dato/paginator'
3
+ require "dato/json_api_serializer"
4
+ require "dato/json_api_deserializer"
5
+ require "dato/paginator"
6
6
 
7
7
  module Dato
8
8
  class Repo
9
9
  attr_reader :client, :type, :schema
10
10
 
11
- IDENTITY_REGEXP = /\{\(.*?definitions%2F(.*?)%2Fdefinitions%2Fidentity\)}/
11
+ IDENTITY_REGEXP = /\{\(.*?definitions%2F(.*?)%2Fdefinitions%2Fidentity\)}/.freeze
12
12
 
13
13
  METHOD_NAMES = {
14
- 'instances' => :all,
15
- 'self' => :find
14
+ "instances" => :all,
15
+ "self" => :find,
16
16
  }.freeze
17
17
 
18
18
  def initialize(client, type, schema)
@@ -32,23 +32,23 @@ module Dato
32
32
  private
33
33
 
34
34
  def method_missing(method, *args, &block)
35
- link = schema.links.find do |link|
36
- METHOD_NAMES.fetch(link.rel, link.rel).to_sym == method.to_sym
35
+ link = schema.links.find do |ilink|
36
+ METHOD_NAMES.fetch(ilink.rel, ilink.rel).to_sym == method.to_sym
37
37
  end
38
38
 
39
- return super if !link
39
+ return super unless link
40
40
 
41
41
  min_arguments_count = [
42
42
  link.href.scan(IDENTITY_REGEXP).size,
43
- link.schema && link.method != :get ? 1 : 0
43
+ link.schema && link.method != :get ? 1 : 0,
44
44
  ].reduce(0, :+)
45
45
 
46
- (args.size >= min_arguments_count) or
47
- raise ArgumentError, "wrong number of arguments (given #{args.size}, expected #{min_arguments_count})"
46
+ (args.size >= min_arguments_count) ||
47
+ raise(ArgumentError, "wrong number of arguments (given #{args.size}, expected #{min_arguments_count})")
48
48
 
49
49
  placeholders = []
50
50
 
51
- url = link['href'].gsub(IDENTITY_REGEXP) do |_stuff|
51
+ url = link["href"].gsub(IDENTITY_REGEXP) do |_stuff|
52
52
  placeholder = args.shift.to_s
53
53
  placeholders << placeholder
54
54
  placeholder
@@ -61,19 +61,16 @@ module Dato
61
61
  body = link.schema ? args.shift : {}
62
62
  query_string = args.shift || {}
63
63
 
64
- elsif link.method == :delete
65
- query_string = args.shift || {}
66
-
67
- elsif link.method == :get
64
+ elsif %i[get delete].include?(link.method)
68
65
  query_string = args.shift || {}
69
66
  end
70
67
 
71
68
  options = args.any? ? args.shift.symbolize_keys : {}
72
69
 
73
70
  if link.schema && %i[post put].include?(link.method) && options.fetch(:serialize_response, true)
74
- body = JsonApiSerializer.new(type, link).serialize(
71
+ body = JsonApiSerializer.new(link: link).serialize(
75
72
  body,
76
- link.method == :post ? nil : placeholders.last
73
+ link.method == :post ? nil : placeholders.last,
77
74
  )
78
75
  end
79
76
 
@@ -92,21 +89,19 @@ module Dato
92
89
  if response && response[:data] && response[:data].is_a?(Hash) && response[:data][:type] == "job"
93
90
  job_result = nil
94
91
 
95
- while !job_result do
92
+ until job_result
96
93
  begin
97
94
  sleep(1)
98
95
  job_result = client.job_result.find(response[:data][:id])
99
- rescue ApiError => error
100
- if error.response[:status] != 404
101
- raise error
102
- end
96
+ rescue ApiError => e
97
+ raise e if e.response[:status] != 404
103
98
  end
104
99
  end
105
100
 
106
101
  if job_result[:status] < 200 || job_result[:status] >= 300
107
102
  error = ApiError.new(
108
103
  status: job_result[:status],
109
- body: JSON.dump(job_result[:payload])
104
+ body: JSON.dump(job_result[:payload]),
110
105
  )
111
106
 
112
107
  puts "===="
@@ -121,12 +116,10 @@ module Dato
121
116
  else
122
117
  job_result.payload
123
118
  end
119
+ elsif options.fetch(:deserialize_response, true)
120
+ JsonApiDeserializer.new(link.target_schema).deserialize(response)
124
121
  else
125
- if options.fetch(:deserialize_response, true)
126
- JsonApiDeserializer.new(link.target_schema).deserialize(response)
127
- else
128
- response
129
- end
122
+ response
130
123
  end
131
124
  end
132
125
  end
@@ -1,15 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dato/api_client'
4
- require 'dato/upload/file'
5
- require 'dato/upload/create_upload_path'
3
+ require "dato/api_client"
4
+ require "dato/upload/file"
5
+ require "dato/upload/create_upload_path"
6
6
 
7
7
  module Dato
8
8
  module Site
9
9
  class Client
10
10
  include ApiClient
11
11
 
12
- json_schema 'site-api'
12
+ json_schema "site-api"
13
13
 
14
14
  def create_upload_path(path_or_url)
15
15
  file = Upload::CreateUploadPath.new(self, path_or_url)
@@ -30,7 +30,7 @@ module Dato
30
30
  request(
31
31
  :post,
32
32
  "/pusher/authenticate",
33
- { socket_id: socket_id, channel_name: channel}
33
+ { socket_id: socket_id, channel_name: channel },
34
34
  )
35
35
  end
36
36
  end
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'mime/types'
4
- require 'tempfile'
5
- require 'addressable'
6
- require 'net/http'
3
+ require "mime/types"
4
+ require "tempfile"
5
+ require "addressable"
6
+ require "net/http"
7
7
 
8
8
  module Dato
9
9
  module Upload
@@ -19,7 +19,7 @@ module Dato
19
19
  @file ||= if http_source?
20
20
  uri = Addressable::URI.parse(source)
21
21
  ext = ::File.extname(uri.path).downcase
22
- tempfile = Tempfile.new(['file', ext])
22
+ tempfile = Tempfile.new(["file", ext])
23
23
  tempfile.binmode
24
24
  tempfile.write(download_file(source))
25
25
  tempfile.rewind
@@ -31,7 +31,7 @@ module Dato
31
31
 
32
32
  def http_source?
33
33
  uri = Addressable::URI.parse(source)
34
- uri.scheme == 'http' || uri.scheme == 'https'
34
+ uri.scheme == "http" || uri.scheme == "https"
35
35
  rescue Addressable::URI::InvalidURIError
36
36
  false
37
37
  end
@@ -51,9 +51,7 @@ module Dato
51
51
  mime_type = MIME::Types.of(filename).first
52
52
 
53
53
  request = Net::HTTP::Put.new(uri)
54
- if mime_type
55
- request.add_field("Content-Type", mime_type.to_s)
56
- end
54
+ request.add_field("Content-Type", mime_type.to_s) if mime_type
57
55
  request.body = file.read
58
56
 
59
57
  http = Net::HTTP.new(uri.host, uri.port)
@@ -78,4 +76,3 @@ module Dato
78
76
  end
79
77
  end
80
78
  end
81
-
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dato/upload/create_upload_path'
3
+ require "dato/upload/create_upload_path"
4
4
 
5
5
  module Dato
6
6
  module Upload
@@ -18,14 +18,14 @@ module Dato
18
18
  upload_path = CreateUploadPath.new(client, source).upload_path
19
19
 
20
20
  upload = client.uploads.create(
21
- upload_attributes.merge(path: upload_path)
21
+ upload_attributes.merge(path: upload_path),
22
22
  )
23
23
 
24
24
  {
25
25
  alt: nil,
26
26
  title: nil,
27
27
  custom_data: {},
28
- }.merge(field_attributes).merge(upload_id: upload['id'])
28
+ }.merge(field_attributes).merge(upload_id: upload["id"])
29
29
  end
30
30
  end
31
31
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dato/upload/file'
3
+ require "dato/upload/file"
4
4
 
5
5
  module Dato
6
6
  module Upload
@@ -1,22 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dato/json_api_serializer'
3
+ require "dato/json_api_serializer"
4
4
 
5
5
  module Dato
6
6
  module Utils
7
7
  module BuildModularBlock
8
8
  def self.build(unserialized_body)
9
- json_api_serializer = JsonApiSerializer.new('item', nil)
9
+ json_api_serializer = JsonApiSerializer.new(type: "item")
10
10
  attributes = json_api_serializer.serialized_attributes(unserialized_body)
11
11
 
12
12
  payload = {
13
- type: 'item',
13
+ type: "item",
14
14
  attributes: attributes,
15
15
  relationships: {
16
16
  item_type: {
17
17
  data: {
18
18
  id: unserialized_body[:item_type],
19
- type: 'item_type',
19
+ type: "item_type",
20
20
  },
21
21
  },
22
22
  },
@@ -20,7 +20,7 @@ module Dato
20
20
  build_apple_icon_tags,
21
21
  build_windows_tags,
22
22
  build_color_tags,
23
- build_app_name_tag
23
+ build_app_name_tag,
24
24
  ].flatten.compact
25
25
  end
26
26
 
@@ -29,9 +29,9 @@ module Dato
29
29
 
30
30
  APPLE_TOUCH_ICON_SIZES.map do |size|
31
31
  link_tag(
32
- 'apple-touch-icon',
32
+ "apple-touch-icon",
33
33
  url(size),
34
- sizes: "#{size}x#{size}"
34
+ sizes: "#{size}x#{size}",
35
35
  )
36
36
  end
37
37
  end
@@ -41,10 +41,10 @@ module Dato
41
41
 
42
42
  ICON_SIZES.map do |size|
43
43
  link_tag(
44
- 'icon',
44
+ "icon",
45
45
  url(size),
46
46
  sizes: "#{size}x#{size}",
47
- type: "image/#{site.favicon.format}"
47
+ type: "image/#{site.favicon.format}",
48
48
  )
49
49
  end
50
50
  end
@@ -58,15 +58,15 @@ module Dato
58
58
  end
59
59
 
60
60
  def build_app_name_tag
61
- meta_tag('application-name', site.name)
61
+ meta_tag("application-name", site.name)
62
62
  end
63
63
 
64
64
  def build_color_tags
65
65
  return unless theme_color
66
66
 
67
67
  [
68
- meta_tag('theme-color', theme_color),
69
- meta_tag('msapplication-TileColor', theme_color)
68
+ meta_tag("theme-color", theme_color),
69
+ meta_tag("msapplication-TileColor", theme_color),
70
70
  ]
71
71
  end
72
72
 
@@ -75,11 +75,11 @@ module Dato
75
75
  end
76
76
 
77
77
  def meta_tag(name, value)
78
- { tag_name: 'meta', attributes: { name: name, content: value } }
78
+ { tag_name: "meta", attributes: { name: name, content: value } }
79
79
  end
80
80
 
81
81
  def link_tag(rel, href, attrs = {})
82
- { tag_name: 'link', attributes: attrs.merge(rel: rel, href: href) }
82
+ { tag_name: "link", attributes: attrs.merge(rel: rel, href: href) }
83
83
  end
84
84
  end
85
85
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'i18n/backend/fallbacks'
3
+ require "i18n/backend/fallbacks"
4
4
 
5
5
  module Dato
6
6
  module Utils
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dato/utils/meta_tags/base'
4
- require 'time'
3
+ require "dato/utils/meta_tags/base"
4
+ require "time"
5
5
 
6
6
  module Dato
7
7
  module Utils
8
8
  module MetaTags
9
9
  class ArticleModifiedTime < Base
10
10
  def build
11
- og_tag('article:modified_time', item.updated_at.iso8601) if item
11
+ og_tag("article:modified_time", item.updated_at.iso8601) if item
12
12
  end
13
13
  end
14
14
  end
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dato/utils/meta_tags/base'
3
+ require "dato/utils/meta_tags/base"
4
4
 
5
5
  module Dato
6
6
  module Utils
7
7
  module MetaTags
8
8
  class ArticlePublisher < Base
9
9
  def build
10
- og_tag('article:publisher', facebook_page_url) if facebook_page_url
10
+ og_tag("article:publisher", facebook_page_url) if facebook_page_url
11
11
  end
12
12
 
13
13
  def facebook_page_url
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'forwardable'
4
- require 'dato/local/field_type/seo'
5
- require 'active_support/core_ext/object/blank'
3
+ require "forwardable"
4
+ require "dato/local/field_type/seo"
5
+ require "active_support/core_ext/object/blank"
6
6
 
7
7
  module Dato
8
8
  module Utils
@@ -19,7 +19,7 @@ module Dato
19
19
  fallback_seo = site.global_seo && site.global_seo.fallback_seo
20
20
 
21
21
  seo_field = item &&
22
- item.fields.detect { |f| f.field_type == 'seo' }
22
+ item.fields.detect { |f| f.field_type == "seo" }
23
23
 
24
24
  item_seo_value = seo_field &&
25
25
  item[seo_field.api_key] &&
@@ -36,11 +36,11 @@ module Dato
36
36
  end
37
37
 
38
38
  def meta_tag(name, content)
39
- tag('meta', name: name, content: content)
39
+ tag("meta", name: name, content: content)
40
40
  end
41
41
 
42
42
  def og_tag(property, content)
43
- tag('meta', property: property, content: content)
43
+ tag("meta", property: property, content: content)
44
44
  end
45
45
 
46
46
  def card_tag(name, content)