transloadit-rails 1.0.8 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.travis.yml +31 -0
- data/README.md +45 -1
- data/Rakefile +1 -33
- data/gemfiles/3.0.gemfile +4 -0
- data/gemfiles/3.1.gemfile +4 -0
- data/gemfiles/3.2.gemfile +4 -0
- data/gemfiles/4.0.gemfile +4 -0
- data/lib/templates/transloadit/transloadit.yml +44 -5
- data/lib/transloadit/rails/engine.rb +0 -6
- data/lib/transloadit/rails/version.rb +1 -1
- data/lib/transloadit/rails/view_helper.rb +34 -0
- data/transloadit-rails.gemspec +9 -9
- metadata +10 -6
- data/app/helpers/transloadit_helper.rb +0 -33
data/.gitignore
CHANGED
data/.travis.yml
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- ree
|
4
|
+
- 1.8.7
|
5
|
+
- 1.9.2
|
6
|
+
- 1.9.3
|
7
|
+
- 2.0.0
|
8
|
+
- rbx-18mode
|
9
|
+
- rbx-19mode
|
10
|
+
- jruby-18mode
|
11
|
+
- jruby-19mode
|
12
|
+
script: "bundle exec rake test"
|
13
|
+
|
14
|
+
gemfile:
|
15
|
+
- gemfiles/3.0.gemfile
|
16
|
+
- gemfiles/3.1.gemfile
|
17
|
+
- gemfiles/3.2.gemfile
|
18
|
+
- gemfiles/4.0.gemfile
|
19
|
+
|
20
|
+
matrix:
|
21
|
+
exclude:
|
22
|
+
- rvm: jruby-18mode
|
23
|
+
gemfile: gemfiles/4.0.gemfile
|
24
|
+
- rvm: rbx-18mode
|
25
|
+
gemfile: gemfiles/4.0.gemfile
|
26
|
+
- rvm: 1.8.7
|
27
|
+
gemfile: gemfiles/4.0.gemfile
|
28
|
+
- rvm: ree
|
29
|
+
gemfile: gemfiles/4.0.gemfile
|
30
|
+
- rvm: 1.9.2
|
31
|
+
gemfile: gemfiles/4.0.gemfile
|
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/transloadit/rails-sdk.png?branch=master)](https://travis-ci.org/transloadit/rails-sdk)
|
2
|
+
|
1
3
|
# transloadit-rails
|
2
4
|
|
3
5
|
Fantastic file uploading for your Rails application.
|
@@ -33,7 +35,8 @@ $ rails g transloadit:install
|
|
33
35
|
|
34
36
|
Edit `config/transloadit.yml`. It has an `auth` section for your transloadit
|
35
37
|
credentials and a `templates` section to define or refer to existing
|
36
|
-
templates.
|
38
|
+
templates. It is highly recommended to [enable authentication](https://transloadit.com/docs/authentication) and signing for
|
39
|
+
the upload forms.
|
37
40
|
|
38
41
|
```yaml
|
39
42
|
auth:
|
@@ -54,6 +57,47 @@ templates:
|
|
54
57
|
height: 200
|
55
58
|
```
|
56
59
|
|
60
|
+
### Configuration by Environment
|
61
|
+
|
62
|
+
The transloadit configurations can be further broken up by environment tags to
|
63
|
+
match the environments used by the application (i.e. development, test,
|
64
|
+
production).
|
65
|
+
|
66
|
+
Please note, the environment tags must match the application's environments
|
67
|
+
exactly in order to be used.
|
68
|
+
|
69
|
+
```yaml
|
70
|
+
development:
|
71
|
+
auth:
|
72
|
+
key : '4d2e...'
|
73
|
+
...
|
74
|
+
|
75
|
+
templates:
|
76
|
+
s3_store: '4d2e...'
|
77
|
+
...
|
78
|
+
|
79
|
+
production:
|
80
|
+
auth:
|
81
|
+
key : '123a...'
|
82
|
+
...
|
83
|
+
|
84
|
+
templates:
|
85
|
+
s3_store: '789b...'
|
86
|
+
...
|
87
|
+
```
|
88
|
+
|
89
|
+
## Support IE6 or jQuery < 1.9
|
90
|
+
|
91
|
+
If you have to support IE6 and use a jQuery version below 1.9, you have to change
|
92
|
+
the jquery_sdk_version in the config to 'v1.0.0':
|
93
|
+
|
94
|
+
```yaml
|
95
|
+
production:
|
96
|
+
jquery_sdk_version: 'v1.0.0'
|
97
|
+
auth:
|
98
|
+
...
|
99
|
+
```
|
100
|
+
|
57
101
|
## Usage
|
58
102
|
|
59
103
|
Refer to the templates with the `transloadit` helper. This requires jQuery,
|
data/Rakefile
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'rubygems/package_task'
|
2
2
|
require 'rake/testtask'
|
3
3
|
|
4
|
-
RUBIES = %w{ 1.9.2 1.8.7 1.8.6 rbx-1.2.0 }
|
5
|
-
|
6
4
|
GEMSPEC = 'transloadit-rails.gemspec'
|
7
5
|
|
8
6
|
spec = eval open(GEMSPEC).read
|
@@ -15,40 +13,10 @@ Rake::TestTask.new do |test|
|
|
15
13
|
test.pattern = 'test/**/test_*.rb'
|
16
14
|
end
|
17
15
|
|
18
|
-
namespace :test do
|
19
|
-
begin
|
20
|
-
`rvm -v` # raise an exception if RVM isn't installed
|
21
|
-
|
22
|
-
desc 'Run tests against all supported Rubies'
|
23
|
-
task :multiruby do
|
24
|
-
system "rvm #{RUBIES.join(',')} ruby bundle exec rake -s test"
|
25
|
-
|
26
|
-
# clean up after Rubinius
|
27
|
-
require 'pathname'
|
28
|
-
Pathname.glob('**/*.rbc').each {|path| path.unlink }
|
29
|
-
end
|
30
|
-
|
31
|
-
namespace :multiruby do
|
32
|
-
desc 'Prepare supported rubiesfor testing'
|
33
|
-
task :setup do
|
34
|
-
warn 'Preparing multiruby. This may take awhile...'
|
35
|
-
|
36
|
-
# create gemsets, install bundler, bundle
|
37
|
-
RUBIES.each {|ruby| system "rvm #{ruby} gemset create transloadit" }
|
38
|
-
system "rvm #{RUBIES.join(',')} gem install bundler --no-ri --no-rdoc"
|
39
|
-
system "rvm #{RUBIES.join(',')} ruby bundle install"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
rescue Errno::ENOENT
|
43
|
-
desc 'You need `rvm` installed to test against multiple Rubies'
|
44
|
-
task :multiruby
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
16
|
begin
|
49
17
|
require 'yard'
|
50
18
|
require 'yard/rake/yardoc_task'
|
51
|
-
|
19
|
+
|
52
20
|
YARD::Rake::YardocTask.new :doc do |yard|
|
53
21
|
yard.options = %w{
|
54
22
|
--title Transloadit Rails
|
@@ -1,6 +1,45 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
development:
|
2
|
+
# the jquery_sdk version you want to use, read up on it here:
|
3
|
+
# https://transloadit.com/blog/2013/02/transloadit-javascript-plugin-and-jquery-1-9
|
4
|
+
# defaults to latest
|
5
|
+
# use "v1.0.0" if you need IE6 support (using jQuery < 1.9)
|
6
|
+
jquery_sdk_version: 'latest'
|
7
|
+
auth:
|
8
|
+
key : 'YOUR_KEY'
|
9
|
+
secret : 'YOUR_SECRET' # this is optional, but highly recommended, https://transloadit.com/docs/authentication
|
10
|
+
duration: 1800 # 30 minute validity period for signed upload forms
|
5
11
|
|
6
|
-
templates:
|
12
|
+
templates:
|
13
|
+
# template identified by template_id
|
14
|
+
s3_store: 'S3_STORE_TEMPLATE_ID'
|
15
|
+
|
16
|
+
# template defined inline
|
17
|
+
image_resize:
|
18
|
+
steps:
|
19
|
+
resize:
|
20
|
+
robot : '/image/resize'
|
21
|
+
width : 320
|
22
|
+
height: 200
|
23
|
+
|
24
|
+
production:
|
25
|
+
# the jquery_sdk version you want to use, read up on it here:
|
26
|
+
# https://transloadit.com/blog/2013/02/transloadit-javascript-plugin-and-jquery-1-9
|
27
|
+
# defaults to latest
|
28
|
+
# use "v1.0.0" if you need IE6 support (using jQuery < 1.9)
|
29
|
+
jquery_sdk_version: 'latest'
|
30
|
+
auth:
|
31
|
+
key : 'YOUR_KEY'
|
32
|
+
secret : 'YOUR_SECRET' # this is optional, but highly recommended, https://transloadit.com/docs/authentication
|
33
|
+
duration: 1800 # 30 minute validity period for signed upload forms
|
34
|
+
|
35
|
+
templates:
|
36
|
+
# template identified by template_id
|
37
|
+
s3_store: 'S3_STORE_TEMPLATE_ID'
|
38
|
+
|
39
|
+
# template defined inline
|
40
|
+
image_resize:
|
41
|
+
steps:
|
42
|
+
resize:
|
43
|
+
robot : '/image/resize'
|
44
|
+
width : 320
|
45
|
+
height: 200
|
@@ -10,12 +10,6 @@ class Transloadit
|
|
10
10
|
class Engine < ::Rails::Engine
|
11
11
|
CONFIG_PATH = 'config/transloadit.yml'
|
12
12
|
|
13
|
-
initializer 'transloadit-rails.action_controller' do |app|
|
14
|
-
ActiveSupport.on_load :action_controller do
|
15
|
-
helper TransloaditHelper
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
13
|
initializer 'transloadit-rails.action_view' do |app|
|
20
14
|
ActiveSupport.on_load :action_view do
|
21
15
|
include Transloadit::Rails::ViewHelper
|
@@ -16,4 +16,38 @@ module Transloadit::Rails::ViewHelper
|
|
16
16
|
|
17
17
|
fields
|
18
18
|
end
|
19
|
+
|
20
|
+
#
|
21
|
+
# Enables the jQuery integration for Transloadit, and ensures the form is
|
22
|
+
# marked with an encoding type of `multipart/form-data`.
|
23
|
+
#
|
24
|
+
def transloadit_jquerify(id, options = {})
|
25
|
+
version = Transloadit::Rails::Engine.configuration['jquery_sdk_version'] || 'latest'
|
26
|
+
|
27
|
+
javascript_tag %{
|
28
|
+
jQuery(function($) {
|
29
|
+
var script = '//assets.transloadit.com/js/jquery.transloadit2-#{version}.js';
|
30
|
+
|
31
|
+
$.getScript(script, function() {
|
32
|
+
$('##{id}')
|
33
|
+
.attr('enctype', 'multipart/form-data')
|
34
|
+
.transloadit(#{options_to_json(options)});
|
35
|
+
});
|
36
|
+
});
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def options_to_json(options)
|
43
|
+
callbacks = [
|
44
|
+
:onstart, :onprogress, :onupload, :onresult, :oncancel, :onerror, :onsuccess
|
45
|
+
]
|
46
|
+
|
47
|
+
js_options = options.map do |key, val|
|
48
|
+
"#{key.to_json}: #{callbacks.include?(key.downcase) ? val : val.to_json}"
|
49
|
+
end.join(",\n")
|
50
|
+
|
51
|
+
"{#{js_options}}"
|
52
|
+
end
|
19
53
|
end
|
data/transloadit-rails.gemspec
CHANGED
@@ -6,28 +6,28 @@ Gem::Specification.new do |gem|
|
|
6
6
|
gem.name = 'transloadit-rails'
|
7
7
|
gem.version = Transloadit::Rails::VERSION
|
8
8
|
gem.platform = Gem::Platform::RUBY
|
9
|
-
|
9
|
+
|
10
10
|
gem.authors = ['Stephen Touset', 'Robin Mehner']
|
11
11
|
gem.email = ['stephen@touset.org', 'robin@coding-robin.de']
|
12
12
|
gem.homepage = 'http://github.com/transloadit/rails-sdk/'
|
13
|
-
|
13
|
+
|
14
14
|
gem.summary = 'Official Rails gem for Transloadit'
|
15
15
|
gem.description = 'The transloadit-rails gem allows you to automate uploading files through the Transloadit REST API'
|
16
|
-
|
16
|
+
|
17
17
|
gem.required_rubygems_version = '>= 1.3.6'
|
18
18
|
gem.rubyforge_project = 'transloadit-rails'
|
19
|
-
|
19
|
+
|
20
20
|
gem.files = `git ls-files`.split("\n")
|
21
21
|
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
22
|
gem.require_paths = %w{ lib }
|
23
|
-
|
23
|
+
|
24
24
|
gem.add_dependency 'transloadit', '>= 1.0.2'
|
25
|
-
gem.add_dependency 'railties', '
|
26
|
-
|
25
|
+
gem.add_dependency 'railties', '>= 3'
|
26
|
+
|
27
27
|
gem.add_development_dependency 'rake'
|
28
28
|
gem.add_development_dependency 'minitest' # needed for < 1.9.2
|
29
29
|
gem.add_development_dependency 'simplecov'
|
30
|
-
|
30
|
+
|
31
31
|
gem.add_development_dependency 'yard'
|
32
|
-
gem.add_development_dependency '
|
32
|
+
gem.add_development_dependency 'kramdown' # for YARD rdoc formatting
|
33
33
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: transloadit-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2013-03-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: transloadit
|
@@ -33,7 +33,7 @@ dependencies:
|
|
33
33
|
requirement: !ruby/object:Gem::Requirement
|
34
34
|
none: false
|
35
35
|
requirements:
|
36
|
-
- -
|
36
|
+
- - ! '>='
|
37
37
|
- !ruby/object:Gem::Version
|
38
38
|
version: '3'
|
39
39
|
type: :runtime
|
@@ -41,7 +41,7 @@ dependencies:
|
|
41
41
|
version_requirements: !ruby/object:Gem::Requirement
|
42
42
|
none: false
|
43
43
|
requirements:
|
44
|
-
- -
|
44
|
+
- - ! '>='
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '3'
|
47
47
|
- !ruby/object:Gem::Dependency
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: kramdown
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
none: false
|
115
115
|
requirements:
|
@@ -134,10 +134,14 @@ extensions: []
|
|
134
134
|
extra_rdoc_files: []
|
135
135
|
files:
|
136
136
|
- .gitignore
|
137
|
+
- .travis.yml
|
137
138
|
- Gemfile
|
138
139
|
- README.md
|
139
140
|
- Rakefile
|
140
|
-
-
|
141
|
+
- gemfiles/3.0.gemfile
|
142
|
+
- gemfiles/3.1.gemfile
|
143
|
+
- gemfiles/3.2.gemfile
|
144
|
+
- gemfiles/4.0.gemfile
|
141
145
|
- lib/generators/transloadit/install_generator.rb
|
142
146
|
- lib/templates/transloadit/transloadit.yml
|
143
147
|
- lib/transloadit-rails.rb
|
@@ -1,33 +0,0 @@
|
|
1
|
-
module TransloaditHelper
|
2
|
-
#
|
3
|
-
# Enables the jQuery integration for Transloadit, and ensures the form is
|
4
|
-
# marked with an encoding type of `multipart/form-data`.
|
5
|
-
#
|
6
|
-
def transloadit_jquerify(id, options = {})
|
7
|
-
javascript_tag %{
|
8
|
-
jQuery(function($) {
|
9
|
-
var script = '//assets.transloadit.com/js/jquery.transloadit2.js';
|
10
|
-
|
11
|
-
$.getScript(script, function() {
|
12
|
-
$('##{id}')
|
13
|
-
.attr('enctype', 'multipart/form-data')
|
14
|
-
.transloadit(#{options_to_json(options)});
|
15
|
-
});
|
16
|
-
});
|
17
|
-
}
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def options_to_json(options)
|
23
|
-
callbacks = [
|
24
|
-
:onstart, :onprogress, :onupload, :onresult, :oncancel, :onerror, :onsuccess
|
25
|
-
]
|
26
|
-
|
27
|
-
js_options = options.map do |key, val|
|
28
|
-
"#{key.to_json}: #{callbacks.include?(key.downcase) ? val : val.to_json}"
|
29
|
-
end.join(",\n")
|
30
|
-
|
31
|
-
"{#{js_options}}"
|
32
|
-
end
|
33
|
-
end
|