siteleaf 2.0.0.pre.beta5 → 2.0.0.pre.beta7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 48d3961018a2ae31f7ca22554980a52a96475580
4
- data.tar.gz: e740115d270c4aa5ecc5445ee17354f041199984
3
+ metadata.gz: 4b323d004281cc83a6c93bb857122cb9cfcdf919
4
+ data.tar.gz: 255f89f85b0e20da5cbf28696358fb41774d6973
5
5
  SHA512:
6
- metadata.gz: 474722209144aa393cfef32d18ebe46084fff1e7f27373b0b0d7fcd403e15ce119d24a5f20bcfe1ea092aaa9b74c335b2d3bb5807894274c3a17f9eb2d760e8a
7
- data.tar.gz: 233518fcafc51888e0d73204e782543f8f1da09df4239add4b8f52ecc20e199903c608c0236c79801699e19cf87cd20d25370b75a2695b0eb0cf562bea8d11cd
6
+ metadata.gz: 295888d2c12d9f1863d2891a7691911aa6981c8dfb3008fe798875bfae29eb751e586650d7d8df4d173067b26abf70cefe60cc7a4a052ba4274675f717e61c27
7
+ data.tar.gz: 188f454e20e56a245cfff4238181b1be54fd5abb197401c7219558e44c76da26bef6d9ad0738b6f2833665ca508e66a2a1c77636ca90b6dcc806caae02c87943
data/bin/siteleaf CHANGED
@@ -3,7 +3,6 @@
3
3
  require 'siteleaf'
4
4
  require 'fileutils'
5
5
  require 'open-uri'
6
- require 'digest/sha1'
7
6
  require 'tempfile'
8
7
  require 'yaml'
9
8
 
@@ -34,7 +33,7 @@ def auth(re_auth = false)
34
33
  Siteleaf.load_settings if !re_auth && !Siteleaf.api_key
35
34
 
36
35
  if re_auth or !Siteleaf.api_key
37
- print 'Enter your Siteleaf e-mail: '
36
+ print 'Enter your Siteleaf email: '
38
37
  email = $stdin.gets.chomp
39
38
 
40
39
  print 'Enter your Siteleaf password: '
@@ -49,7 +48,7 @@ def auth(re_auth = false)
49
48
  puts "=> Gem authorized." if re_auth
50
49
  return true
51
50
  else
52
- puts auth['error'] || "Could not authorize, check your e-mail or password."
51
+ puts auth['error'] || "Could not authorize, check your email or password."
53
52
  return false
54
53
  end
55
54
  end
@@ -75,18 +74,15 @@ end
75
74
 
76
75
  def pull(site_id)
77
76
  # get all the things
78
- site = Siteleaf::Site.new(id: site_id)
77
+ site = Siteleaf::Site.find(site_id)
79
78
  files = site.files
80
79
  uploads = site.uploads
81
80
  pages = site.pages
82
81
  posts = site.posts
83
82
  collections = site.collections
84
- documents = []
85
- collections.each do |collection|
86
- documents += collection.documents
87
- end
83
+ documents = collections.map{ |collection| collection.documents }.flatten
88
84
 
89
- assets = files + uploads + pages + posts + documents
85
+ assets = [site] + files + uploads + pages + posts + documents
90
86
 
91
87
  updated_count = 0
92
88
 
@@ -112,7 +108,7 @@ def push(site_id)
112
108
  markdown_ext = (config['markdown_ext'] || 'markdown,mdw,mdwn,md,text').split(',')
113
109
 
114
110
  # get all the things
115
- site = Siteleaf::Site.new(id: site_id)
111
+ site = Siteleaf::Site.find(site_id)
116
112
  files = site.files
117
113
  uploads = site.uploads
118
114
  pages = site.pages
@@ -130,35 +126,90 @@ def push(site_id)
130
126
  ignore_paths += ::File.read('.siteleafignore').split(/\r?\n/) if ::File.exists?('.siteleafignore')
131
127
  ignore_paths += config['exclude'] if config['exclude'].is_a? Array
132
128
 
129
+ # push site config
130
+ path = '_config.yml'
131
+ if site.sha != Digest::SHA1.hexdigest(::File.read(path))
132
+ print "Uploading #{path}..."
133
+
134
+ metadata = config.dup
135
+ metadata.delete('collections')
136
+ attrs = { 'id' => site_id }
137
+ attrs['title'] = metadata.delete('title') if metadata['title']
138
+ attrs['domain'] = metadata.delete('url') if metadata['url']
139
+ attrs['timezone'] = metadata.delete('timezone') if metadata['timezone']
140
+ attrs['defaults'] = metadata.delete('defaults').map{|default|
141
+ {
142
+ 'path' => default['scope']['path'],
143
+ 'type' => default['scope']['type'],
144
+ 'values' => default['values']
145
+ }
146
+ } if metadata['defaults']
147
+ attrs['metadata'] = metadata
148
+
149
+ response = Siteleaf::Site.new(attrs).save
150
+
151
+ if error = !response || response.error || response.message
152
+ print (error) ? "error: #{error}\n" : "error.\n"
153
+ return
154
+ else
155
+ updated_count += 1
156
+ print "complete.\n"
157
+ end
158
+ end
159
+
133
160
  # create collections
134
- existing_collections = config['collections'] || {}
135
- existing_collections.each do |label, metadata|
136
- path = label.gsub(/[^a-z0-9_\-\.]/i, '')
137
- unless collections.find {|c| c.path == path }
161
+ collection_paths = []
162
+ collections_config = config['collections'] || {}
163
+ collections_config.each do |path, metadata|
164
+ path = path.gsub(/[^a-z0-9_\-\.]/i, '')
165
+ collection_paths << "_#{path}"
166
+ collection = collections.find{|c| c.path.casecmp(path) == 0 }
167
+ title = metadata.delete('title') || path
168
+ output = metadata.delete('output')
169
+ permalink = metadata.delete('permalink')
170
+
171
+ if !collection
138
172
  # create any new collections
139
- output = metadata.delete('output')
140
- permalink = metadata.delete('permalink')
141
- collections << Siteleaf::Collection.create(site_id: site.id, title: label, path: path, permalink: permalink, metadata: metadata)
173
+ collections << Siteleaf::Collection.create(site_id: site.id, title: title, path: path, output: output, permalink: permalink, metadata: metadata)
174
+ elsif collection.title != title || collection.output != output || collection.permalink != permalink || collection.metadata != metadata
175
+ # update any changed collections
176
+ collections.delete(collection)
177
+ colllection = Siteleaf::Collection.new(id: collection.id, title: title, path: path, output: output, permalink: permalink, metadata: metadata).save
178
+ collections << colllection
142
179
  end
143
180
  end
144
- collection_dirs = collections.map{|c| c.basename }
145
181
 
146
182
  # upload files
147
183
  paths = Dir.glob("**/*")
148
184
  paths.each do |path|
149
185
  if !::File.directory?(path) && !ignore_paths.any?{|i| ::File.fnmatch?(i, path, File::FNM_CASEFOLD) || ::File.fnmatch?(i, ::File.basename(path), File::FNM_CASEFOLD) }
150
- asset = assets.find{|a| a.filename == path }
186
+
187
+ asset = assets.find{|a| a.filename.casecmp(path) == 0 }
188
+ basedir = ::File.dirname(path).split('/').first
189
+ basename = ::File.basename(path)
190
+ ext = ::File.extname(path).sub('.', '')
151
191
  sha = Digest::SHA1.hexdigest(::File.read(path))
152
- if asset.nil? || asset.sha != sha
192
+ static = !has_yaml_header?(path)
193
+ collection_id = nil
194
+
195
+ model = if ['_drafts', '_posts'].include?(basedir)
196
+ Siteleaf::Post
197
+ elsif basedir == '_uploads'
198
+ Siteleaf::Upload
199
+ elsif collection_paths.include?(basedir) && (collection = collections.find {|c| basedir == "_#{c.path}" })
200
+ collection_id = collection.id
201
+ Siteleaf::Document
202
+ elsif !static && markdown_ext.include?(ext)
203
+ Siteleaf::Page
204
+ else
205
+ Siteleaf::File
206
+ end
207
+
208
+ if asset.nil? || asset.sha != sha || !asset.is_a?(model) || asset.filename != path
153
209
 
154
210
  print "Uploading #{path}..."
155
-
156
- static = !has_yaml_header?(path)
157
- basename = ::File.basename(path)
158
- basedir = ::File.dirname(path).split('/').first
159
- ext = ::File.extname(path).sub('.', '')
160
-
161
- response = if !static && markdown_ext.include?(ext) && basedir != '_uploads'
211
+
212
+ response = if [Siteleaf::Post, Siteleaf::Document, Siteleaf::Page].include?(model)
162
213
 
163
214
  # handle content
164
215
  metadata = {}
@@ -172,18 +223,15 @@ def push(site_id)
172
223
  attrs = {site_id: site.id, title: title, path: clean_path, static: static}
173
224
  attrs[:body] = body if body && body != ""
174
225
  attrs[:metadata] = metadata if metadata && !metadata.empty?
175
- model = if basedir == '_drafts'
226
+
227
+ if basedir == '_drafts'
176
228
  attrs[:visibility] = 'draft'
177
- Siteleaf::Post
178
229
  elsif basedir == '_posts'
179
230
  attrs[:visibility] = (metadata['published'].delete == false) ? 'hidden' : 'visible'
180
- Siteleaf::Post
181
- elsif collection = collections.find {|c| c.basename == basedir }
182
- attrs[:collection_id] = collection.id
183
- Siteleaf::Document
231
+ elsif model == Siteleaf::Document
232
+ attrs[:collection_id] = collection_id
184
233
  else
185
234
  attrs[:path] = path.sub(".#{ext}",'')
186
- Siteleaf::Page
187
235
  end
188
236
 
189
237
  if asset && asset.is_a?(model)
@@ -206,11 +254,8 @@ def push(site_id)
206
254
  end
207
255
 
208
256
  attrs = {site_id: site.id, file: ::File.new(file), path: path, static: static}
209
- model = if basedir == '_uploads'
257
+ if basedir == '_uploads'
210
258
  attrs[:path] = path.sub("#{basedir}/",'')
211
- Siteleaf::Upload
212
- else
213
- Siteleaf::File
214
259
  end
215
260
 
216
261
  asset.delete if asset
@@ -224,7 +269,7 @@ def push(site_id)
224
269
 
225
270
  if error = !response || response.error || response.message
226
271
  print (error) ? "error: #{error}\n" : "error.\n"
227
- break
272
+ return
228
273
  else
229
274
  updated_count += 1
230
275
  print "complete.\n"
@@ -236,8 +281,11 @@ def push(site_id)
236
281
 
237
282
  # check for old files
238
283
  missing_assets = []
284
+ collections.each do |collection|
285
+ missing_assets << collection if !collection_paths.find{|p| p.casecmp("_#{collection.path}") == 0}
286
+ end
239
287
  assets.each do |asset|
240
- missing_assets << asset if !paths.include?(asset.filename)
288
+ missing_assets << asset if !paths.find{|p| p.casecmp(asset.filename) == 0 }
241
289
  end
242
290
  if missing_assets.empty?
243
291
  puts "=> #{updated_count} file(s) uploaded.\n"
@@ -258,6 +306,23 @@ def push(site_id)
258
306
  end
259
307
  end
260
308
 
309
+ def import(file, quiet = true)
310
+ job = Siteleaf::Site.import(file: ::File.new(file))
311
+
312
+ if quiet
313
+ puts "=> Import queued.\n"
314
+ else
315
+ last_msg = nil
316
+ job.stream do |s|
317
+ if (msg = s["message"]) && (msg != last_msg)
318
+ puts msg
319
+ last_msg = msg
320
+ end
321
+ end
322
+ puts "=> Import completed.\n"
323
+ end
324
+ end
325
+
261
326
  def publish(site_id, quiet = true)
262
327
  site = Siteleaf::Site.new(id: site_id)
263
328
  job = site.publish
@@ -354,6 +419,19 @@ when 'publish'
354
419
  puts "Site not configured, run `siteleaf config yoursite.com`.\n"
355
420
  end
356
421
  end
422
+ when 'import'
423
+ site_id = get_site_id
424
+ if auth != false
425
+ file = ARGV[1]
426
+ if File.extname(file) != '.zip'
427
+ puts "Import file must be ZIP format.\n"
428
+ elsif !File.exist?(file)
429
+ puts "Import file not found.\n"
430
+ else
431
+ quiet = %w[-q --quiet].include?(ARGV[2]) && ARGV[2]
432
+ import(file, quiet)
433
+ end
434
+ end
357
435
  else
358
436
  puts "`#{ARGV[0]}` command not found.\n"
359
437
  puts help
@@ -0,0 +1,12 @@
1
+ class Time
2
+ def encode_with(coder)
3
+ label =
4
+ if utc?
5
+ usec.zero? ? '%Y-%m-%d %H:%M:%S Z' : '%Y-%m-%d %H:%M:%S.%9N Z'
6
+ else
7
+ usec.zero? ? '%Y-%m-%d %H:%M:%S %:z' : '%Y-%m-%d %H:%M:%S.%9N %:z'
8
+ end
9
+
10
+ coder.represent_scalar(nil, strftime(label))
11
+ end
12
+ end
data/lib/siteleaf.rb CHANGED
@@ -15,6 +15,8 @@ require 'siteleaf/collection'
15
15
  require 'siteleaf/document'
16
16
  require 'siteleaf/site'
17
17
  require 'siteleaf/user'
18
+ require 'patches/time_with_zone_encode_with'
19
+ require 'digest/sha1'
18
20
  require 'rbconfig'
19
21
  require 'uri'
20
22
  require 'yaml'
@@ -23,7 +25,7 @@ module Siteleaf
23
25
 
24
26
  @api_key = ENV['SITELEAF_API_KEY']
25
27
  @api_secret = ENV['SITELEAF_API_SECRET']
26
- @api_base = 'http://api.v2.siteleaf.com'
28
+ @api_base = 'https://api.v2.siteleaf.com'
27
29
  @api_version = 'v2'
28
30
 
29
31
  class << self
@@ -33,7 +33,7 @@ module Siteleaf
33
33
  def self.execute(method, path, params = nil)
34
34
  Siteleaf.load_settings if !Siteleaf.api_key
35
35
  begin
36
- if (method == :post || method == :put) && !params.has_key?('file')
36
+ if (method == :post || method == :put) && !params.has_key?('file') && !params.has_key?(:file)
37
37
  request = HTTParty.send(method, Siteleaf.api_url(path), {
38
38
  :headers => { 'Content-Type' => 'application/json' },
39
39
  :body => params.to_json,
@@ -1,8 +1,8 @@
1
1
  module Siteleaf
2
2
  class Collection < Entity
3
3
 
4
- attr_accessor :title, :path, :output, :site_id, :metadata
5
- attr_reader :id, :basename, :directory, :created_at, :updated_at
4
+ attr_accessor :title, :path, :permalink, :output, :site_id, :metadata
5
+ attr_reader :id, :directory, :created_at, :updated_at
6
6
 
7
7
  def create_endpoint
8
8
  "sites/#{self.site_id}/collections"
@@ -14,7 +14,15 @@ module Siteleaf
14
14
 
15
15
  def documents
16
16
  result = Client.get "collections/#{self.id}/documents"
17
- result.map { |r| Document.new(r) } if result
17
+ result.map { |r| Document.new(r) } if result.is_a? Array
18
+ end
19
+
20
+ def output?
21
+ output == true
22
+ end
23
+
24
+ def filename
25
+ path
18
26
  end
19
27
 
20
28
  end
@@ -9,15 +9,20 @@ module Siteleaf
9
9
  end
10
10
 
11
11
  def draft?
12
- !published?
12
+ visibility == 'draft'
13
13
  end
14
14
 
15
- def published?
16
- published != false
15
+ def hidden?
16
+ visibility == 'hidden'
17
17
  end
18
+
19
+ def visible?
20
+ visibility == 'visible'
21
+ end
22
+ alias_method :published?, :visible?
18
23
 
19
24
  def to_file
20
- [frontmatter, "---\n\n".freeze, body].join('')
25
+ frontmatter + "---\n\n".freeze + body.to_s
21
26
  end
22
27
 
23
28
  protected
@@ -25,8 +30,8 @@ module Siteleaf
25
30
  def frontmatter
26
31
  attrs = metadata || {}
27
32
  attrs['title'] = title
28
- attrs['date'] = Time.parse(published_at).utc.strftime('%F %T %z') unless published_at.nil?
29
- attrs['published'] = false if draft?
33
+ attrs['date'] = Time.parse(published_at).utc unless published_at.nil?
34
+ attrs['published'] = false if hidden?
30
35
  attrs['permalink'] = permalink unless permalink.nil?
31
36
 
32
37
  attrs.empty? ? "---\n".freeze : attrs.to_yaml
@@ -9,7 +9,7 @@ module Siteleaf
9
9
 
10
10
  def self.all
11
11
  result = Client.get "#{self.endpoint}"
12
- result.map { |r| self.new(r) } if result
12
+ result.map { |r| self.new(r) } if result.is_a? Array
13
13
  end
14
14
 
15
15
  def self.find(id)
data/lib/siteleaf/site.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Siteleaf
2
2
  class Site < Entity
3
3
 
4
- attr_accessor :title, :domain, :timezone, :metadata
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)
@@ -10,34 +10,89 @@ module Siteleaf
10
10
  self.new(result) if result
11
11
  end
12
12
 
13
+ def self.import(attrs)
14
+ result = Client.post "import", attrs
15
+ Job.new(id: result["job_id"]) if result
16
+ end
17
+
13
18
  def files
14
19
  result = Client.get "sites/#{self.id}/files"
15
- result.map { |r| File.new(r) } if result
20
+ result.map { |r| File.new(r) } if result.is_a? Array
16
21
  end
17
22
 
18
23
  def uploads
19
24
  result = Client.get "sites/#{self.id}/uploads"
20
- result.map { |r| Upload.new(r) } if result
25
+ result.map { |r| Upload.new(r) } if result.is_a? Array
21
26
  end
22
27
 
23
28
  def pages
24
29
  result = Client.get "sites/#{self.id}/pages"
25
- result.map { |r| Page.new(r) } if result
30
+ result.map { |r| Page.new(r) } if result.is_a? Array
26
31
  end
27
32
 
28
33
  def posts
29
34
  result = Client.get "sites/#{self.id}/posts"
30
- result.map { |r| Post.new(r) } if result
35
+ result.map { |r| Post.new(r) } if result.is_a? Array
31
36
  end
32
37
 
33
38
  def collections
34
39
  result = Client.get "sites/#{self.id}/collections"
35
- result.map { |r| Collection.new(r) } if result
40
+ result.map { |r| Collection.new(r) } if result.is_a? Array
36
41
  end
37
42
 
38
43
  def publish
39
44
  result = Client.post "sites/#{self.id}/publish", {}
40
- Job.new(id: result.parsed_response["job_id"]) if result
45
+ Job.new(id: result["job_id"]) if result
46
+ end
47
+
48
+ def full_url
49
+ "http://#{domain}"
50
+ end
51
+
52
+ def filename
53
+ "_config.yml"
54
+ end
55
+
56
+ def sha
57
+ Digest::SHA1.hexdigest(to_file)
58
+ end
59
+
60
+ def to_file
61
+ config
62
+ end
63
+
64
+ protected
65
+
66
+ def uploads_collection
67
+ Collection.new('title' => 'Uploads', 'path' => 'uploads', 'output' => true)
68
+ end
69
+
70
+ def defaults_config
71
+ defaults.map do |d|
72
+ { 'scope' => {}, 'values' => d['values'] }.tap do |default|
73
+ default['scope']['path'] = d['path'] if d['path']
74
+ default['scope']['type'] = d['type'] if d['type']
75
+ end
76
+ end
77
+ end
78
+
79
+ def collections_config
80
+ collections.unshift(uploads_collection).each_with_object({}) do |collection, hash|
81
+ hash[collection.path] = collection.metadata || {}
82
+ hash[collection.path]['title'] = collection.title
83
+ hash[collection.path]['output'] = collection.output
84
+ hash[collection.path]['permalink'] = collection.permalink unless collection.permalink.nil?
85
+ end
86
+ end
87
+
88
+ def config
89
+ attrs = metadata || {}
90
+ attrs['title'] = title
91
+ attrs['url'] = full_url
92
+ attrs['timezone'] = timezone
93
+ attrs['collections'] = collections_config
94
+ attrs['defaults'] = defaults_config unless defaults.empty?
95
+ attrs.to_yaml
41
96
  end
42
97
 
43
98
  end
@@ -1,3 +1,3 @@
1
1
  module Siteleaf
2
- VERSION = "2.0.0.pre.beta5"
2
+ VERSION = "2.0.0.pre.beta7"
3
3
  end
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.pre.beta5
4
+ version: 2.0.0.pre.beta7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Siteleaf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-10 00:00:00.000000000 Z
11
+ date: 2015-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -80,6 +80,7 @@ files:
80
80
  - README.md
81
81
  - Rakefile
82
82
  - bin/siteleaf
83
+ - lib/patches/time_with_zone_encode_with.rb
83
84
  - lib/siteleaf.rb
84
85
  - lib/siteleaf/asset.rb
85
86
  - lib/siteleaf/client.rb