dato 0.6.9 → 0.6.10
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile +1 -0
- data/Rakefile +1 -0
- data/bin/rspec +29 -0
- data/dato.gemspec +2 -1
- data/exe/dato +1 -1
- data/lib/dato.rb +1 -0
- data/lib/dato/account/client.rb +1 -0
- data/lib/dato/api_client.rb +6 -3
- data/lib/dato/api_error.rb +1 -0
- data/lib/dato/cli.rb +1 -2
- data/lib/dato/dump/dsl/add_to_data_file.rb +1 -0
- data/lib/dato/dump/dsl/create_data_file.rb +1 -0
- data/lib/dato/dump/dsl/create_post.rb +1 -0
- data/lib/dato/dump/dsl/directory.rb +1 -0
- data/lib/dato/dump/dsl/root.rb +1 -0
- data/lib/dato/dump/format.rb +1 -0
- data/lib/dato/dump/format/json.rb +1 -0
- data/lib/dato/dump/format/toml.rb +1 -0
- data/lib/dato/dump/format/yaml.rb +1 -0
- data/lib/dato/dump/operation/add_to_data_file.rb +1 -0
- data/lib/dato/dump/operation/create_data_file.rb +1 -0
- data/lib/dato/dump/operation/create_post.rb +1 -0
- data/lib/dato/dump/operation/directory.rb +1 -0
- data/lib/dato/dump/operation/root.rb +1 -0
- data/lib/dato/dump/runner.rb +1 -0
- data/lib/dato/dump/ssg_detector.rb +6 -5
- data/lib/dato/json_api_deserializer.rb +2 -3
- data/lib/dato/json_api_serializer.rb +20 -27
- data/lib/dato/local/entities_repo.rb +1 -0
- data/lib/dato/local/field_type/boolean.rb +1 -0
- data/lib/dato/local/field_type/color.rb +2 -2
- data/lib/dato/local/field_type/date.rb +1 -0
- data/lib/dato/local/field_type/date_time.rb +1 -0
- data/lib/dato/local/field_type/file.rb +2 -1
- data/lib/dato/local/field_type/float.rb +1 -0
- data/lib/dato/local/field_type/gallery.rb +1 -0
- data/lib/dato/local/field_type/global_seo.rb +1 -0
- data/lib/dato/local/field_type/integer.rb +1 -0
- data/lib/dato/local/field_type/json.rb +1 -1
- data/lib/dato/local/field_type/lat_lon.rb +1 -0
- data/lib/dato/local/field_type/link.rb +1 -0
- data/lib/dato/local/field_type/links.rb +1 -0
- data/lib/dato/local/field_type/rich_text.rb +1 -0
- data/lib/dato/local/field_type/seo.rb +1 -0
- data/lib/dato/local/field_type/slug.rb +1 -0
- data/lib/dato/local/field_type/string.rb +1 -0
- data/lib/dato/local/field_type/text.rb +1 -0
- data/lib/dato/local/field_type/theme.rb +2 -0
- data/lib/dato/local/field_type/video.rb +2 -1
- data/lib/dato/local/item.rb +4 -3
- data/lib/dato/local/items_repo.rb +1 -0
- data/lib/dato/local/json_api_entity.rb +7 -0
- data/lib/dato/local/json_api_meta.rb +37 -0
- data/lib/dato/local/loader.rb +2 -1
- data/lib/dato/local/site.rb +4 -3
- data/lib/dato/paginator.rb +5 -2
- data/lib/dato/repo.rb +33 -34
- data/lib/dato/site/client.rb +1 -0
- data/lib/dato/upload/file.rb +3 -2
- data/lib/dato/upload/image.rb +1 -0
- data/lib/dato/utils/favicon_tags_builder.rb +1 -0
- data/lib/dato/utils/locale_value.rb +1 -0
- data/lib/dato/utils/meta_tags/article_modified_time.rb +1 -0
- data/lib/dato/utils/meta_tags/article_publisher.rb +1 -0
- data/lib/dato/utils/meta_tags/base.rb +1 -0
- data/lib/dato/utils/meta_tags/description.rb +1 -0
- data/lib/dato/utils/meta_tags/image.rb +1 -0
- data/lib/dato/utils/meta_tags/og_locale.rb +1 -0
- data/lib/dato/utils/meta_tags/og_site_name.rb +1 -0
- data/lib/dato/utils/meta_tags/og_type.rb +1 -0
- data/lib/dato/utils/meta_tags/robots.rb +1 -0
- data/lib/dato/utils/meta_tags/title.rb +1 -0
- data/lib/dato/utils/meta_tags/twitter_card.rb +2 -1
- data/lib/dato/utils/meta_tags/twitter_site.rb +1 -0
- data/lib/dato/utils/seo_tags_builder.rb +1 -0
- data/lib/dato/version.rb +2 -1
- data/lib/dato/watch/site_change_watcher.rb +1 -0
- metadata +20 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e965d544e11d85ebaf829b6aff17334fc58b9aab772297a47d409f2f858ed622
|
|
4
|
+
data.tar.gz: 5898c9367032bc65546562070207ef1ad66a4da4196e82cf03f0d4b20e4eeacf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5a7f9f76d1b9fcbd035186f5e1cb696b82c17a5a68a56cdb70fcc65704dac5c97a109941d836925265260cca3330279f1b68c1ad8510ac7553b0a08a0ec4caf0
|
|
7
|
+
data.tar.gz: '035934e55ecef6d1173ee2bfd0f8ea6c20607a88d31acbe43b7ba94633098c07c72de97eb949b89b4ef000c0accec85660d15423a9d3aa1349633dbc62d6b62b'
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/Rakefile
CHANGED
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
data/lib/dato.rb
CHANGED
data/lib/dato/account/client.rb
CHANGED
data/lib/dato/api_client.rb
CHANGED
|
@@ -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 ===
|
|
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)
|
|
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' =>
|
|
86
|
+
'X-Api-Version' => '2'
|
|
84
87
|
}
|
|
85
88
|
|
|
86
89
|
options = {
|
data/lib/dato/api_error.rb
CHANGED
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'
|
data/lib/dato/dump/dsl/root.rb
CHANGED
data/lib/dato/dump/format.rb
CHANGED
data/lib/dato/dump/runner.rb
CHANGED
|
@@ -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
|
|
12
|
+
RUBY = %w[middleman jekyll nanoc].freeze
|
|
12
13
|
|
|
13
|
-
NODE = %w
|
|
14
|
-
roots docpad wintersmith gatsby harp grunt gulp
|
|
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
|
|
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.
|
|
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 ==
|
|
69
|
-
return resource.keys.map(&:to_sym) - [
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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[
|
|
81
|
+
link_attributes['properties'].keys.map(&:to_sym)
|
|
81
82
|
end
|
|
82
83
|
|
|
83
84
|
def required_attributes
|
|
84
|
-
if type ==
|
|
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 ==
|
|
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
|
-
|
|
101
|
-
return {}
|
|
102
|
-
end
|
|
99
|
+
return {} unless link_relationships
|
|
103
100
|
|
|
104
|
-
link_relationships.properties.
|
|
105
|
-
is_collection = schema.properties[
|
|
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 ==
|
|
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[
|
|
131
|
+
link.schema.properties['data'].properties['attributes']
|
|
139
132
|
end
|
|
140
133
|
|
|
141
134
|
def link_relationships
|
|
142
|
-
link.schema.properties[
|
|
135
|
+
link.schema.properties['data'].properties['relationships']
|
|
143
136
|
end
|
|
144
137
|
end
|
|
145
138
|
end
|
|
@@ -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
|
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(
|
|
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
|
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&byline=0&portrait=0" width="#{width}" height="#{height}" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>)
|
|
56
57
|
elsif provider == 'facebook'
|
|
57
|
-
|
|
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
|
data/lib/dato/local/item.rb
CHANGED
|
@@ -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(
|
|
67
|
+
Time.parse(meta.updated_at).utc
|
|
67
68
|
end
|
|
68
69
|
|
|
69
70
|
def created_at
|
|
70
|
-
Time.parse(
|
|
71
|
+
Time.parse(meta.created_at).utc
|
|
71
72
|
end
|
|
72
73
|
|
|
73
74
|
def to_s
|
|
@@ -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
|
data/lib/dato/local/loader.rb
CHANGED
|
@@ -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
|
-
{
|
|
54
|
+
{ 'filter[type]' => 'used' },
|
|
54
55
|
deserialize_response: false,
|
|
55
56
|
all_pages: true
|
|
56
57
|
)
|
data/lib/dato/local/site.rb
CHANGED
|
@@ -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
|
-
|
|
45
|
-
|
|
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|
|
data/lib/dato/paginator.rb
CHANGED
|
@@ -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
|
|
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
|
-
|
|
14
|
-
|
|
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
|
-
|
|
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.
|
|
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[
|
|
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
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
response = if %i[post put].include?(link.method)
|
|
44
|
+
body = if link.schema
|
|
45
|
+
unserialized_body = args.shift
|
|
47
46
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
55
|
+
client.request(link.method, url, body)
|
|
57
56
|
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
elsif link.method == :delete
|
|
58
|
+
client.request(:delete, url)
|
|
60
59
|
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
elsif link.method == :get
|
|
61
|
+
query_string = args.shift
|
|
63
62
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
all_pages = (args[0] || {})
|
|
64
|
+
.symbolize_keys
|
|
65
|
+
.fetch(:all_pages, false)
|
|
67
66
|
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
is_paginated_endpoint = link.schema &&
|
|
68
|
+
link.schema.properties.key?('page[limit]')
|
|
70
69
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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?
|
data/lib/dato/site/client.rb
CHANGED
data/lib/dato/upload/file.rb
CHANGED
|
@@ -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
|
|
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[
|
|
67
|
+
uploads['id']
|
|
67
68
|
end
|
|
68
69
|
|
|
69
70
|
def format_resource(upload_request)
|
data/lib/dato/upload/image.rb
CHANGED
|
@@ -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) ||
|
|
10
|
+
card_tag('twitter:card', seo_field_with_fallback(:twitter_card, nil) || 'summary')
|
|
10
11
|
end
|
|
11
12
|
end
|
|
12
13
|
end
|
data/lib/dato/version.rb
CHANGED
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.
|
|
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
|
+
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:
|
|
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:
|
|
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
|