transloadit-rails 0.9.0

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.
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ .bundle
2
+ .rvmrc
3
+ .yardoc
4
+
5
+ Gemfile.lock
6
+
7
+ coverage
8
+ doc
9
+ pkg
10
+
11
+ test/tmp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # transloadit-rails
2
+
3
+ Fantastic file uploading for your Rails application.
4
+
5
+ ## Description
6
+
7
+ This is the official Rails gem for [Transloadit](transloadit.com). It allows
8
+ you to automate uploading files through the Transloadit REST API.
9
+
10
+ ## Install
11
+
12
+ gem install transloadit
13
+
14
+ ## Getting started
15
+
16
+ To get started, you need to add the 'transloadit-rails' gem to your Rails
17
+ project's Gemfile.
18
+
19
+ gem 'transloadit-rails'
20
+
21
+ Now update your bundle and run the generator.
22
+
23
+ $ bundle install
24
+ $ rails g transloadit:install
25
+
26
+ ## Configuration
27
+
28
+ Edit `config/transloadit.yml`. It has an `auth` section for your transloadit
29
+ credentials and a `templates` section to define or refer to existing
30
+ templates.
31
+
32
+ auth:
33
+ key : '4d2e...'
34
+ secret: '8ad1...' # optional, but highly recommended
35
+
36
+ templates:
37
+ # template identified by template_id
38
+ s3_store: '4d2e...'
39
+
40
+ # template defined inline
41
+ image_resize:
42
+ steps:
43
+ resize:
44
+ robot : '/image/resize'
45
+ width : 320
46
+ height: 200
47
+
48
+ ## Usage
49
+
50
+ Refer to the templates with the `transloadify` helper. This requires jQuery,
51
+ and loads the [Transloadit jQuery plugin](https://github.com/transloadit/jquery-sdk).
52
+ It also uses JavaScript to ensure your form is encoded as `multipart/form-data`.
53
+
54
+ <%= form_for :thing, :html => { :id => 'upload' } do |form| %>
55
+ <%= form.transloadit :s3_store %>
56
+ <%= form.file_field :file, 'File to upload' %>
57
+ <% end %>
58
+
59
+ <%= transloadit_jquerify :upload %>
data/Rakefile ADDED
@@ -0,0 +1,62 @@
1
+ require 'rake/gempackagetask'
2
+ require 'rake/testtask'
3
+
4
+ RUBIES = %w{ 1.9.2 1.8.7 1.8.6 rbx-1.2.0 }
5
+
6
+ GEMSPEC = 'transloadit-rails.gemspec'
7
+
8
+ spec = eval open(GEMSPEC).read
9
+ Rake::GemPackageTask.new(spec) do |gem|
10
+ gem.need_tar = true
11
+ end
12
+
13
+ Rake::TestTask.new do |test|
14
+ test.libs << 'test'
15
+ test.pattern = 'test/**/test_*.rb'
16
+ end
17
+
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
+ begin
49
+ require 'yard'
50
+ require 'yard/rake/yardoc_task'
51
+
52
+ YARD::Rake::YardocTask.new :doc do |yard|
53
+ yard.options = %w{
54
+ --title Transloadit Rails
55
+ --readme README.md
56
+ --markup rdoc
57
+ }
58
+ end
59
+ rescue
60
+ desc 'You need the `yard` gem to generate documentation'
61
+ task :doc
62
+ end
@@ -0,0 +1,18 @@
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
+ $(document).ready(function() {
9
+ var script = '#{javascript_path('jquery.transloadit2.js')}';
10
+
11
+ $.getScript(script, function() {
12
+ $('##{id}').attr('enctype', 'multipart/form-data');
13
+ $('##{id}').transloadit(#{options.to_json});
14
+ });
15
+ });
16
+ }
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ require 'transloadit/rails'
2
+ require 'rails/generators'
3
+
4
+ class Transloadit::Generators::InstallGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('../../../templates/transloadit', __FILE__)
6
+
7
+ desc %{Installs the Transloadit jQuery plugin and creates the config file}
8
+
9
+ def copy_configuration
10
+ template 'transloadit.yml', 'config/transloadit.yml'
11
+ end
12
+
13
+ def copy_jquery_plugin
14
+ get 'http://assets.transloadit.com/js/jquery.transloadit2.js',
15
+ 'public/javascripts/jquery.transloadit2.js'
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ auth:
2
+ key :
3
+ secret:
4
+
5
+ templates:
@@ -0,0 +1 @@
1
+ require 'transloadit/rails'
@@ -0,0 +1,5 @@
1
+ require 'transloadit/rails'
2
+
3
+ module Transloadit::Generators
4
+ autoload :InstallGenerator, 'generators/transloadit/install_generator'
5
+ end
@@ -0,0 +1,56 @@
1
+ require 'transloadit'
2
+ require 'transloadit/generators'
3
+ require 'rails'
4
+
5
+ class Transloadit::Rails < Rails::Engine
6
+ autoload :FormHelper, 'transloadit/rails/form_helper'
7
+
8
+ config.to_prepare do
9
+ # add the two helpers to the view stack
10
+ ApplicationController.helper TransloaditHelper
11
+
12
+ class ActionView::Helpers::FormBuilder
13
+ include Transloadit::Rails::FormHelper
14
+ end
15
+ end
16
+
17
+ initializer 'transloadit.configure' do |app|
18
+ # preload the contents of the configuration file.
19
+ app.root.join('config/transloadit.yml').open do |file|
20
+ self.class.config = YAML.load(file)
21
+ end rescue nil
22
+ end
23
+
24
+ class << self
25
+ attr_accessor :config
26
+ end
27
+
28
+ #
29
+ # Returns the Transloadit authentication object.
30
+ #
31
+ def self.transloadit
32
+ Transloadit.new(
33
+ :key => self.config['auth']['key'],
34
+ :secret => self.config['auth']['secret']
35
+ )
36
+ end
37
+
38
+ #
39
+ # Creates an assembly for the named template.
40
+ #
41
+ def self.template(name, options = {})
42
+ template = self.config['templates'][name.to_s]
43
+
44
+ self.transloadit.assembly case template
45
+ when String then { :template_id => template }.merge(options)
46
+ when Hash then template .merge(options)
47
+ end
48
+ end
49
+
50
+ #
51
+ # Signs a request to the Transloadit API.
52
+ #
53
+ def self.sign(params)
54
+ Transloadit::Request.send :_hmac, self.transloadit.secret, params
55
+ end
56
+ end
@@ -0,0 +1,15 @@
1
+ require 'transloadit/rails'
2
+
3
+ module Transloadit::Rails::FormHelper
4
+ #
5
+ # Inserts hidden fields specifying and signing the template for Transloadit
6
+ # to process.
7
+ #
8
+ def transloadit(template, options = {})
9
+ params = Transloadit::Rails.template(template, options).to_json
10
+ signature = Transloadit::Rails.sign(params)
11
+
12
+ @template.hidden_field_tag(:params, params, :id => nil) +
13
+ @template.hidden_field_tag(:signature, signature, :id => nil)
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ require 'transloadit/rails'
2
+
3
+ class Transloadit::Rails
4
+ VERSION = '0.9.0'
5
+ end
@@ -0,0 +1,29 @@
1
+ require 'test_helper'
2
+
3
+ class InstallGeneratorTest < Rails::Generators::TestCase
4
+ tests Transloadit::Generators::InstallGenerator
5
+ destination File.expand_path('../../../tmp', __FILE__)
6
+
7
+ setup do
8
+ prepare_destination
9
+ end
10
+
11
+ test 'the jQuery plugin is installed' do
12
+ run_generator
13
+
14
+ assert_file 'public/javascripts/jquery.transloadit2.js'
15
+ end
16
+
17
+ test 'the Transloadit config file is installed' do
18
+ run_generator
19
+
20
+ assert_file 'config/transloadit.yml' do |contents|
21
+ assert_match /auth/, contents
22
+ assert_match /templates/, contents
23
+ end
24
+ end
25
+
26
+ test 'the namespace is transloadit:install' do
27
+ assert_equal 'transloadit:install', generator_class.namespace
28
+ end
29
+ end
@@ -0,0 +1,12 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+
4
+ # require 'simplecov'
5
+ #
6
+ # SimpleCov.start { add_filter '/test/' }
7
+
8
+ require 'minitest/autorun'
9
+ require 'transloadit/rails'
10
+
11
+ require 'rails/test_help'
12
+ require 'rails/generators/test_case'
@@ -0,0 +1,33 @@
1
+ $:.unshift File.expand_path('../lib', __FILE__)
2
+
3
+ require 'transloadit/rails/version'
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = 'transloadit-rails'
7
+ gem.version = Transloadit::Rails::VERSION
8
+ gem.platform = Gem::Platform::RUBY
9
+
10
+ gem.authors = %w{ Stephen Touset }
11
+ gem.email = %w{ stephen@touset.org }
12
+ gem.homepage = 'http://github.com/transloadit/rails-sdk/'
13
+
14
+ gem.summary = 'Official Rails gem for Transloadit'
15
+ gem.description = 'The transloadit-rails gem allows you to automate uploading files through the Transloadit REST API'
16
+
17
+ gem.required_rubygems_version = '>= 1.3.6'
18
+ gem.rubyforge_project = 'transloadit-rails'
19
+
20
+ gem.files = `git ls-files`.split("\n")
21
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
+ gem.require_paths = %w{ lib }
23
+
24
+ gem.add_dependency 'transloadit'
25
+ gem.add_dependency 'rails', '~> 3'
26
+
27
+ gem.add_development_dependency 'rake'
28
+ gem.add_development_dependency 'minitest' # needed for < 1.9.2
29
+ gem.add_development_dependency 'simplecov'
30
+
31
+ gem.add_development_dependency 'yard'
32
+ gem.add_development_dependency 'rdiscount' # for YARD rdoc formatting
33
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: transloadit-rails
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.9.0
6
+ platform: ruby
7
+ authors:
8
+ - Stephen
9
+ - Touset
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+
14
+ date: 2011-04-13 00:00:00 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: transloadit
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: "3"
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: rake
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ type: :development
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: minitest
51
+ prerelease: false
52
+ requirement: &id004 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ type: :development
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: simplecov
62
+ prerelease: false
63
+ requirement: &id005 !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ type: :development
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: yard
73
+ prerelease: false
74
+ requirement: &id006 !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ type: :development
81
+ version_requirements: *id006
82
+ - !ruby/object:Gem::Dependency
83
+ name: rdiscount
84
+ prerelease: false
85
+ requirement: &id007 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: "0"
91
+ type: :development
92
+ version_requirements: *id007
93
+ description: The transloadit-rails gem allows you to automate uploading files through the Transloadit REST API
94
+ email:
95
+ - stephen@touset.org
96
+ executables: []
97
+
98
+ extensions: []
99
+
100
+ extra_rdoc_files: []
101
+
102
+ files:
103
+ - .gitignore
104
+ - Gemfile
105
+ - README.md
106
+ - Rakefile
107
+ - app/helpers/transloadit_helper.rb
108
+ - lib/generators/transloadit/install_generator.rb
109
+ - lib/templates/transloadit/transloadit.yml
110
+ - lib/transloadit-rails.rb
111
+ - lib/transloadit/generators.rb
112
+ - lib/transloadit/rails.rb
113
+ - lib/transloadit/rails/form_helper.rb
114
+ - lib/transloadit/rails/version.rb
115
+ - test/generators/transloadit/test_install_generator.rb
116
+ - test/test_helper.rb
117
+ - transloadit-rails.gemspec
118
+ homepage: http://github.com/transloadit/rails-sdk/
119
+ licenses: []
120
+
121
+ post_install_message:
122
+ rdoc_options: []
123
+
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: "0"
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ none: false
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: 1.3.6
138
+ requirements: []
139
+
140
+ rubyforge_project: transloadit-rails
141
+ rubygems_version: 1.7.2
142
+ signing_key:
143
+ specification_version: 3
144
+ summary: Official Rails gem for Transloadit
145
+ test_files:
146
+ - test/generators/transloadit/test_install_generator.rb
147
+ - test/test_helper.rb