tinymce_aws_file_upload 0.0.3
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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +22 -0
- data/README.md +44 -0
- data/Rakefile +1 -0
- data/app/assets/javascripts/tinymce-aws-file-upload.js +3 -0
- data/app/assets/javascripts/tinymce_file_browser.js.coffee +60 -0
- data/app/assets/javascripts/tinymce_initializer.js.coffee +13 -0
- data/app/controllers/tinymce_aws_file_upload/signed_urls_controller.rb +42 -0
- data/config/routes.rb +3 -0
- data/lib/tinymce_aws_file_upload.rb +6 -0
- data/lib/tinymce_aws_file_upload/engine.rb +4 -0
- data/lib/tinymce_aws_file_upload/version.rb +3 -0
- data/tinymce_aws_file_upload.gemspec +26 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a7721887fbdced3a74f986a26f70483bd53d984d
|
4
|
+
data.tar.gz: 2daa0c440d477d48ecedccb12d8872c7ca3a8fa9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 97d508ba65b3fd95cfa9d95fcedc62389bb47b3afb9a1da588dd40939f57872da7ba4b13d337a92639685e70a1e9efcd448b397a272468f82af94d4294c925c1
|
7
|
+
data.tar.gz: e1c93737c25a06299d9791d6d855f0c723afb467319a8edbb7f8b92709a07d1cc70e87541b628a2077c4d912a052b3ed4835f324ee835bb3ec3e174a30370ad3
|
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in tinymce_aws_file_upload.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
gem 'tinymce-rails', :github => 'spohlenz/tinymce-rails', :branch => 'tinymce-4'
|
7
|
+
# Use Uglifier as compressor for JavaScript assets
|
8
|
+
gem 'uglifier', '~> 2.5.0'
|
9
|
+
# Use CoffeeScript for .js.coffee assets and views
|
10
|
+
gem 'coffee-rails', '~> 4.0.0'
|
11
|
+
# Use jquery as the JavaScript library
|
12
|
+
gem 'jquery-rails', '~> 3.1.0'
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Ariel Schvartz
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# TinymceAwsFileUpload
|
2
|
+
|
3
|
+
This gem basically includes TinyMCE 4 (thanks to gem 'tinymce-rails' on https://github.com/spohlenz/tinymce-rails/tree/tinymce-4) and adds a File Upload functionality to it.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'tinymce_aws_file_upload'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install tinymce_aws_file_upload
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### On your application.js add the line:
|
22
|
+
//= require tinymce-aws-file-upload
|
23
|
+
|
24
|
+
### Add these 3 environment variables:
|
25
|
+
|
26
|
+
1. AWS_ACCESS_KEY_ID
|
27
|
+
2. AWS_SECRET_ACCESS_KEY
|
28
|
+
3. AWS_BUCKET
|
29
|
+
|
30
|
+
To get this values, go to AWS and create an Amazon S3 account. (http://aws.amazon.com/s3/)
|
31
|
+
|
32
|
+
### In your coffeescript files add
|
33
|
+
|
34
|
+
root = exports ? this
|
35
|
+
root.initTinyMCE('class')
|
36
|
+
where class is a class you should add to all textareas which you want to add the Tinymce rich text editor.
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
1. Fork it ( http://github.com/arielschvartz/tinymce_aws_file_upload/fork )
|
41
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
42
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
43
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
44
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,60 @@
|
|
1
|
+
root = exports ? this
|
2
|
+
|
3
|
+
root.set_amazon_direct_upload = (elem) ->
|
4
|
+
input = $('<input>')
|
5
|
+
input.prop 'type' : 'file'
|
6
|
+
input.hide()
|
7
|
+
elem.before(input)
|
8
|
+
input.click()
|
9
|
+
|
10
|
+
input.change ->
|
11
|
+
$file = $(this)[0].files[0]
|
12
|
+
$.ajax
|
13
|
+
url: '/signed_urls',
|
14
|
+
type: 'get',
|
15
|
+
dataType: 'json',
|
16
|
+
data:
|
17
|
+
doc:
|
18
|
+
title: $file.name
|
19
|
+
success: (data) ->
|
20
|
+
fd = create_form_data(data, 'public-read', $file)
|
21
|
+
$url = "https://#{data.bucket}.s3.amazonaws.com/"
|
22
|
+
$full_url = $url + data.key
|
23
|
+
create_cors_request(fd, $url, $full_url, elem)
|
24
|
+
|
25
|
+
create_form_data = (data, acl, file) ->
|
26
|
+
fd = new FormData()
|
27
|
+
fd.append('key', data.key)
|
28
|
+
fd.append('AWSAccessKeyId', data.access_key_id)
|
29
|
+
fd.append('acl', acl)
|
30
|
+
# fd.append('success_action_redirect', data.success_action_redirect)
|
31
|
+
fd.append('policy', data.policy)
|
32
|
+
fd.append('signature', data.signature)
|
33
|
+
fd.append('Content-Type', file.type)
|
34
|
+
fd.append('file', file)
|
35
|
+
return fd
|
36
|
+
|
37
|
+
create_cors_request = (form_data, url, full_url, elem) ->
|
38
|
+
root.start_loading()
|
39
|
+
xhr = new XMLHttpRequest()
|
40
|
+
xhr.upload.addEventListener "progress", uploadProgress, false
|
41
|
+
xhr.addEventListener "load", (evt) ->
|
42
|
+
uploadComplete full_url, elem
|
43
|
+
, false
|
44
|
+
xhr.addEventListener "error", uploadFailed, false
|
45
|
+
xhr.open 'POST', url, true
|
46
|
+
xhr.send form_data
|
47
|
+
|
48
|
+
uploadComplete = (full_url, elem) ->
|
49
|
+
elem.val full_url
|
50
|
+
root.stop_loading()
|
51
|
+
|
52
|
+
uploadProgress = (evt) ->
|
53
|
+
if evt.lengthComputable
|
54
|
+
percentComplete = Math.round(evt.loaded * 100 / evt.total)
|
55
|
+
else
|
56
|
+
alert 'upload failed'
|
57
|
+
|
58
|
+
uploadFailed = (evt) ->
|
59
|
+
root.stop_loading()
|
60
|
+
alert 'Ocorreu um erro.'
|
@@ -0,0 +1,13 @@
|
|
1
|
+
root = exports ? this
|
2
|
+
|
3
|
+
root.initTinyMCE = (class_name) ->
|
4
|
+
tinyMCE.init
|
5
|
+
selector: ".#{class_name}"
|
6
|
+
plugins: [
|
7
|
+
"autolink lists link image preview anchor",
|
8
|
+
"fullscreen hr code visualblocks visualchars",
|
9
|
+
"table paste"
|
10
|
+
],
|
11
|
+
file_browser_callback: (field_name, url, type, win) ->
|
12
|
+
root.set_amazon_direct_upload $('#' + field_name)
|
13
|
+
, toolbar: "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module TinymceAwsFileUpload
|
2
|
+
class SignedUrlsController < ::ApplicationController
|
3
|
+
def index
|
4
|
+
render json: {
|
5
|
+
policy: s3_upload_policy_document,
|
6
|
+
signature: s3_upload_signature,
|
7
|
+
key: "uploads/#{SecureRandom.uuid}/#{params[:doc][:title]}",
|
8
|
+
success_action_redirect: "http://localhost:3000/",
|
9
|
+
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
|
10
|
+
bucket: ENV['AWS_BUCKET']
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
# generate the policy document that amazon is expecting.
|
17
|
+
def s3_upload_policy_document
|
18
|
+
Base64.encode64(
|
19
|
+
{
|
20
|
+
expiration: 10.hours.from_now.utc.strftime("%Y-%m-%dT%H:%M:%S0Z"),
|
21
|
+
conditions: [
|
22
|
+
{ bucket: ENV['AWS_BUCKET'] },
|
23
|
+
["starts-with", "$key", "uploads/"],
|
24
|
+
{ acl: 'public-read' },
|
25
|
+
["starts-with", "$Content-Type", ""]
|
26
|
+
]
|
27
|
+
}.to_json
|
28
|
+
).gsub("\n", "")
|
29
|
+
end
|
30
|
+
|
31
|
+
# sign our request by Base64 encoding the policy document.
|
32
|
+
def s3_upload_signature
|
33
|
+
Base64.encode64(
|
34
|
+
OpenSSL::HMAC.digest(
|
35
|
+
OpenSSL::Digest.new('sha1'),
|
36
|
+
ENV['AWS_SECRET_ACCESS_KEY'],
|
37
|
+
s3_upload_policy_document
|
38
|
+
)
|
39
|
+
).gsub("\n","")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'tinymce_aws_file_upload/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "tinymce_aws_file_upload"
|
8
|
+
spec.version = TinymceAwsFileUpload::VERSION
|
9
|
+
spec.authors = ["Ariel Schvartz"]
|
10
|
+
spec.email = ["ari.shh@gmail.com"]
|
11
|
+
spec.summary = %q{TinyMCE AWS file upload}
|
12
|
+
spec.description = %q{Add file upload functionality to TinyMCE rich text editor using aws direct upload.}
|
13
|
+
spec.homepage = "https://github.com/arielschvartz/tinymce_aws_file_upload"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_runtime_dependency 'tinymce-rails'
|
24
|
+
spec.add_runtime_dependency 'coffee-rails'
|
25
|
+
spec.add_dependency 'railties', '~> 4'
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tinymce_aws_file_upload
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ariel Schvartz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: tinymce-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: coffee-rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: railties
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '4'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '4'
|
83
|
+
description: Add file upload functionality to TinyMCE rich text editor using aws direct
|
84
|
+
upload.
|
85
|
+
email:
|
86
|
+
- ari.shh@gmail.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- app/assets/javascripts/tinymce-aws-file-upload.js
|
97
|
+
- app/assets/javascripts/tinymce_file_browser.js.coffee
|
98
|
+
- app/assets/javascripts/tinymce_initializer.js.coffee
|
99
|
+
- app/controllers/tinymce_aws_file_upload/signed_urls_controller.rb
|
100
|
+
- config/routes.rb
|
101
|
+
- lib/tinymce_aws_file_upload.rb
|
102
|
+
- lib/tinymce_aws_file_upload/engine.rb
|
103
|
+
- lib/tinymce_aws_file_upload/version.rb
|
104
|
+
- tinymce_aws_file_upload.gemspec
|
105
|
+
homepage: https://github.com/arielschvartz/tinymce_aws_file_upload
|
106
|
+
licenses:
|
107
|
+
- MIT
|
108
|
+
metadata: {}
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 2.2.2
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: TinyMCE AWS file upload
|
129
|
+
test_files: []
|