siteleaf 0.9.12 → 0.9.13
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/siteleaf +49 -14
- data/lib/siteleaf.rb +4 -2
- data/lib/siteleaf/asset.rb +36 -0
- data/lib/siteleaf/page.rb +5 -10
- data/lib/siteleaf/post.rb +5 -10
- data/lib/siteleaf/site.rb +14 -1
- data/lib/siteleaf/theme.rb +25 -0
- data/lib/siteleaf/version.rb +1 -1
- data/siteleaf.gemspec +0 -1
- metadata +4 -18
data/bin/siteleaf
CHANGED
@@ -83,16 +83,18 @@ def get_site_id
|
|
83
83
|
end
|
84
84
|
|
85
85
|
def get_theme_assets(site_id)
|
86
|
-
if assets = Siteleaf::
|
86
|
+
if assets = Siteleaf::Theme.assets_by_site_id(site_id)
|
87
87
|
updated_count = 0
|
88
88
|
assets.each do |asset|
|
89
|
-
if File.exist?(asset
|
89
|
+
if File.exist?(asset.filename) && asset.checksum == Digest::MD5.hexdigest(File.read(asset.filename))
|
90
90
|
# file is up to date
|
91
91
|
else
|
92
|
-
|
93
|
-
|
94
|
-
File.
|
92
|
+
print "Downloading #{asset.filename}..."
|
93
|
+
file = open("#{asset.file['url']}?#{SecureRandom.hex(16)}", /^1\.8/.match(RUBY_VERSION) ? 'r' : 'r:UTF-8') { |f| f.read }
|
94
|
+
FileUtils.mkdir_p(File.dirname(asset.filename))
|
95
|
+
File.open(asset.filename, /^1\.8/.match(RUBY_VERSION) ? 'w' : 'w:UTF-8') { |f| f.write(file) }
|
95
96
|
updated_count += 1
|
97
|
+
print "complete.\n"
|
96
98
|
end
|
97
99
|
end
|
98
100
|
puts "=> #{updated_count} asset(s) downloaded.\n"
|
@@ -100,20 +102,53 @@ def get_theme_assets(site_id)
|
|
100
102
|
end
|
101
103
|
|
102
104
|
def put_theme_assets(site_id)
|
103
|
-
theme =
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
105
|
+
theme = Siteleaf::Theme.find_by_site_id(site_id)
|
106
|
+
assets = theme.assets
|
107
|
+
updated_count = 0
|
108
|
+
ignore_paths = ['config.ru', '.*']
|
109
|
+
ignore_paths += File.read('.siteleafignore').split(/\r?\n/) if File.exists?('.siteleafignore')
|
110
|
+
|
111
|
+
# upload files
|
112
|
+
paths = Dir.glob("**/*")
|
113
|
+
paths.each do |path|
|
114
|
+
if !File.directory?(path) && !ignore_paths.any?{|i| File.fnmatch?(i, path, File::FNM_CASEFOLD) || File.fnmatch?(i, File.basename(path), File::FNM_CASEFOLD) }
|
115
|
+
asset = assets.find{|a| a.filename == path }
|
116
|
+
if asset.nil? || (asset && asset.checksum != Digest::MD5.hexdigest(File.read(path)))
|
117
|
+
print "Uploading #{path}..."
|
118
|
+
asset.delete if asset
|
119
|
+
if response = Siteleaf::Asset.create({:site_id => site_id, :theme_id => theme.id, :file => File.new(path), :filename => path})
|
120
|
+
updated_count += 1
|
121
|
+
print "complete.\n"
|
122
|
+
else
|
123
|
+
print "error.\n"
|
124
|
+
break
|
125
|
+
end
|
126
|
+
end
|
108
127
|
end
|
109
128
|
end
|
110
|
-
|
111
|
-
|
129
|
+
|
130
|
+
# check for old files
|
131
|
+
missing_assets = []
|
132
|
+
assets.each do |asset|
|
133
|
+
missing_assets << asset if !paths.include?(asset.filename)
|
134
|
+
end
|
135
|
+
if missing_assets.empty?
|
112
136
|
puts "=> #{updated_count} asset(s) uploaded.\n"
|
113
137
|
else
|
114
|
-
|
138
|
+
print "=> #{updated_count} asset(s) uploaded. Delete the following #{missing_assets.size} unmatched asset(s)?\n"
|
139
|
+
missing_assets.each do |asset|
|
140
|
+
puts asset.filename
|
141
|
+
end
|
142
|
+
print '(y/n)? '
|
143
|
+
if $stdin.gets.chomp == 'y'
|
144
|
+
missing_assets.each do |asset|
|
145
|
+
print "Deleteing #{asset.filename}..."
|
146
|
+
asset.delete
|
147
|
+
print "complete.\n"
|
148
|
+
end
|
149
|
+
puts "=> #{missing_assets.size} asset(s) deleted.\n"
|
150
|
+
end
|
115
151
|
end
|
116
|
-
FileUtils.rm(theme) if File.exist?(theme)
|
117
152
|
end
|
118
153
|
|
119
154
|
case ARGV[0]
|
data/lib/siteleaf.rb
CHANGED
@@ -3,11 +3,13 @@ $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
|
3
3
|
|
4
4
|
require 'siteleaf/version'
|
5
5
|
require 'siteleaf/client'
|
6
|
-
require 'siteleaf/server'
|
7
6
|
require 'siteleaf/entity'
|
8
|
-
require 'siteleaf/
|
7
|
+
require 'siteleaf/asset'
|
9
8
|
require 'siteleaf/page'
|
10
9
|
require 'siteleaf/post'
|
10
|
+
require 'siteleaf/server'
|
11
|
+
require 'siteleaf/site'
|
12
|
+
require 'siteleaf/theme'
|
11
13
|
require 'siteleaf/user'
|
12
14
|
require 'rbconfig'
|
13
15
|
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Siteleaf
|
2
|
+
class Asset < Entity
|
3
|
+
|
4
|
+
attr_accessor :file, :filename, :replace, :site_id, :page_id, :post_id, :theme_id
|
5
|
+
attr_reader :id, :url, :content_type, :filesize, :checksum, :created_at, :updated_at
|
6
|
+
|
7
|
+
def create_endpoint
|
8
|
+
if !self.post_id.nil?
|
9
|
+
"posts/#{self.post_id}/assets"
|
10
|
+
elsif !self.page_id.nil?
|
11
|
+
"pages/#{self.page_id}/assets"
|
12
|
+
elsif !self.theme_id.nil?
|
13
|
+
"sites/#{self.site_id}/theme/assets"
|
14
|
+
else
|
15
|
+
"sites/#{self.site_id}/assets"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def post
|
20
|
+
Post.find(self.post_id) if self.post_id
|
21
|
+
end
|
22
|
+
|
23
|
+
def page
|
24
|
+
Page.find(self.page_id) if self.page_id
|
25
|
+
end
|
26
|
+
|
27
|
+
def theme
|
28
|
+
Theme.find(self.theme_id) if self.theme_id
|
29
|
+
end
|
30
|
+
|
31
|
+
def site
|
32
|
+
Site.find(self.site_id) if self.site_id
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
data/lib/siteleaf/page.rb
CHANGED
@@ -4,16 +4,6 @@ module Siteleaf
|
|
4
4
|
attr_accessor :title, :body, :slug, :url, :parent_id, :site_id, :published_at, :user_id, :meta, :assets
|
5
5
|
attr_reader :id, :created_at, :updated_at
|
6
6
|
|
7
|
-
def self.all
|
8
|
-
result = Client.get "#{self.endpoint}"
|
9
|
-
result.map { |r| self.new(r) } if result
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.find(id)
|
13
|
-
result = Client.get "#{self.endpoint}/#{id}"
|
14
|
-
self.new(result) if result
|
15
|
-
end
|
16
|
-
|
17
7
|
def create_endpoint
|
18
8
|
"sites/#{self.site_id}/pages"
|
19
9
|
end
|
@@ -22,6 +12,11 @@ module Siteleaf
|
|
22
12
|
Site.find(self.site_id) if self.site_id
|
23
13
|
end
|
24
14
|
|
15
|
+
def assets
|
16
|
+
result = Client.get "pages/#{self.id}/assets"
|
17
|
+
result.map { |r| Asset.new(r) } if result
|
18
|
+
end
|
19
|
+
|
25
20
|
def posts
|
26
21
|
result = Client.get "pages/#{self.id}/posts"
|
27
22
|
result.map { |r| Post.new(r) } if result
|
data/lib/siteleaf/post.rb
CHANGED
@@ -3,16 +3,6 @@ module Siteleaf
|
|
3
3
|
|
4
4
|
attr_accessor :taxonomy
|
5
5
|
|
6
|
-
def self.all
|
7
|
-
result = Client.get "#{self.endpoint}"
|
8
|
-
result.map { |r| self.new(r) } if result
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.find(id)
|
12
|
-
result = Client.get "#{self.endpoint}/#{id}"
|
13
|
-
self.new(result) if result
|
14
|
-
end
|
15
|
-
|
16
6
|
def create_endpoint
|
17
7
|
"pages/#{self.parent_id}/posts"
|
18
8
|
end
|
@@ -21,5 +11,10 @@ module Siteleaf
|
|
21
11
|
Page.find(self.parent_id)
|
22
12
|
end
|
23
13
|
|
14
|
+
def assets
|
15
|
+
result = Client.get "posts/#{self.id}/assets"
|
16
|
+
result.map { |r| Asset.new(r) } if result
|
17
|
+
end
|
18
|
+
|
24
19
|
end
|
25
20
|
end
|
data/lib/siteleaf/site.rb
CHANGED
@@ -5,10 +5,23 @@ module Siteleaf
|
|
5
5
|
attr_reader :id, :user_id, :created_at, :updated_at
|
6
6
|
|
7
7
|
def self.find_by_domain(domain)
|
8
|
-
result = Client.get
|
8
|
+
result = Client.get self.endpoint, {"domain" => domain}
|
9
9
|
self.new(result.first) if result and result.size >= 1
|
10
10
|
end
|
11
11
|
|
12
|
+
def theme
|
13
|
+
@theme ||= if result = Client.get("sites/#{self.id}/theme")
|
14
|
+
theme = Theme.new(result)
|
15
|
+
theme.site_id = self.id
|
16
|
+
theme
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def assets
|
21
|
+
result = Client.get "sites/#{self.id}/assets"
|
22
|
+
result.map { |r| Asset.new(r) } if result
|
23
|
+
end
|
24
|
+
|
12
25
|
def pages
|
13
26
|
result = Client.get "sites/#{self.id}/pages"
|
14
27
|
result.map { |r| Page.new(r) } if result
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Siteleaf
|
2
|
+
class Theme < Entity
|
3
|
+
|
4
|
+
attr_accessor :name, :site_id
|
5
|
+
attr_reader :id, :created_at, :updated_at
|
6
|
+
|
7
|
+
def self.find_by_site_id(site_id)
|
8
|
+
Site.new({:id => site_id}).theme
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.assets_by_site_id(site_id)
|
12
|
+
Theme.new({:site_id => site_id}).assets
|
13
|
+
end
|
14
|
+
|
15
|
+
def site
|
16
|
+
Site.find(self.site_id)
|
17
|
+
end
|
18
|
+
|
19
|
+
def assets
|
20
|
+
result = Client.get "sites/#{self.site_id}/theme/assets"
|
21
|
+
result.map { |r| Asset.new(r) } if result
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
data/lib/siteleaf/version.rb
CHANGED
data/siteleaf.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: siteleaf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.13
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-08
|
12
|
+
date: 2013-09-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
@@ -43,22 +43,6 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
-
- !ruby/object:Gem::Dependency
|
47
|
-
name: zip
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
|
-
requirements:
|
51
|
-
- - ! '>='
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '0'
|
54
|
-
type: :runtime
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
|
-
requirements:
|
59
|
-
- - ! '>='
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
46
|
- !ruby/object:Gem::Dependency
|
63
47
|
name: rack
|
64
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -90,12 +74,14 @@ files:
|
|
90
74
|
- Rakefile
|
91
75
|
- bin/siteleaf
|
92
76
|
- lib/siteleaf.rb
|
77
|
+
- lib/siteleaf/asset.rb
|
93
78
|
- lib/siteleaf/client.rb
|
94
79
|
- lib/siteleaf/entity.rb
|
95
80
|
- lib/siteleaf/page.rb
|
96
81
|
- lib/siteleaf/post.rb
|
97
82
|
- lib/siteleaf/server.rb
|
98
83
|
- lib/siteleaf/site.rb
|
84
|
+
- lib/siteleaf/theme.rb
|
99
85
|
- lib/siteleaf/user.rb
|
100
86
|
- lib/siteleaf/version.rb
|
101
87
|
- siteleaf.gemspec
|