siteleaf 2.0.0 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 381d797618975d09040410063221c28047e1e4cb
4
- data.tar.gz: f672e44c0c7476f66cbf936ccdaaf99d1c4edc0b
2
+ SHA256:
3
+ metadata.gz: 7632e9291c8a7111f572ac0380262e85d8ed86791fad2baa9ac7ef4bdea37973
4
+ data.tar.gz: 280efe8fe737f575fee142871d0b77334f5ee03e84e3d1613b42b5daa65c08c3
5
5
  SHA512:
6
- metadata.gz: 1fd6a066558b67b11360c4412e2936c04e2b8545d293ca6fd93eb91fcbda321b358eb262afcb5120d6019a1fcc5bb74b20882b5d1ac06b50d7ffecce0f3f4f1e
7
- data.tar.gz: 073d3a4f6acf1c36484d6ea6116bd6f38df5dc4a96ac42c3f4ea12613af8c9195ebc6b91d23b3bd7a29207a8ad8516e7883be5ded383dd7bb56d5df99f303489
6
+ metadata.gz: 6d641ff9b139f5ea7c49beb1bcab152fe19dde0996e3043cf3e137d0ba41488ff4f8250e47bd41042d0e5d35c36b9df11df845981cfc55438ba4d90e35a4c260
7
+ data.tar.gz: fe6f49d7ad52adce8522b35c77775e85b2170e327dd442fba6a043cf2b0f4482008643a3be544641e1480ae47293fec544e316feeb928bb503f00d94814d06f6
data/CNAME ADDED
@@ -0,0 +1 @@
1
+ gem.siteleaf.net
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
- Siteleaf Gem V2
1
+ <img alt="Siteleaf" src="https://learn.siteleaf.com/assets/images/logo.svg" width="10%">
2
+
3
+ Siteleaf v2 Gem
2
4
  ===============
3
5
 
6
+ - [Prerequisites](#prerequisites)
4
7
  - [Installation](#installation)
5
8
  - [Using the CLI](#using-the-cli)
6
9
  - [Using this gem in your application](#using-this-gem-in-your-application)
@@ -8,14 +11,23 @@ Siteleaf Gem V2
8
11
  - [Troubleshooting](#troubleshooting)
9
12
  - [Contributing](#contributing)
10
13
 
14
+
15
+ Prerequisites
16
+ -------------
17
+
18
+ Install Ruby and RubyGems: https://jekyllrb.com/docs/installation/
19
+
20
+
11
21
  Installation
12
22
  ------------
13
23
 
14
- The Siteleaf gem is available for installation on [Rubygems](https://rubygems.org/gems/siteleaf). To install run:
24
+ The [Siteleaf](https://www.siteleaf.com) gem is available for installation on [RubyGems](https://rubygems.org/gems/siteleaf). To install run:
15
25
 
16
- gem install siteleaf --pre
26
+ gem install siteleaf
17
27
 
18
- Important: make sure to use `--pre` for V2. If maintaining sites with multiple versions, we recommend using a Gemfile.
28
+ **Note:** the v2 gem only works with v2 sites. For documentation on v1 see: https://github.com/siteleaf/siteleaf-gem/tree/v1
29
+
30
+ If maintaining sites with multiple versions, we recommend using a [Gemfile](#using-this-gem-in-your-application).
19
31
 
20
32
 
21
33
  Using the CLI
@@ -78,7 +90,7 @@ Using this gem in your application
78
90
 
79
91
  To use this gem in your application, add the following to your Gemfile:
80
92
 
81
- gem 'siteleaf', :git => 'git://github.com/siteleaf/siteleaf-gem.git', :branch => '2.0.0.pre'
93
+ gem 'siteleaf', '~>2'
82
94
 
83
95
 
84
96
  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'
@@ -17,6 +19,7 @@ Commands:
17
19
  pull Pulls files for configured site from Siteleaf
18
20
  push Pushes all files in dir to configured site
19
21
  publish Publish website to hosting provider
22
+ preview Generate cloud preview
20
23
  help Prints this help document
21
24
  version Prints the siteleaf gem version
22
25
 
@@ -30,9 +33,9 @@ See https://github.com/siteleaf/siteleaf-gem for additional documentation.
30
33
  end
31
34
 
32
35
  def auth(re_auth = false)
33
- Siteleaf.load_settings if !re_auth && !Siteleaf.api_key
36
+ Siteleaf.load_settings if !re_auth && !(Siteleaf.api_key && Siteleaf.api_secret)
34
37
 
35
- if re_auth or !Siteleaf.api_key
38
+ if re_auth or !(Siteleaf.api_key && Siteleaf.api_secret)
36
39
  print 'Enter your Siteleaf email: '
37
40
  email = $stdin.gets.chomp
38
41
 
@@ -42,28 +45,28 @@ def auth(re_auth = false)
42
45
  system 'stty echo'
43
46
 
44
47
  puts "\nAuthorizing..."
45
-
46
- if (auth = Siteleaf::Client.auth(email, password)) && (auth.is_a?(Hash)) && (auth.has_key?('api_key'))
48
+
49
+ auth = Siteleaf::Client.auth(email, password)
50
+ if auth.is_a?(Hash) && auth.has_key?('api_key')
47
51
  Siteleaf.save_settings({api_key: auth['api_key'], api_secret: auth['api_secret']})
48
- puts "=> Gem authorized." if re_auth
52
+ Siteleaf.load_settings
53
+ puts "=> Account authorized." if re_auth
49
54
  return true
50
55
  else
51
- puts auth['error'] || "Could not authorize, check your email or password."
52
- return false
56
+ raise "Could not authorize, check your email or password."
53
57
  end
54
58
  end
55
- rescue Exception => e
56
- print "Error: #{e.message}\n"
57
59
  end
58
60
 
59
61
  def pull(site_id)
60
62
  print "Reading site...\n"
61
-
63
+
62
64
  # get all the things
63
65
  site = Siteleaf::Site.find(site_id)
64
- site_files = site.source_tree
66
+ site_files = site.source_files('.', recursive: true)
67
+
65
68
  updated_count = 0
66
-
69
+
67
70
  # download unmatched files
68
71
  site_files.each do |file|
69
72
  sha = ::File.exist?(file.name) && Siteleaf::GitHash.file(file.name)
@@ -75,11 +78,11 @@ def pull(site_id)
75
78
  print "complete.\n"
76
79
  end
77
80
  end
78
-
81
+
79
82
  # check for old files
80
83
  local_files = read_dir
81
84
  missing_files = []
82
- local_files.each do |path|
85
+ local_files.each do |path|
83
86
  missing_files << path if !site_files.find{|a| a.name.casecmp(path) == 0 }
84
87
  end
85
88
  if missing_files.empty?
@@ -99,42 +102,40 @@ def pull(site_id)
99
102
  puts "=> #{missing_files.size} file(s) deleted.\n"
100
103
  end
101
104
  end
102
- rescue Exception => e
103
- print "Error: #{e.message}\n"
104
105
  end
105
106
 
106
107
  def push(site_id)
107
108
  print "Reading site...\n"
108
-
109
+
109
110
  # get all the things
110
111
  site = Siteleaf::Site.find(site_id)
111
- site_files = site.source_tree
112
+
113
+ site_files = site.source_files('.', recursive: true)
112
114
  local_files = read_dir
113
115
  updated_count = 0
114
-
116
+
115
117
  # find changed files
116
118
  changed_files = local_files.reject do |path|
117
119
  file = site_files.find{|a| a.name.casecmp(path) == 0 }
118
120
  file && Siteleaf::GitHash.file(path) == file.sha
119
121
  end
120
- changed_files.unshift('_config.yml') if changed_files.delete('_config.yml')
121
-
122
+ changed_files.unshift('_config.yml') if changed_files.delete('_config.yml')
123
+
122
124
  # upload changed files
123
- changed_files.each do |path|
124
- print "Uploading #{path}..."
125
+ changed_files.each do |path|
126
+ print "Uploading #{path}..."
125
127
  response = Siteleaf::SourceFile.create(site_id: site_id, name: path, file: ::File.new(path))
126
- if error = !response || response.error || response.message
127
- print (error) ? "error: #{error}\n" : "error.\n"
128
- return
129
- else
130
- updated_count += 1
131
- print "complete.\n"
128
+ updated_count += 1
129
+ print "complete.\n"
130
+ if response.name && response.name != path
131
+ local_files.push(response.name)
132
+ puts "Warning: Remote filename has been normalized to `#{response.name}`."
132
133
  end
133
134
  end
134
-
135
+
135
136
  # check for old files
136
137
  missing_assets = []
137
- site_files.each do |asset|
138
+ site_files.each do |asset|
138
139
  missing_assets << asset if !local_files.find{|p| p.casecmp(asset.name) == 0 }
139
140
  end
140
141
  if missing_assets.empty?
@@ -154,13 +155,11 @@ def push(site_id)
154
155
  puts "=> #{missing_assets.size} file(s) deleted.\n"
155
156
  end
156
157
  end
157
- rescue Exception => e
158
- print "Error: #{e.message}\n"
159
158
  end
160
159
 
161
160
  def import(file, quiet = true)
162
161
  job = Siteleaf::Site.import(file: ::File.new(file))
163
-
162
+
164
163
  if quiet
165
164
  puts "=> Import queued.\n"
166
165
  else
@@ -173,14 +172,12 @@ def import(file, quiet = true)
173
172
  end
174
173
  puts "=> Import completed.\n"
175
174
  end
176
- rescue Exception => e
177
- print "Error: #{e.message}\n"
178
175
  end
179
176
 
180
177
  def publish(site_id, quiet = true)
181
178
  site = Siteleaf::Site.new(id: site_id)
182
179
  job = site.publish
183
-
180
+
184
181
  if quiet
185
182
  puts "=> Publish queued.\n"
186
183
  else
@@ -193,8 +190,24 @@ def publish(site_id, quiet = true)
193
190
  end
194
191
  puts "=> Publish completed.\n"
195
192
  end
196
- rescue Exception => e
197
- print "Error: #{e.message}\n"
193
+ end
194
+
195
+ def preview(site_id, quiet = true)
196
+ site = Siteleaf::Site.new(id: site_id)
197
+ job = site.preview
198
+
199
+ if quiet
200
+ puts "=> Preview queued.\n"
201
+ else
202
+ last_msg = nil
203
+ job.stream do |s|
204
+ if (msg = s["message"]) && (msg != last_msg)
205
+ puts msg
206
+ last_msg = msg
207
+ end
208
+ end
209
+ puts "=> Preview completed: https://#{site_id}.cloud-preview.siteleaf.com\n"
210
+ end
198
211
  end
199
212
 
200
213
  def config(site)
@@ -209,101 +222,115 @@ def get_site_id
209
222
  Siteleaf.send "#{key}=", value
210
223
  end
211
224
  end
212
-
225
+
213
226
  ENV['SITELEAF_SITE_ID'] || if settings = Siteleaf.load_settings('.siteleaf.yml')
214
227
  settings[:site_id]
215
228
  end
216
229
  end
217
230
 
218
231
  def read_dir
219
- jekyll_config = ::File.exist?('_config.yml') ? YAML::load(::File.read('_config.yml')) : {}
220
-
232
+ jekyll_site = Jekyll::Site.new(Jekyll.configuration(quiet: true))
233
+
221
234
  ignore_paths = ['config.ru', '.*', '_site/*', 'Gemfile', 'Gemfile.lock']
222
235
  ignore_paths += ::File.read('.siteleafignore').split(/\r?\n/) if ::File.exists?('.siteleafignore')
223
- ignore_paths += jekyll_config['exclude'] if jekyll_config['exclude'].is_a? Array
236
+ ignore_paths += jekyll_site.exclude
224
237
 
238
+ entry_filter = Jekyll::EntryFilter.new(jekyll_site)
239
+
225
240
  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) }
241
+ ::File.directory?(path) || entry_filter.glob_include?(ignore_paths, path)
228
242
  end
229
243
  end
230
244
 
231
- case ARGV[0]
232
- when '-v', '--version', 'version'
233
- puts Siteleaf::VERSION
234
- when '-h', '--help', 'help'
235
- puts help
236
- when 'auth'
237
- auth true
238
- when 'c', 'config', 'setup'
239
- if auth != false
240
- if site = Siteleaf::Site.find_by_domain(ARGV[1])
241
- config site
242
- else
243
- puts "No site found for `#{ARGV[1]}`, run `siteleaf new #{ARGV[1]}` to create it.\n"
245
+ begin
246
+ case ARGV[0]
247
+ when '-v', '--version', 'version'
248
+ puts Siteleaf::VERSION
249
+ when '-h', '--help', 'help'
250
+ puts help
251
+ when 'auth'
252
+ auth true
253
+ when 'c', 'config', 'setup'
254
+ if auth != false
255
+ if site = Siteleaf::Site.find_by_domain(ARGV[1])
256
+ config site
257
+ else
258
+ raise "No site found for `#{ARGV[1]}`, run `siteleaf new #{ARGV[1]}` to create it.\n"
259
+ end
244
260
  end
245
- end
246
- when 'n', 'new'
247
- if auth != false
248
- if (site = Siteleaf::Site.create(:title => ARGV[1], :domain => ARGV[1])) && (!site.error)
261
+ when 'n', 'new'
262
+ if auth != false
263
+ site = Siteleaf::Site.create(:title => ARGV[1], :domain => ARGV[1])
249
264
  dir = ARGV.size >= 3 ? ARGV[2] : ARGV[1]
250
265
  Dir.mkdir(dir) unless ::File.directory?(dir)
251
266
  Dir.chdir(dir)
252
267
  config site
268
+ end
269
+ when 'pull'
270
+ if ARGV.size == 1
271
+ site_id = get_site_id
272
+ if auth != false
273
+ if site_id
274
+ pull(site_id)
275
+ else
276
+ raise "Site not configured, run `siteleaf config yoursite.com`.\n"
277
+ end
278
+ end
253
279
  else
254
- puts "Could not create site `#{ARGV[1]}`.\n"
280
+ raise "`#{ARGV.join(' ')}` command not found.\n"
255
281
  end
256
- end
257
- when 'pull'
258
- if ARGV.size == 1
282
+ when 'push'
283
+ if ARGV.size == 1
284
+ site_id = get_site_id
285
+ if auth != false
286
+ if site_id
287
+ push(site_id)
288
+ else
289
+ raise "Site not configured, run `siteleaf config yoursite.com`.\n"
290
+ end
291
+ end
292
+ else
293
+ raise "`#{ARGV.join(' ')}` command not found.\n"
294
+ end
295
+ when 'publish'
259
296
  site_id = get_site_id
260
297
  if auth != false
298
+ quiet = %w[-q --quiet].include?(ARGV[1]) && ARGV[1]
261
299
  if site_id
262
- pull(site_id)
300
+ publish(site_id, quiet)
263
301
  else
264
- puts "Site not configured, run `siteleaf config yoursite.com`.\n"
302
+ raise "Site not configured, run `siteleaf config yoursite.com`.\n"
265
303
  end
266
304
  end
267
- else
268
- puts "`#{ARGV.join(' ')}` command not found.\n"
269
- end
270
- when 'push'
271
- if ARGV.size == 1
305
+ when 'preview'
272
306
  site_id = get_site_id
273
307
  if auth != false
308
+ quiet = %w[-q --quiet].include?(ARGV[1]) && ARGV[1]
274
309
  if site_id
275
- push(site_id)
310
+ preview(site_id, quiet)
276
311
  else
277
- puts "Site not configured, run `siteleaf config yoursite.com`.\n"
312
+ raise "Site not configured, run `siteleaf config yoursite.com`.\n"
278
313
  end
279
314
  end
280
- else
281
- puts "`#{ARGV.join(' ')}` command not found.\n"
282
- end
283
- when 'publish'
284
- site_id = get_site_id
285
- if auth != false
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)
315
+ when 'import'
316
+ site_id = get_site_id
317
+ if auth != false
318
+ file = ARGV[1]
319
+ if File.extname(file) != '.zip'
320
+ raise "Import file must be ZIP format.\n"
321
+ elsif !File.exist?(file)
322
+ raise "Import file not found.\n"
323
+ else
324
+ quiet = %w[-q --quiet].include?(ARGV[2]) && ARGV[2]
325
+ import(file, quiet)
326
+ end
304
327
  end
328
+ else
329
+ puts "Error: `#{ARGV[0]}` command not found.\n"
330
+ puts help
331
+ exit(1)
305
332
  end
306
- else
307
- puts "`#{ARGV[0]}` command not found.\n"
308
- puts help
333
+ rescue Exception => e
334
+ puts "Error: #{e.message}\n"
335
+ exit(1)
309
336
  end
@@ -1,17 +1,17 @@
1
- require 'httmultiparty'
1
+ require 'httparty'
2
2
 
3
3
  module Siteleaf
4
4
  class Client
5
5
  def self.auth(email, password)
6
- begin
7
- request = HTTParty.post(Siteleaf.api_url('auth'), {
8
- :basic_auth => {:username => email, :password => password},
9
- :headers => {"User-Agent" => "Siteleaf Gem/#{Siteleaf::VERSION}"}
10
- })
11
- return request.parsed_response # parse JSON
12
- rescue => e
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
- begin
37
- if (method == :post || method == :put) && !params.has_key?('file') && !params.has_key?(:file)
38
- request = HTTParty.send(method, Siteleaf.api_url(path), {
39
- :body => params.to_json,
40
- :basic_auth => {:username => Siteleaf.api_key, :password => Siteleaf.api_secret},
41
- :headers => {
42
- "Content-Type" => "application/json",
43
- "User-Agent" => "Siteleaf Gem/#{Siteleaf::VERSION}"
44
- },
45
- :timeout => 300
46
- })
47
- else
48
- request = HTTMultiParty.send(method, Siteleaf.api_url(path), {
49
- :query => params,
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
@@ -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
@@ -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
@@ -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,62 @@ 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
+ def preview
47
+ result = Client.post "#{entity_endpoint}/preview", {}
48
+ Job.new(id: result["job_id"]) if result
49
+ end
50
+
46
51
  def full_url
47
52
  "http://#{domain}"
48
53
  end
49
-
54
+
50
55
  def filename
51
56
  "_config.yml"
52
57
  end
53
-
58
+
54
59
  def sha
55
60
  Siteleaf::GitHash.string(to_file)
56
61
  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
-
62
+
80
63
  end
81
- end
64
+ end
@@ -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
- ::File.join("sites", site_id, "source", URI.escape(identifier))
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
- response = Client.get(::File.join("sites", site_id, "source", "#{URI.escape(identifier)}?download"))
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
@@ -1,3 +1,3 @@
1
1
  module Siteleaf
2
- VERSION = "2.0.0"
2
+ VERSION = "2.1.2"
3
3
  end
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 = "http://siteleaf.com"
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.13.3'
19
- gem.add_dependency 'httmultiparty', '>= 0.3.13'
20
- gem.add_dependency 'psych', '2.0.8'
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.0.0
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Siteleaf
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-07 00:00:00.000000000 Z
11
+ date: 2021-06-24 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.13.3
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.13.3
26
+ version: 0.16.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: httmultiparty
28
+ name: psych
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.3.13
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: 0.3.13
40
+ version: 2.1.0
41
41
  - !ruby/object:Gem::Dependency
42
- name: psych
42
+ name: jekyll
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 2.0.8
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: 2.0.8
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,11 +96,11 @@ files:
95
96
  - lib/siteleaf/user.rb
96
97
  - lib/siteleaf/version.rb
97
98
  - siteleaf.gemspec
98
- homepage: http://siteleaf.com
99
+ homepage: https://www.siteleaf.com
99
100
  licenses:
100
101
  - MIT
101
102
  metadata: {}
102
- post_install_message:
103
+ post_install_message:
103
104
  rdoc_options: []
104
105
  require_paths:
105
106
  - lib
@@ -114,9 +115,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
115
  - !ruby/object:Gem::Version
115
116
  version: '0'
116
117
  requirements: []
117
- rubyforge_project:
118
- rubygems_version: 2.4.7
119
- signing_key:
118
+ rubygems_version: 3.1.4
119
+ signing_key:
120
120
  specification_version: 4
121
121
  summary: Siteleaf Ruby interface
122
122
  test_files: []