siteleaf 2.0.0.pre.beta9 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CNAME +1 -0
- data/README.md +7 -5
- data/bin/siteleaf +101 -103
- data/lib/siteleaf/client.rb +30 -35
- data/lib/siteleaf/collection.rb +10 -10
- data/lib/siteleaf/content.rb +6 -6
- data/lib/siteleaf/entity.rb +7 -5
- data/lib/siteleaf/site.rb +16 -38
- data/lib/siteleaf/source_file.rb +11 -11
- data/lib/siteleaf/version.rb +1 -1
- data/siteleaf.gemspec +6 -6
- metadata +17 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1ec284cc046f9c5e51dfbba051755160066b078f14301e874b4196b2fe046d96
|
4
|
+
data.tar.gz: 964a33326bb9753b4676dc1754345b6de1dc8fc7786c75675faea4f178681fd9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95c90c707c9cc8f90ee16d9d07a2b00756a440d5c4201aeedda7d2d9511b70be421be8d7175be69ee8a3f810b864d634f3c3d3e6dc58291253fff205964b5b3c
|
7
|
+
data.tar.gz: aad52462704662408a6adbe07b39bd78ac1f125267a01bf34feb6cdc8e078208498dcfa28bbbb97b7eab755f3e95ea9ca8e19523760688abfcfb4cde33c26584
|
data/CNAME
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
gem.siteleaf.net
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Siteleaf Gem
|
1
|
+
Siteleaf v2 Gem
|
2
2
|
===============
|
3
3
|
|
4
4
|
- [Installation](#installation)
|
@@ -11,11 +11,13 @@ Siteleaf Gem V2
|
|
11
11
|
Installation
|
12
12
|
------------
|
13
13
|
|
14
|
-
The Siteleaf gem is available for installation on [Rubygems](https://rubygems.org/gems/siteleaf). To install run:
|
14
|
+
The [Siteleaf](https://www.siteleaf.com) gem is available for installation on [Rubygems](https://rubygems.org/gems/siteleaf). To install run:
|
15
15
|
|
16
|
-
gem install siteleaf
|
16
|
+
gem install siteleaf
|
17
17
|
|
18
|
-
|
18
|
+
**Note:** the v2 gem only works with v2 sites. For documentation on v1 see: https://github.com/siteleaf/siteleaf-gem/tree/v1
|
19
|
+
|
20
|
+
If maintaining sites with multiple versions, we recommend using a [Gemfile](#using-this-gem-in-your-application).
|
19
21
|
|
20
22
|
|
21
23
|
Using the CLI
|
@@ -78,7 +80,7 @@ Using this gem in your application
|
|
78
80
|
|
79
81
|
To use this gem in your application, add the following to your Gemfile:
|
80
82
|
|
81
|
-
gem 'siteleaf',
|
83
|
+
gem 'siteleaf', '~>2'
|
82
84
|
|
83
85
|
|
84
86
|
Using the API
|
data/bin/siteleaf
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'siteleaf'
|
4
|
+
require 'jekyll'
|
4
5
|
require 'fileutils'
|
6
|
+
require 'pathutil'
|
5
7
|
require 'open-uri'
|
6
8
|
require 'tempfile'
|
7
9
|
require 'yaml'
|
@@ -30,9 +32,9 @@ See https://github.com/siteleaf/siteleaf-gem for additional documentation.
|
|
30
32
|
end
|
31
33
|
|
32
34
|
def auth(re_auth = false)
|
33
|
-
Siteleaf.load_settings if !re_auth && !Siteleaf.api_key
|
35
|
+
Siteleaf.load_settings if !re_auth && !(Siteleaf.api_key && Siteleaf.api_secret)
|
34
36
|
|
35
|
-
if re_auth or !Siteleaf.api_key
|
37
|
+
if re_auth or !(Siteleaf.api_key && Siteleaf.api_secret)
|
36
38
|
print 'Enter your Siteleaf email: '
|
37
39
|
email = $stdin.gets.chomp
|
38
40
|
|
@@ -42,28 +44,28 @@ def auth(re_auth = false)
|
|
42
44
|
system 'stty echo'
|
43
45
|
|
44
46
|
puts "\nAuthorizing..."
|
45
|
-
|
46
|
-
|
47
|
+
|
48
|
+
auth = Siteleaf::Client.auth(email, password)
|
49
|
+
if auth.is_a?(Hash) && auth.has_key?('api_key')
|
47
50
|
Siteleaf.save_settings({api_key: auth['api_key'], api_secret: auth['api_secret']})
|
48
|
-
|
51
|
+
Siteleaf.load_settings
|
52
|
+
puts "=> Account authorized." if re_auth
|
49
53
|
return true
|
50
54
|
else
|
51
|
-
|
52
|
-
return false
|
55
|
+
raise "Could not authorize, check your email or password."
|
53
56
|
end
|
54
57
|
end
|
55
|
-
rescue Exception => e
|
56
|
-
print "Error: #{e.message}\n"
|
57
58
|
end
|
58
59
|
|
59
60
|
def pull(site_id)
|
60
61
|
print "Reading site...\n"
|
61
|
-
|
62
|
+
|
62
63
|
# get all the things
|
63
64
|
site = Siteleaf::Site.find(site_id)
|
64
|
-
site_files = site.
|
65
|
+
site_files = site.source_files('.', recursive: true)
|
66
|
+
|
65
67
|
updated_count = 0
|
66
|
-
|
68
|
+
|
67
69
|
# download unmatched files
|
68
70
|
site_files.each do |file|
|
69
71
|
sha = ::File.exist?(file.name) && Siteleaf::GitHash.file(file.name)
|
@@ -75,11 +77,11 @@ def pull(site_id)
|
|
75
77
|
print "complete.\n"
|
76
78
|
end
|
77
79
|
end
|
78
|
-
|
80
|
+
|
79
81
|
# check for old files
|
80
82
|
local_files = read_dir
|
81
83
|
missing_files = []
|
82
|
-
local_files.each do |path|
|
84
|
+
local_files.each do |path|
|
83
85
|
missing_files << path if !site_files.find{|a| a.name.casecmp(path) == 0 }
|
84
86
|
end
|
85
87
|
if missing_files.empty?
|
@@ -99,42 +101,40 @@ def pull(site_id)
|
|
99
101
|
puts "=> #{missing_files.size} file(s) deleted.\n"
|
100
102
|
end
|
101
103
|
end
|
102
|
-
rescue Exception => e
|
103
|
-
print "Error: #{e.message}\n"
|
104
104
|
end
|
105
105
|
|
106
106
|
def push(site_id)
|
107
107
|
print "Reading site...\n"
|
108
|
-
|
108
|
+
|
109
109
|
# get all the things
|
110
110
|
site = Siteleaf::Site.find(site_id)
|
111
|
-
|
111
|
+
|
112
|
+
site_files = site.source_files('.', recursive: true)
|
112
113
|
local_files = read_dir
|
113
114
|
updated_count = 0
|
114
|
-
|
115
|
+
|
115
116
|
# find changed files
|
116
117
|
changed_files = local_files.reject do |path|
|
117
118
|
file = site_files.find{|a| a.name.casecmp(path) == 0 }
|
118
119
|
file && Siteleaf::GitHash.file(path) == file.sha
|
119
120
|
end
|
120
|
-
changed_files.unshift('_config.yml') if changed_files.delete('_config.yml')
|
121
|
-
|
121
|
+
changed_files.unshift('_config.yml') if changed_files.delete('_config.yml')
|
122
|
+
|
122
123
|
# upload changed files
|
123
|
-
changed_files.each do |path|
|
124
|
-
print "Uploading #{path}..."
|
124
|
+
changed_files.each do |path|
|
125
|
+
print "Uploading #{path}..."
|
125
126
|
response = Siteleaf::SourceFile.create(site_id: site_id, name: path, file: ::File.new(path))
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
print "complete.\n"
|
127
|
+
updated_count += 1
|
128
|
+
print "complete.\n"
|
129
|
+
if response.name && response.name != path
|
130
|
+
local_files.push(response.name)
|
131
|
+
puts "Warning: Remote filename has been normalized to `#{response.name}`."
|
132
132
|
end
|
133
133
|
end
|
134
|
-
|
134
|
+
|
135
135
|
# check for old files
|
136
136
|
missing_assets = []
|
137
|
-
site_files.each do |asset|
|
137
|
+
site_files.each do |asset|
|
138
138
|
missing_assets << asset if !local_files.find{|p| p.casecmp(asset.name) == 0 }
|
139
139
|
end
|
140
140
|
if missing_assets.empty?
|
@@ -154,13 +154,11 @@ def push(site_id)
|
|
154
154
|
puts "=> #{missing_assets.size} file(s) deleted.\n"
|
155
155
|
end
|
156
156
|
end
|
157
|
-
rescue Exception => e
|
158
|
-
print "Error: #{e.message}\n"
|
159
157
|
end
|
160
158
|
|
161
159
|
def import(file, quiet = true)
|
162
160
|
job = Siteleaf::Site.import(file: ::File.new(file))
|
163
|
-
|
161
|
+
|
164
162
|
if quiet
|
165
163
|
puts "=> Import queued.\n"
|
166
164
|
else
|
@@ -173,14 +171,12 @@ def import(file, quiet = true)
|
|
173
171
|
end
|
174
172
|
puts "=> Import completed.\n"
|
175
173
|
end
|
176
|
-
rescue Exception => e
|
177
|
-
print "Error: #{e.message}\n"
|
178
174
|
end
|
179
175
|
|
180
176
|
def publish(site_id, quiet = true)
|
181
177
|
site = Siteleaf::Site.new(id: site_id)
|
182
178
|
job = site.publish
|
183
|
-
|
179
|
+
|
184
180
|
if quiet
|
185
181
|
puts "=> Publish queued.\n"
|
186
182
|
else
|
@@ -193,8 +189,6 @@ def publish(site_id, quiet = true)
|
|
193
189
|
end
|
194
190
|
puts "=> Publish completed.\n"
|
195
191
|
end
|
196
|
-
rescue Exception => e
|
197
|
-
print "Error: #{e.message}\n"
|
198
192
|
end
|
199
193
|
|
200
194
|
def config(site)
|
@@ -209,101 +203,105 @@ def get_site_id
|
|
209
203
|
Siteleaf.send "#{key}=", value
|
210
204
|
end
|
211
205
|
end
|
212
|
-
|
206
|
+
|
213
207
|
ENV['SITELEAF_SITE_ID'] || if settings = Siteleaf.load_settings('.siteleaf.yml')
|
214
208
|
settings[:site_id]
|
215
209
|
end
|
216
210
|
end
|
217
211
|
|
218
212
|
def read_dir
|
219
|
-
|
220
|
-
|
213
|
+
jekyll_site = Jekyll::Site.new(Jekyll.configuration(quiet: true))
|
214
|
+
|
221
215
|
ignore_paths = ['config.ru', '.*', '_site/*', 'Gemfile', 'Gemfile.lock']
|
222
216
|
ignore_paths += ::File.read('.siteleafignore').split(/\r?\n/) if ::File.exists?('.siteleafignore')
|
223
|
-
ignore_paths +=
|
217
|
+
ignore_paths += jekyll_site.exclude
|
224
218
|
|
219
|
+
entry_filter = Jekyll::EntryFilter.new(jekyll_site)
|
220
|
+
|
225
221
|
Dir.glob("**/*").reject do |path|
|
226
|
-
::File.directory?(path) ||
|
227
|
-
ignore_paths.any? {|i| ::File.fnmatch?(i, path, File::FNM_CASEFOLD) || ::File.fnmatch?(i, ::File.basename(path), File::FNM_CASEFOLD) }
|
222
|
+
::File.directory?(path) || entry_filter.glob_include?(ignore_paths, path)
|
228
223
|
end
|
229
224
|
end
|
230
225
|
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
auth
|
238
|
-
|
239
|
-
|
240
|
-
if
|
241
|
-
|
242
|
-
|
243
|
-
|
226
|
+
begin
|
227
|
+
case ARGV[0]
|
228
|
+
when '-v', '--version', 'version'
|
229
|
+
puts Siteleaf::VERSION
|
230
|
+
when '-h', '--help', 'help'
|
231
|
+
puts help
|
232
|
+
when 'auth'
|
233
|
+
auth true
|
234
|
+
when 'c', 'config', 'setup'
|
235
|
+
if auth != false
|
236
|
+
if site = Siteleaf::Site.find_by_domain(ARGV[1])
|
237
|
+
config site
|
238
|
+
else
|
239
|
+
raise "No site found for `#{ARGV[1]}`, run `siteleaf new #{ARGV[1]}` to create it.\n"
|
240
|
+
end
|
244
241
|
end
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
if (site = Siteleaf::Site.create(:title => ARGV[1], :domain => ARGV[1])) && (!site.error)
|
242
|
+
when 'n', 'new'
|
243
|
+
if auth != false
|
244
|
+
site = Siteleaf::Site.create(:title => ARGV[1], :domain => ARGV[1])
|
249
245
|
dir = ARGV.size >= 3 ? ARGV[2] : ARGV[1]
|
250
246
|
Dir.mkdir(dir) unless ::File.directory?(dir)
|
251
247
|
Dir.chdir(dir)
|
252
248
|
config site
|
249
|
+
end
|
250
|
+
when 'pull'
|
251
|
+
if ARGV.size == 1
|
252
|
+
site_id = get_site_id
|
253
|
+
if auth != false
|
254
|
+
if site_id
|
255
|
+
pull(site_id)
|
256
|
+
else
|
257
|
+
raise "Site not configured, run `siteleaf config yoursite.com`.\n"
|
258
|
+
end
|
259
|
+
end
|
253
260
|
else
|
254
|
-
|
261
|
+
raise "`#{ARGV.join(' ')}` command not found.\n"
|
255
262
|
end
|
256
|
-
|
257
|
-
|
258
|
-
|
263
|
+
when 'push'
|
264
|
+
if ARGV.size == 1
|
265
|
+
site_id = get_site_id
|
266
|
+
if auth != false
|
267
|
+
if site_id
|
268
|
+
push(site_id)
|
269
|
+
else
|
270
|
+
raise "Site not configured, run `siteleaf config yoursite.com`.\n"
|
271
|
+
end
|
272
|
+
end
|
273
|
+
else
|
274
|
+
raise "`#{ARGV.join(' ')}` command not found.\n"
|
275
|
+
end
|
276
|
+
when 'publish'
|
259
277
|
site_id = get_site_id
|
260
278
|
if auth != false
|
279
|
+
quiet = %w[-q --quiet].include?(ARGV[1]) && ARGV[1]
|
261
280
|
if site_id
|
262
|
-
|
281
|
+
publish(site_id, quiet)
|
263
282
|
else
|
264
|
-
|
283
|
+
raise "Site not configured, run `siteleaf config yoursite.com`.\n"
|
265
284
|
end
|
266
285
|
end
|
267
|
-
|
268
|
-
puts "`#{ARGV.join(' ')}` command not found.\n"
|
269
|
-
end
|
270
|
-
when 'push'
|
271
|
-
if ARGV.size == 1
|
286
|
+
when 'import'
|
272
287
|
site_id = get_site_id
|
273
288
|
if auth != false
|
274
|
-
|
275
|
-
|
289
|
+
file = ARGV[1]
|
290
|
+
if File.extname(file) != '.zip'
|
291
|
+
raise "Import file must be ZIP format.\n"
|
292
|
+
elsif !File.exist?(file)
|
293
|
+
raise "Import file not found.\n"
|
276
294
|
else
|
277
|
-
|
295
|
+
quiet = %w[-q --quiet].include?(ARGV[2]) && ARGV[2]
|
296
|
+
import(file, quiet)
|
278
297
|
end
|
279
298
|
end
|
280
299
|
else
|
281
|
-
puts "`#{ARGV
|
300
|
+
puts "Error: `#{ARGV[0]}` command not found.\n"
|
301
|
+
puts help
|
302
|
+
exit(1)
|
282
303
|
end
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
quiet = %w[-q --quiet].include?(ARGV[1]) && ARGV[1]
|
287
|
-
if site_id
|
288
|
-
publish(site_id, quiet)
|
289
|
-
else
|
290
|
-
puts "Site not configured, run `siteleaf config yoursite.com`.\n"
|
291
|
-
end
|
292
|
-
end
|
293
|
-
when 'import'
|
294
|
-
site_id = get_site_id
|
295
|
-
if auth != false
|
296
|
-
file = ARGV[1]
|
297
|
-
if File.extname(file) != '.zip'
|
298
|
-
puts "Import file must be ZIP format.\n"
|
299
|
-
elsif !File.exist?(file)
|
300
|
-
puts "Import file not found.\n"
|
301
|
-
else
|
302
|
-
quiet = %w[-q --quiet].include?(ARGV[2]) && ARGV[2]
|
303
|
-
import(file, quiet)
|
304
|
-
end
|
305
|
-
end
|
306
|
-
else
|
307
|
-
puts "`#{ARGV[0]}` command not found.\n"
|
308
|
-
puts help
|
304
|
+
rescue Exception => e
|
305
|
+
puts "Error: #{e.message}\n"
|
306
|
+
exit(1)
|
309
307
|
end
|
data/lib/siteleaf/client.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
require '
|
1
|
+
require 'httparty'
|
2
2
|
|
3
3
|
module Siteleaf
|
4
4
|
class Client
|
5
5
|
def self.auth(email, password)
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
return 'error' => e.message # error
|
6
|
+
request = HTTParty.post(Siteleaf.api_url('auth'), {
|
7
|
+
:basic_auth => {:username => email, :password => password},
|
8
|
+
:headers => {"User-Agent" => "Siteleaf Gem/#{Siteleaf::VERSION}"}
|
9
|
+
})
|
10
|
+
response = request.parsed_response
|
11
|
+
if response.is_a?(Hash) && error = response['message'] || response['error']
|
12
|
+
raise error
|
14
13
|
end
|
14
|
+
response
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.get(path, params = {})
|
@@ -33,33 +33,28 @@ module Siteleaf
|
|
33
33
|
|
34
34
|
def self.execute(method, path, params = nil)
|
35
35
|
Siteleaf.load_settings if !Siteleaf.api_key
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
:basic_auth => {:username => Siteleaf.api_key, :password => Siteleaf.api_secret},
|
51
|
-
:headers => {"User-Agent" => "Siteleaf Gem/#{Siteleaf::VERSION}"},
|
52
|
-
:timeout => 300
|
53
|
-
})
|
54
|
-
end
|
55
|
-
if request.respond_to?('parsed_response')
|
56
|
-
return request.parsed_response # parse JSON
|
57
|
-
else
|
58
|
-
return request # raw
|
59
|
-
end
|
60
|
-
rescue => e
|
61
|
-
return 'error' => e.message # error
|
36
|
+
|
37
|
+
options = {
|
38
|
+
:basic_auth => {:username => Siteleaf.api_key, :password => Siteleaf.api_secret},
|
39
|
+
:headers => {"User-Agent" => "Siteleaf Gem/#{Siteleaf::VERSION}"},
|
40
|
+
:timeout => 300
|
41
|
+
}
|
42
|
+
|
43
|
+
if method == :get || method == :delete
|
44
|
+
options[:query] = params
|
45
|
+
elsif params.has_key?('file') || params.has_key?(:file)
|
46
|
+
options[:body] = params
|
47
|
+
else
|
48
|
+
options[:body] = params.to_json
|
49
|
+
options[:headers]["Content-Type"] = "application/json"
|
62
50
|
end
|
51
|
+
|
52
|
+
request = HTTParty.send(method, Siteleaf.api_url(path), options)
|
53
|
+
response = request.parsed_response
|
54
|
+
if response.is_a?(Hash) && error = response['message'] || response['error']
|
55
|
+
raise error
|
56
|
+
end
|
57
|
+
response
|
63
58
|
end
|
64
59
|
end
|
65
60
|
end
|
data/lib/siteleaf/collection.rb
CHANGED
@@ -3,40 +3,40 @@ module Siteleaf
|
|
3
3
|
|
4
4
|
attr_accessor :title, :path, :permalink, :output, :site_id, :user_id, :metadata
|
5
5
|
attr_reader :id, :directory, :created_at, :updated_at
|
6
|
-
|
6
|
+
|
7
7
|
def create_endpoint
|
8
8
|
::File.join("sites", site_id, "collections")
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def entity_endpoint
|
12
12
|
::File.join(create_endpoint, identifier)
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def identifier
|
16
16
|
path
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def site
|
20
20
|
Site.find(site_id)
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def documents
|
24
24
|
result = Client.get "#{entity_endpoint}/documents"
|
25
25
|
result.map { |r| Document.new(r) } if result.is_a? Array
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
def files
|
29
29
|
result = Client.get "#{entity_endpoint}/files"
|
30
30
|
result.map { |r| File.new(r) } if result.is_a? Array
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
def output?
|
34
34
|
output == true
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
def filename
|
38
38
|
path
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
end
|
42
|
-
end
|
42
|
+
end
|
data/lib/siteleaf/content.rb
CHANGED
@@ -3,27 +3,27 @@ module Siteleaf
|
|
3
3
|
|
4
4
|
attr_accessor :title, :body, :path, :permalink, :visibility, :date, :user_id, :site_id, :metadata
|
5
5
|
attr_reader :id, :filename, :basename, :directory, :url, :sha, :created_at, :updated_at
|
6
|
-
|
6
|
+
|
7
7
|
def site
|
8
8
|
Site.find(site_id) if site_id
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def draft?
|
12
12
|
visibility == 'draft'
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def hidden?
|
16
16
|
visibility == 'hidden'
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def visible?
|
20
20
|
visibility == 'visible'
|
21
21
|
end
|
22
22
|
alias_method :published?, :visible?
|
23
|
-
|
23
|
+
|
24
24
|
def to_file
|
25
25
|
SourceFile.new(site_id: site_id, name: filename).to_file
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
end
|
29
29
|
end
|
data/lib/siteleaf/entity.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Siteleaf
|
2
2
|
class Entity
|
3
|
-
|
3
|
+
|
4
4
|
attr_reader :error, :message
|
5
5
|
|
6
6
|
def initialize(attributes = {})
|
@@ -20,7 +20,7 @@ module Siteleaf
|
|
20
20
|
def self.create(attributes = {})
|
21
21
|
new(attributes).save
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
def self.delete(identifier)
|
25
25
|
Client.delete "#{endpoint}/#{identifier}"
|
26
26
|
end
|
@@ -31,9 +31,11 @@ module Siteleaf
|
|
31
31
|
else
|
32
32
|
result = Client.post create_endpoint, attributes
|
33
33
|
end
|
34
|
-
if result
|
34
|
+
if result.is_a?(Hash)
|
35
35
|
self.attributes = result
|
36
36
|
return self
|
37
|
+
else
|
38
|
+
raise 'Invalid response'
|
37
39
|
end
|
38
40
|
end
|
39
41
|
|
@@ -60,11 +62,11 @@ module Siteleaf
|
|
60
62
|
def create_endpoint
|
61
63
|
self.class.endpoint
|
62
64
|
end
|
63
|
-
|
65
|
+
|
64
66
|
def entity_endpoint
|
65
67
|
"#{self.class.endpoint}/#{identifier}"
|
66
68
|
end
|
67
|
-
|
69
|
+
|
68
70
|
def identifier
|
69
71
|
id
|
70
72
|
end
|
data/lib/siteleaf/site.rb
CHANGED
@@ -3,79 +3,57 @@ module Siteleaf
|
|
3
3
|
|
4
4
|
attr_accessor :title, :domain, :timezone, :metadata, :defaults
|
5
5
|
attr_reader :id, :user_id, :created_at, :updated_at
|
6
|
-
|
6
|
+
|
7
7
|
def self.find_by_domain(domain)
|
8
8
|
results = Client.get self.endpoint
|
9
9
|
result = results.find {|d| d['domain'] == domain }
|
10
10
|
self.new(result) if result
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
def self.import(attrs)
|
14
14
|
result = Client.post "import", attrs
|
15
15
|
Job.new(id: result["job_id"]) if result
|
16
16
|
end
|
17
|
-
|
18
|
-
def source_files(dir = '.')
|
19
|
-
result = Client.get ::File.join(entity_endpoint, "source", dir)
|
17
|
+
|
18
|
+
def source_files(dir = '.', opts = {})
|
19
|
+
result = Client.get ::File.join(entity_endpoint, "source", dir), opts
|
20
20
|
result.map { |r| SourceFile.new(r.merge('site_id' => id)) } if result.is_a? Array
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def pages
|
24
24
|
result = Client.get "#{entity_endpoint}/pages"
|
25
25
|
result.map { |r| Page.new(r) } if result.is_a? Array
|
26
|
-
end
|
27
|
-
|
26
|
+
end
|
27
|
+
|
28
28
|
def collections
|
29
29
|
result = Client.get "#{entity_endpoint}/collections"
|
30
30
|
result.map { |r| Collection.new(r) } if result.is_a? Array
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
def posts
|
34
34
|
Collection.new(path: 'posts', site_id: id).documents
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
def uploads
|
38
38
|
Collection.new(path: 'uploads', site_id: id).files
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
def publish
|
42
42
|
result = Client.post "#{entity_endpoint}/publish", {}
|
43
43
|
Job.new(id: result["job_id"]) if result
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
def full_url
|
47
47
|
"http://#{domain}"
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
def filename
|
51
51
|
"_config.yml"
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
def sha
|
55
55
|
Siteleaf::GitHash.string(to_file)
|
56
56
|
end
|
57
|
-
|
58
|
-
def source_tree(dir = '.')
|
59
|
-
@tree_files = []
|
60
|
-
@tree_dirs = []
|
61
|
-
recursive_source_files(dir)
|
62
|
-
@tree_files
|
63
|
-
end
|
64
|
-
|
65
|
-
protected
|
66
|
-
|
67
|
-
def recursive_source_files(dir = '.')
|
68
|
-
source_files(dir).each do |file|
|
69
|
-
if file.type == 'directory'
|
70
|
-
unless @tree_dirs.include?(file.name)
|
71
|
-
@tree_dirs << file.name
|
72
|
-
recursive_source_files(file.name)
|
73
|
-
end
|
74
|
-
else
|
75
|
-
@tree_files << file
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
57
|
+
|
80
58
|
end
|
81
|
-
end
|
59
|
+
end
|
data/lib/siteleaf/source_file.rb
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
module Siteleaf
|
2
2
|
class SourceFile < Entity
|
3
|
-
|
3
|
+
|
4
4
|
attr_accessor :file, :name, :site_id
|
5
5
|
attr_reader :name, :url, :download_url, :type, :filesize, :sha, :created_at, :updated_at, :user_id
|
6
|
-
|
6
|
+
|
7
7
|
def create_endpoint
|
8
|
-
|
8
|
+
uri = URI.encode(identifier)
|
9
|
+
uri = uri.gsub('[', '%5B').gsub(']', '%5D') # workaround for https://bugs.ruby-lang.org/issues/12235
|
10
|
+
::File.join('sites', site_id, 'source', uri)
|
9
11
|
end
|
10
|
-
|
12
|
+
|
11
13
|
def entity_endpoint
|
12
14
|
create_endpoint
|
13
15
|
end
|
14
|
-
|
16
|
+
|
15
17
|
def identifier
|
16
18
|
name
|
17
19
|
end
|
18
|
-
|
20
|
+
|
19
21
|
def to_file
|
20
|
-
|
21
|
-
raise response['message'] if response['message'] # indicates API error
|
22
|
-
response.body
|
22
|
+
Client.get("#{entity_endpoint}?download")
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
end
|
26
|
-
end
|
26
|
+
end
|
data/lib/siteleaf/version.rb
CHANGED
data/siteleaf.gemspec
CHANGED
@@ -11,13 +11,13 @@ Gem::Specification.new do |gem|
|
|
11
11
|
gem.email = ["api@siteleaf.com"]
|
12
12
|
gem.description = %q{A Ruby interface and command line utility for the Siteleaf API.}
|
13
13
|
gem.summary = "Siteleaf Ruby interface"
|
14
|
-
gem.homepage = "
|
15
|
-
|
14
|
+
gem.homepage = "https://www.siteleaf.com"
|
15
|
+
|
16
16
|
gem.required_ruby_version = '>= 1.9.3'
|
17
|
-
|
18
|
-
gem.add_dependency 'httparty', '>= 0.
|
19
|
-
gem.add_dependency '
|
20
|
-
gem.add_dependency '
|
17
|
+
|
18
|
+
gem.add_dependency 'httparty', '>= 0.16.0'
|
19
|
+
gem.add_dependency 'psych', '>= 2.1.0'
|
20
|
+
gem.add_dependency 'jekyll', '>= 1.4.1'
|
21
21
|
gem.add_dependency 'rack'
|
22
22
|
|
23
23
|
gem.files = `git ls-files`.split($/)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: siteleaf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Siteleaf
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -16,42 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.16.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.16.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: psych
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 2.1.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 2.1.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: jekyll
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 1.4.1
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 1.4.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rack
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -75,6 +75,7 @@ extensions: []
|
|
75
75
|
extra_rdoc_files: []
|
76
76
|
files:
|
77
77
|
- ".gitignore"
|
78
|
+
- CNAME
|
78
79
|
- Gemfile
|
79
80
|
- LICENSE.txt
|
80
81
|
- README.md
|
@@ -95,7 +96,7 @@ files:
|
|
95
96
|
- lib/siteleaf/user.rb
|
96
97
|
- lib/siteleaf/version.rb
|
97
98
|
- siteleaf.gemspec
|
98
|
-
homepage:
|
99
|
+
homepage: https://www.siteleaf.com
|
99
100
|
licenses:
|
100
101
|
- MIT
|
101
102
|
metadata: {}
|
@@ -110,12 +111,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
110
111
|
version: 1.9.3
|
111
112
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
113
|
requirements:
|
113
|
-
- - "
|
114
|
+
- - ">="
|
114
115
|
- !ruby/object:Gem::Version
|
115
|
-
version:
|
116
|
+
version: '0'
|
116
117
|
requirements: []
|
117
|
-
|
118
|
-
rubygems_version: 2.4.7
|
118
|
+
rubygems_version: 3.1.2
|
119
119
|
signing_key:
|
120
120
|
specification_version: 4
|
121
121
|
summary: Siteleaf Ruby interface
|