bongo 0.0.3 → 0.0.4
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 +4 -4
- data/app/assets/javascripts/bongo/attachments.js.erb +51 -0
- data/app/controllers/bongo/files_controller.rb +22 -0
- data/app/views/bongo/articles/index.html.erb +3 -1
- data/app/views/bongo/articles/show.html.erb +3 -1
- data/config/routes.rb +1 -0
- data/lib/bongo/version.rb +1 -1
- metadata +17 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2bc70af78c51e19b4b5604d0c34c6e07e3cf30a89d60800a0e4c6cf25b03506
|
4
|
+
data.tar.gz: 02eb299fee060a5b1521c60e34ce38570849a265a5c2a330bfd28340686a125e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3bc88b9d3bea48d39eac422ffd9d5396ee2037347ace140acfd2eec6109ee7c31891eed7aa00eb49f263fe9c8e28bed72412f78d67d2db0720ee12208c007f8
|
7
|
+
data.tar.gz: 360242447c9b911dad60780486b26739603bd31ee9af8b47aad668b42a9ae671d6fb172ab9f2e17a805d93c1493661916538907b5ca84e7ebd40dd54145014a6
|
@@ -0,0 +1,51 @@
|
|
1
|
+
(function() {
|
2
|
+
var HOST = "<%= Bongo::Engine.routes.url_helpers.files_path %>"
|
3
|
+
|
4
|
+
addEventListener("trix-attachment-add", function(event) {
|
5
|
+
if (event.attachment.file) {
|
6
|
+
uploadFileAttachment(event.attachment)
|
7
|
+
}
|
8
|
+
})
|
9
|
+
|
10
|
+
function uploadFileAttachment(attachment) {
|
11
|
+
uploadFile(attachment.file, setProgress, setAttributes)
|
12
|
+
|
13
|
+
function setProgress(progress) {
|
14
|
+
attachment.setUploadProgress(progress)
|
15
|
+
}
|
16
|
+
|
17
|
+
function setAttributes(attributes) {
|
18
|
+
attachment.setAttributes(attributes)
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
function uploadFile(file, progressCallback, successCallback) {
|
23
|
+
var formData = createFormData(file)
|
24
|
+
var xhr = new XMLHttpRequest()
|
25
|
+
|
26
|
+
xhr.open("POST", HOST, true)
|
27
|
+
|
28
|
+
xhr.upload.addEventListener("progress", function(event) {
|
29
|
+
var progress = event.loaded / event.total * 100
|
30
|
+
progressCallback(progress)
|
31
|
+
})
|
32
|
+
|
33
|
+
xhr.addEventListener("load", function(event) {
|
34
|
+
if (xhr.status == 200) {
|
35
|
+
var attributes = {
|
36
|
+
url: xhr.response
|
37
|
+
}
|
38
|
+
successCallback(attributes)
|
39
|
+
}
|
40
|
+
})
|
41
|
+
|
42
|
+
xhr.send(formData)
|
43
|
+
}
|
44
|
+
|
45
|
+
function createFormData(file) {
|
46
|
+
var data = new FormData()
|
47
|
+
data.append("Content-Type", file.type)
|
48
|
+
data.append("file", file)
|
49
|
+
return data
|
50
|
+
}
|
51
|
+
})();
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_dependency "bongo/application_controller"
|
2
|
+
|
3
|
+
require "aws-sdk-s3"
|
4
|
+
|
5
|
+
module Bongo
|
6
|
+
class FilesController < ApplicationController
|
7
|
+
before_action :authenticate_user!
|
8
|
+
|
9
|
+
skip_before_action :verify_authenticity_token
|
10
|
+
|
11
|
+
def create
|
12
|
+
extension = File.extname(params[:file].original_filename)
|
13
|
+
s3 = Aws::S3::Resource.new
|
14
|
+
obj = s3.bucket(ENV["AWS_S3_BUCKET"]).object(SecureRandom.uuid + extension)
|
15
|
+
obj.upload_file(params[:file])
|
16
|
+
|
17
|
+
respond_to do |format|
|
18
|
+
format.json { render json: obj.public_url }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -2,7 +2,9 @@
|
|
2
2
|
<article>
|
3
3
|
<h2><%= link_to article.title, article %></h2>
|
4
4
|
<small><%= article.publish_at ? l(article.publish_at, format: :long) : "Unpublished draft"%></small>
|
5
|
-
<
|
5
|
+
<main class="trix-content">
|
6
|
+
<%= article.text.html_safe %>
|
7
|
+
</main>
|
6
8
|
</article>
|
7
9
|
<br>
|
8
10
|
<% end %>
|
@@ -3,7 +3,9 @@
|
|
3
3
|
<h2><%= @article.title %></h2>
|
4
4
|
<small><%= @article.publish_at ? l(@article.publish_at, format: :long) : "Unpublished draft"%></small>
|
5
5
|
</header>
|
6
|
-
<main
|
6
|
+
<main class="trix-content">
|
7
|
+
<%= @article.text.html_safe %>
|
8
|
+
</main>
|
7
9
|
</article>
|
8
10
|
|
9
11
|
<br>
|
data/config/routes.rb
CHANGED
data/lib/bongo/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bongo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Hutterer
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 7.0.5
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: aws-sdk-s3
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1'
|
41
55
|
description: Rails engine for blogging using MongoDB.
|
42
56
|
email:
|
43
57
|
- tohu@tuta.io
|
@@ -50,11 +64,13 @@ files:
|
|
50
64
|
- Rakefile
|
51
65
|
- app/assets/config/bongo_manifest.js
|
52
66
|
- app/assets/javascripts/bongo/application.js
|
67
|
+
- app/assets/javascripts/bongo/attachments.js.erb
|
53
68
|
- app/assets/javascripts/bongo/trix.js
|
54
69
|
- app/assets/stylesheets/bongo/application.css
|
55
70
|
- app/assets/stylesheets/bongo/trix.css
|
56
71
|
- app/controllers/bongo/application_controller.rb
|
57
72
|
- app/controllers/bongo/articles_controller.rb
|
73
|
+
- app/controllers/bongo/files_controller.rb
|
58
74
|
- app/helpers/bongo/application_helper.rb
|
59
75
|
- app/helpers/bongo/articles_helper.rb
|
60
76
|
- app/jobs/bongo/application_job.rb
|