dato 0.6.9 → 0.6.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/Gemfile +1 -0
  4. data/Rakefile +1 -0
  5. data/bin/rspec +29 -0
  6. data/dato.gemspec +2 -1
  7. data/exe/dato +1 -1
  8. data/lib/dato.rb +1 -0
  9. data/lib/dato/account/client.rb +1 -0
  10. data/lib/dato/api_client.rb +6 -3
  11. data/lib/dato/api_error.rb +1 -0
  12. data/lib/dato/cli.rb +1 -2
  13. data/lib/dato/dump/dsl/add_to_data_file.rb +1 -0
  14. data/lib/dato/dump/dsl/create_data_file.rb +1 -0
  15. data/lib/dato/dump/dsl/create_post.rb +1 -0
  16. data/lib/dato/dump/dsl/directory.rb +1 -0
  17. data/lib/dato/dump/dsl/root.rb +1 -0
  18. data/lib/dato/dump/format.rb +1 -0
  19. data/lib/dato/dump/format/json.rb +1 -0
  20. data/lib/dato/dump/format/toml.rb +1 -0
  21. data/lib/dato/dump/format/yaml.rb +1 -0
  22. data/lib/dato/dump/operation/add_to_data_file.rb +1 -0
  23. data/lib/dato/dump/operation/create_data_file.rb +1 -0
  24. data/lib/dato/dump/operation/create_post.rb +1 -0
  25. data/lib/dato/dump/operation/directory.rb +1 -0
  26. data/lib/dato/dump/operation/root.rb +1 -0
  27. data/lib/dato/dump/runner.rb +1 -0
  28. data/lib/dato/dump/ssg_detector.rb +6 -5
  29. data/lib/dato/json_api_deserializer.rb +2 -3
  30. data/lib/dato/json_api_serializer.rb +20 -27
  31. data/lib/dato/local/entities_repo.rb +1 -0
  32. data/lib/dato/local/field_type/boolean.rb +1 -0
  33. data/lib/dato/local/field_type/color.rb +2 -2
  34. data/lib/dato/local/field_type/date.rb +1 -0
  35. data/lib/dato/local/field_type/date_time.rb +1 -0
  36. data/lib/dato/local/field_type/file.rb +2 -1
  37. data/lib/dato/local/field_type/float.rb +1 -0
  38. data/lib/dato/local/field_type/gallery.rb +1 -0
  39. data/lib/dato/local/field_type/global_seo.rb +1 -0
  40. data/lib/dato/local/field_type/integer.rb +1 -0
  41. data/lib/dato/local/field_type/json.rb +1 -1
  42. data/lib/dato/local/field_type/lat_lon.rb +1 -0
  43. data/lib/dato/local/field_type/link.rb +1 -0
  44. data/lib/dato/local/field_type/links.rb +1 -0
  45. data/lib/dato/local/field_type/rich_text.rb +1 -0
  46. data/lib/dato/local/field_type/seo.rb +1 -0
  47. data/lib/dato/local/field_type/slug.rb +1 -0
  48. data/lib/dato/local/field_type/string.rb +1 -0
  49. data/lib/dato/local/field_type/text.rb +1 -0
  50. data/lib/dato/local/field_type/theme.rb +2 -0
  51. data/lib/dato/local/field_type/video.rb +2 -1
  52. data/lib/dato/local/item.rb +4 -3
  53. data/lib/dato/local/items_repo.rb +1 -0
  54. data/lib/dato/local/json_api_entity.rb +7 -0
  55. data/lib/dato/local/json_api_meta.rb +37 -0
  56. data/lib/dato/local/loader.rb +2 -1
  57. data/lib/dato/local/site.rb +4 -3
  58. data/lib/dato/paginator.rb +5 -2
  59. data/lib/dato/repo.rb +33 -34
  60. data/lib/dato/site/client.rb +1 -0
  61. data/lib/dato/upload/file.rb +3 -2
  62. data/lib/dato/upload/image.rb +1 -0
  63. data/lib/dato/utils/favicon_tags_builder.rb +1 -0
  64. data/lib/dato/utils/locale_value.rb +1 -0
  65. data/lib/dato/utils/meta_tags/article_modified_time.rb +1 -0
  66. data/lib/dato/utils/meta_tags/article_publisher.rb +1 -0
  67. data/lib/dato/utils/meta_tags/base.rb +1 -0
  68. data/lib/dato/utils/meta_tags/description.rb +1 -0
  69. data/lib/dato/utils/meta_tags/image.rb +1 -0
  70. data/lib/dato/utils/meta_tags/og_locale.rb +1 -0
  71. data/lib/dato/utils/meta_tags/og_site_name.rb +1 -0
  72. data/lib/dato/utils/meta_tags/og_type.rb +1 -0
  73. data/lib/dato/utils/meta_tags/robots.rb +1 -0
  74. data/lib/dato/utils/meta_tags/title.rb +1 -0
  75. data/lib/dato/utils/meta_tags/twitter_card.rb +2 -1
  76. data/lib/dato/utils/meta_tags/twitter_site.rb +1 -0
  77. data/lib/dato/utils/seo_tags_builder.rb +1 -0
  78. data/lib/dato/version.rb +2 -1
  79. data/lib/dato/watch/site_change_watcher.rb +1 -0
  80. metadata +20 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5ae3d060427e32a0e8240e4ec18a7dc66d2457aa9be2101679d21a637226121a
4
- data.tar.gz: 30a4ef8ebf7dccbf40787016c1ab328a8bb39b5ba1d6bcc7b8d5291e71b99688
3
+ metadata.gz: e965d544e11d85ebaf829b6aff17334fc58b9aab772297a47d409f2f858ed622
4
+ data.tar.gz: 5898c9367032bc65546562070207ef1ad66a4da4196e82cf03f0d4b20e4eeacf
5
5
  SHA512:
6
- metadata.gz: bd48be79a2d9ce658ae571353e9c2e788e16f7ee78645d59119074b2ff4ee56c45e3b7bfd70547ec81038403cb23f94503186f5a48ef4746edf26bf6b3e419a9
7
- data.tar.gz: fc73eddecfa27ec33119090bacbf6275fa79e96b75c262761b4a54edf5b9d73261d627327f7b2290250c998c64fc5bc413da8e31b44b6c6e00ae6ee33d44dca2
6
+ metadata.gz: 5a7f9f76d1b9fcbd035186f5e1cb696b82c17a5a68a56cdb70fcc65704dac5c97a109941d836925265260cca3330279f1b68c1ad8510ac7553b0a08a0ec4caf0
7
+ data.tar.gz: '035934e55ecef6d1173ee2bfd0f8ea6c20607a88d31acbe43b7ba94633098c07c72de97eb949b89b4ef000c0accec85660d15423a9d3aa1349633dbc62d6b62b'
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.6.10
2
+
3
+ * Introduced `.meta` on `Dato::Local::Item` to fetch all meta information about the records
4
+
1
5
  # 0.6.5
2
6
 
3
7
  * The `.seo_meta_tags` method now generates fallback titles based on the model field title
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  source 'https://rubygems.org'
3
4
 
4
5
  # Specify your gem's dependencies in dato.gemspec
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'bundler/gem_tasks'
3
4
  require 'rspec/core/rake_task'
4
5
 
data/bin/rspec ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rspec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require 'pathname'
12
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path('bundle', __dir__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require 'rubygems'
27
+ require 'bundler/setup'
28
+
29
+ load Gem.bin_path('rspec-core', 'rspec')
data/dato.gemspec CHANGED
@@ -28,8 +28,9 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency 'vcr'
29
29
  spec.add_development_dependency 'webmock'
30
30
  spec.add_development_dependency 'rubocop'
31
- spec.add_development_dependency 'diff_dirs'
32
31
  spec.add_development_dependency 'coveralls'
32
+ spec.add_development_dependency 'pry'
33
+ spec.add_runtime_dependency 'front_matter_parser'
33
34
 
34
35
  spec.add_runtime_dependency 'faraday', ['>= 0.9.0']
35
36
  spec.add_runtime_dependency 'faraday_middleware', ['>= 0.9.0']
data/exe/dato CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
+ $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
5
5
 
6
6
  require 'dotenv'
7
7
  Dotenv.load
data/lib/dato.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'dato/version'
3
4
 
4
5
  require 'dato/site/client'
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'dato/api_client'
3
4
 
4
5
  module Dato
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'faraday'
2
4
  require 'faraday_middleware'
3
5
  require 'json'
@@ -40,7 +42,7 @@ module Dato
40
42
  schema.expand_references!
41
43
 
42
44
  schema.definitions.each do |type, schema|
43
- is_collection = schema.links.select{|x| x.rel === "instances"}.any?
45
+ is_collection = schema.links.select { |x| x.rel === 'instances' }.any?
44
46
  namespace = is_collection ? type.pluralize : type
45
47
 
46
48
  define_method(namespace) do
@@ -55,7 +57,8 @@ module Dato
55
57
  end
56
58
 
57
59
  def request(*args)
58
- connection.send(*args).body.with_indifferent_access
60
+ response = connection.send(*args)
61
+ response.body.with_indifferent_access
59
62
  rescue Faraday::SSLError => e
60
63
  raise e if ENV['SSL_CERT_FILE'] == Cacert.pem
61
64
 
@@ -80,7 +83,7 @@ module Dato
80
83
  'Content-Type' => 'application/json',
81
84
  'Authorization' => "Bearer #{@token}",
82
85
  'User-Agent' => "ruby-client v#{Dato::VERSION}",
83
- 'X-Api-Version' => "2"
86
+ 'X-Api-Version' => '2'
84
87
  }
85
88
 
86
89
  options = {
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Dato
3
4
  class ApiError < StandardError
4
5
  attr_reader :faraday_error
data/lib/dato/cli.rb CHANGED
@@ -1,11 +1,10 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'thor'
3
4
  require 'dato/dump/runner'
4
5
  require 'dato/dump/ssg_detector'
5
6
  require 'dato/watch/site_change_watcher'
6
7
  require 'listen'
7
- require 'thread'
8
-
9
8
  module Dato
10
9
  class Cli < Thor
11
10
  package_name 'DatoCMS'
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'dato/dump/operation/add_to_data_file'
3
4
 
4
5
  module Dato
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'dato/dump/operation/create_data_file'
3
4
 
4
5
  module Dato
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'dato/dump/operation/create_post'
3
4
 
4
5
  module Dato
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'dato/dump/dsl/create_post'
3
4
  require 'dato/dump/dsl/create_data_file'
4
5
  require 'dato/dump/dsl/add_to_data_file'
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'dato/dump/dsl/directory'
3
4
  require 'dato/dump/dsl/create_post'
4
5
  require 'dato/dump/dsl/create_data_file'
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'dato/dump/format/toml'
3
4
  require 'dato/dump/format/yaml'
4
5
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'json'
3
4
 
4
5
  module Dato
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'active_support/core_ext/hash/keys'
3
4
  require 'toml'
4
5
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'active_support/core_ext/hash/keys'
3
4
  require 'yaml'
4
5
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'dato/dump/format'
3
4
 
4
5
  module Dato
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'fileutils'
3
4
  require 'dato/dump/format'
4
5
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'fileutils'
3
4
  require 'dato/dump/format'
4
5
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'fileutils'
3
4
 
4
5
  module Dato
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Dato
3
4
  module Dump
4
5
  module Operation
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'dato/dump/dsl/root'
3
4
  require 'dato/dump/operation/root'
4
5
  require 'dato/dump/ssg_detector'
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'toml'
3
4
  require 'json'
4
5
  require 'yaml'
@@ -8,12 +9,12 @@ module Dato
8
9
  class SsgDetector
9
10
  attr_reader :path
10
11
 
11
- RUBY = %w(middleman jekyll nanoc).freeze
12
+ RUBY = %w[middleman jekyll nanoc].freeze
12
13
 
13
- NODE = %w(brunch assemble ember-cli hexo metalsmith react-scripts
14
- roots docpad wintersmith gatsby harp grunt gulp).freeze
14
+ NODE = %w[brunch assemble ember-cli hexo metalsmith react-scripts
15
+ roots docpad wintersmith gatsby harp grunt gulp].freeze
15
16
 
16
- PYTHON = %w(mkdocs pelican cactus).freeze
17
+ PYTHON = %w[mkdocs pelican cactus].freeze
17
18
 
18
19
  HUGO = [
19
20
  {
@@ -22,7 +23,7 @@ module Dato
22
23
  },
23
24
  {
24
25
  file: 'config.yaml',
25
- loader: ->(content) { YAML.load(content) }
26
+ loader: ->(content) { YAML.safe_load(content) }
26
27
  },
27
28
  {
28
29
  file: 'config.json',
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Dato
3
4
  class JsonApiDeserializer
4
5
  def deserialize(data)
@@ -14,9 +15,7 @@ module Dato
14
15
  def deserialize_resource(data)
15
16
  result = { id: data[:id] }
16
17
 
17
- if data[:attributes]
18
- result.merge!(data[:attributes])
19
- end
18
+ result.merge!(data[:attributes]) if data[:attributes]
20
19
 
21
20
  relationships = data.delete(:relationships)
22
21
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Dato
3
4
  class JsonApiSerializer
4
5
  attr_reader :link, :type
@@ -65,31 +66,29 @@ module Dato
65
66
  end
66
67
 
67
68
  def attributes(resource)
68
- if type == "item"
69
- return resource.keys.map(&:to_sym) - [
70
- :item_type,
71
- :id,
72
- :created_at,
73
- :updated_at,
74
- :is_valid,
75
- :published_version,
76
- :current_version
69
+ if type == 'item'
70
+ return resource.keys.map(&:to_sym) - %i[
71
+ item_type
72
+ id
73
+ created_at
74
+ updated_at
75
+ is_valid
76
+ published_version
77
+ current_version
77
78
  ]
78
79
  end
79
80
 
80
- link_attributes["properties"].keys.map(&:to_sym)
81
+ link_attributes['properties'].keys.map(&:to_sym)
81
82
  end
82
83
 
83
84
  def required_attributes
84
- if type == "item"
85
- return []
86
- end
85
+ return [] if type == 'item'
87
86
 
88
87
  (link_attributes.required || []).map(&:to_sym)
89
88
  end
90
89
 
91
90
  def relationships
92
- if type == "item"
91
+ if type == 'item'
93
92
  if link.rel == :create
94
93
  return { item_type: { collection: false, type: 'item_type' } }
95
94
  else
@@ -97,12 +96,10 @@ module Dato
97
96
  end
98
97
  end
99
98
 
100
- if !link_relationships
101
- return {}
102
- end
99
+ return {} unless link_relationships
103
100
 
104
- link_relationships.properties.reduce({}) do |acc, (relationship, schema)|
105
- is_collection = schema.properties["data"].type.first == 'array'
101
+ link_relationships.properties.each_with_object({}) do |(relationship, schema), acc|
102
+ is_collection = schema.properties['data'].type.first == 'array'
106
103
 
107
104
  definition = if is_collection
108
105
  schema.properties['data'].items
@@ -119,27 +116,23 @@ module Dato
119
116
 
120
117
  acc[relationship.to_sym] = {
121
118
  collection: is_collection,
122
- type: type,
119
+ type: type
123
120
  }
124
-
125
- acc
126
121
  end
127
122
  end
128
123
 
129
124
  def required_relationships
130
- if type == "item"
131
- return %i(item_type)
132
- end
125
+ return %i[item_type] if type == 'item'
133
126
 
134
127
  (link_relationships.required || []).map(&:to_sym)
135
128
  end
136
129
 
137
130
  def link_attributes
138
- link.schema.properties["data"].properties["attributes"]
131
+ link.schema.properties['data'].properties['attributes']
139
132
  end
140
133
 
141
134
  def link_relationships
142
- link.schema.properties["data"].properties["relationships"]
135
+ link.schema.properties['data'].properties['relationships']
143
136
  end
144
137
  end
145
138
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'dato/local/json_api_entity'
3
4
 
4
5
  module Dato
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Dato
3
4
  module Local
4
5
  module FieldType
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- #
2
+
3
3
  module Dato
4
4
  module Local
5
5
  module FieldType
@@ -25,7 +25,7 @@ module Dato
25
25
  def rgb
26
26
  if alpha == 1.0
27
27
  "rgb(#{red}, #{green}, #{blue})"
28
- else #
28
+ else
29
29
  "rgba(#{red}, #{green}, #{blue}, #{alpha})"
30
30
  end
31
31
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Dato
3
4
  module Local
4
5
  module FieldType
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Dato
3
4
  module Local
4
5
  module FieldType
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'imgix'
3
4
 
4
5
  module Dato
@@ -9,7 +10,7 @@ module Dato
9
10
 
10
11
  def self.parse(upload_id, repo)
11
12
  if upload_id
12
- upload = repo.entities_repo.find_entity("upload", upload_id)
13
+ upload = repo.entities_repo.find_entity('upload', upload_id)
13
14
 
14
15
  if upload
15
16
  new(
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Dato
3
4
  module Local
4
5
  module FieldType
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'dato/local/field_type/file'
3
4
 
4
5
  module Dato
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'dato/local/field_type/seo'
3
4
 
4
5
  module Dato
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Dato
3
4
  module Local
4
5
  module FieldType
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Dato
3
4
  module Local
4
5
  module FieldType
@@ -10,4 +11,3 @@ module Dato
10
11
  end
11
12
  end
12
13
  end
13
-
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Dato
3
4
  module Local
4
5
  module FieldType
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Dato
3
4
  module Local
4
5
  module FieldType
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Dato
3
4
  module Local
4
5
  module FieldType
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Dato
3
4
  module Local
4
5
  module FieldType
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Dato
3
4
  module Local
4
5
  module FieldType
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Dato
3
4
  module Local
4
5
  module FieldType
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Dato
3
4
  module Local
4
5
  module FieldType
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Dato
3
4
  module Local
4
5
  module FieldType
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dato
2
4
  module Local
3
5
  module FieldType
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'active_support/core_ext/hash/compact'
3
4
 
4
5
  module Dato
@@ -54,7 +55,7 @@ module Dato
54
55
  elsif provider == 'vimeo'
55
56
  %(<iframe src="//player.vimeo.com/video/#{provider_uid}?title=0&amp;byline=0&amp;portrait=0" width="#{width}" height="#{height}" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>)
56
57
  elsif provider == 'facebook'
57
- %(<iframe src="//www.facebook.com/plugins/video.php?href=#{url}&width=#{width}&show_text=false&height=#{height}" width="#{width}" height="#{height}" style="border:none;overflow:hidden;width:100%;" scrolling="no" frameborder="0" allowTransparency="true" allow="encrypted-media" allowFullScreen="true"></iframe>)
58
+ %(<iframe src="//www.facebook.com/plugins/video.php?href=#{url}&width=#{width}&show_text=false&height=#{height}" width="#{width}" height="#{height}" style="border:none;overflow:hidden;width:100%;" scrolling="no" frameborder="0" allowTransparency="true" allow="encrypted-media" allowFullScreen="true"></iframe>)
58
59
  end
59
60
  # rubocop:enable Metrics/LineLength
60
61
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'forwardable'
3
4
  require 'active_support/inflector/transliterate'
4
5
  require 'active_support/hash_with_indifferent_access'
@@ -14,7 +15,7 @@ module Dato
14
15
  extend Forwardable
15
16
 
16
17
  attr_reader :entity
17
- def_delegators :entity, :id
18
+ def_delegators :entity, :id, :meta
18
19
 
19
20
  def initialize(entity, items_repo)
20
21
  @entity = entity
@@ -63,11 +64,11 @@ module Dato
63
64
  end
64
65
 
65
66
  def updated_at
66
- Time.parse(entity.updated_at).utc
67
+ Time.parse(meta.updated_at).utc
67
68
  end
68
69
 
69
70
  def created_at
70
- Time.parse(entity.created_at).utc
71
+ Time.parse(meta.created_at).utc
71
72
  end
72
73
 
73
74
  def to_s
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'active_support/core_ext/string'
3
4
  require 'dato/local/item'
4
5
  require 'dato/local/site'
@@ -1,4 +1,7 @@
1
1
  # frozen_string_literal: true
2
+
3
+ require 'dato/local/json_api_meta'
4
+
2
5
  module Dato
3
6
  module Local
4
7
  class JsonApiEntity
@@ -17,6 +20,10 @@ module Dato
17
20
  @payload[:type]
18
21
  end
19
22
 
23
+ def meta
24
+ @meta ||= JsonApiMeta.new(@payload[:meta])
25
+ end
26
+
20
27
  def ==(other)
21
28
  if other.is_a? JsonApiEntity
22
29
  id == other.id && type == other.type
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dato
4
+ module Local
5
+ class JsonApiMeta
6
+ attr_reader :payload
7
+
8
+ def initialize(payload)
9
+ @payload = payload || {}
10
+ end
11
+
12
+ def [](key)
13
+ @payload[key]
14
+ end
15
+
16
+ def respond_to_missing?(method, include_private = false)
17
+ if @payload.key?(method)
18
+ true
19
+ else
20
+ super
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def method_missing(method, *arguments, &block)
27
+ return super unless arguments.empty?
28
+
29
+ if @payload.key?(method)
30
+ @payload[method]
31
+ else
32
+ super
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'dato/local/entities_repo'
3
4
  require 'dato/local/items_repo'
4
5
 
@@ -50,7 +51,7 @@ module Dato
50
51
 
51
52
  def all_uploads
52
53
  client.uploads.all(
53
- { "filter[type]" => "used" },
54
+ { 'filter[type]' => 'used' },
54
55
  deserialize_response: false,
55
56
  all_pages: true
56
57
  )
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'forwardable'
3
4
  require 'active_support/inflector/transliterate'
4
5
  require 'active_support/hash_with_indifferent_access'
@@ -40,9 +41,9 @@ module Dato
40
41
  end
41
42
 
42
43
  def to_hash
43
- attributes = [
44
- :id, :name, :locales, :theme, :domain, :internal_domain,
45
- :no_index, :global_seo, :favicon, :frontend_url
44
+ attributes = %i[
45
+ id name locales theme domain internal_domain
46
+ no_index global_seo favicon frontend_url
46
47
  ]
47
48
 
48
49
  attributes.each_with_object({}) do |attribute, result|
@@ -1,7 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dato
2
4
  class Paginator
3
5
  def initialize(client, base_endpoint, filters)
4
- @client, @base_endpoint, @filters = client, base_endpoint, filters
6
+ @client = client
7
+ @base_endpoint = base_endpoint
8
+ @filters = filters
5
9
  end
6
10
 
7
11
  def response
@@ -30,4 +34,3 @@ module Dato
30
34
  end
31
35
  end
32
36
  end
33
-
data/lib/dato/repo.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'dato/json_api_serializer'
3
4
  require 'dato/json_api_deserializer'
4
5
  require 'dato/paginator'
@@ -10,9 +11,9 @@ module Dato
10
11
  IDENTITY_REGEXP = /\{\(.*?definitions%2F(.*?)%2Fdefinitions%2Fidentity\)}/
11
12
 
12
13
  METHOD_NAMES = {
13
- "instances" => :all,
14
- "self" => :find,
15
- }
14
+ 'instances' => :all,
15
+ 'self' => :find
16
+ }.freeze
16
17
 
17
18
  def initialize(client, type, schema)
18
19
  @client = client
@@ -22,57 +23,55 @@ module Dato
22
23
  schema.links.each do |link|
23
24
  method_name = METHOD_NAMES.fetch(link.rel, link.rel)
24
25
 
25
- self.define_singleton_method(method_name) do |*args|
26
+ define_singleton_method(method_name) do |*args|
26
27
  min_arguments_count = [
27
28
  link.href.scan(IDENTITY_REGEXP).size,
28
29
  link.schema && link.method != :get ? 1 : 0
29
30
  ].reduce(0, :+)
30
31
 
31
- args.size >= min_arguments_count or
32
- raise ArgumentError.new(
33
- "wrong number of arguments (given #{args.size}, expected #{min_arguments_count})"
34
- )
32
+ (args.size >= min_arguments_count) or
33
+ raise ArgumentError, "wrong number of arguments (given #{args.size}, expected #{min_arguments_count})"
35
34
 
36
35
  placeholders = []
37
36
 
38
- url = link["href"].gsub(IDENTITY_REGEXP) do |_stuff|
37
+ url = link['href'].gsub(IDENTITY_REGEXP) do |_stuff|
39
38
  placeholder = args.shift.to_s
40
39
  placeholders << placeholder
41
40
  placeholder
42
41
  end
43
42
 
44
- response = if %i(post put).include?(link.method)
45
- body = if link.schema
46
- unserialized_body = args.shift
43
+ response = if %i[post put].include?(link.method)
44
+ body = if link.schema
45
+ unserialized_body = args.shift
47
46
 
48
- JsonApiSerializer.new(type, link).serialize(
49
- unserialized_body,
50
- link.method == :post ? nil : placeholders.last
51
- )
52
- else
53
- {}
54
- end
47
+ JsonApiSerializer.new(type, link).serialize(
48
+ unserialized_body,
49
+ link.method == :post ? nil : placeholders.last
50
+ )
51
+ else
52
+ {}
53
+ end
55
54
 
56
- client.request(link.method, url, body)
55
+ client.request(link.method, url, body)
57
56
 
58
- elsif link.method == :delete
59
- client.request(:delete, url)
57
+ elsif link.method == :delete
58
+ client.request(:delete, url)
60
59
 
61
- elsif link.method == :get
62
- query_string = args.shift
60
+ elsif link.method == :get
61
+ query_string = args.shift
63
62
 
64
- all_pages = (args[0] || {}).
65
- symbolize_keys.
66
- fetch(:all_pages, false)
63
+ all_pages = (args[0] || {})
64
+ .symbolize_keys
65
+ .fetch(:all_pages, false)
67
66
 
68
- is_paginated_endpoint = link.schema &&
69
- link.schema.properties.has_key?("page[limit]")
67
+ is_paginated_endpoint = link.schema &&
68
+ link.schema.properties.key?('page[limit]')
70
69
 
71
- if is_paginated_endpoint && all_pages
72
- Paginator.new(client, url, query_string).response
73
- else
74
- client.request(:get, url, query_string)
75
- end
70
+ if is_paginated_endpoint && all_pages
71
+ Paginator.new(client, url, query_string).response
72
+ else
73
+ client.request(:get, url, query_string)
74
+ end
76
75
  end
77
76
 
78
77
  options = if args.any?
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'dato/api_client'
3
4
  require 'dato/upload/file'
4
5
  require 'dato/upload/image'
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'downloadr'
3
4
  require 'tempfile'
4
5
  require 'addressable'
@@ -8,7 +9,7 @@ require 'fastimage'
8
9
  module Dato
9
10
  module Upload
10
11
  class File
11
- IMAGE_FORMATS = %w(png jpg jpeg gif)
12
+ IMAGE_FORMATS = %w[png jpg jpeg gif].freeze
12
13
 
13
14
  attr_reader :client, :source
14
15
 
@@ -63,7 +64,7 @@ module Dato
63
64
  format_resource(upload_request)
64
65
  )
65
66
 
66
- uploads["id"]
67
+ uploads['id']
67
68
  end
68
69
 
69
70
  def format_resource(upload_request)
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'dato/upload/file'
3
4
 
4
5
  module Dato
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Dato
3
4
  module Utils
4
5
  class FaviconTagsBuilder
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'i18n/backend/fallbacks'
3
4
 
4
5
  module Dato
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'dato/utils/meta_tags/base'
3
4
  require 'time'
4
5
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'dato/utils/meta_tags/base'
3
4
 
4
5
  module Dato
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'forwardable'
3
4
  require 'dato/local/field_type/seo'
4
5
  require 'active_support/core_ext/object/blank'
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'dato/utils/meta_tags/base'
3
4
 
4
5
  module Dato
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'dato/utils/meta_tags/base'
3
4
 
4
5
  module Dato
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'dato/utils/meta_tags/base'
3
4
 
4
5
  module Dato
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'dato/utils/meta_tags/base'
3
4
 
4
5
  module Dato
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'dato/utils/meta_tags/base'
3
4
 
4
5
  module Dato
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'dato/utils/meta_tags/base'
3
4
 
4
5
  module Dato
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'dato/utils/meta_tags/base'
3
4
 
4
5
  module Dato
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'dato/utils/meta_tags/base'
3
4
 
4
5
  module Dato
@@ -6,7 +7,7 @@ module Dato
6
7
  module MetaTags
7
8
  class TwitterCard < Base
8
9
  def build
9
- card_tag('twitter:card', seo_field_with_fallback(:twitter_card, nil) || "summary")
10
+ card_tag('twitter:card', seo_field_with_fallback(:twitter_card, nil) || 'summary')
10
11
  end
11
12
  end
12
13
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'dato/utils/meta_tags/base'
3
4
 
4
5
  module Dato
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'dato/utils/meta_tags/title'
3
4
  require 'dato/utils/meta_tags/description'
4
5
  require 'dato/utils/meta_tags/image'
data/lib/dato/version.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Dato
3
- VERSION = '0.6.9'
4
+ VERSION = '0.6.10'
4
5
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'pusher-client'
3
4
 
4
5
  module Dato
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dato
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.9
4
+ version: 0.6.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefano Verna
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-23 00:00:00.000000000 Z
11
+ date: 2018-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -123,7 +123,7 @@ dependencies:
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
- name: diff_dirs
126
+ name: coveralls
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - ">="
@@ -137,7 +137,7 @@ dependencies:
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
- name: coveralls
140
+ name: pry
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - ">="
@@ -150,6 +150,20 @@ dependencies:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: front_matter_parser
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: faraday
155
169
  requirement: !ruby/object:Gem::Requirement
@@ -366,6 +380,7 @@ files:
366
380
  - README.md
367
381
  - Rakefile
368
382
  - bin/console
383
+ - bin/rspec
369
384
  - bin/setup
370
385
  - dato.gemspec
371
386
  - exe/dato
@@ -416,6 +431,7 @@ files:
416
431
  - lib/dato/local/item.rb
417
432
  - lib/dato/local/items_repo.rb
418
433
  - lib/dato/local/json_api_entity.rb
434
+ - lib/dato/local/json_api_meta.rb
419
435
  - lib/dato/local/loader.rb
420
436
  - lib/dato/local/site.rb
421
437
  - lib/dato/paginator.rb