dato 0.1.6 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/dato.gemspec +4 -3
- data/exe/dato +7 -0
- data/lib/dato.rb +1 -0
- data/lib/dato/dump/cli.rb +19 -0
- data/lib/dato/dump/dsl/add_to_data_file.rb +14 -0
- data/lib/dato/dump/dsl/create_data_file.rb +14 -0
- data/lib/dato/dump/dsl/create_post.rb +33 -0
- data/lib/dato/dump/dsl/directory.rb +25 -0
- data/lib/dato/dump/dsl/root.rb +37 -0
- data/lib/dato/dump/format.rb +26 -0
- data/lib/dato/dump/format/toml.rb +19 -0
- data/lib/dato/dump/format/yaml.rb +19 -0
- data/lib/dato/dump/operation/add_to_data_file.rb +39 -0
- data/lib/dato/dump/operation/create_data_file.rb +25 -0
- data/lib/dato/dump/operation/create_post.rb +31 -0
- data/lib/dato/dump/operation/directory.rb +34 -0
- data/lib/dato/dump/operation/root.rb +27 -0
- data/lib/dato/dump/runner.rb +38 -0
- data/lib/dato/local/item.rb +4 -2
- data/lib/dato/version.rb +1 -1
- metadata +36 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa6cd26ac346a262967adba55486b614dec900d2
|
4
|
+
data.tar.gz: 5df73d12129516a164298059aee45ee57c21a98f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b251136ad1db77b6ba2d98adb07a8557980ca829871f11726a9cc8c0881265212eb2783c9fc2768cbd7096527515aa89f8b6a8369e3dbba37e73533becb6320a
|
7
|
+
data.tar.gz: ce4c415f552fdafefaea3ba81b158b34e17e86fc669ffb7d0a3f417134e22294ae88056ffd4c69df822f7cea9d6ee9b3af42018f8277fde281a60c76592342ce
|
data/dato.gemspec
CHANGED
@@ -36,7 +36,8 @@ Gem::Specification.new do |spec|
|
|
36
36
|
spec.add_runtime_dependency 'fastimage'
|
37
37
|
spec.add_runtime_dependency 'downloadr'
|
38
38
|
spec.add_runtime_dependency 'addressable'
|
39
|
-
spec.add_runtime_dependency
|
40
|
-
spec.add_runtime_dependency
|
41
|
-
spec.add_runtime_dependency
|
39
|
+
spec.add_runtime_dependency 'thor'
|
40
|
+
spec.add_runtime_dependency 'imgix', ['>= 0.3.1']
|
41
|
+
spec.add_runtime_dependency 'video_embed'
|
42
|
+
spec.add_runtime_dependency 'toml'
|
42
43
|
end
|
data/exe/dato
ADDED
data/lib/dato.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'thor'
|
3
|
+
require 'dato/dump/runner'
|
4
|
+
|
5
|
+
module Dato
|
6
|
+
module Dump
|
7
|
+
class Cli < Thor
|
8
|
+
package_name 'DatoCMS'
|
9
|
+
|
10
|
+
desc 'dump', 'dumps DatoCMS contents into local files'
|
11
|
+
option :config, default: 'dato.config.rb'
|
12
|
+
option :token, default: ENV['DATO_API_TOKEN'], required: true
|
13
|
+
def dump
|
14
|
+
config_file = File.expand_path(options[:config])
|
15
|
+
Runner.new(config_file, options[:token]).run
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'dato/dump/operation/add_to_data_file'
|
3
|
+
|
4
|
+
module Dato
|
5
|
+
module Dump
|
6
|
+
module Dsl
|
7
|
+
module AddToDataFile
|
8
|
+
def add_to_data_file(*args)
|
9
|
+
operations.add Operation::AddToDataFile.new(operations, *args)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'dato/dump/operation/create_data_file'
|
3
|
+
|
4
|
+
module Dato
|
5
|
+
module Dump
|
6
|
+
module Dsl
|
7
|
+
module CreateDataFile
|
8
|
+
def create_data_file(*args)
|
9
|
+
operations.add Operation::CreateDataFile.new(operations, *args)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'dato/dump/operation/create_post'
|
3
|
+
|
4
|
+
module Dato
|
5
|
+
module Dump
|
6
|
+
module Dsl
|
7
|
+
class DataFile
|
8
|
+
def initialize(operation, &block)
|
9
|
+
@operation = operation
|
10
|
+
instance_eval(&block)
|
11
|
+
end
|
12
|
+
|
13
|
+
def frontmatter(format, value)
|
14
|
+
@operation.frontmatter_format = format
|
15
|
+
@operation.frontmatter_value = value
|
16
|
+
end
|
17
|
+
|
18
|
+
def content(value)
|
19
|
+
@operation.content = value
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module CreatePost
|
24
|
+
def create_post(path, &block)
|
25
|
+
operation = Operation::CreatePost.new(operations, path)
|
26
|
+
DataFile.new(operation, &block)
|
27
|
+
|
28
|
+
operations.add operation
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'dato/dump/dsl/create_post'
|
3
|
+
require 'dato/dump/dsl/create_data_file'
|
4
|
+
require 'dato/dump/dsl/add_to_data_file'
|
5
|
+
|
6
|
+
module Dato
|
7
|
+
module Dump
|
8
|
+
module Dsl
|
9
|
+
class Directory
|
10
|
+
include Dsl::CreateDataFile
|
11
|
+
include Dsl::CreatePost
|
12
|
+
include Dsl::AddToDataFile
|
13
|
+
|
14
|
+
attr_reader :dato, :operations
|
15
|
+
|
16
|
+
def initialize(dato, operations, &block)
|
17
|
+
@dato = dato
|
18
|
+
@operations = operations
|
19
|
+
|
20
|
+
instance_eval(&block)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'dato/dump/dsl/directory'
|
3
|
+
require 'dato/dump/dsl/create_post'
|
4
|
+
require 'dato/dump/dsl/create_data_file'
|
5
|
+
require 'dato/dump/dsl/add_to_data_file'
|
6
|
+
|
7
|
+
require 'dato/dump/operation/directory'
|
8
|
+
|
9
|
+
module Dato
|
10
|
+
module Dump
|
11
|
+
module Dsl
|
12
|
+
class Root
|
13
|
+
include Dsl::CreateDataFile
|
14
|
+
include Dsl::CreatePost
|
15
|
+
include Dsl::AddToDataFile
|
16
|
+
|
17
|
+
attr_reader :dato, :operations
|
18
|
+
|
19
|
+
def initialize(config_code, dato, operations)
|
20
|
+
@dato = dato
|
21
|
+
@operations = operations
|
22
|
+
|
23
|
+
# rubocop:disable Lint/Eval
|
24
|
+
eval(config_code)
|
25
|
+
# rubocop:enable Lint/Eval
|
26
|
+
end
|
27
|
+
|
28
|
+
def directory(path, &block)
|
29
|
+
operation = Operation::Directory.new(operations, path)
|
30
|
+
operations.add operation
|
31
|
+
|
32
|
+
Directory.new(dato, operation, &block)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'dato/dump/format/toml'
|
3
|
+
require 'dato/dump/format/yaml'
|
4
|
+
|
5
|
+
module Dato
|
6
|
+
module Dump
|
7
|
+
module Format
|
8
|
+
def self.dump(format, value)
|
9
|
+
converter_for(format).dump(value)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.frontmatter_dump(format, value)
|
13
|
+
converter_for(format).frontmatter_dump(value)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.converter_for(format)
|
17
|
+
case format
|
18
|
+
when :toml
|
19
|
+
Format::Toml
|
20
|
+
when :yaml
|
21
|
+
Format::Yaml
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'active_support/core_ext/hash/keys'
|
3
|
+
require 'toml'
|
4
|
+
|
5
|
+
module Dato
|
6
|
+
module Dump
|
7
|
+
module Format
|
8
|
+
module Toml
|
9
|
+
def self.dump(value)
|
10
|
+
TOML::Generator.new(value).body
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.frontmatter_dump(value)
|
14
|
+
"+++\n#{dump(value)}+++"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'active_support/core_ext/hash/keys'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module Dato
|
6
|
+
module Dump
|
7
|
+
module Format
|
8
|
+
module Yaml
|
9
|
+
def self.dump(value)
|
10
|
+
YAML.dump(value).chomp.gsub(/^\-+\n/, '')
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.frontmatter_dump(value)
|
14
|
+
"---\n#{dump(value)}\n---"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'dato/dump/format'
|
3
|
+
|
4
|
+
module Dato
|
5
|
+
module Dump
|
6
|
+
module Operation
|
7
|
+
class AddToDataFile
|
8
|
+
attr_reader :context, :path, :format, :value
|
9
|
+
|
10
|
+
def initialize(context, path, format, value)
|
11
|
+
@context = context
|
12
|
+
@path = path
|
13
|
+
@format = format
|
14
|
+
@value = value
|
15
|
+
end
|
16
|
+
|
17
|
+
def perform
|
18
|
+
complete_path = File.join(context.path, path)
|
19
|
+
content_to_add = Format.dump(format, value)
|
20
|
+
|
21
|
+
old_content = if File.exist? complete_path
|
22
|
+
::File.read(complete_path)
|
23
|
+
else
|
24
|
+
''
|
25
|
+
end
|
26
|
+
|
27
|
+
new_content = old_content.sub(
|
28
|
+
/\n*(#\s*datocms:start.*#\s*datocms:end|\Z)/m,
|
29
|
+
"\n\n# datocms:start\n#{content_to_add}\n# datocms:end"
|
30
|
+
)
|
31
|
+
|
32
|
+
File.open(complete_path, 'w') do |f|
|
33
|
+
f.write new_content
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'dato/dump/format'
|
3
|
+
|
4
|
+
module Dato
|
5
|
+
module Dump
|
6
|
+
module Operation
|
7
|
+
class CreateDataFile
|
8
|
+
attr_reader :context, :path, :format, :value
|
9
|
+
|
10
|
+
def initialize(context, path, format, value)
|
11
|
+
@context = context
|
12
|
+
@path = path
|
13
|
+
@format = format
|
14
|
+
@value = value
|
15
|
+
end
|
16
|
+
|
17
|
+
def perform
|
18
|
+
File.open(File.join(context.path, path), 'w') do |file|
|
19
|
+
file.write Format.dump(format, value)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'dato/dump/format'
|
3
|
+
|
4
|
+
module Dato
|
5
|
+
module Dump
|
6
|
+
module Operation
|
7
|
+
class CreatePost
|
8
|
+
attr_reader :context, :path
|
9
|
+
|
10
|
+
attr_accessor :frontmatter_format, :frontmatter_value
|
11
|
+
attr_accessor :content
|
12
|
+
|
13
|
+
def initialize(context, path)
|
14
|
+
@context = context
|
15
|
+
@path = path
|
16
|
+
end
|
17
|
+
|
18
|
+
def perform
|
19
|
+
File.open(File.join(context.path, path), 'w') do |file|
|
20
|
+
file.write Format.frontmatter_dump(
|
21
|
+
frontmatter_format,
|
22
|
+
frontmatter_value
|
23
|
+
)
|
24
|
+
file.write "\n\n"
|
25
|
+
file.write content
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module Dato
|
5
|
+
module Dump
|
6
|
+
module Operation
|
7
|
+
class Directory
|
8
|
+
attr_reader :context, :path
|
9
|
+
|
10
|
+
def initialize(context, path)
|
11
|
+
@context = context
|
12
|
+
@path = File.join(context.path, path)
|
13
|
+
@operations = []
|
14
|
+
end
|
15
|
+
|
16
|
+
def add(operation)
|
17
|
+
@operations << operation
|
18
|
+
end
|
19
|
+
|
20
|
+
def perform
|
21
|
+
FileUtils.remove_dir(path) if Dir.exist?(path)
|
22
|
+
|
23
|
+
FileUtils.mkdir_p(path)
|
24
|
+
|
25
|
+
operations.each(&:perform)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
attr_reader :operations
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Dato
|
3
|
+
module Dump
|
4
|
+
module Operation
|
5
|
+
class Root
|
6
|
+
attr_reader :path
|
7
|
+
|
8
|
+
def initialize(path)
|
9
|
+
@operations = []
|
10
|
+
@path = path
|
11
|
+
end
|
12
|
+
|
13
|
+
def add(operation)
|
14
|
+
@operations << operation
|
15
|
+
end
|
16
|
+
|
17
|
+
def perform
|
18
|
+
operations.each(&:perform)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
attr_reader :operations
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'dato/dump/dsl/root'
|
3
|
+
require 'dato/dump/operation/root'
|
4
|
+
|
5
|
+
module Dato
|
6
|
+
module Dump
|
7
|
+
class Runner
|
8
|
+
attr_reader :config_path, :api_token
|
9
|
+
|
10
|
+
def initialize(config_path, api_token)
|
11
|
+
@config_path = config_path
|
12
|
+
@api_token = api_token
|
13
|
+
end
|
14
|
+
|
15
|
+
def run
|
16
|
+
site.load
|
17
|
+
|
18
|
+
root = Operation::Root.new(Dir.pwd)
|
19
|
+
|
20
|
+
Dsl::Root.new(
|
21
|
+
File.read(config_path),
|
22
|
+
site.items_repo,
|
23
|
+
root
|
24
|
+
)
|
25
|
+
|
26
|
+
root.perform
|
27
|
+
end
|
28
|
+
|
29
|
+
def site
|
30
|
+
@site ||= Dato::Local::Site.new(client)
|
31
|
+
end
|
32
|
+
|
33
|
+
def client
|
34
|
+
@client ||= Dato::Site::Client.new(api_token)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/dato/local/item.rb
CHANGED
@@ -24,13 +24,15 @@ module Dato
|
|
24
24
|
other.is_a?(Item) && other.id == id
|
25
25
|
end
|
26
26
|
|
27
|
-
def slug
|
27
|
+
def slug(prefix_with_id: true)
|
28
28
|
return item_type.api_key.humanize.parameterize if singleton?
|
29
29
|
return id.to_s unless title_attribute
|
30
30
|
|
31
31
|
title = send(title_attribute)
|
32
|
-
if title
|
32
|
+
if title && prefix_with_id
|
33
33
|
"#{id}-#{title.parameterize[0..50]}"
|
34
|
+
elsif title
|
35
|
+
title.parameterize[0..50]
|
34
36
|
else
|
35
37
|
id.to_s
|
36
38
|
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.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefano Verna
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -220,6 +220,20 @@ dependencies:
|
|
220
220
|
- - ">="
|
221
221
|
- !ruby/object:Gem::Version
|
222
222
|
version: '0'
|
223
|
+
- !ruby/object:Gem::Dependency
|
224
|
+
name: thor
|
225
|
+
requirement: !ruby/object:Gem::Requirement
|
226
|
+
requirements:
|
227
|
+
- - ">="
|
228
|
+
- !ruby/object:Gem::Version
|
229
|
+
version: '0'
|
230
|
+
type: :runtime
|
231
|
+
prerelease: false
|
232
|
+
version_requirements: !ruby/object:Gem::Requirement
|
233
|
+
requirements:
|
234
|
+
- - ">="
|
235
|
+
- !ruby/object:Gem::Version
|
236
|
+
version: '0'
|
223
237
|
- !ruby/object:Gem::Dependency
|
224
238
|
name: imgix
|
225
239
|
requirement: !ruby/object:Gem::Requirement
|
@@ -249,7 +263,7 @@ dependencies:
|
|
249
263
|
- !ruby/object:Gem::Version
|
250
264
|
version: '0'
|
251
265
|
- !ruby/object:Gem::Dependency
|
252
|
-
name:
|
266
|
+
name: toml
|
253
267
|
requirement: !ruby/object:Gem::Requirement
|
254
268
|
requirements:
|
255
269
|
- - ">="
|
@@ -265,7 +279,8 @@ dependencies:
|
|
265
279
|
description: Ruby client for DatoCMS API
|
266
280
|
email:
|
267
281
|
- s.verna@cantierecreativo.net
|
268
|
-
executables:
|
282
|
+
executables:
|
283
|
+
- dato
|
269
284
|
extensions: []
|
270
285
|
extra_rdoc_files: []
|
271
286
|
files:
|
@@ -281,12 +296,28 @@ files:
|
|
281
296
|
- bin/console
|
282
297
|
- bin/setup
|
283
298
|
- dato.gemspec
|
299
|
+
- exe/dato
|
284
300
|
- lib/dato.rb
|
285
301
|
- lib/dato/account/client.rb
|
286
302
|
- lib/dato/account/repo/account.rb
|
287
303
|
- lib/dato/account/repo/base.rb
|
288
304
|
- lib/dato/account/repo/site.rb
|
289
305
|
- lib/dato/api_error.rb
|
306
|
+
- lib/dato/dump/cli.rb
|
307
|
+
- lib/dato/dump/dsl/add_to_data_file.rb
|
308
|
+
- lib/dato/dump/dsl/create_data_file.rb
|
309
|
+
- lib/dato/dump/dsl/create_post.rb
|
310
|
+
- lib/dato/dump/dsl/directory.rb
|
311
|
+
- lib/dato/dump/dsl/root.rb
|
312
|
+
- lib/dato/dump/format.rb
|
313
|
+
- lib/dato/dump/format/toml.rb
|
314
|
+
- lib/dato/dump/format/yaml.rb
|
315
|
+
- lib/dato/dump/operation/add_to_data_file.rb
|
316
|
+
- lib/dato/dump/operation/create_data_file.rb
|
317
|
+
- lib/dato/dump/operation/create_post.rb
|
318
|
+
- lib/dato/dump/operation/directory.rb
|
319
|
+
- lib/dato/dump/operation/root.rb
|
320
|
+
- lib/dato/dump/runner.rb
|
290
321
|
- lib/dato/json_api_deserializer.rb
|
291
322
|
- lib/dato/json_api_serializer.rb
|
292
323
|
- lib/dato/local/entities_repo.rb
|
@@ -345,3 +376,4 @@ signing_key:
|
|
345
376
|
specification_version: 4
|
346
377
|
summary: Ruby client for DatoCMS API
|
347
378
|
test_files: []
|
379
|
+
has_rdoc:
|