lib/siteleaf/site.rb in siteleaf-2.0.0.pre.beta7 vs lib/siteleaf/site.rb in siteleaf-2.0.0.pre.beta9
- old
+ new
@@ -13,37 +13,35 @@
def self.import(attrs)
result = Client.post "import", attrs
Job.new(id: result["job_id"]) if result
end
- def files
- result = Client.get "sites/#{self.id}/files"
- result.map { |r| File.new(r) } if result.is_a? Array
+ def source_files(dir = '.')
+ result = Client.get ::File.join(entity_endpoint, "source", dir)
+ result.map { |r| SourceFile.new(r.merge('site_id' => id)) } if result.is_a? Array
end
- def uploads
- result = Client.get "sites/#{self.id}/uploads"
- result.map { |r| Upload.new(r) } if result.is_a? Array
- end
-
def pages
- result = Client.get "sites/#{self.id}/pages"
+ result = Client.get "#{entity_endpoint}/pages"
result.map { |r| Page.new(r) } if result.is_a? Array
+ end
+
+ def collections
+ result = Client.get "#{entity_endpoint}/collections"
+ result.map { |r| Collection.new(r) } if result.is_a? Array
end
def posts
- result = Client.get "sites/#{self.id}/posts"
- result.map { |r| Post.new(r) } if result.is_a? Array
+ Collection.new(path: 'posts', site_id: id).documents
end
- def collections
- result = Client.get "sites/#{self.id}/collections"
- result.map { |r| Collection.new(r) } if result.is_a? Array
+ def uploads
+ Collection.new(path: 'uploads', site_id: id).files
end
def publish
- result = Client.post "sites/#{self.id}/publish", {}
+ result = Client.post "#{entity_endpoint}/publish", {}
Job.new(id: result["job_id"]) if result
end
def full_url
"http://#{domain}"
@@ -52,48 +50,32 @@
def filename
"_config.yml"
end
def sha
- Digest::SHA1.hexdigest(to_file)
+ Siteleaf::GitHash.string(to_file)
end
- def to_file
- config
+ def source_tree(dir = '.')
+ @tree_files = []
+ @tree_dirs = []
+ recursive_source_files(dir)
+ @tree_files
end
protected
- def uploads_collection
- Collection.new('title' => 'Uploads', 'path' => 'uploads', 'output' => true)
- end
-
- def defaults_config
- defaults.map do |d|
- { 'scope' => {}, 'values' => d['values'] }.tap do |default|
- default['scope']['path'] = d['path'] if d['path']
- default['scope']['type'] = d['type'] if d['type']
+ def recursive_source_files(dir = '.')
+ source_files(dir).each do |file|
+ if file.type == 'directory'
+ unless @tree_dirs.include?(file.name)
+ @tree_dirs << file.name
+ recursive_source_files(file.name)
+ end
+ else
+ @tree_files << file
end
end
- end
-
- def collections_config
- collections.unshift(uploads_collection).each_with_object({}) do |collection, hash|
- hash[collection.path] = collection.metadata || {}
- hash[collection.path]['title'] = collection.title
- hash[collection.path]['output'] = collection.output
- hash[collection.path]['permalink'] = collection.permalink unless collection.permalink.nil?
- end
- end
-
- def config
- attrs = metadata || {}
- attrs['title'] = title
- attrs['url'] = full_url
- attrs['timezone'] = timezone
- attrs['collections'] = collections_config
- attrs['defaults'] = defaults_config unless defaults.empty?
- attrs.to_yaml
end
end
end
\ No newline at end of file