octodmin 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/app/assets/javascripts/app.js.coffee +1 -0
- data/app/assets/javascripts/components/header.js.cjsx +1 -1
- data/app/assets/javascripts/components/posts.js.cjsx +37 -2
- data/app/config/routes.rb +1 -0
- data/app/controllers/posts/destroy.rb +4 -4
- data/app/controllers/posts/manage.rb +9 -0
- data/app/controllers/posts/restore.rb +4 -4
- data/app/controllers/posts/revert.rb +4 -4
- data/app/controllers/posts/show.rb +4 -5
- data/app/controllers/posts/upload.rb +22 -0
- data/app/controllers/syncs/create.rb +23 -22
- data/app/octodmin.rb +4 -1
- data/app/views/posts/upload.rb +10 -0
- data/bower.json +1 -0
- data/lib/octodmin/version.rb +1 -1
- data/spec/api/posts_spec.rb +18 -0
- data/spec/api/syncs_spec.rb +13 -1
- data/spec/fixtures/ear.png +0 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0bf286fc4c638a5552de1e48cae1442f6334202b
|
4
|
+
data.tar.gz: a7fcaa4243fb13481b1b7370efcdaafaff495882
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6afa97affb291815163e250291a0bc156d43d3bae6f7d8efcb9adba28a452c196a89a490e3314170791b0d40f532c84ce4d5842c7e835bdc7be8f737cbea6d11
|
7
|
+
data.tar.gz: a9edd643b252f7e11c7935e920a8c9923f59a4539ccd05ad621b2d295375177abce22bedbf77e8b7bc9792de4bbfc0233d9ecbc96320d1ad8bb0058c4ed1e2cc
|
data/CHANGELOG.md
CHANGED
@@ -29,7 +29,7 @@
|
|
29
29
|
$(document).trigger("fetchPosts")
|
30
30
|
|
31
31
|
handleError: (error) ->
|
32
|
-
$.growl(error.responseJSON?.errors.join("\n").replace(/\n/g, "<br>"), growlError)
|
32
|
+
$.growl(error.responseJSON?.errors.join("\n").replace(/\n/g, "<br>") || error.statusText, growlError)
|
33
33
|
|
34
34
|
render: ->
|
35
35
|
<div>
|
@@ -79,7 +79,7 @@
|
|
79
79
|
@transitionTo("post_edit", post_id: response.posts.identifier)
|
80
80
|
|
81
81
|
handleError: (error) ->
|
82
|
-
$.growl(error.responseJSON?.errors.join(", "), growlError)
|
82
|
+
$.growl(error.responseJSON?.errors.join(", ") || error.statusText, growlError)
|
83
83
|
|
84
84
|
render: ->
|
85
85
|
<div className="panel panel-default">
|
@@ -211,6 +211,30 @@
|
|
211
211
|
@setState(loading: true)
|
212
212
|
$.getq("default", "/api/posts/#{@getParams().post_id}").always(@handleResponse).done(@handleSuccess).fail(@handleError)
|
213
213
|
|
214
|
+
handleUpload: (event)->
|
215
|
+
form = $("<form><input type='file' name='file' /></form>")
|
216
|
+
event.disableButtons("cmdUpload")
|
217
|
+
|
218
|
+
form.find("input").on("change", (->
|
219
|
+
data = new FormData(form[0])
|
220
|
+
$.ajaxq("default",
|
221
|
+
type: "POST"
|
222
|
+
url: "/api/posts/#{@state.post.identifier}/upload"
|
223
|
+
data: data
|
224
|
+
cache: false
|
225
|
+
contentType: false
|
226
|
+
processData: false
|
227
|
+
).always(->
|
228
|
+
event.enableButtons("cmdUpload")
|
229
|
+
).done(((result) ->
|
230
|
+
@handleUploadSuccess(event, result)
|
231
|
+
).bind(this)).fail(@handleError)
|
232
|
+
).bind(this))
|
233
|
+
form.find("input").click()
|
234
|
+
|
235
|
+
handleUploadSuccess: (event, response) ->
|
236
|
+
event.replaceSelection(response.uploads[0])
|
237
|
+
|
214
238
|
handleBack: (event) ->
|
215
239
|
event.preventDefault()
|
216
240
|
@transitionTo("app")
|
@@ -237,7 +261,7 @@
|
|
237
261
|
@transitionTo("post_edit", post_id: response.posts.identifier)
|
238
262
|
|
239
263
|
handleError: (error) ->
|
240
|
-
$.growl(error.responseJSON?.errors.join(", "), growlError)
|
264
|
+
$.growl(error.responseJSON?.errors.join(", ") || error.statusText, growlError)
|
241
265
|
|
242
266
|
componentWillMount: ->
|
243
267
|
@fetchPost()
|
@@ -253,6 +277,17 @@
|
|
253
277
|
resize: "vertical"
|
254
278
|
fullscreen:
|
255
279
|
enable: false
|
280
|
+
additionalButtons: [
|
281
|
+
[{
|
282
|
+
name: "customGroup"
|
283
|
+
data: [{
|
284
|
+
name: "cmdUpload"
|
285
|
+
title: "Upload"
|
286
|
+
icon: "fa fa-upload"
|
287
|
+
callback: @handleUpload
|
288
|
+
}]
|
289
|
+
}]
|
290
|
+
]
|
256
291
|
)
|
257
292
|
|
258
293
|
render: ->
|
data/app/config/routes.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
+
require_relative "manage"
|
2
|
+
|
1
3
|
module Octodmin::Controllers::Posts
|
2
|
-
class Destroy
|
4
|
+
class Destroy < Manage
|
3
5
|
include Octodmin::Action
|
4
6
|
expose :post
|
5
7
|
|
6
8
|
def call(params)
|
7
|
-
|
9
|
+
super
|
8
10
|
|
9
|
-
@post = Octodmin::Post.find(params[:id])
|
10
|
-
halt 400, JSON.dump(errors: ["Could not find post"]) unless @post
|
11
11
|
@post.delete
|
12
12
|
end
|
13
13
|
end
|
@@ -1,13 +1,13 @@
|
|
1
|
+
require_relative "manage"
|
2
|
+
|
1
3
|
module Octodmin::Controllers::Posts
|
2
|
-
class Restore
|
4
|
+
class Restore < Manage
|
3
5
|
include Octodmin::Action
|
4
6
|
expose :post
|
5
7
|
|
6
8
|
def call(params)
|
7
|
-
|
9
|
+
super
|
8
10
|
|
9
|
-
@post = Octodmin::Post.find(params[:id])
|
10
|
-
halt 400, JSON.dump(errors: ["Could not find post"]) unless @post
|
11
11
|
@post.restore
|
12
12
|
end
|
13
13
|
end
|
@@ -1,13 +1,13 @@
|
|
1
|
+
require_relative "manage"
|
2
|
+
|
1
3
|
module Octodmin::Controllers::Posts
|
2
|
-
class Revert
|
4
|
+
class Revert < Manage
|
3
5
|
include Octodmin::Action
|
4
6
|
expose :post
|
5
7
|
|
6
8
|
def call(params)
|
7
|
-
|
9
|
+
super
|
8
10
|
|
9
|
-
@post = Octodmin::Post.find(params[:id])
|
10
|
-
halt 400, JSON.dump(errors: ["Could not find post"]) unless @post
|
11
11
|
@post.revert
|
12
12
|
end
|
13
13
|
end
|
@@ -1,13 +1,12 @@
|
|
1
|
+
require_relative "manage"
|
2
|
+
|
1
3
|
module Octodmin::Controllers::Posts
|
2
|
-
class Show
|
4
|
+
class Show < Manage
|
3
5
|
include Octodmin::Action
|
4
6
|
expose :post
|
5
7
|
|
6
8
|
def call(params)
|
7
|
-
|
8
|
-
|
9
|
-
@post = Octodmin::Post.find(params[:id])
|
10
|
-
halt 400, JSON.dump(errors: ["Could not find post"]) unless @post
|
9
|
+
super
|
11
10
|
end
|
12
11
|
end
|
13
12
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative "manage"
|
2
|
+
|
3
|
+
module Octodmin::Controllers::Posts
|
4
|
+
class Upload < Manage
|
5
|
+
include Octodmin::Action
|
6
|
+
expose :upload
|
7
|
+
|
8
|
+
def call(params)
|
9
|
+
super
|
10
|
+
|
11
|
+
site = Octodmin::Site.new
|
12
|
+
file = params[:file]
|
13
|
+
dir = File.join(site.source, "octodmin", @post.identifier)
|
14
|
+
path = File.join(dir, file["filename"])
|
15
|
+
|
16
|
+
FileUtils.mkdir_p(dir)
|
17
|
+
FileUtils.cp(file["tempfile"].path, path)
|
18
|
+
|
19
|
+
@upload = path.sub(site.source, "")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -9,25 +9,14 @@ module Octodmin::Controllers::Syncs
|
|
9
9
|
site = Octodmin::Site.new
|
10
10
|
git = Git.open(Octodmin::App.dir)
|
11
11
|
|
12
|
-
# Add
|
12
|
+
# Add files to commit stage
|
13
13
|
stage(site, git)
|
14
14
|
|
15
|
-
# Compute staged paths
|
16
|
-
staged = paths(site, git)
|
17
|
-
|
18
15
|
# Pull changes
|
19
16
|
git.pull
|
20
17
|
|
21
18
|
# Commit and push changes if any
|
22
|
-
|
23
|
-
@message = "Octodmin sync for #{staged.count} file#{"s" if staged.count > 1}"
|
24
|
-
@message += "\n\n#{staged.join("\n")}"
|
25
|
-
|
26
|
-
git.commit(@message)
|
27
|
-
git.push
|
28
|
-
else
|
29
|
-
@message = "Everything is up-to-date"
|
30
|
-
end
|
19
|
+
commit(site, git)
|
31
20
|
rescue Git::GitExecuteError => e
|
32
21
|
halt 400, JSON.dump(errors: [e.message])
|
33
22
|
ensure
|
@@ -37,26 +26,38 @@ module Octodmin::Controllers::Syncs
|
|
37
26
|
private
|
38
27
|
|
39
28
|
def stage(site, git)
|
29
|
+
# Posts
|
40
30
|
deleted = site.status.deleted.keys.map { |path| File.join(Octodmin::App.dir, path) }
|
41
|
-
|
42
31
|
site.posts.each do |post|
|
43
32
|
path = File.join(site.source, post.path)
|
44
33
|
git.add(path) unless deleted.include?(path)
|
45
34
|
end
|
35
|
+
|
36
|
+
# Uploads
|
37
|
+
git.add(File.join(site.source, "octodmin"))
|
46
38
|
end
|
47
39
|
|
48
40
|
def paths(site, git)
|
49
41
|
status = site.reset.status
|
42
|
+
keys = status.changed.keys + status.added.keys + status.deleted.keys
|
50
43
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
44
|
+
keys.sort.reverse.map do |path|
|
45
|
+
File.join(Octodmin::App.dir, path).sub(File.join(site.source, ""), "")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def commit(site, git)
|
50
|
+
staged = paths(site, git)
|
56
51
|
|
57
|
-
|
58
|
-
|
59
|
-
|
52
|
+
if staged.any?
|
53
|
+
@message = "Octodmin sync for #{staged.count} file#{"s" if staged.count > 1}"
|
54
|
+
@message += "\n\n#{staged.join("\n")}"
|
55
|
+
|
56
|
+
git.commit(@message)
|
57
|
+
git.push
|
58
|
+
else
|
59
|
+
@message = "Everything is up-to-date"
|
60
|
+
end
|
60
61
|
end
|
61
62
|
end
|
62
63
|
end
|
data/app/octodmin.rb
CHANGED
data/bower.json
CHANGED
data/lib/octodmin/version.rb
CHANGED
data/spec/api/posts_spec.rb
CHANGED
@@ -408,4 +408,22 @@ describe "posts" do
|
|
408
408
|
end
|
409
409
|
end
|
410
410
|
end
|
411
|
+
|
412
|
+
describe "upload" do
|
413
|
+
context "valid" do
|
414
|
+
before do
|
415
|
+
post "/api/posts/2015-01-30-test/upload", {
|
416
|
+
file: Rack::Test::UploadedFile.new("spec/fixtures/ear.png")
|
417
|
+
}
|
418
|
+
end
|
419
|
+
after do
|
420
|
+
File.delete("sample/octodmin/2015-01-30-test/ear.png")
|
421
|
+
end
|
422
|
+
subject { parse_json(last_response.body)["posts"] }
|
423
|
+
|
424
|
+
specify do
|
425
|
+
expect(File.exists?("sample/octodmin/2015-01-30-test/ear.png")).to be_truthy
|
426
|
+
end
|
427
|
+
end
|
428
|
+
end
|
411
429
|
end
|
data/spec/api/syncs_spec.rb
CHANGED
@@ -62,6 +62,11 @@ end
|
|
62
62
|
# Delete post
|
63
63
|
delete "/api/posts/2015-01-29-welcome-to-jekyll"
|
64
64
|
|
65
|
+
# Upload file
|
66
|
+
post "/api/posts/2015-01-30-test/upload", {
|
67
|
+
file: Rack::Test::UploadedFile.new("spec/fixtures/ear.png")
|
68
|
+
}
|
69
|
+
|
65
70
|
post "/api/syncs"
|
66
71
|
end
|
67
72
|
after do
|
@@ -69,11 +74,18 @@ end
|
|
69
74
|
git = Git.open(Octodmin::App.dir)
|
70
75
|
git.checkout("sample/_posts/2015-01-30-test.markdown")
|
71
76
|
git.checkout("sample/_posts/2015-01-29-welcome-to-jekyll.markdown")
|
77
|
+
File.delete("sample/octodmin/2015-01-30-test/ear.png")
|
72
78
|
end
|
73
79
|
subject { parse_json(last_response.body)["syncs"] }
|
74
80
|
|
75
81
|
it "returns syncs" do
|
76
|
-
expect(subject).to eql([
|
82
|
+
expect(subject).to eql([[
|
83
|
+
"Octodmin sync for 4 files\n",
|
84
|
+
"octodmin/2015-01-30-test/ear.png",
|
85
|
+
"_posts/#{date}-yo.markdown",
|
86
|
+
"_posts/2015-01-30-test.markdown",
|
87
|
+
"_posts/2015-01-29-welcome-to-jekyll.markdown",
|
88
|
+
].join("\n")])
|
77
89
|
end
|
78
90
|
end
|
79
91
|
end
|
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: octodmin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Krasnoukhov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: octopress
|
@@ -101,10 +101,12 @@ files:
|
|
101
101
|
- app/controllers/posts/create.rb
|
102
102
|
- app/controllers/posts/destroy.rb
|
103
103
|
- app/controllers/posts/index.rb
|
104
|
+
- app/controllers/posts/manage.rb
|
104
105
|
- app/controllers/posts/restore.rb
|
105
106
|
- app/controllers/posts/revert.rb
|
106
107
|
- app/controllers/posts/show.rb
|
107
108
|
- app/controllers/posts/update.rb
|
109
|
+
- app/controllers/posts/upload.rb
|
108
110
|
- app/controllers/site/show.rb
|
109
111
|
- app/controllers/syncs/create.rb
|
110
112
|
- app/controllers/version/show.rb
|
@@ -185,6 +187,7 @@ files:
|
|
185
187
|
- app/views/posts/revert.rb
|
186
188
|
- app/views/posts/show.rb
|
187
189
|
- app/views/posts/update.rb
|
190
|
+
- app/views/posts/upload.rb
|
188
191
|
- app/views/site/show.rb
|
189
192
|
- app/views/syncs/create.rb
|
190
193
|
- app/views/version/show.rb
|
@@ -220,6 +223,7 @@ files:
|
|
220
223
|
- spec/api/site_spec.rb
|
221
224
|
- spec/api/syncs_spec.rb
|
222
225
|
- spec/api/version_spec.rb
|
226
|
+
- spec/fixtures/ear.png
|
223
227
|
- spec/frontend/assets_spec.rb
|
224
228
|
- spec/frontend/home_spec.rb
|
225
229
|
- spec/spec_helper.rb
|
@@ -254,6 +258,7 @@ test_files:
|
|
254
258
|
- spec/api/site_spec.rb
|
255
259
|
- spec/api/syncs_spec.rb
|
256
260
|
- spec/api/version_spec.rb
|
261
|
+
- spec/fixtures/ear.png
|
257
262
|
- spec/frontend/assets_spec.rb
|
258
263
|
- spec/frontend/home_spec.rb
|
259
264
|
- spec/spec_helper.rb
|